Re: [PATCH] mm/madvise: use folio_trylock() in the cold/pageout PMD split

From: Gregory Price

Date: Fri Aug 21 2026 - 14:42:11 EST


On Fri, Aug 21, 2026 at 07:23:34PM +0100, Lorenzo Stoakes (ARM) wrote:
> On Fri, Aug 21, 2026 at 11:09:12AM -0400, Gregory Price wrote:
>
> I am _so_ glad to see an actual reproducer used in a sashiko bug fix. THANKS. :)
>

fwiw i try to produce reproducers on all my sashiko submitted fixes,
i've just been dumb about including them in the changelog. Trying to
fix that from now on.

> > + if (!folio_trylock(folio))
> > + goto huge_unlock;
>
> Doesn't this violate lock ordering?
>
> From rmap.c:
>
> folio_lock
> ...
> mm->page_table_lock or pte_lock
>
> So now you hold the ptl lock _before_ you obtain the folio lock?
>
> I'm not sure if it being a trylock gets us out of that particular situation? And
> I'd be reticent for us to violate it... unless I'm missing something :)
>

This was the thing i was least sure about, but the deadlock condition
should only happen if we tried to spin on the folio lock right?

It does look weird, so it would be wrong of me to say i'm 100%
confident this is the best change.

~Gregory