Re: [PATCH v8 14/19] mm/madvise: adapt for LRU refs based operations for MGLRU
From: Kairui Song
Date: Fri Dec 04 2026 - 08:12:02 EST
On Fri, Dec 4, 2026 at 8:19 PM Lorenzo Stoakes (ARM) <ljs@xxxxxxxxxx> wrote:
>
> On Fri, Dec 04, 2026 at 01:02:45AM +0800, Kairui Song via B4 Relay wrote:
> > From: Kairui Song <kasong@xxxxxxxxxxx>
> >
> > For the active/inactive LRU, madvise clears PG_referenced so that one more
> > access is not enough to reactivate a folio, and keeps PG_workingset on a
> > folio demoted out of the active list so its refault is still accounted as
> > a workingset refault (PSI).
> >
> > MGLRU keeps that history in the folio's refs count instead, which now
> > lives in PG_referenced, PG_workingset and LRU_REFS_MASK, so writing to
> > those bits directly corrupts the count. The two hints want different
> > things:
> >
> > - MADV_COLD resets the count in folio_deactivate(), which also requests
> > deactivation.
> > - MADV_PAGEOUT clears non-workingset refs and caps the rest at
> > LRU_REFS_WORKINGSET after isolation, before handing the folio to
> > reclaim_pages(). The hint marks the folio as cold, so the
> > eviction shadow records the capped count and does not inflate the
> > eviction/refault counters of the hot tiers that drive aging, while
> > folios at or above the workingset threshold keep their PSI
> > classification.
> >
> > PG_young is cleared for both LRUs as before, so the referenced walk does
> > not count stale history as a recent access.
> >
> > Reviewed-by: Kunwu Chan <kunwu.chan@xxxxxxxxx>
> > Tested-by: Andrew Morton <akpm@xxxxxxxxxxxxxxxxxxxx>
> > Signed-off-by: Kairui Song <kasong@xxxxxxxxxxx>
>
> It'd be nice for us to figure out a way eventually to make this modular re:
> reclaim backends.
Don't worry, anything that looks not so nice here won't stay for too long :-D
> The implementation looks sensible and you're breaking things out sensibly also
> so not objecting to it though :)
>
> Also hopefully Gregory's rework of the cold/pageout bits can make this even
> nicer (I realise I owe review on that, swamped etc. :)
Totally understandable :), BTW, any spoiler available for that rework?
I have quite a few ambitious plans for maybe related parts, mostly
included in the cover letter and previous discussions, hopefully,
there won't be too many conflicts.