Re: [PATCH v5 00/17] mm/mglru: frequency guided promotion (MGLRU-FG) and flag cleanup

From: Kairui Song

Date: Fri Nov 20 2026 - 06:17:01 EST


On Fri, Nov 20, 2026 at 7:40 AM Andrew Morton <akpm@xxxxxxxxxxxxxxxxxxxx> wrote:
>
> On Thu, 19 Nov 2026 05:03:32 +0800 Kairui Song <kasong@xxxxxxxxxxx> wrote:
>
> > This series implements MGLRU-FG following the idea proposed at LSF/MM/BPF
> > this year [1], based on current mm-new. Depending on the workload, it
> > improves the performance or reduces IO by roughly 10% to over 50%,
> > fixes multiple long-standing issues with MGLRU metrics, and drops one
> > page flag.
>
> This is looking really good - great stuff.
>
> Review is thin, so I'll remain in wait-and-see mode for now. What do
> people think?
>
> I told LLM to put this series through its paces. The performance gains
> were confirmed (actually muchly exceeded) and it couldn't find a way to
> break anything. It found a smallish slowdown in writes to clear_refs,
> which doesn't seem very important?

Thanks! Glad to see another positive report. And yeah I think
everything is fine.

The reply below is a bit long (and 99% not LLM generated :-), so
TLDR: We fixed a long standing "bug" here in with a small (IMO)
interface performance drop, and that interface's user was already broken
(which we fixed), and I think the performance can be easily recovered too.

("bug": it's just messed up metrics readings, there is no leak or
race, just these values are just no longer meaningful in anyway and
are breaking real world usage, see appendix)

A slightly (~10% end to end, that one interface only) clear_refs
writer slow down is expected, smap is the only user for that (maybe
DAMON too but it works differently and won't cause this many calls).
However, the thing is smap reading was almost broken for MGLRU in
mainline, just like K8s users have to disable MGLRU by default for
years because it keeps giving gibberish readings (See Link [20], the
refs and workingset are tangled in PID controller / aging in a
hard-to-describe way so we see seeing unrealistic values).

This series fixed that, metric readings are now sane, stable and
accurate, close to CLRU and provide useful data for workingset
estimation, so the trivial slowdown of a lessly used interface seems
very reasonable, and we only slow down the even colder hard reset
part, readers are good as before. (We'll also need to update the tools
ABI part later, but that's too long for now, and I think we can live
with it for a little longer considering it has been broken for so long
time...)

Meanwhile, if we want better smap reset performance (I'm not sure if
we really need that, since it is costly by itself already, a whole VMA
locked walk & PTE update per page, and ruins the hotness info), we can
do this:

diff --git a/include/linux/mm_inline.h b/include/linux/mm_inline.h
index a2442e49aca2..45808f7ae50c 100644
--- a/include/linux/mm_inline.h
+++ b/include/linux/mm_inline.h
@@ -562,10 +562,12 @@ static inline bool folio_check_lru_refs(const
struct folio *folio)
*/
static inline void folio_clear_lru_refs(struct folio *folio)
{
- if (lru_gen_enabled())
- folio_reset_lru_refs(folio);
- else
+ if (lru_gen_enabled()) {
+ if (folio_lru_refs(folio))
+ folio_reset_lru_refs(folio);
+ } else {
folio_clear_referenced(folio);
+ }
}

It should speed it up instead for most cases, I didn't include it just
to keep the code a little bit simpler. Smap and DAMON are the only two
users, so it's safe to squash this into Patch 10 "convert to LRU refs
based operations for MGLRU" directly.

In fact, if we really care about smap performance we should start
batching it instead of doing things page by page like right now, I
think that may bring a much larger speed up.

And a Appendix: Measuring the smap Referenced, and active / inactive
reading during a build test (LLM did help on this :-D ):

│ smaps Referenced/Rss % min/med/max │ span │ stdev
CLRU │ 99.4 / 100.0 / 100.0 │ 0.6 │ 0.0
MGLRU │ 38.0 / 99.6 / 100.0 │ 62.0 │ 12.3 - erratic and unstable
FG │ 99.9 / 100.0 / 100.0 │ 0.1 │ 0.0 - matches CLRU

│ active_anon % min/med/max │ span │ stdev
CLRU │ 0.0 / 1.1 / 24.9 │ 24.8 │ 4.5
MGLRU │ 3.7 / 96.4 / 100.0 │ 96.3 │ 23.7 * chaotic, almost random
FG │ 0.0 / 0.9 / 12.3 │ 12.2 │ 1.9 - matches CLRU

│ active_file % min/med/max │ span │ stdev
CLRU │ 34.1 / 43.8 / 52.2 │ 18.1 │ 4.7
MGLRU │ 0.0 / 0.1 / 0.1 │ 0.1 │ 0.0 * entirely wrong, always ~0
FG │ 24.3 / 33.5 / 42.2 │ 18.0 │ 5.7 - matches CLRU

Pool over 3 test run with make -j48, defconfig, ZRAM as swap, 3G memory.

It can be seen clearly that the metrics readings before FG were almost
gibberish, FG fixed that just fine. These are causing issues that
describe in the Link [20] above, and many other components. And they
don't write to clear_refs, they just read meminfo, smap is also
included here but less used.

The active anon reading for both CLRU and FG seems a bit low, mostly
because this task is under heavy pressure and aging/reclaming fast,
and FG also provides the way to tweak it in the future
(LRU_REFS_ACTIVE). And FG reporting a bit lower is somewhat reasonable
since it does reclaim better.

Note, the goal here is not to match CLRU, but CLRU was clearly doing
much better on this, so using that as an reference shows the
reworked readings are indeed normal and reliable.