Re: [PATCH v6 17/18] mm/mglru: folio LRU refs based active/inactive number accounting

From: David Hildenbrand (Arm)

Date: Wed Nov 25 2026 - 05:17:47 EST


On 11/23/26 19:53, Kairui Song via B4 Relay wrote:
> From: Kairui Song <kasong@xxxxxxxxxxx>
>
> Currently the active/inactive LRU sizes exported through /proc/vmstat
> and memory.stat are derived from the generation window: folios in the
> two newest generations are accounted as active, the rest as inactive.
> This causes several problems:
>
> - Unmapped file folios can stay in older gens despite repeated use,
> so active files can be under-reported, unlike classical LRU.
>
> - The reading is jumpy: on aging, the second-newest gen, previously
> active, becomes inactive all at once, causing a huge drop of active
> folios without any change in use.
>
> - The reading is reversed on swapless machines. When swapping is
> disabled or unavailable, MGLRU ages anon by moving the gens directly
> without walking or touching any folio, to reduce the overhead. So
> inactive anon folios can suddenly count as active, or vice versa,
> despite no change in their hotness.
>
> With frequency guided promotion, hotness is already tracked per folio by
> its referenced count, so we can do folio level accounting instead: a
> folio is active once its refs reach LRU_REFS_ACTIVATED (currently
> LRU_REFS_PROTECTED).
>
> On reaching this threshold, folios are accounted to the active part.
> On forced per-folio aging or PID protection, refs are capped at
> LRU_REFS_WORKINGSET, dropping active folios to the inactive part.
> Note that on swapless machines anon refs are not reset by aging (the
> shortcut skips the per-folio walk), but the counts no longer oscillate
> as the generation indices wrap.
>
> The accounting is now per folio and lruvec independent, so no size
> adjustment is needed when reparenting a dying memcg: the hierarchical
> stats keep the counts in the parent automatically.
>
> folio_migrate_lru_refs() also gains off-LRU VM_WARN_ON_ONCE checks and
> __folio_set_lru_refs() leaves a folio that is still on a gen list alone,
> as its refs are already in the active/inactive counters.
>
> Reviewed-by: Kunwu Chan <kunwu.chan@xxxxxxxxx>
> Signed-off-by: Kairui Song <kasong@xxxxxxxxxxx>
> ---
> Documentation/admin-guide/mm/multigen_lru.rst | 4 +-
> include/linux/mm_inline.h | 100 ++++++-----

Another clear indication that this should go into a separate header. Maybe
mglru.h or vmscan.h ... or both.

--
Cheers,

David