Re: [RESEND PATCH] mm/madvise: use folio_trylock() in the cold/pageout PMD split
From: Gregory Price
Date: Tue Sep 15 2026 - 23:29:08 EST
On Tue, Sep 15, 2026 at 06:46:33PM -0700, Andrew Morton wrote:
> >
> > On failure the walker returns 0 and nothing retries. The PMD path becomes
> > best effort when the folio lock is held elsewhere - same as the PTE path.
>
> Can this result in more EAGAINs being returned to userspace?
>
I don't see where this can result in more EAGAIN, at least from the
madvise side. The race is the same, we're just giving up and saying
"I tried, doesn't matter if i succeeded".
> > --- a/mm/madvise.c
> > +++ b/mm/madvise.c
> > @@ -419,9 +419,10 @@ static int madvise_cold_or_pageout_pte_range(pmd_t *pmd,
> > if (next - addr != HPAGE_PMD_SIZE) {
> > int err;
> >
> > + if (!folio_trylock(folio))
> > + goto huge_unlock;
> > folio_get(folio);
> > spin_unlock(ptl);
> > - folio_lock(folio);
> > err = split_folio(folio);
> > folio_unlock(folio);
> > folio_put(folio);
>
> Sashiko shares my reaction, "dear god, why does that function exist".
>
> https://sashiko.dev/#/patchset/20260912110540.3203010-1-gourry@xxxxxxxxxx
>
> Like the entire function, that random mix of "goto foo" with "return
> whatever" needs to die.
>
> Anyway, please check it out while you're on a roll.
I've been trying to shore up the sashiko garbage first in a backportable
manner before doing a full restructure.
I would hate to rewrite this just to carry bugs forward, and clearly the
code isn't even remotely correct as-is.
The remaining issue on that link is the memory leak patch you already
looked at.
It's taken a bit to generate positive tests for these bugs and go
through validation, but I think we are finally at the end of the
nasty part and can actually get to cleaning this up.
~Gregory