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

From: Gregory Price

Date: Fri Aug 21 2026 - 16:39:06 EST


On Fri, Aug 21, 2026 at 08:48:12PM +0100, Matthew Wilcox wrote:
> On Fri, Aug 21, 2026 at 07:23:34PM +0100, Lorenzo Stoakes (ARM) wrote:
>
> For the task running on CPU 1, yes. But the folio does get split rather
> than probably both failing.
>

Which, thinking about it, this patch actually solves non-spurious
(but exceedingly rare) failures as well, since prior both CPU0 and CPU1
can fail. After this patch, one of them is guaranteed to succeed.

The inflated failure count otherwise are the spurious ones.

> We couldn't quite make that work here since the whole point is to _never_
> get the refcount on the folio if somebody else has the lock, and once
> we've dropped the PTL, the folio might have been split and thus not be
> the folio we want any more (indeed it may have been freed, reallocated
> and now be a pointer to a tail page instead of a folio).
>

Makes me wonder how many more of these conditions are peppered around
THPs just eating cpu time.

~Gregory