Re: [PATCH] mm/madvise: reclaim isolated folios if PTE restart fails

From: Gregory Price

Date: Tue Sep 15 2026 - 11:13:31 EST


On Mon, Sep 14, 2026 at 11:32:09PM -0700, Andrew Morton wrote:
> On Sat, 12 Sep 2026 07:08:32 -0400 Gregory Price <gourry@xxxxxxxxxx> wrote:
>
> > MADV_PAGEOUT collects isolated folios on a local list before reclaiming
> > them after the PTE walk. The reschedule path drops the PTE lock and then
> > restarts the mapping with pte_offset_map_lock().
> >
> > A concurrent operation can remove or replace the PTE table while the lock
> > is dropped, causing pte_offset_map_lock() to return NULL. Returning directly
> > in that case bypasses reclaim_pages(), leaving the collected folios off the
> > LRU with elevated references.
>
> aw man, you got so close then left us hanging.
>
> So what happened next? Machine crashed? Permanent leak?
>

Permanent leak.

nr_isolated_anon increases reliably and does not decrease when the
process dies.

> >
> > Fixes: b2f557a21bc8 ("mm/madvise: add cond_resched() in madvise_cold_or_pageout_pte_range()")
> > Reported-by: sashiko-bot <sashiko-bot@xxxxxxxxxx>
> > Closes: https://sashiko.dev/#/patchset/20260821150912.183976-1-gourry@xxxxxxxxxx
> > Cc: <stable@xxxxxxxxxxxxxxx>
>
> #include "Documentation/process/stable-kernel-rules.rst"
>
> (sorry, getting snarky. I'm saying this stuff 100x/day at present and
> it just isn't sticking).
>
> > Assisted-by: LLM
>
> Can I suggest you update LLM's prompts so it checks that the changelog
> includes userspace-visible runtime effects and so that it checks that
> the patch is approximately compliant with stable-kernel-rules?
>
> If you do, please share that prompt with me and I'll put it in ~/.signature
>

I typically (re)write (or at least heavily edit) the messages to ensure I
actually understand what's going on. I'll update my brainmeats.

I get it though, rather than permanent leak say how to observe said leak
(vmstat or etc). ack :]

~Gregory