Re: [PATCH v9 10/16] mm/mglru: Run aging when pages are rare outside the youngest gen

From: Andrew Morton

Date: Sun Nov 15 2026 - 23:50:52 EST


On Mon, 16 Nov 2026 12:25:56 +0800 "Barry Song (Xiaomi)" <baohua@xxxxxxxxxx> wrote:

> On Sun, Nov 15, 2026 at 11:55 PM Kairui Song <ryncsn@xxxxxxxxx> wrote:
> [...]
> >
> > A little nit: with the rounding above, I think we don't need youngest
> > / old as an array, just an accumulative value seems enough now? But
> > feel free to ignore this so we can avoid more update noise in this
> > series.
>
> Makes sense to me!
>
> I guess Andrew could help squash the cleanup below into the patch?

yep.

> As suggested by Kairui[1], we don't need youngest and old as
> array. just an accumulative value should be enough.
>
> No functional change.

It got a bit messy because the later "mm/mglru: restrict eviction
accounting to eligible zones" alters this code also, but I think I
figured it out. And I might have accidentally fixed an 80-col thing
while in there ;)

Here's the end-of-series result - please check. It compiles!


static bool lru_gen_imbalanced(struct lruvec *lruvec, struct scan_control *sc,
int swappiness)
{
struct lru_gen_folio *lrugen = &lruvec->lrugen;
unsigned long youngest = 0, old = 0;
DEFINE_MAX_SEQ(lruvec);
DEFINE_MIN_SEQ(lruvec);
int type;

if (sc->priority > AGING_PRIORITY)
return false;

/*
* Round up or down corner swappiness, to balance the heavy biased
* type better
*/
if (swappiness == MIN_SWAPPINESS + 1)
swappiness = MIN_SWAPPINESS;
else if (swappiness == MAX_SWAPPINESS)
swappiness = MAX_SWAPPINESS + 1;

for_each_evictable_type(type, swappiness) {
unsigned long seq;

youngest += lruvec_gen_size(lrugen, type, max_seq,
sc->reclaim_idx + 1);
for (seq = min_seq[type]; seq < max_seq; seq++)
old += lruvec_gen_size(lrugen, type, seq,
sc->reclaim_idx + 1);
}

/* the vast majority of pages sit in the youngest gen */
return youngest > old * MAX_NR_GENS;
}