Re: [PATCH v2 2/2] mm: multi-gen LRU: remove get_lruvec()
From: Barry Song
Date: Mon Nov 02 2026 - 19:20:45 EST
On Tue, Nov 3, 2026 at 7:35 AM Siddharth Chintamaneni
<sidchintamaneni@xxxxxxxxx> wrote:
>
> On Mon, 2 Nov 2026 at 14:56, Barry Song <baohua@xxxxxxxxxx> wrote:
> >
> > On Tue, Oct 27, 2026 at 4:23 AM Siddharth Chintamaneni
> > <sidchintamaneni@xxxxxxxxx> wrote:
> > >
> > > get_lruvec() was originally introduced in commit ec1c86b25f4b ("mm:
> > > multi-gen LRU: groundwork") to guard against NULL NODE_DATA(nid) on
> > > uninitialized NUMA nodes (`return pgdat ? &pgdat->__lruvec : NULL;`).
> > > After commit 09f49dca570a ("mm: handle uninitialized numa nodes
> > > gracefully") and commit 931b6a8b36a2 ("mm: multi-gen LRU: remove NULL
> > > checks on NODE_DATA()"), that NULL check was removed, leaving
> > > get_lruvec() as a thin wrapper around mem_cgroup_lruvec().
> > >
> > > Remove get_lruvec() and call mem_cgroup_lruvec() directly at all call
> > > sites.
> > >
> > > Suggested-by: Barry Song <baohua@xxxxxxxxxx>
> > > Reviewed-by: Baolin Wang <baolin.wang@xxxxxxxxxxxxxxxxx>
> > > Signed-off-by: Siddharth Chintamaneni <sidchintamaneni@xxxxxxxxx>
> > > Signed-off-by: Hardik Garg <hargar@xxxxxxxxxxxxxxxxxxx>
> > > ---
> >
> > It's great to see the MGLRU-specific get_lruvec() gone. Thanks!
> > Hopefully, we can get rid of more MGLRU-specific code,
> > such as get_swappiness().
> >
>
> I just looked into removing get_swappiness() in favor of its LRU variant
> (sc_swappiness()). Do you mean moving the additional conditionals
> directly into the callsites?
Nop. In MGLRU, swappiness has values: 0, 1–200,
and 201.
With swappiness=0, MGLRU only reclaims file pages and
doesn't care about the hotness of anon pages.
With swappiness=201, MGLRU only reclaims anon pages and
doesn't care about the hotness of file pages.
In both cases, we allow cold/hot inversions in
inc_min_seq(), which can help reduce CPU usage:
static bool inc_min_seq(struct lruvec *lruvec, int type, int swappiness)
{
/* For file type, skip the check if swappiness is anon only */
if (type && (swappiness == SWAPPINESS_ANON_ONLY))
goto done;
/* For anon type, skip the check if swappiness is zero (file only) */
if (!type && !swappiness)
goto done;
...
}
Then we could have cases where swappiness is 1 ~ 200, but
we still cannot reclaim anon due to:
1. Swap is full, or the memcg's swap quota is exhausted.
2. The allocation uses GFP_NOIO, but the swap cache is low
[1].
So right now, we have to hack get_swappiness() to return 0
to ensure that reclaim only happens on file pages, or we at
least need to hack reclamation path to use swappiness=0.
This is quite bad, as it can cause cold/hot inversions for
anon pages. I believe this is already a bug in the current
get_swappiness() implementation when swap is full.
Ideally, swappiness values from 1 to 200 and the reclaimable
type should be orthogonal; they should not be coupled.
In other words, we shouldn't need to force swappiness=0 to
reclaim only file pages. If swappiness is set to 60, it
should remain 60 across all MGLRU reclaim paths. The
reclaimable type should be handled separately, without
forcing swappiness to 0 and introducing confusion and bugs.
[1] https://lore.kernel.org/linux-mm/179248830836.1744016.8424217811286616919.noio-mglru-rfc-v2@xxxxxxxxxxxxx/
Best,
Barry