Re: [RFC PATCH 0/1] mm/mglru: MADV_RANDOM page cache never ages and thrashes the oldest generation
From: Maxim Muzafarov
Date: Sat Nov 21 2026 - 16:00:06 EST
Hi Tianyi, Kairui,
Sorry for the late reply. There was a lot of new information for me
to digest.
I've checked the reproducer you provided. It tests a slightly
different scenario from the one I mentioned in my first email.
However, I managed to adapt it [1] to my case and tested everything
with the same setup (x86-64 VM), and I also reproduced your results.
The key difference [1] is that I added two new knobs:
- SCAN_PASSES (default 1, your value), how many times each scan page
is touched
- SCAN_MB (default 96, your value), the cold scan size in MiB
This is important because 300 MiB scan forces reclaim to reach the
pages during the first pass, which clears their accessed bits and
evicts some of them. The second pass then gives the scan pages a
second visible access. The reproducer from my first email also reads
the cold data twice (--loops=2).
So the idea is to get the cold data promoted to newer generations
and watch whether the workload recovers while the oldest generation
is thrashing.
With a 300 MiB scan and 2 passes, neither MGLRU nor MGLRU-FG5 can
recover. FG5 handles the 96 MiB scans and the 300 MiB single pass
scan.
The Patch
---------
Kairui,
On Mon, Nov 02, 2026 at 02:02:33AM +0800, Kairui Song wrote:
> This code snip:
> + /* Set refault as active. */
> + if (distance < total / 2) {
> + folio_set_active(folio);
[...]
> That way, even a random folio will be put to the head directly instead
> of keep thrasing on tail. And placing on head or newer gen will
> trigger aging.
As I understand it, the refault distance series will break this loop
on tail. However, will the loop survive when the hot random set
is much bigger than half of memory? E.g. when its refault
distances exceed total / 2 and refaults land in the oldest
generation again? Should we in this case use the aging logic from
this patch as a fallback?
Anyway I'd be happy to test the refault distance implementation as
part of this work when it's ready.
I also rebased the patch onto mm-new (25fee5b1762b) [2] and on top
of the MGLRU-FG5 branch [3]. The patch applies unchanged to both.
Please, let me know if I need to send v2 of the patch to this thread.
Setup
-----
The same .config, and a fresh 4 vCPU x86-64 KVM guest per kernel.
OpenSearch and a cold mmap scan (96/300 MiB, one/two passes)
share a 1 GiB memcg with no swap. Median of 5 seeds,
lru_gen enabled=7 vs 0.
mmbase 7.4.0-rc1-mmbase+, mm-new (25fee5b1762b)
fg5 7.4.0-rc1-fg5+, 25fee5b1762b with 17 MGLRU-FG5 patches [4]
age2 7.4.0-rc1-age2+, mmbase with the patch on top
fg5age 7.4.0-rc1-fg5age+, fg5 with the patch on top
Results
-------
First, the good news. I can confirm that FG5 keeps .vec in memory
with a 96 MiB scan and MGLRU doesn't. With passes=2 it also
looks fine.
My guess is that at 96 MiB reclaim never reaches the scan pages
between the two passes, so their accessed bits stay set and the
second pass is not seen as a new access? I haven't confirmed this.
96 MiB scan:
kernel passes LRU p50 p99 refaults .vec scan .vec late
fg5 1 MGLRU 1.1 2.6 2 117.2 117.2
fg5 1 classic 1.1 2.4 7 117.2 117.2
fg5 2 MGLRU 1.0 2.1 1 117.2 117.2
fg5 2 classic 1.0 2.0 0 117.2 117.2
mmbase 1 MGLRU 15.4 69.0 510691 75.3 102.2
mmbase 1 classic 1.0 2.2 3 117.2 117.2
mmbase 2 MGLRU 16.6 73.4 558370 70.1 100.0
mmbase 2 classic 1.1 2.6 3 117.2 117.2
With a 300 MiB scan, .vec is fully evicted during the scan on every
kernel, so these runs show whether it comes back. With passes=2,
MGLRU-FG5 is NOT able to recover, and this is where the refault
distance implementation should help?
300 MiB scan:
kernel passes LRU p50 p99 refaults .vec scan .vec late scan late
fg5 1 MGLRU 1.0 2.2 413 0.0 117.2 115.8
fg5 1 classic 1.1 2.4 409 0.0 117.2 104.5
fg5 2 MGLRU 156.1 248.5 12548335 0.0 4.7 292.0
fg5 2 classic 1.1 2.4 686 0.0 117.2 157.5
mmbase 1 MGLRU 146.3 227.4 11247224 0.0 15.0 293.5
mmbase 1 classic 1.0 2.3 409 0.0 117.2 102.0
mmbase 2 MGLRU 150.2 248.9 11643192 0.0 11.3 295.0
mmbase 2 classic 1.1 2.5 547 0.0 117.2 157.2
The patch runs aging when the oldest generation is thrashing, so
min_seq moves again, and both MGLRU and MGLRU-FG5 recover.
300 MiB scan, with the patch:
kernel passes LRU p50 p99 refaults .vec scan .vec late scan late
age 1 MGLRU 1.1 2.4 571 0.0 117.2 152.8
age 1 classic 1.1 2.3 410 0.0 117.2 106.5
age 2 MGLRU 1.1 2.3 565 0.0 117.2 150.8
age 2 classic 1.1 2.5 866 0.0 117.2 153.8
fg5age 1 MGLRU 1.1 2.3 410 0.0 117.2 112.1
fg5age 1 classic 1.1 2.3 407 0.0 117.2 102.2
fg5age 2 MGLRU 1.1 2.3 430 0.0 117.2 143.0
fg5age 2 classic 1.1 2.6 955 0.0 117.2 154.5
The full results are in the gist [5].
Links
-----
[1] https://gist.github.com/Mmuzaf/263806a5bfae85e75c3331467f85353e/030e6f11096e1980303aa153da0a35b220b4eecc
[2] https://github.com/Mmuzaf/linux/commit/cbd48001580bf1ad8a8767b1afd8e4ad969b3432
[3] https://github.com/Mmuzaf/linux/commit/1e889df5c555e99d437c608e25c22ccb5286ff8f
[4] https://lore.kernel.org/linux-mm/20261120103250.1241429-1-hi@xxxxxxxxx/
[5] https://gist.github.com/Mmuzaf/e87acbefc15acc2cac40c2181de984dd
Thanks,
Maxim Muzafarov