All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v6 00/18] mm/mglru: frequency guided promotion (MGLRU-FG) and flag cleanup
@ 2026-11-23 18:52 ` Kairui Song
  0 siblings, 0 replies; 124+ messages in thread
From: Kairui Song via B4 Relay @ 2026-11-23 18:52 UTC (permalink / raw)
  To: linux-mm
  Cc: Andrew Morton, Johannes Weiner, Muchun Song, Qi Zheng, Ying Huang,
	Chris Li, Baoquan He, Nico Pache, Usama Arif, Michal Hocko,
	Roman Gushchin, Shakeel Butt, David Hildenbrand, Lorenzo Stoakes,
	Liam R. Howlett, Barry Song, Axel Rasmussen, Yuanchu Xie, Wei Xu,
	Vlastimil Babka, Suren Baghdasaryan, Nhat Pham, Youngjun Park,
	Zi Yan, Gregory Price, Matthew Wilcox (Oracle), Baolin Wang,
	Ryan Roberts, Dev Jain, Lance Yang, Hugh Dickins, SJ Park,
	David Rientjes, Yu Zhao, Vernon Yang, Zicheng Wang, Tal Zussman,
	Kairui Song, Xiang Liu, Ehab Ababneh, Zhao Zhenzhuo, Lian Wang,
	Joanne Koong, Kunwu Chan, Hui Zhu, Maxim Muzafarov, linux-kernel,
	cgroups, damon, linux-doc, Tianyi Chen, Kairui Song, Ridong Chen

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.

The series has been tested on multiple platforms (desktop, large server,
Android phone, x86_64 and arm64 VM boxes) covering many typical benchmarks,
databases and real applications, so far everything looks nice, with good
test reports from other individual testers too.

Different workloads may get a flat, minor or dramatic improvement, the
gain here is mostly from real improvement of LRU's ability to distinguish
the hotter workingset.

It also redefines the Active workingset metric for MGLRU, which fixes
under-accounted PSI and poor active workingset readings. Cloud
platforms like Kubernetes derive pods' working set from it and use
it to make eviction decisions, MGLRU gave an unstable one there, and
users ended up disabling MGLRU to work around it [20]. That is also
a major blocker for us to deploy MGLRU widely.

The new MGLRU-FG's design is kind of a mixture with LFU, it uses unified
access frequency to distinguish hotter folios, but it still reclaims by
generation. The generation and bounded refs together form a
"logical refs count".

Accesses increase refs. When a folio's refs reach a threshold, the folio
is promoted to the next newer gen, and promotion caps the refs at a lower
threshold. A folio with lower physical refs in a newer gen is
logically hotter than a folio in an older gen with higher physical refs.
Hence gen aging lowers all logical refs without updating every folio,
avoiding hot cache pollution at no added overhead, while greatly
extending the ref counting and hotness distinguishing ability. It also
balances page table access counting against file descriptor (FD)
access with a defined rule.

The work here is mostly just a re-explanation of MGLRU's existing
mechanisms, everything is already there, we just connect them together
in a different way.

This version is rebased and retested on top of mm-new, which includes
Barry's swappiness rework [16], and this series combines very well and
became more important after that. High swappiness now drives file reclaim
much more aggressively, making the existing PID protection very
inefficient. Meanwhile FG can promote reused file folios much more
proactively, and the build kernel test shows a significant improvement
for that case. I also observed FG performing better in generic cases
after that series, as the more proactive aging populates more gens,
which lets FG distribute folios among them more evenly [19].

Test results (CLRU means classical LRU):

Build kernel test:
==================
This test is reworked: with the recent swappiness changes, behavior
differs dramatically between setups, so it is now split into two groups,
mild swappiness under mild pressure, and extreme swappiness.

For the mild swappiness range (60/100/150), with ZRAM as swap (256G,
lzo-rle) and a clean make -j48 defconfig build from an existing source
tree on an NVMe drive in a 3G/2G memcg, the average of 2 rounds across the
three swappiness levels:

Reading with 3G memcg (lower is better):
         real       sys    pgpgin   pgpgout pgmajfault refault_file refault_anon
CLRU     1m33s   10m08s     9.76M    38.05M      1.85M         466k        1.85M
Before   1m32s    9m27s    12.56M    40.49M      2.35M         345k        2.31M
After    1m32s    9m15s    10.44M    35.74M      1.80M         347k        1.76M
delta    -0.2%    -2.1%    -16.9%    -11.7%     -23.4%        +0.4%       -23.8%

Reading with 2G memcg (lower is better):
         real       sys    pgpgin   pgpgout pgmajfault refault_file refault_anon
CLRU     1m54s   25m47s    66.35M   158.02M     15.51M        1.57M       15.52M
Before   1m54s   25m15s    75.47M   183.48M     17.33M         973k       17.17M
After    1m52s   24m00s    69.67M   171.01M     15.51M        1.19M       15.36M
delta    -2.0%    -4.9%     -7.7%     -6.8%     -10.5%       +21.8%       -10.5%

We can see the performance is better with lower sys time and total pgpgin
with the mild setup. The slight drift of the file/anon counters is mostly
swappiness balance policy differences, which looks OK to me as the total
refault and IO dropped together with the build time.

Swappiness is still respected. The extreme points below show a major
improvement with disk as swap:

Using the same setup, first with ZRAM as swap, then with an NVMe device
as disk swap:
ZRAM as swap:
        sw   real  pgpgin  pg{steal/scan}_anon  pg{steal/scan}_file {anon/file}_refault
CLRU     1  2m06s  68.70M       9.86M / 50.91M     15.14M / 25.67M  2.08M / 14.97M
       100  1m32s   8.88M       9.15M / 49.65M     562.0k / 667.9k  1.69M / 409.9k
       200  1m36s  22.35M      19.53M / 79.35M     151.1k / 227.7k  5.52M /  84.2k
Before   1  1m42s  36.95M       8.45M / 15.43M      7.02M / 15.49M  2.19M /  3.58M
       100  1m32s  11.80M       9.83M / 20.29M     780.5k / 830.1k  2.16M / 321.8k
       200  1m41s  46.04M      29.87M / 68.96M          0 /      0 11.68M /      0
After    1  1m46s  42.75M       8.84M / 15.80M      8.72M / 20.35M  1.96M /  4.54M
       100  1m32s  11.08M       9.69M / 19.64M     804.0k / 856.6k  1.95M / 364.1k
       200  1m41s  32.89M      27.00M / 57.04M       1148 /   1152  8.13M /    480

Disk as swap:
        sw   real  pgpgin  pg{steal/scan}_anon  pg{steal/scan}_file {anon/file}_refault
CLRU     1  4m23s 153.56M      10.90M / 61.31M     36.00M / 55.81M   2.43M / 35.83M
       100  3m16s   9.95M       8.22M / 52.72M     588.5k / 652.4k   1.93M / 435.3k
       200  6m19s  25.36M      20.21M / 98.19M      94.6k /  94.7k   6.30M /   9365
Before   1  3m07s  27.18M       6.41M / 11.55M      4.83M /  8.80M   1.38M /  2.53M
       100  2m56s   9.52M       6.31M / 13.75M     609.1k / 628.3k   1.26M / 251.7k
       200 10m30s  71.66M      38.59M / 92.30M          0 /      0  13.87M /      0
After    1  3m18s  33.86M       7.60M / 14.89M      7.74M / 16.41M   1.37M /  4.14M
       100  2m46s   8.94M       5.69M / 13.86M     704.1k / 741.3k   1.09M / 268.8k
       200  6m03s  30.04M      19.72M / 49.85M        194 /    194   5.00M /    142

For sw=1, pgpgin looks higher, but that is because files are reclaimed
even harder, as swappiness asks for, while the performance is still OK and
better than CLRU.

For sw=100, the reading suggests the performance is better with a better
reclaim balance: pgpgin and total refault are down with both swap
devices, and building is ~10s faster on disk swap.

At sw=200 the disk swap build goes from 10m30s to 6m03s, almost halved.
The recent swappiness fix also exposes the weakness of the PID controller,
which almost stalls the build when reclaim is aimed at file folios, while
FG promotes file folios much more proactively. This is consistent with
the pgrefill counter below (Before -> After: the PID protects
almost nothing at sw=200):

pgrefill         sw=1              sw=100            sw=200
DISK       3.78M -> 10.23M   16.02M -> 24.17M    8.17k -> 34.28M
ZRAM       6.28M -> 11.09M   22.21M -> 30.94M   5.20M -> 42.85M

Note, this may read as if reclaim efficiency dropped slightly, which is
quite the opposite: FG softens the ineffective PID factor, and the lazy
promotion filters the workingset out proactively, so the scan count
may look bigger. We are just lacking an activation counter for MGLRU to
separate the two. Unfortunately that does not fit directly as there is no
activation for MGLRU; we may discuss and improve MGLRU's statistic
counters as a follow up.

In summary: MGLRU with FG respects swappiness well and improves the
performance by a lot, with lower pgpgin and almost half the build time at
the high swappiness values. The cases where MGLRU used to fall behind CLRU
now lead as well.

FIO cached read with zipf
=========================
(This is a simplified version, fuller coverage can be seen in [17])

Using an NVMe device, in a 16G cgroup, total file size 40G, this
measures the LRU's theoretical ability to distinguish the hotter
portion, 2 interleaved runs per config (only n=2, but it reproduces
the picture of the matrix in [17] just fine), THP off, swap off:

Using read()
------------
numactl --membind=0 --cpunodebind=0 \
fio --name=fg --numjobs=16 --nrfiles=1 \
    --filename_format="/var/lib/kmultibench/realdk.\$jobnum.img" \
    --size=2560M \
    --buffered=1 --ioengine=sync --rw=randread \
    --random_distribution=zipf:$ZIPF --bs=4k --time_based \
    --ramp_time=120s --runtime=600s --group_reporting

Avg IOPS (higher is better)
 zipf:θ       CLRU | MGLRU before (vs CLRU) |        FG (vs CLRU) |  Imprv.
  0.8       396,247|      403,014 ( +1.7%)  |    468,872 (+18.3%) |  +16.3%
  0.9       601,304|      616,291 ( +2.5%)  |    713,928 (+18.7%) |  +15.8%
  1.1     2,077,516|    2,158,626 ( +3.9%)  |  2,462,189 (+18.5%) |  +14.1%
  1.2     4,439,193|    4,546,680 ( +2.4%)  |  5,204,998 (+17.3%) |  +14.5%
  1.4    14,318,444|   14,122,531 ( -1.4%)  | 14,620,584 ( +2.1%) |   +3.5%

refault/read (lower is better, defined as workingset_refault_file / reads)
 zipf:θ      CLRU | MGLRU before (vs CLRU) |     FG (vs CLRU) |  Imprv.
  0.8     0.21707 |       0.21288 ( -1.9%) | 0.18887 (-13.0%) |  +11.3%
  0.9     0.14359 |       0.13994 ( -2.5%) | 0.12292 (-14.4%) |  +12.2%
  1.1     0.03919 |       0.03785 ( -3.4%) | 0.03267 (-16.6%) |  +13.7%
  1.2     0.01609 |       0.01551 ( -3.6%) | 0.01323 (-17.8%) |  +14.7%
  1.4     0.00167 |       0.00182 ( +9.0%) | 0.00133 (-20.4%) |  +26.9%

For typical read() following zipf distributions, FG improves every case,
mean +12.9% IOPS and -15.7% refault rate.  FG protects the hotter part
of the workingset better when under pressure, the only case where MGLRU
is behind CLRU is also ahead now.

Using mmap
----------
command: numactl --membind=0 --cpunodebind=0 \
fio --name=fg --numjobs=16 --nrfiles=1 \
    --filename_format="/var/lib/kmultibench/realdk.\$jobnum.img" \
    --size=2560M \
    --ioengine=mmap --rw=randread --fadvise_hint=0 \
    --random_distribution=zipf:$ZIPF --bs=4k --time_based \
    --ramp_time=120s --runtime=600s --group_reporting

Avg IOPS (higher is better)
 zipf:θ       CLRU | MGLRU before (vs CLRU) |        FG (vs CLRU) | Imprv.
  0.8     1,062,221|    3,591,468 (+238.1%) | 4,066,055 (+282.8%) | +13.2%
  0.9       658,512|    3,785,168 (+474.8%) | 4,475,720 (+579.7%) | +18.2%
  1.1     2,183,796|     2,166,070 ( -0.8%) |  2,451,181 (+12.2%) | +13.2%
  1.2     4,785,117|     4,710,772 ( -1.6%) |  5,199,245 ( +8.7%) | +10.4%
  1.4    20,654,851|    20,685,287 ( +0.1%) | 21,598,890 ( +4.6%) |  +4.4%

refault/read (lower is better, defined as workingset_refault_file / reads)
 zipf:θ     CLRU | MGLRU before (vs CLRU) |     FG (vs CLRU) |  Imprv.
  0.8     0.12460|      0.02124 (-83.0%)  | 0.01898 (-84.8%) |  +10.6%
  0.9     0.13972|      0.02010 (-85.6%)  | 0.01717 (-87.7%) |  +14.6%
  1.1     0.04036|      0.03955 ( -2.0%)  | 0.03446 (-14.6%) |  +12.9%
  1.2     0.01689|      0.01673 ( -0.9%)  | 0.01507 (-10.8%) |   +9.9%
  1.4     0.00209|      0.00206 ( -1.4%)  | 0.00184 (-12.0%) |  +10.7%

For typical mmap read of file following zipf distributions, FG also
improves every case here: mean +11.9% IOPS and -11.7% refault rate.
MGLRU remains far ahead of CLRU at theta < 1.

Worth noting, without fadvise_hint=0, we will see a regression like this:
 zipf:θ      CLRU | MGLRU before (vs CLRU) |       FG (vs CLRU) | Imprv.
  1.1    1,949,856|     1,667,041 (-14.5%) | 1,708,521 (-12.4%) |  +2.5%

That's because MGLRU deliberately disables hotness tracking for
MADV_RANDOM areas while CLRU still has refault distance. I don't think
this is a blocker: that is exactly what userspace asked for, and we do
plan to unify refault distance and improve shadow usage [8], [9], which
should also help with workingset shift [18]. FG is the baseline and we
will revisit that later.

Worth mentioning: a previous version test showed FG slightly lower on IOPS
for one config while its refault rate was actually lower. It is mostly
due to locking contention:

The earlier perf lock contention analysis shows the lazy promotion could
make MGLRU's isolation a bit slower than before:

command:
<same test command above, with 4G memcg, zipf:1.2 and a 300s runtime, and below tracing>
perf lock contention -ab -- sleep 355

Result (runtime=300s, 4G memcg, zipf:1.2):
  config:θ       IOPS | mean clat | sys% | lruvec lock total wait |
  CLRU          1,868k|    8195 ns| 6.01%|          ~10 s         |
  MGLRU before  1,677k|    9173 ns| 7.25%|          ~75 s         |
  MGLRU after   1,837k|    8488 ns| 7.33%|          ~78 s         |

MGLRU now promotes more folios due to FG lazy promotion while holding
the LRU lock, which is a good thing for most cases since it protects the
workingset better. The lazy promotion cost can be reduced later by
batching and prefetching during scanning as demonstrated before [12].

MongoDB YCSB [2]
================
With recordcount:18000000 operationcount:27000000, threads:16,
100% zipfian reads, workloads a/b/c, in a 12G memcg, n=2, with a
5000 IOPS cap on the block device, and a 0.25G WiredTiger cache to
simulate a slower device and stress the LRU more:

Throughput (ops/sec, higher is better):
CLRU:         13,474.85 ops/s
MGLRU Before: 14,101.40 ops/s (+4.6% vs CLRU)
MGLRU After:  16,577.92 ops/s (+23.0% vs CLRU) +17.6% vs Before

READ p99 latency (us, lower is better):
CLRU:         69,028.33 us
MGLRU Before: 65,065.67 us (-5.7% vs CLRU)
MGLRU After:  6,977.67 us (-89.9% vs CLRU) -89.3% vs Before

READ p50 latency is essentially unchanged. The setup differs from
previous posted ones as I'm trying to enlarge the test matrix, but
still we are seeing very nice results.

Chromium & Node.js test [3]
===========================
Using ZRAM as swap, 64 workers (32 memcgs x 2 NUMA nodes), 256G
zram, 1h testing:

                 Total requests:
MGLRU Before:            146,229
MGLRU After:             242,644 (+65.9%)

Worth noting there seems to be some reclaim balance jitter for this
test, while the balancing in upstream is not doing very well at this
point too, so this is worth more investigation later.

LevelDB Scan/Get
================
I also retested the LevelDB benchmark from the cache_ext paper [4].
Interestingly, mainline MGLRU already beats CLRU on this one after a
recent change in lru_gen_folio_seq that bumps new folios with refs == 1
to the second-oldest generation as discussed. That change accidentally
gave random reads a higher hotness level while making sequential reads
much colder as described before [13]. However it's unreliable and
incorrect because it depends on LRU drain timing, and hurts some workloads
as reported, or where the sequential part is actually hotter (any workload
involving hotter large file and many small cold files will be affected)
which is reproduced below.

This series improves it while covering ordinary workloads too and fixing
more regressions:

LevelDB Scan / Get, Throughput Total:
CLRU:         4708.3 ops/s
MGLRU:        5026.9 ops/s (faster than CLRU, but hurts other workloads)
MGLRU After:  5179.2 ops/s (even better in all cases, and no regression)

The hot-sequential and cold-random workload can be easily reproduced with
SQLite and grep. SQLite continuously scans and looks up a small hot
portion of a DB file, while grep iterates over a set of small files much
larger than RAM [5]:

         SQLite scan & lookup time:       Grep iterate time:
CLRU:                       14.51ms               13281.37ms
MGLRU mainline:            567.05ms               13694.47ms
MGLRU After this series:    10.58ms               12930.43ms

The grep cold portion is larger than RAM and accessed only once per
iteration, so there's no promotion of any of it. CLRU handles
this reasonably. Mainline MGLRU has a clear regression; MGLRU-FG not
only recovers but is able to catch some hot parts from the cold grep
workload. This test is somewhat subjective, but the signal is clear.

An alternative fix was discussed previously too and I tested it as well
[17]. FG is still better, and its gain holds on top of it.

Android (For reference)
=======================
Testing on Android is quite difficult: lack of mainline support, and it
is very noisy, but I did an informal backport on top of the 6.1 GKI tree,
testing with a Pixel 9 Pro (16 GB RAM, 8 GB ZRAM, Android 17), preserving
the frozen kABI layouts so the implementation is limited [14].

The "before" and "after" kernels share the same base and differ only by
the FG series: the "before" tree has MGLRU aligned to the current upstream
code. (And BTW that alignment also improved the performance by a lot,
which matches the report from previous MGLRU reclaim optimization
series [11]).

The workload is a churn loop driven over adb: 34 common apps and 20 Chrome
tabs are launched and cycled, with a brief scroll per app during the cold
build of each iteration, 16 iterations per run, about one hour per run. The
loop exhausts memory in every iteration (zram peaks at 6.9-7.8 GB of 8 GB,
MemFree down to 130-335 MB in every run). The two kernels are run in an
interleaved rotation and compared both on matched per-iteration samples
(same period, same iteration index) and on paired run totals, which
cancels most of the run-to-run drift. I've repeated the test for several
days and times getting similar results.

The memory-management stack in Android is built around the non-FG MGLRU
behavior, and the 6.1 base lacks some of the upstream infrastructure. Even
so, FG holds its own, it lowers reclaim traffic on both the file and the anon
side:

                          Before     After   Delta 95% CI   Avg Improv.
-----------------------------------------------------------------------
workingset_refault_anon    1.43M     1.25M   [-23%, -3%]          +12%
workingset_refault_file    1.54M     1.39M   [-17%, +2%]          +10%
pgscan_anon                4.04M     3.56M   [-20%, -5%]          +12%
pgsteal_anon               1.64M     1.45M   [-23%, -1%]          +12%
pgscan_file                7.49M     6.52M   [-17%, -5%]          +13%
pgsteal_file               6.55M     5.63M   [-18%, -7%]          +14%
pswpout                    1.82M     1.62M   [-22%, -1%]          +11%
pgpgin                    23.56M    20.33M   [-18%, -7%]          +14%
pgmajfault                 1.61M     1.42M   [-21%, -4%]          +12%
pgpgout                    3.39M     3.48M   [ +0%, +5%]           -3%

Numbers are trimmed means over the 12 interleaved runs per kernel: the
highest and lowest run are dropped and the middle ten averaged. It's
the vmstat delta of one full run. The 95% CI is a bootstrap over the
12 rounds of the paired run-total ratio (After vs Before).

Despite being noisy, every counter except pgpgout and
workingset_refault_file is improved by ~10% on average, with a 95% CI
that stays clear of zero. We have been seeing
positive readings since v2 of this series, and still holds the same
pattern with a few days of testing. I think we can safely say that this
series is beneficial for generic Android workloads.

I also ran the Android Jank test from Zicheng [6] for previous versions,
and did a test on another Android phone with a 5.15 kernel on Xperia 1 V,
[15], the results are all looking good or basically flat.

Redis / Valkey
==============
Valkey in a 2G ARM64 VM, 2.4G dataset, using 8G ZRAM as swap and THP never.
Note, PT walk is missing there due to lack of hardware capability:

$ cat /sys/kernel/mm/lru_gen/enabled
0x0001

valkey-server --maxmemory 2560M
valkey-benchmark -r 3000000 -n 3000000 -d 1024 -c 12 -P 32 -t get

For every sample, 20 rounds each:

                            Before         After
plain GET              679,151 rps   707,938 rps  +4.2%
plain GET + BGSAVE     481,886 rps   494,153 rps  +2.5%

Small wins: the dataset does not fit in the guest, so this case runs
mostly under swap pressure. Nothing regresses, and GET throughput still
improves by ~4%.

Metrics
=======
The new defined LRU refs based MGLRU metrics reading also provide a more
stable and useful active / inactive / referenced metrics:

Pool over 3 test run with make -j48, defconfig, ZRAM as swap, 3G memory.
reading during a build test:

      │ 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 * useless, always ~0
FG    │  24.3 / 33.5 / 42.2      │ 18.0 │  5.7 - matches CLRU

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, which should hoefully
help solve the metrics problems, for example, the one in link [20].

Others
======

Additionally, PSI, smaps, and readahead should all benefit from better
accuracy since this series unifies the flag usage between classical
LRU and MGLRU.

Other tests such as MySQL are looking fine, with no regressions. There is
also community test report [7].

Refault distance is not included yet, so MGLRU may respond more slowly to
workingset shifts. That can be added later, as previously demonstrated
[8], [9].

Extra note about future development: this series is actually highly
compatible with ideas like workingset reporting [10]. The "gen climbing
folio" design may appear to conflict with workingset reporting's idea,
but it doesn't. The solution is simple and straightforward: once we can
extend the generation number to a larger value (e.g. 64 or 128), the
refs-driven promotion can stop at a lower gen (e.g. oldest_gen + 16),
leaving the remaining newer generations as perfectly time-gap-separated
bins. These older gens can be considered as expiring gen.

The tier count is not fixed either, we'll need to find a way to tune it
if tiers go beyond 4 though, but that shouldn't be hard, not a blocker
either.

More details are in the individual commit messages. LLM is used to help
improve the comments and tests, all results are double checked.

Link: https://lore.kernel.org/linux-mm/CAMgjq7BoekNjg-Ra3C8M7=8=75su38w=HD782T5E_cxyeCeH_g@mail.gmail.com/ [1]
Link: https://github.com/brianfrankcooper/YCSB/tree/master/workloads [2]
Link: https://lore.kernel.org/all/20221220214923.1229538-1-yuzhao@google.com/ [3]
Link: https://dl.acm.org/doi/10.1145/3731569.3764820 [4]
Link: https://github.com/ryncsn/emm-test-project/tree/master/sqlite-grep [5]
Link: https://github.com/purplewall1206/android-perf-bench [6]
Link: https://lore.kernel.org/linux-mm/92DCEFFD13221261+20260828102344.1537874-1-zhaozhengzhuo@uniontech.com/ [7]
Link: https://lwn.net/Articles/945266/ [8]
Link: https://lore.kernel.org/linux-mm/20260502-mglru-fg-v1-0-913619b014d9@tencent.com/ [9]
Link: https://lwn.net/Articles/976985/ [10]
Link: https://lore.kernel.org/linux-mm/20260417025123.2971253-1-wxy2009nrrr@163.com/ [11]
Link: https://lore.kernel.org/linux-mm/20240123184552.59758-1-ryncsn@gmail.com/ [12]
Link: https://lore.kernel.org/all/CAMgjq7Agqr1FLcG3HqT_M_1s8cHc21qQKTM-JS67-3gfQ6azPQ@mail.gmail.com/ [13]
Link: https://github.com/ryncsn/linux/tree/kasong/android/android14-6.1-mglru-fg-v4c-20261010 [14]
Link: https://github.com/ryncsn/linux/tree/silsrc/android/android13-5.15-yodo [15]
Link: https://lore.kernel.org/all/20261114200803.23129-1-baohua@kernel.org/ [16]
Link: https://lore.kernel.org/linux-mm/avd5bI-b9y1nKWw5@KASONG-MC4 [17]
Link: https://lore.kernel.org/linux-mm/CAMgjq7AEf_cJsLw4fxs7m5ntYPW9mjCOC_-w5j6ihk8F=xLRWA@mail.gmail.com/ [18]
Link: https://lore.kernel.org/all/CAMgjq7C1A2axrGiQzo2_9d6N9MQNP6Lg+ZqcHsac+qGvt8OL4A@mail.gmail.com/ [19]
Link: https://github.com/kubernetes/kubernetes/issues/127844 [20]

Tested-by: Zhao Zhenzhuo <zhaozhengzhuo@uniontech.com>
Tested-by: Andrew Morton <akpm@linux-foundation.org>
Link: https://lore.kernel.org/all/20261119154001.9b9f953136935a09e8a50af6@linux-foundation.org/
Tested-by: Wang Lian (ByteDance) <lianux.mm@gmail.com>
Tested-by: Tianyi Chen <hi@tychen.cc>
Signed-off-by: Kairui Song <kasong@tencent.com>
---
Changes in v6:
- Fixes potential active / inactive counter drift when MGLRU enable /
  disable switching race with counter update.
- Minor optimization for clearing refs:
  https://lore.kernel.org/all/CAMgjq7Dd=Y+GekSD9WO5oGdoa+S1eG3T-U=VsCexopvb723zFA@mail.gmail.com/
- Re-measure most tests, I got a +3.88% - +28.61% reading vs letter +3.5%
  - +16.3% reading for FIO with a single round of testing, so kept
  the old data as the code change is minimal and the readings basically
  matches. Similiar result for build kernel and other tests.
- Avoid potential counter leak when reparenting local stats:
  https://lore.kernel.org/linux-mm/CAN_Opa-+nb0vxQ+HsENCG2fEEMZoxG9Sy_DBC4CLkWjNLzDWKw@mail.gmail.com/
- Collect tags, and adjust according to patch update.
- Adjust a few patch order, rename one patch about PG_workingset helper.
- Link to v5: https://patch.msgid.link/20261119-mglru-fg-v5-0-9eee2fe97a2d@tencent.com

Changes in v5:
- Rebased onto current mm-new.
- Code and design are basically the same, mostly rebase and adaption and
  comment updates.
- Drop "mm: mglru: reparent folios from all generations": the fix it
  carried is upstream now.
- Pick up two patches from Ridong Chen to avoid conflicts.
- Fix a build warning with CONFIG_LRU_GEN=n.
- Share the ancestor walk between lruvec_live_lock_irq() and the new
  folio_lruvec_live_get()
- Note in __lru_gen_reparent_memcg() why the read/set/add of the child's
  counter cannot lose a lockless update.
- Say in the gup fast helper changelog what the fast path gains from it.
- Re-measure almost all tests as the recent swappiness rework changes a
  lot of things, and it turns out most result are still same or even better.
- Comment and kdoc updated, documentations needs more systematic update later.
- Link to v4: https://patch.msgid.link/20261016-mglru-fg-v4-0-2106750c0bfa@tencent.com

Changes in v4:
- Defer folios at the tail of their LRU instead of min_seq only:
  https://lore.kernel.org/linux-mm/CAMgjq7AOhDkuZZnWrGDguMvNtarZ7s0Ouzs1xYi2O4AkPEPbTQ@mail.gmail.com/
- Re-read max_seq inside the folio_inc_lru_refs_walk() cmpxchg loop, and
  apply the reparent fix before the lockless change.
- Tidy up a few code shuffles.
- Use generic refs-based helper for smaps, DAMON, khugepaged
  and madvise with better kdocs.
- Add community Tested-by tags for unchanged parts.
- Link to v3: https://patch.msgid.link/20261003-mglru-fg-v3-0-cbd4546a5bd9@tencent.com

Changes in v3:
- Micro-optimization for page flags operations: if the flags are
  unchanged after calculation, skip the cmpxchg.
- Avoid touching folio_activate even in the cold path. I tried multiple
  ways for that lockless promotion, PG_lru in the earlier RFC, and
  previous folio_activate, the new speculative barrier + retry seem the
  best solution.
- Apply tier cap for MADV_PAGEOUT.
- Only promote folio during page table walk or rmap if the folio
  is in the min gen. May be worth trying to enlarge the range to
  (max_seq - MIN_NR_GENS) in the next version.
- Fix a potential folio leak caused by reparenting.
- Retest shows great results especially for the Android case.
- Link to v2: https://patch.msgid.link/20260911-mglru-fg-v2-0-f26e5cb26da7@tencent.com

Changes in v2:
- Rebased; dropped v1 03/05/06 (already upstream), folded v1 01 and 07
  into patches 01 and 04; new patches 06, 07, 10, 12, 13.
- Make folio_test_workingset() itself arbitrate, dropping the parallel
  folio_is_* helpers; convert the last raw PageWorkingset() user
  (erofs). (Johannes)
- Use LRU_REF_MAPPED/LRU_REF_EXEC flags instead of is_fault/is_exec
  booleans. (Barry)
- Fix syzbot "WARNING in folio_inc_lru_refs" on off-LRU folios.
- Account active/inactive per folio from refs, not the gen window:
  /proc/vmstat and memory.stat no longer jump on aging or reverse on
  swapless machines.
- Make folio_inc_lru_refs() lockless; add folio_inc_lru_refs_fast()
  for the gup fast paths.
- Convert DAMON and khugepaged to the refs-based operations.
- Drop the lru_size WARN_ON_ONCE() and lockdep_assert_held(): the
  counter is lockless now, so transient negatives are expected.
- Link to v1: https://patch.msgid.link/20260804-mglru-fg-v1-0-4d8dad39dad6@tencent.com

---
Kairui Song (16):
      mm/memcontrol: allow update of LRU statistic without holding LRU lock
      mm/memcontrol: avoid potential counter leak when reparenting local stats
      mm/mglru: make generation page counters atomic
      mm/memcg: add folio-based lruvec live helper
      mm/mglru: frequency guided workingset promotion (MGLRU-FG)
      mm/mglru: make folio lru referenced times count a generic API
      mm/mglru: move add/del LRU size accounting out of lru_gen_update_size()
      mm/mglru, gup: mark folios referenced via a fast helper
      mm/mglru, smaps: convert to LRU refs based operations for MGLRU
      mm/damon: convert to LRU refs based operations for MGLRU
      mm/khugepaged: convert to LRU refs based operations for MGLRU
      mm/madvise: adapt for LRU refs based operations for MGLRU
      mm/huge_memory: mark folio as accessed more accurately on split
      mm/mglru: make PG_workingset helpers work based on folio LRU refs
      mm/mglru: folio LRU refs based active/inactive number accounting
      mm/mglru: make folio_inc_lru_refs lruvec lockless

Ridong Chen (2):
      mm/mglru: rename the generation offset in lru_gen_folio_seq()
      mm/mglru: skip the flags cmpxchg when nothing changes

 Documentation/admin-guide/mm/multigen_lru.rst |   4 +-
 fs/btrfs/compression.c                        |   1 +
 fs/erofs/zdata.c                              |   3 +-
 fs/proc/task_mmu.c                            |   6 +-
 include/linux/memcontrol.h                    |  71 +++-
 include/linux/mm_inline.h                     | 388 ++++++++++++------
 include/linux/mmzone.h                        | 150 ++++---
 include/linux/page-flags.h                    |   2 -
 kernel/bounds.c                               |   2 +-
 mm/damon/paddr.c                              |   3 +-
 mm/filemap.c                                  |   1 +
 mm/folio.c                                    |  92 +----
 mm/gup.c                                      |   6 +-
 mm/huge_memory.c                              |   8 +-
 mm/khugepaged.c                               |   4 +-
 mm/madvise.c                                  |  54 ++-
 mm/memcontrol.c                               |  15 +-
 mm/migrate.c                                  |   2 -
 mm/page_io.c                                  |   1 +
 mm/vmscan.c                                   | 548 ++++++++++++++++++--------
 mm/vmscan.h                                   |   2 +-
 mm/workingset.c                               |  47 ++-
 22 files changed, 910 insertions(+), 500 deletions(-)
---
base-commit: 87cdbd9bd63174de47ba16555bfe9800a8f3da07
change-id: 20260722-mglru-fg-3a2c8574725b

Best regards,
--  
Kairui Song <kasong@tencent.com>



^ permalink raw reply	[flat|nested] 124+ messages in thread
* [PATCH v7 07/19] mm/mglru: frequency guided workingset promotion (MGLRU-FG)
@ 2026-12-01 20:18 Kairui Song
  2026-12-02  1:51 ` + mm-mglru-frequency-guided-workingset-promotion-mglru-fg.patch added to mm-new branch Andrew Morton
  0 siblings, 1 reply; 124+ messages in thread
From: Kairui Song @ 2026-12-01 20:18 UTC (permalink / raw)
  To: linux-mm
  Cc: Andrew Morton, Johannes Weiner, Muchun Song, Qi Zheng, Ying Huang,
	Chris Li, Baoquan He, Nico Pache, Usama Arif, Michal Hocko,
	Roman Gushchin, Shakeel Butt, David Hildenbrand, Lorenzo Stoakes,
	Liam R. Howlett, Barry Song, Axel Rasmussen, Yuanchu Xie, Wei Xu,
	Vlastimil Babka, Suren Baghdasaryan, Nhat Pham, Youngjun Park,
	Zi Yan, Gregory Price, Matthew Wilcox (Oracle), Baolin Wang,
	Ryan Roberts, Dev Jain, Lance Yang, Hugh Dickins, SJ Park,
	David Rientjes, Yu Zhao, Vernon Yang, Zicheng Wang, Tal Zussman,
	Kairui Song, Xiang Liu, Ehab Ababneh, Zhao Zhenzhuo, Lian Wang,
	Joanne Koong, Kunwu Chan, Hui Zhu, Maxim Muzafarov, Tianyi Chen,
	linux-kernel, cgroups, damon, linux-doc, Kairui Song, Ridong Chen

Complement MGLRU's eviction-time tier-PID protection with access-time
frequency-guided promotion.  Introduce a unified set of helpers based on
the referenced (access) count of a folio.

Like LFU, this uses access frequency to distinguish hotter folios, but it
still reclaims by generation: the generation and the bounded refs together
form a "logical refs" count.

Accesses increase refs; refs crossing a threshold trigger promotion, which
moves the folio one generation newer and caps its refs at a lower
threshold, so a folio in a newer generation with lower refs is hotter than
a folio in an older generation with higher refs.  Gen aging then lowers
the logical refs without updating every folio.  Accesses from the page
table and from file descriptors are balanced with defined rules.

This limits protection from old hotness at close to no overhead, and
enhances MGLRU's ability to distinguish hotness levels over a much larger
range.

A folio's refs still map to a logarithmic tier just like before, but with
more formal bit definitions and more finely defined thresholds:
LRU_REFS_REFERENCED (1), LRU_REFS_WORKINGSET (2), LRU_REFS_PROTECTED (3),
and LRU_REFS_MAX (7).  The PID controller can still operate coherently
with the new FG promotion, but the protection ratio is softer (2:3 -> 1:2)
since proactive promotion is mostly good enough.  The setpoint now also
spans the cumulative mass of the tiers below the candidate instead of tier
0 alone, as the new thresholds are fallback tiers that a folio never falls
below.

By making use of the newly defined thresholds, simplify MGLRU's usage of
PG_workingset and PG_referenced: they become the low two bits of the refs
count, with the higher bits provided by LRU_REFS_MASK.  This reduces
MGLRU's original refs count bit usage by one, since only one extra bit is
now needed to record a max referenced count of 7.

This doesn't affect classical LRU, and it addresses several shortcomings
of MGLRU's file-descriptor cache protection:

- Long feedback loop: protection is only activated after enough re-faults,
  by which time the hot folios are already evicted, or no longer hot.

- Limited tier resolution: once the refs count saturated, MGLRU could no
  longer distinguish hotter folios within a tier.  PG_workingset also
  forces a folio to stay on tier 3.

- Eviction hotness reversion: because PID protection activates upon
  eviction and always targets the LRU tail, it tends to protect cold tail
  folios at the expense of hotter head folios.  Once the tail folios
  consume the PID protection budget, head folios lose their protection.

- Additionally, the PID cannot distinguish the access time of folios that
  share the same reference count, and there are only 4 tiers.

To achieve a frequency-guided framework, this commit introduces and
reworks the LRU_REFS related helpers and definitions. Most of the work
are done by the helpers below, check their inline comments for details.
They collect references from different access channels, following the
same rule but different context:

- folio_inc_lru_refs(): Called on any cache access (folio_mark_accessed)
  or page table access.  This is the main helper: it promotes folios
  according to their access frequency. This performs lazy promotion.

- folio_inc_lru_refs_walk(): Used by the PTE walk path during aging and by
  the batched look-around, both without the LRU lock.  This also performs
  lazy promotion.

- folio_inc_lru_refs_isolated(): Used by the rmap check before eviction.
  The folio is isolated and hence this doesn't perform promotion by
  itself; the folio will be added back to the right gen upon return
  according to the refs and PG_active placement hint.

Refaults restore the saved refs, capped at LRU_REFS_PROTECTED.
Fault-driven refaults with prior references also set PG_active, keeping
the stronger protection for page table access.

Consequently the placement hint for newly added file folios also uses
LRU_REFS_WORKINGSET instead of PG_referenced, so a folio accessed only
once now starts in the oldest generation rather than the second oldest.
The previous one-generation grace was an artifact of the fault bias which
is well described in the cover letter of this series, and it depended on
LRU drain timing.

PG_workingset and PG_referenced are no longer independent flags under
MGLRU, so existing raw folio_test_*() callers need to be adjusted, which
is covered by the following commits.

Tested-by: Andrew Morton <akpm@linux-foundation.org>
Reviewed-by: Kunwu Chan <kunwu.chan@gmail.com>
Tested-by: Wang Lian (ByteDance) <lianux.mm@gmail.com>
Tested-by: Tianyi Chen <hi@tychen.cc>
Signed-off-by: Kairui Song <kasong@tencent.com>
---
 include/linux/mm_inline.h | 107 +++++++++------
 include/linux/mmzone.h    | 126 +++++++++++------
 kernel/bounds.c           |   2 +-
 mm/folio.c                |  49 +------
 mm/vmscan.c               | 341 +++++++++++++++++++++++++++++++---------------
 mm/workingset.c           |  47 ++++---
 6 files changed, 416 insertions(+), 256 deletions(-)

diff --git a/include/linux/mm_inline.h b/include/linux/mm_inline.h
index a86f680f1257..3cdad5765b58 100644
--- a/include/linux/mm_inline.h
+++ b/include/linux/mm_inline.h
@@ -166,12 +166,14 @@ static inline int lru_hist_from_seq(unsigned long seq)
 	return seq % NR_HIST_GENS;
 }
 
-static inline int lru_tier_from_refs(int refs, bool workingset)
+static inline int lru_tier_from_refs(unsigned int refs)
 {
-	VM_WARN_ON_ONCE(refs > BIT(LRU_REFS_WIDTH));
-
-	/* see the comment on MAX_NR_TIERS */
-	return workingset ? MAX_NR_TIERS - 1 : order_base_2(refs);
+	/* The refs range must map into the tier index space. */
+	BUILD_BUG_ON(BIT(LRU_TIER_MAX) < LRU_REFS_MAX);
+	VM_WARN_ON_ONCE(refs > LRU_REFS_MAX);
+	if (refs < LRU_REFS_WORKINGSET)
+		return 0;
+	return fls(refs - 1);
 }
 
 /**
@@ -209,21 +211,24 @@ static inline int lru_get_gen_flags(unsigned long flags)
  * @flags: pointer to the folio flags
  * @refs: referenced / access count number, between 0 and LRU_REFS_MAX, inclusive.
  *
- * For MGLRU, PG_referenced holds the first ref, and the extra bits hold the
- * remaining refs. For classical LRU the extra bits are not used, so it can
- * also be seen as the refs count never exceeds 1. In both cases, refs == 1
- * means PG_referenced is set and the extra bits are zero, and refs == 0 means
- * PG_referenced and the extra bits are all unset.
+ * For MGLRU, PG_referenced, PG_workingset are used as the lower two bits of
+ * refs counter, and extra bits hold the remaining higher bits. For classical
+ * LRU the extra bits are not used, and the two flags have no direct
+ * relationship with each other, but this helper can still be used to sync
+ * them. For both cases, refs == 0 means these two flags and the extra bits
+ * are all unset. And refs == 1 / 2 / 3 means PG_referenced and PG_workingset
+ * encode the low two bits in binary order.
  */
 static inline void lru_set_refs_flags(unsigned long *flags, unsigned int refs)
 {
 	VM_WARN_ON_ONCE(refs > LRU_REFS_MAX);
-	BUILD_BUG_ON(LRU_REFS_MAX != (LRU_REFS_MASK >> LRU_REFS_PGOFF) + 1);
-
+	BUILD_BUG_ON(LRU_REFS_MASK & (BIT(PG_referenced) | BIT(PG_workingset)));
 	*flags &= ~LRU_REFS_FLAGS;
-	if (!refs)
-		return;
-	*flags |= (BIT(PG_referenced) | ((refs - 1UL) << LRU_REFS_PGOFF));
+	if (refs & BIT(0))
+		*flags |= BIT(PG_referenced);
+	if (refs & BIT(1))
+		*flags |= BIT(PG_workingset);
+	*flags |= ((unsigned long)refs >> 2) << LRU_REFS_PGOFF;
 }
 
 /**
@@ -232,22 +237,31 @@ static inline void lru_set_refs_flags(unsigned long *flags, unsigned int refs)
  *
  * Reads the LRU referenced count set by lru_set_refs_flags().
  */
-static inline int lru_get_refs_flags(unsigned long flags)
+static inline unsigned int lru_get_refs_flags(unsigned long flags)
 {
-	if (!(flags & BIT(PG_referenced)))
-		return 0;
-	/*
-	 * Return the total number of accesses including PG_referenced. Also see
-	 * the comment on LRU_REFS_FLAGS.
-	 */
-	return ((flags & LRU_REFS_MASK) >> LRU_REFS_PGOFF) + 1;
+	unsigned int refs;
+
+	/* Decode the per-folio reference state. */
+	refs  = !!(flags & BIT(PG_referenced));
+	refs |= !!(flags & BIT(PG_workingset)) << 1;
+	refs |= ((flags & LRU_REFS_MASK) >> LRU_REFS_PGOFF) << 2;
+	return refs;
 }
 
-static inline int folio_lru_refs(const struct folio *folio)
+static inline unsigned int folio_lru_refs(const struct folio *folio)
 {
 	return lru_get_refs_flags(READ_ONCE(*const_folio_flags(folio, 0)));
 }
 
+/*
+ * Referenced at least twice. Unlike lru_refs_is_active() this is not
+ * bounds-checked: folio_inc_lru_refs() evaluates refs unclamped.
+ */
+static inline bool lru_refs_is_workingset(unsigned int refs)
+{
+	return refs >= LRU_REFS_WORKINGSET;
+}
+
 static inline void folio_set_lru_refs(struct folio *folio, unsigned int refs)
 {
 	unsigned long new_flags, old_flags = READ_ONCE(*folio_flags(folio, 0));
@@ -260,14 +274,26 @@ static inline void folio_set_lru_refs(struct folio *folio, unsigned int refs)
 	} while (!try_cmpxchg(folio_flags(folio, 0), &old_flags, new_flags));
 }
 
+void folio_inc_lru_refs(struct folio *folio, unsigned int flags);
+
 static inline int folio_lru_gen(const struct folio *folio)
 {
 	return lru_get_gen_flags(READ_ONCE(*const_folio_flags(folio, 0)));
 }
 
+static inline bool lru_gen_is_old(struct lruvec *lruvec, int type, int gen)
+{
+	unsigned long min_seq = READ_ONCE(lruvec->lrugen.min_seq[type]);
+
+	/* The MIN_NR_GENS oldest generations, which eviction scans next */
+	BUILD_BUG_ON(MIN_NR_GENS != 2);
+	return gen == lru_gen_from_seq(min_seq) ||
+	       gen == lru_gen_from_seq(min_seq + 1);
+}
+
 static inline bool lru_gen_is_active(const struct lruvec *lruvec, int gen)
 {
-	unsigned long max_seq = lruvec->lrugen.max_seq;
+	unsigned long max_seq = READ_ONCE(lruvec->lrugen.max_seq);
 
 	VM_WARN_ON_ONCE(gen >= MAX_NR_GENS);
 
@@ -325,27 +351,28 @@ static inline unsigned long lru_gen_folio_seq(const struct lruvec *lruvec,
 	int age;
 	int type = folio_is_file_lru(folio);
 	const struct lru_gen_folio *lrugen = &lruvec->lrugen;
+	bool workingset = lru_refs_is_workingset(folio_lru_refs(folio));
 
 	/*
-	 * +-----------------------------------+-----------------------------------+
-	 * | Accessed through page tables and  | Accessed through file descriptors |
-	 * | promoted by folio_update_gen()    | and protected by folio_inc_gen()  |
-	 * +-----------------------------------+-----------------------------------+
-	 * | PG_active (set while isolated)    |                                   |
-	 * +-----------------+-----------------+-----------------+-----------------+
-	 * |  PG_workingset  |  PG_referenced  |  PG_workingset  |  LRU_REFS_FLAGS |
-	 * +-----------------------------------+-----------------------------------+
-	 * |<---------- MIN_NR_GENS ---------->|                                   |
-	 * |<---------------------------- MAX_NR_GENS ---------------------------->|
+	 * +------------------------------------------+------------------------------------------+
+	 * |     Accessed through page tables and     |     Accessed through file descriptors    |
+	 * | promoted by folio_inc_lru_refs_walk()    | protected by folio_inc_lru_refs/inc_gen  |
+	 * +------------------------------------------+------------------------------------------+
+	 * | PG_active (set at isolation or refault)  |                                          |
+	 * +--------------------+---------------------+--------------------+---------------------+
+	 * |     LRU_REFS_MAX   | LRU_REFS_WORKINGSET |    LRU_REFS_MAX    | LRU_REFS_WORKINGSET |
+	 * +------------------------------------------+------------------------------------------+
+	 * |<-------------- MIN_NR_GENS ------------->|                                          |
+	 * |<----------------------------------- MAX_NR_GENS ----------------------------------->|
 	 */
 	if (folio_test_active(folio))
-		age = MIN_NR_GENS - folio_test_workingset(folio);
+		age = MIN_NR_GENS - workingset;
 	else if ((!folio_is_file_lru(folio) && !folio_test_swapcache(folio)) ||
 		 (folio_test_reclaim(folio) &&
 		  (folio_test_dirty(folio) || folio_test_writeback(folio))))
 		age = MIN_NR_GENS;
 	else
-		age = MAX_NR_GENS - (folio_test_workingset(folio) || folio_test_referenced(folio));
+		age = MAX_NR_GENS - workingset;
 
 	return max(READ_ONCE(lrugen->max_seq) - age + 1, READ_ONCE(lrugen->min_seq[type]));
 }
@@ -366,6 +393,7 @@ static inline bool lru_gen_add_folio(struct lruvec *lruvec, struct folio *folio,
 	int zone = folio_zonenum(folio);
 	struct lru_gen_folio *lrugen = &lruvec->lrugen;
 
+	BUILD_BUG_ON(BIT(LRU_GEN_WIDTH - 1) != MAX_NR_GENS);
 	VM_WARN_ON_ONCE_FOLIO(gen != -1, folio);
 
 	if (folio_test_unevictable(folio) || !lrugen->enabled)
@@ -422,7 +450,6 @@ static inline bool lru_gen_del_folio(struct lruvec *lruvec, struct folio *folio,
  */
 static inline void folio_migrate_lru_refs(struct folio *new, const struct folio *old)
 {
-	BUILD_BUG_ON(LRU_REFS_MASK & BIT(PG_referenced));
 	folio_set_lru_refs(new, folio_lru_refs(old));
 }
 #else /* !CONFIG_LRU_GEN */
@@ -454,6 +481,10 @@ static inline bool lru_gen_del_folio(struct lruvec *lruvec, struct folio *folio,
 	return false;
 }
 
+static inline void folio_inc_lru_refs(struct folio *folio, unsigned int flags)
+{
+}
+
 static inline void folio_migrate_lru_refs(struct folio *new, const struct folio *old)
 {
 	if (folio_test_referenced(old))
diff --git a/include/linux/mmzone.h b/include/linux/mmzone.h
index 4e85bb520f76..27ba7fa6ddd6 100644
--- a/include/linux/mmzone.h
+++ b/include/linux/mmzone.h
@@ -453,57 +453,103 @@ enum lruvec_flags {
 #define MAX_NR_GENS		4U
 
 /*
- * Each generation is divided into multiple tiers. A folio accessed N times
- * through file descriptors is in tier order_base_2(N). A folio in the first
- * tier (N=0,1) is marked by PG_referenced unless it was faulted in through page
- * tables or read ahead. A folio in the last tier (MAX_NR_TIERS-1) is marked by
- * PG_workingset. A folio in any other tier (1<N<5) between the first and last
- * is marked by additional bits of LRU_REFS_WIDTH in folio->flags.
+ * Each generation is divided into multiple tiers. A folio's referenced
+ * count maps to a tier as shown below (with one extra refs bit):
  *
- * In contrast to moving across generations which requires the LRU lock, moving
- * across tiers only involves atomic operations on folio->flags and therefore
- * has a negligible cost in the buffered access path. In the eviction path,
- * comparisons of refaulted/(evicted+protected) from the first tier and the rest
- * infer whether folios accessed multiple times through file descriptors are
- * statistically hot and thus worth protecting.
+ * MGLRU (frequency guidance)
+ *  Refs  Tier  |- Refs: observed accesses, capped on promotion.
+ *   0      0   |- Mostly cold pages, readahead, etc. [1]
+ *   1      0   |= LRU_REFS_REFERENCED: Used at least once. [2]
+ * -WORKINGSET-+|- Workingset floor, unless explicitly reset. [3]
+ *   2      1<-+|= LRU_REFS_WORKINGSET: Classical workingset, accessed twice, protected. [4]
+ *   3      2   |- LRU_REFS_PROTECTED: Protected workingset, promoted pages capped at here. [5]
+ *   4      2   |
+ *   5      3   |- The tier here is MAX_NR_TIERS - 1
+ *   6      3   |
+ *   7      3   |= LRU_REFS_MAX: Promotion candidate. [6]
+ * -PROMOTION->-/
  *
- * MAX_NR_TIERS is set to 4 so that the multi-gen LRU can support twice the
- * number of categories of the active/inactive LRU when keeping track of
- * accesses through file descriptors. This uses MAX_NR_TIERS-2 spare bits in
- * folio->flags, masked by LRU_REFS_MASK.
+ * Ideally each tier holds folios of similar access patterns: lower tiers
+ * are less important and evicted faster.  A page's reference count and
+ * tier are capped when it changes generation, preventing it from
+ * dominating the new generation based on old-generation access history.
+ * The generation and refs together represent logical refs: hotness relative
+ * to the aging window. Promotion moves the folio forward and caps refs;
+ * gen aging then lowers logical refs even without updating the stored count.
+ * This avoids a separate full-cache aging walk to reduce old hotness.
+ *
+ * Refs tracks accesses from two sources: page table (lazily collected by
+ * the page table aging walk or rmap eviction lookup) and file descriptors
+ * (by folio_mark_accessed).  Page table accesses promote more readily
+ * because the accessed bit is sticky (undercounts repeated accesses),
+ * passively collected, and page faults are generally more important as
+ * userspace does not expect a memory access to block on reclaim.  Both
+ * access types increment refs by one; the result is capped at
+ * LRU_REFS_PROTECTED on promotion or deferral, or LRU_REFS_MAX otherwise.
+ *
+ * 1. Tier is fls(N-1) for N > 1, 0 otherwise.  Folios with zero
+ *    accesses (refs == 0) are generally cold, e.g. readahead folios.
+ *
+ * 2. Folios accessed once stay on tier 0: one-time usage does not
+ *    qualify for tier protection. A second access can advance the folio,
+ *    aligning with classical LRU's use-twice threshold.  A page table
+ *    access that brings refs to LRU_REFS_WORKINGSET promotes to the
+ *    latest gen. A file access at that refs count only defers eviction
+ *    from the tail gens of its type.
+ *
+ * 3. Folios accessed at least twice are considered workingset.  This
+ *    mostly aligns with classical LRU: at least one I/O is saved by
+ *    keeping them in memory. Unless explicitly reset, these folios stay
+ *    at or above tier 1 (the workingset floor), so tier 0 stays a clean tier
+ *    for cold cache while tier 1 serves as the fallback line for
+ *    actually reused or historically hot folios.
+ *
+ * 4. Starting from tier 1, PID protection sacrifices lower tiers to
+ *    protect higher tiers by comparing refault rates for long-term
+ *    accuracy, and caps higher refs to LRU_REFS_WORKINGSET.  Rejected
+ *    folios also keep at most that count on putback, allowing further
+ *    accesses to distinguish their hotness again.
+ *
+ * 5. Pages beyond the ordinary workingset tier form new tiers for the
+ *    PID controller to protect differently.  Folios at or above this
+ *    level are capped at LRU_REFS_PROTECTED on promotion or deferral,
+ *    and at LRU_REFS_WORKINGSET under PID protection in the oldest
+ *    generation, where they represent a historical workingset.
+ *
+ * 6. A further cache access at LRU_REFS_MAX advances an older folio by one
+ *    generation, with refs capped to LRU_REFS_PROTECTED. Folios already in
+ *    the newest generation just saturate their refs.
+ *
+ * Tiering uses PG_referenced and PG_workingset as the lower two bits,
+ * and the bits masked by LRU_REFS_MASK as the higher bits, so the refs
+ * count ranges from 0 to LRU_REFS_MAX.
+ *
+ * Cold hints can reset refs with lru_gen_clear_refs(). Refault restores
+ * its referenced count, capped at LRU_REFS_PROTECTED, which aligns with
+ * promotion.  Fault-driven refaults of previous workingset folios set
+ * PG_active, so they are placed in the latest gen.
+ *
+ * MAX_NR_TIERS is set to 4 so that the multi-gen LRU can support twice
+ * the number of categories of the active/inactive LRU.
  */
 #define MAX_NR_TIERS		4U
 #define LRU_TIER_MIN		0U
 #define LRU_TIER_MAX		(MAX_NR_TIERS - 1)
 
+/* Access source flags for folio_inc_lru_refs() */
+#define LRU_REF_MAPPED		0x1U
+#define LRU_REF_EXEC		0x2U
+
+#define LRU_REFS_REFERENCED	0x1
+#define LRU_REFS_WORKINGSET	0x2
+#define LRU_REFS_PROTECTED	0x3
+
 #ifndef __GENERATING_BOUNDS_H
 
 #define LRU_GEN_MASK		((BIT(LRU_GEN_WIDTH) - 1) << LRU_GEN_PGOFF)
 #define LRU_REFS_MASK		((BIT(LRU_REFS_WIDTH) - 1) << LRU_REFS_PGOFF)
-#define LRU_REFS_MAX		BIT(LRU_REFS_WIDTH)
-
-/*
- * For folios accessed multiple times through file descriptors,
- * lru_gen_inc_refs() sets additional bits of LRU_REFS_WIDTH in folio->flags
- * after PG_referenced, then PG_workingset after LRU_REFS_WIDTH. After all its
- * bits are set, i.e., LRU_REFS_FLAGS|BIT(PG_workingset), a folio is lazily
- * promoted into the second oldest generation in the eviction path. And when
- * folio_inc_gen() does that, it clears LRU_REFS_FLAGS so that
- * lru_gen_inc_refs() can start over. Note that for this case, LRU_REFS_MASK is
- * only valid when PG_referenced is set.
- *
- * For folios accessed multiple times through page tables, folio_update_gen()
- * from a page table walk or lru_gen_set_refs() from a rmap walk sets
- * PG_referenced after the accessed bit is cleared for the first time.
- * Thereafter, those two paths set PG_workingset and promote folios to the
- * youngest generation. Like folio_inc_gen(), folio_update_gen() also clears
- * PG_referenced. Note that for this case, LRU_REFS_MASK is not used.
- *
- * For both cases above, after PG_workingset is set on a folio, it remains until
- * this folio is either reclaimed, or "deactivated" by lru_gen_clear_refs(). It
- * can be set again if lru_gen_test_recent() returns true upon a refault.
- */
-#define LRU_REFS_FLAGS		(LRU_REFS_MASK | BIT(PG_referenced))
+#define LRU_REFS_FLAGS		(LRU_REFS_MASK | BIT(PG_referenced) | BIT(PG_workingset))
+#define LRU_REFS_MAX		(BIT(LRU_REFS_WIDTH + 2) - 1)
 
 struct lruvec;
 struct page_vma_mapped_walk;
diff --git a/kernel/bounds.c b/kernel/bounds.c
index 02b619eb6106..06a034713b5d 100644
--- a/kernel/bounds.c
+++ b/kernel/bounds.c
@@ -25,7 +25,7 @@ int main(void)
 	DEFINE(SPINLOCK_SIZE, sizeof(spinlock_t));
 #ifdef CONFIG_LRU_GEN
 	DEFINE(LRU_GEN_WIDTH, order_base_2(MAX_NR_GENS + 1));
-	DEFINE(__LRU_REFS_WIDTH, MAX_NR_TIERS - 2);
+	DEFINE(__LRU_REFS_WIDTH, MAX_NR_TIERS - 3);
 #else
 	DEFINE(LRU_GEN_WIDTH, 0);
 	DEFINE(__LRU_REFS_WIDTH, 0);
diff --git a/mm/folio.c b/mm/folio.c
index 789875095f13..c3d0b73f4cf5 100644
--- a/mm/folio.c
+++ b/mm/folio.c
@@ -378,32 +378,6 @@ static void __lru_cache_activate_folio(struct folio *folio)
 
 #ifdef CONFIG_LRU_GEN
 
-static void lru_gen_inc_refs(struct folio *folio)
-{
-	unsigned long new_flags, old_flags = READ_ONCE(*folio_flags(folio, 0));
-	int refs;
-
-	if (folio_test_unevictable(folio))
-		return;
-
-	/* see the comment on LRU_REFS_FLAGS */
-	if (!folio_lru_refs(folio)) {
-		folio_set_lru_refs(folio, 1);
-		return;
-	}
-
-	do {
-		new_flags = old_flags;
-		refs = lru_get_refs_flags(old_flags);
-		if (refs == LRU_REFS_MAX) {
-			if (!folio_test_workingset(folio))
-				folio_set_workingset(folio);
-			return;
-		}
-		lru_set_refs_flags(&new_flags, refs + 1);
-	} while (!try_cmpxchg(folio_flags(folio, 0), &old_flags, new_flags));
-}
-
 static bool lru_gen_clear_refs(struct folio *folio)
 {
 	int gen = folio_lru_gen(folio);
@@ -414,7 +388,6 @@ static bool lru_gen_clear_refs(struct folio *folio)
 		return true;
 
 	folio_set_lru_refs(folio, 0);
-	folio_clear_workingset(folio);
 
 	rcu_read_lock();
 	seq = READ_ONCE(folio_lruvec(folio)->lrugen.min_seq[type]);
@@ -425,10 +398,6 @@ static bool lru_gen_clear_refs(struct folio *folio)
 
 #else /* !CONFIG_LRU_GEN */
 
-static void lru_gen_inc_refs(struct folio *folio)
-{
-}
-
 static bool lru_gen_clear_refs(struct folio *folio)
 {
 	return false;
@@ -454,7 +423,8 @@ void folio_mark_accessed(struct folio *folio)
 	if (folio_test_dropbehind(folio))
 		return;
 	if (lru_gen_enabled()) {
-		lru_gen_inc_refs(folio);
+		if (!folio_test_unevictable(folio))
+			folio_inc_lru_refs(folio, 0);
 		return;
 	}
 
@@ -500,21 +470,6 @@ void folio_add_lru(struct folio *folio)
 			folio_test_unevictable(folio), folio);
 	VM_BUG_ON_FOLIO(folio_test_lru(folio), folio);
 
-	/*
-	 * For refaulted workingset folios, set PG_active so they
-	 * can be added to active generations.
-	 * For prefaulted file folios, folio_mark_accessed() sets
-	 * PG_referenced so lru_gen_folio_seq() places them into
-	 * the second oldest generation.
-	 */
-	if (lru_gen_enabled() && !folio_test_unevictable(folio) &&
-	    lru_gen_in_fault() && !(current->flags & PF_MEMALLOC)) {
-		if (folio_test_workingset(folio))
-			folio_set_active(folio);
-		else if (!folio_test_referenced(folio))
-			folio_mark_accessed(folio);
-	}
-
 	folio_batch_add_and_move(folio, lru_add);
 }
 EXPORT_SYMBOL(folio_add_lru);
diff --git a/mm/vmscan.c b/mm/vmscan.c
index e6dd61583607..b3c4b65028c8 100644
--- a/mm/vmscan.c
+++ b/mm/vmscan.c
@@ -818,38 +818,204 @@ enum folio_references {
 };
 
 #ifdef CONFIG_LRU_GEN
+/******************************************************************************
+ *                     Referenced count feedback
+ ******************************************************************************/
+
 /*
- * Only used on a mapped folio in the eviction (rmap walk) path, where promotion
- * needs to be done by taking the folio off the LRU list and then adding it back
- * with PG_active set. In contrast, the aging (page table walk) path uses
- * folio_update_gen().
+ * The folio_inc_lru_refs{_*} helpers below collect the referenced info
+ * (hotness) from the page table walker, the rmap walk upon eviction, the
+ * rmap look-around, and file descriptors (folio_mark_accessed).
+ *
+ * Each access adds one to the refs count, capped at LRU_REFS_MAX.  A
+ * fresh folio's refs go from 0 to LRU_REFS_REFERENCED to
+ * LRU_REFS_WORKINGSET, and so on.
+ *
+ * Mapped access (PT, LRU_REF_MAPPED) has a higher priority since the
+ * accessed bit is sticky (it under-counts repeated accesses) and a fault
+ * could be more costly than FD I/O. So, a page table access always
+ * promotes a folio on an expiring gen by at least one gen. And starting
+ * from the second access (refs == LRU_REFS_WORKINGSET), it moves the folio
+ * to the newest gen. Executable file folios promote on their first access
+ * to avoid I/O thrashing. The refs are increased at a normal pace though.
+ *
+ * File descriptor accesses (FD) are a precise access method. So, only
+ * since the second access (refs == LRU_REFS_WORKINGSET), every access
+ * will promote a folio if the folio is on an expiring gen (close to
+ * min_seq). If the folio is not on an expiring gen, it will be promoted
+ * when its refs exceed LRU_REFS_MAX; the newest gen just saturates.
+ *
+ * Promotion, regarding the source, always caps the refs at
+ * LRU_REFS_PROTECTED, so folios in a newer gen start at or below the
+ * protected tier, and folios with lower refs in a newer gen are logically
+ * hotter than a folio in an older gen with higher refs.
+ *
+ * A folio with refs at or above LRU_REFS_WORKINGSET is considered a
+ * workingset, and the tiers starting there engage PID protection.
+ * PID-protected folios (folio_inc_gen) are capped at
+ * LRU_REFS_WORKINGSET independently to make full use of tiering.
  */
-static bool lru_gen_set_refs(struct folio *folio, const vma_flags_t *vma_flags)
-{
-	/* see the comment on LRU_REFS_FLAGS */
-	if (!folio_test_referenced(folio) && !folio_test_workingset(folio)) {
-		/* Activate file-backed executable folios after first usage. */
-		if (is_exec_file_folio(folio, vma_flags)) {
-			folio_set_workingset(folio);
-			folio_set_lru_refs(folio, 0);
-			return true;
+
+/**
+ * folio_inc_lru_refs - Update the folio's LRU refs and lazily promote it.
+ * @folio: The folio being accessed.
+ * @flags: The type of ref: FD access, or mapped access optionally with
+ * executable access.
+ *
+ * Used by both cache access (flags == 0) and page table access (flags ==
+ * LRU_REF_MAPPED, optionally with LRU_REF_EXEC).
+ * Context: The caller must keep the folio alive by a reference or the page
+ * table lock of a mapped folio.
+ */
+void folio_inc_lru_refs(struct folio *folio, unsigned int flags)
+{
+	int max_gen;
+	int type, refs, old_gen, gen;
+	unsigned long new_flags, old_flags, max_seq;
+	struct lru_gen_folio *lrugen;
+	struct lruvec *lruvec = NULL;
+
+	type = folio_is_file_lru(folio);
+	old_flags = READ_ONCE(*folio_flags(folio, 0));
+	do {
+		new_flags = old_flags;
+		old_gen = lru_get_gen_flags(old_flags);
+		refs = lru_get_refs_flags(old_flags) + 1;
+		gen = old_gen;
+		if (old_gen < 0)
+			goto out;
+		/*
+		 * Lock the lruvec if the folio is on-list. We are already
+		 * doing lazy promotion so in theory we don't need this,
+		 * but for now, concurrent aging would still corrupt the
+		 * size counters.  This is a temporary limitation and
+		 * will be lifted very soon, so the lock here is not a
+		 * performance concern.
+		 */
+		if (!lruvec) {
+			lruvec = lruvec_live_lock_irq(folio_lruvec(folio));
+			lrugen = &lruvec->lrugen;
 		}
+		max_seq = READ_ONCE(lrugen->max_seq);
+		max_gen = lru_gen_from_seq(max_seq);
+		if (old_gen == max_gen)
+			goto out;
 
-		folio_set_lru_refs(folio, 1);
-		return false;
-	}
+		if (flags & (LRU_REF_MAPPED | LRU_REF_EXEC)) {
+			/* Promote second page table access or executable */
+			if (refs > LRU_REFS_REFERENCED || flags & LRU_REF_EXEC)
+				gen = max_gen;
+			/* First access only defers eviction of an old generation */
+			else if (lru_gen_is_old(lruvec, type, old_gen))
+				gen = (old_gen + 1) % MAX_NR_GENS;
+			refs = min(refs, LRU_REFS_PROTECTED);
+		} else if (refs > LRU_REFS_MAX) {
+			/* LRU refs counting overflow, bump the gen */
+			gen = (old_gen + 1) % MAX_NR_GENS;
+			refs = LRU_REFS_PROTECTED;
+		} else if (lru_gen_is_old(lruvec, type, old_gen) &&
+			   lru_refs_is_workingset(refs)) {
+			/* Defer eviction of just accessed workingset */
+			gen = (old_gen + 1) % MAX_NR_GENS;
+			refs = min(refs, LRU_REFS_PROTECTED);
+		}
+out:
+		refs = min(refs, LRU_REFS_MAX);
+		lru_set_refs_flags(&new_flags, refs);
+		if (gen != old_gen)
+			lru_set_gen_flags(&new_flags, gen);
+		if (new_flags == old_flags)
+			break;
+	} while (!try_cmpxchg(folio_flags(folio, 0), &old_flags, new_flags));
 
-	/* Promote on second access */
-	if (folio_lru_refs(folio) > 1) {
-		folio_set_workingset(folio);
-		folio_set_lru_refs(folio, 0);
-	} else {
-		folio_mark_accessed(folio);
-	}
-	return true;
+	if (gen != old_gen)
+		lru_gen_update_size(lruvec, folio, old_gen, gen);
+	if (lruvec)
+		lruvec_unlock_irq(lruvec);
+}
+
+/**
+ * folio_inc_lru_refs_walk - Update the folio's LRU refs and lazily promote it.
+ * @folio: The folio.
+ * @lruvec: The lruvec the folio belongs to.
+ * @vma_flags: The flags of the VMA being walked.
+ * @new_gen: The gen the folio is moved to; may be unchanged.
+ * @type: Returns the folio's type: file or anon.
+ *
+ * Similar to folio_inc_lru_refs(), but for the page table walker and the
+ * look-around. The LRU size accounting is batched by the caller for
+ * better performance.
+ *
+ * Return: The old generation the folio belongs to if the folio is still
+ * on the LRU and not in the newest generation, or -1 otherwise. -1 means
+ * the folio should not be promoted and @new_gen is not set.
+ */
+static int folio_inc_lru_refs_walk(struct folio *folio, struct lruvec *lruvec,
+				   const vma_flags_t *vma_flags,
+				   int *new_gen, int *type)
+{
+	unsigned long new_flags, old_flags = READ_ONCE(*folio_flags(folio, 0));
+	int refs, gen, max_gen, ret;
+	unsigned long max_seq;
+
+	do {
+		max_seq = READ_ONCE(lruvec->lrugen.max_seq);
+		max_gen = lru_gen_from_seq(max_seq);
+		gen = lru_get_gen_flags(old_flags);
+		refs = lru_get_refs_flags(old_flags) + 1;
+		*type = folio_flags_is_file_lru(&old_flags);
+		new_flags = old_flags;
+
+		if (gen >= 0 && gen != max_gen) {
+			ret = gen;
+			/* Promote second page table access or executable */
+			if (lru_refs_is_workingset(refs) || is_exec_file_folio(folio, vma_flags))
+				*new_gen = max_gen;
+			/* First access only defers eviction of an old generation */
+			else if (lru_gen_is_old(lruvec, *type, gen))
+				*new_gen = (gen + 1) % MAX_NR_GENS;
+			else
+				*new_gen = gen;
+			lru_set_gen_flags(&new_flags, *new_gen);
+			lru_set_refs_flags(&new_flags, min(refs, LRU_REFS_PROTECTED));
+		} else {
+			ret = -1;
+			lru_set_refs_flags(&new_flags, min(refs, LRU_REFS_MAX));
+		}
+		if (new_flags == old_flags)
+			break;
+	} while (!try_cmpxchg(folio_flags(folio, 0), &old_flags, new_flags));
+
+	return ret;
+}
+
+/**
+ * folio_inc_lru_refs_isolated - Update the folio's LRU refs
+ * @folio: The folio.
+ * @vma_flags: The flags of all the VMAs that referenced the folio.
+ *
+ * Similar to folio_inc_lru_refs(), but the folio is isolated.  Only used
+ * on mapped folios upon the final eviction RMAP walk. Since the folio is
+ * isolated, folio promotion needs to be done by the caller.
+ *
+ * Return: true if the caller should activate the folio, false to put it
+ * back in an older gen and wait for a second chance.
+ */
+static bool folio_inc_lru_refs_isolated(struct folio *folio, const vma_flags_t *vma_flags)
+{
+	unsigned long new_flags, old_flags = READ_ONCE(*folio_flags(folio, 0));
+	unsigned int refs;
+
+	do {
+		new_flags = old_flags;
+		refs = lru_get_refs_flags(old_flags) + 1;
+		lru_set_refs_flags(&new_flags, min(refs, LRU_REFS_PROTECTED));
+	} while (!try_cmpxchg(folio_flags(folio, 0), &old_flags, new_flags));
+	/* Promote second page table access or executable */
+	return lru_refs_is_workingset(refs) || is_exec_file_folio(folio, vma_flags);
 }
 #else
-static bool lru_gen_set_refs(struct folio *folio, const vma_flags_t *vma_flags)
+static bool folio_inc_lru_refs_isolated(struct folio *folio, const vma_flags_t *vma_flags)
 {
 	return false;
 }
@@ -884,7 +1050,8 @@ static enum folio_references folio_check_references(struct folio *folio,
 		if (!referenced_ptes)
 			return FOLIOREF_RECLAIM;
 
-		return lru_gen_set_refs(folio, &vma_flags) ? FOLIOREF_ACTIVATE : FOLIOREF_KEEP;
+		return folio_inc_lru_refs_isolated(folio, &vma_flags) ?
+		       FOLIOREF_ACTIVATE : FOLIOREF_KEEP;
 	}
 
 	referenced_folio = folio_test_clear_referenced(folio);
@@ -3218,9 +3385,9 @@ static bool iterate_mm_list_nowalk(struct lruvec *lruvec, unsigned long seq)
  * P term over the generations previously evicted, using the smoothing factor
  * 1/2; the D term isn't supported.
  *
- * The setpoint (SP) is always the first tier of one type; the process variable
- * (PV) is either any tier of the other type or any other tier of the same
- * type.
+ * To select a tier to protect, the setpoint (SP) is the cumulative tiers below
+ * it and the process variable (PV) is the tier itself. Anon/file scan budgets
+ * are handled separately by lru_gen_balance_scan().
  *
  * The error is the difference between the SP and the PV; the correction is to
  * turn off protection when SP>PV or turn on protection when SP<PV.
@@ -3308,52 +3475,15 @@ static bool positive_ctrl_err(struct ctrl_pos *sp, struct ctrl_pos *pv)
  *                          the aging
  ******************************************************************************/
 
-/* promote pages accessed through page tables */
-static int folio_update_gen(struct folio *folio, int new_gen, int *type,
-			    const vma_flags_t *vma_flags)
-{
-	unsigned long new_flags, old_flags = READ_ONCE(*folio_flags(folio, 0));
-	int old_gen;
-
-	/*
-	 * See the comment on LRU_REFS_FLAGS, and activate file-backed
-	 * executable folios after first usage to avoid typical IO
-	 * thrashing from reclaiming.
-	 */
-	if (!folio_test_referenced(folio) && !folio_test_workingset(folio) &&
-	    !is_exec_file_folio(folio, vma_flags)) {
-		folio_set_lru_refs(folio, 1);
-		return -1;
-	}
-
-	do {
-		old_gen = lru_get_gen_flags(old_flags);
-		new_flags = old_flags;
-
-		/* lru_gen_del_folio() has isolated this page? */
-		if (old_gen < 0)
-			break;
-
-		lru_set_gen_flags(&new_flags, new_gen);
-		lru_set_refs_flags(&new_flags, 0);
-		new_flags |= BIT(PG_workingset);
-		if (new_flags == old_flags)
-			break;
-	} while (!try_cmpxchg(folio_flags(folio, 0), &old_flags, new_flags));
-
-	*type = folio_flags_is_file_lru(&old_flags);
-	return old_gen;
-}
-
 static int __folio_inc_gen(struct folio *folio, int old_gen, bool *increased)
 {
 	unsigned long new_flags, old_flags = READ_ONCE(*folio_flags(folio, 0));
-	int new_gen;
+	int refs, new_gen;
 
 	do {
 		new_gen = lru_get_gen_flags(old_flags);
 
-		/* folio_update_gen() has promoted this page? */
+		/* folio_inc_lru_refs() has promoted this page? */
 		if (new_gen >= 0 && new_gen != old_gen) {
 			if (increased)
 				*increased = false;
@@ -3362,9 +3492,9 @@ static int __folio_inc_gen(struct folio *folio, int old_gen, bool *increased)
 
 		new_flags = old_flags;
 		new_gen = (old_gen + 1) % MAX_NR_GENS;
-
+		refs = lru_get_refs_flags(old_flags);
 		lru_set_gen_flags(&new_flags, new_gen);
-		lru_set_refs_flags(&new_flags, 0);
+		lru_set_refs_flags(&new_flags, min(refs, LRU_REFS_WORKINGSET));
 	} while (!try_cmpxchg(folio_flags(folio, 0), &old_flags, new_flags));
 
 	if (increased)
@@ -3372,7 +3502,7 @@ static int __folio_inc_gen(struct folio *folio, int old_gen, bool *increased)
 	return new_gen;
 }
 
-/* protect pages accessed multiple times through file descriptors */
+/* protect pages selected by the tier PID controller */
 static int folio_inc_gen(struct lruvec *lruvec, struct folio *folio, int old_gen)
 {
 	int new_gen;
@@ -3381,6 +3511,7 @@ static int folio_inc_gen(struct lruvec *lruvec, struct folio *folio, int old_gen
 	new_gen = __folio_inc_gen(folio, old_gen, &gen_increased);
 	if (gen_increased)
 		lru_gen_update_size(lruvec, folio, old_gen, new_gen);
+
 	return new_gen;
 }
 
@@ -3575,25 +3706,25 @@ static void walk_update_folio(struct lru_gen_mm_walk *walk, struct vm_area_struc
 		struct lruvec *lruvec, struct folio *folio, bool dirty)
 {
 	int new_gen, old_gen, type;
+	unsigned int flags = LRU_REF_MAPPED;
 
 	if (!folio)
 		return;
 
-	new_gen = lru_gen_from_seq(READ_ONCE(lruvec->lrugen.max_seq));
-
 	if (dirty && !folio_test_dirty(folio) &&
 	    !(folio_test_anon(folio) && folio_test_swapbacked(folio) &&
 	      !folio_test_swapcache(folio)))
 		folio_mark_dirty(folio);
 
 	if (walk) {
-		old_gen = folio_update_gen(folio, new_gen, &type, &vma->flags);
+		old_gen = folio_inc_lru_refs_walk(folio, lruvec, &vma->flags,
+						  &new_gen, &type);
 		if (old_gen >= 0 && old_gen != new_gen)
 			update_batch_size(walk, folio, old_gen, new_gen, type);
-	} else if (lru_gen_set_refs(folio, &vma->flags)) {
-		old_gen = folio_lru_gen(folio);
-		if (old_gen >= 0 && old_gen != new_gen)
-			folio_activate(folio);
+	} else {
+		if (is_exec_file_folio(folio, &vma->flags))
+			flags |= LRU_REF_EXEC;
+		folio_inc_lru_refs(folio, flags);
 	}
 }
 
@@ -3999,8 +4130,8 @@ static bool inc_min_seq(struct lruvec *lruvec, int type, int swappiness)
 		while (pos != head) {
 			struct folio *folio = list_entry(pos, struct folio, lru);
 			long nr_pages = folio_nr_pages(folio);
-			int refs = folio_lru_refs(folio);
-			bool workingset = folio_test_workingset(folio);
+			unsigned int refs = folio_lru_refs(folio);
+			int tier = lru_tier_from_refs(refs);
 			bool gen_increased;
 
 			VM_WARN_ON_ONCE_FOLIO(folio_test_unevictable(folio), folio);
@@ -4020,13 +4151,8 @@ static bool inc_min_seq(struct lruvec *lruvec, int type, int swappiness)
 				delta += nr_pages;
 				batch_end = &folio->lru;
 
-				/* don't count the workingset being lazily promoted */
-				if (refs + workingset != BIT(LRU_REFS_WIDTH) + 1) {
-					int tier = lru_tier_from_refs(refs, workingset);
-
-					WRITE_ONCE(lrugen->protected[hist][type][tier],
-						   lrugen->protected[hist][type][tier] + nr_pages);
-				}
+				WRITE_ONCE(lrugen->protected[hist][type][tier],
+					   lrugen->protected[hist][type][tier] + nr_pages);
 			} else {
 				flush_lru_batch(head, &batch_end, target_list);
 				list_move(&folio->lru, &lrugen->folios[new_gen][type][zone]);
@@ -4756,9 +4882,8 @@ static bool sort_folio(struct lruvec *lruvec, struct folio *folio, struct scan_c
 	int type = folio_is_file_lru(folio);
 	int zone = folio_zonenum(folio);
 	int delta = folio_nr_pages(folio);
-	int refs = folio_lru_refs(folio);
-	bool workingset = folio_test_workingset(folio);
-	int tier = lru_tier_from_refs(refs, workingset);
+	unsigned int refs = folio_lru_refs(folio);
+	int tier = lru_tier_from_refs(refs);
 	struct lru_gen_folio *lrugen = &lruvec->lrugen;
 
 	VM_WARN_ON_ONCE_FOLIO(gen >= MAX_NR_GENS, folio);
@@ -4783,17 +4908,15 @@ static bool sort_folio(struct lruvec *lruvec, struct folio *folio, struct scan_c
 		return false;
 
 	/* protected */
-	if (tier > tier_idx || refs + workingset == BIT(LRU_REFS_WIDTH) + 1) {
+	if (tier > tier_idx) {
+		int hist = lru_hist_from_seq(lrugen->min_seq[type]);
+
 		gen = folio_inc_gen(lruvec, folio, min_gen);
 		list_move(&folio->lru, &lrugen->folios[gen][type][zone]);
 
-		/* don't count the workingset being lazily promoted */
-		if (refs + workingset != BIT(LRU_REFS_WIDTH) + 1) {
-			int hist = lru_hist_from_seq(lrugen->min_seq[type]);
+		WRITE_ONCE(lrugen->protected[hist][type][tier],
+			   lrugen->protected[hist][type][tier] + delta);
 
-			WRITE_ONCE(lrugen->protected[hist][type][tier],
-				   lrugen->protected[hist][type][tier] + delta);
-		}
 		return true;
 	}
 
@@ -4823,10 +4946,6 @@ static bool isolate_folio(struct lruvec *lruvec, struct folio *folio, struct sca
 		return false;
 	}
 
-	/* see the comment on LRU_REFS_FLAGS */
-	if (!folio_test_referenced(folio))
-		folio_set_lru_refs(folio, 0);
-
 	success = lru_gen_del_folio(lruvec, folio, true);
 	VM_WARN_ON_ONCE_FOLIO(!success, folio);
 
@@ -4938,13 +5057,14 @@ static int get_tier_idx(struct lruvec *lruvec, int type)
 	struct ctrl_pos sp, pv;
 
 	/*
-	 * To leave a margin for fluctuations, use a larger gain factor (2:3).
-	 * This value is chosen because any other tier would have at least twice
-	 * as many refaults as the first tier.
+	 * To leave a margin for fluctuations, use a larger gain factor (1:2).
+	 * Stop at the first tier whose refault rate is clearly worse than
+	 * that of the cumulative mass of the tiers below it; the PID
+	 * protects the tiers above it.
 	 */
-	read_ctrl_pos(lruvec, type, LRU_TIER_MIN, LRU_TIER_MIN, 2, &sp);
 	for (tier = LRU_TIER_MIN + 1; tier <= LRU_TIER_MAX; tier++) {
-		read_ctrl_pos(lruvec, type, tier, tier, 3, &pv);
+		read_ctrl_pos(lruvec, type, LRU_TIER_MIN, tier - 1, 1, &sp);
+		read_ctrl_pos(lruvec, type, tier, tier, 2, &pv);
 		if (!positive_ctrl_err(&sp, &pv))
 			break;
 	}
@@ -5122,12 +5242,11 @@ static int evict_folios(unsigned long nr_to_scan, struct lruvec *lruvec,
 		}
 
 		/*
-		 * See the comments on LRU_REFS_FLAGS.
-		 *
-		 * The rejected folios are never added to the oldest generation,
-		 * so this effectively promotes them by at least one generation.
+		 * Putback keeps rejected folios beyond scanned_seq when possible.
+		 * PG_active and refs are placement hints; cap refs to retain
+		 * workingset history without carrying a high tier into the new gen.
 		 */
-		folio_set_lru_refs(folio, 0);
+		folio_set_lru_refs(folio, min(folio_lru_refs(folio), LRU_REFS_WORKINGSET));
 	}
 
 	move_folios_to_lru(&list, scanned_seq, false);
diff --git a/mm/workingset.c b/mm/workingset.c
index 87d5e55dd684..eea711057c72 100644
--- a/mm/workingset.c
+++ b/mm/workingset.c
@@ -188,6 +188,12 @@
 #define EVICTION_SHIFT_ANON	(EVICTION_SHIFT + SWAP_COUNT_SHIFT)
 #define EVICTION_MASK	(~0UL >> EVICTION_SHIFT)
 #define EVICTION_MASK_ANON	(~0UL >> EVICTION_SHIFT_ANON)
+/*
+ * LRU refs uses LRU_REFS_WIDTH + 2 bits, the 2 bits being PG_workingset
+ * and PG_referenced.  The lowest bit is recorded in the workingset field
+ * of the shadow entry (to reuse pack_shadow()).
+ */
+#define LRU_REFS_BITS ((LRU_REFS_WIDTH + 2) - 1)
 
 /*
  * Eviction timestamps need to be able to cover the full range of
@@ -241,14 +247,13 @@ static void *lru_gen_eviction(struct folio *folio)
 	struct lru_gen_folio *lrugen;
 	int type = folio_is_file_lru(folio);
 	int delta = folio_nr_pages(folio);
-	int refs = folio_lru_refs(folio);
-	bool workingset = folio_test_workingset(folio);
-	int tier = lru_tier_from_refs(refs, workingset);
+	unsigned int refs = folio_lru_refs(folio);
+	int tier = lru_tier_from_refs(refs);
 	struct mem_cgroup *memcg;
 	struct pglist_data *pgdat = folio_pgdat(folio);
 	unsigned short memcg_id;
 
-	BUILD_BUG_ON(LRU_GEN_WIDTH + LRU_REFS_WIDTH >
+	BUILD_BUG_ON(LRU_GEN_WIDTH + LRU_REFS_BITS >
 		     BITS_PER_LONG - max(EVICTION_SHIFT, EVICTION_SHIFT_ANON));
 
 	rcu_read_lock();
@@ -256,14 +261,14 @@ static void *lru_gen_eviction(struct folio *folio)
 	lruvec = mem_cgroup_lruvec(memcg, pgdat);
 	lrugen = &lruvec->lrugen;
 	min_seq = READ_ONCE(lrugen->min_seq[type]);
-	token = (min_seq << LRU_REFS_WIDTH) | max(refs - 1, 0);
+	token = (min_seq << LRU_REFS_BITS) | refs >> 1;
 
 	hist = lru_hist_from_seq(min_seq);
 	atomic_long_add(delta, &lrugen->evicted[hist][type][tier]);
 	memcg_id = mem_cgroup_private_id(memcg);
 	rcu_read_unlock();
 
-	return pack_shadow(memcg_id, pgdat, token, workingset, type);
+	return pack_shadow(memcg_id, pgdat, token, refs & 1, type);
 }
 
 /*
@@ -284,9 +289,9 @@ static bool lru_gen_test_recent(void *shadow, struct lruvec **lruvec,
 	*lruvec = mem_cgroup_lruvec(memcg, pgdat);
 
 	max_seq = READ_ONCE((*lruvec)->lrugen.max_seq);
-	max_seq &= (file ? EVICTION_MASK : EVICTION_MASK_ANON) >> LRU_REFS_WIDTH;
+	max_seq &= (file ? EVICTION_MASK : EVICTION_MASK_ANON) >> LRU_REFS_BITS;
 
-	return abs_diff(max_seq, *token >> LRU_REFS_WIDTH) < MAX_NR_GENS;
+	return abs_diff(max_seq, *token >> LRU_REFS_BITS) < MAX_NR_GENS;
 }
 
 static void lru_gen_refault(struct folio *folio, void *shadow)
@@ -314,22 +319,26 @@ static void lru_gen_refault(struct folio *folio, void *shadow)
 	lrugen = &lruvec->lrugen;
 
 	hist = lru_hist_from_seq(READ_ONCE(lrugen->min_seq[type]));
-	refs = (token & (BIT(LRU_REFS_WIDTH) - 1)) + 1;
-	tier = lru_tier_from_refs(refs, workingset);
+	refs = ((token & (BIT(LRU_REFS_BITS) - 1)) << 1) + workingset;
+	tier = lru_tier_from_refs(refs);
 
 	atomic_long_add(delta, &lrugen->refaulted[hist][type][tier]);
 
-	if (workingset) {
-		/*
-		 * see folio_add_lru(), where folio_set_active() is
-		 * called for workingset folios
-		 */
-		if (lru_gen_in_fault())
+	/*
+	 * Activate a fault-driven refault folio, which would have been
+	 * promoted had it stayed in memory.
+	 */
+	if (refs >= LRU_REFS_REFERENCED) {
+		if (lru_gen_in_fault()) {
+			folio_set_active(folio);
 			mod_lruvec_state(lruvec, WORKINGSET_ACTIVATE_BASE + type, delta);
-		folio_set_workingset(folio);
+		}
+		/* Refault is also promotion, cap the refs like folio_inc_lru_refs */
+		folio_set_lru_refs(folio, min(refs, LRU_REFS_PROTECTED));
+	}
+
+	if (lru_refs_is_workingset(refs))
 		mod_lruvec_state(lruvec, WORKINGSET_RESTORE_BASE + type, delta);
-	} else
-		set_mask_bits(&folio->flags.f, LRU_REFS_MASK, (refs - 1UL) << LRU_REFS_PGOFF);
 unlock:
 	rcu_read_unlock();
 }

-- 
2.56.1


^ permalink raw reply related	[flat|nested] 124+ messages in thread

end of thread, other threads:[~2026-12-02  1:51 UTC | newest]

Thread overview: 124+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-23 18:52 [PATCH v6 00/18] mm/mglru: frequency guided promotion (MGLRU-FG) and flag cleanup Kairui Song via B4 Relay
2026-11-23 18:52 ` Kairui Song
2026-11-23 18:52 ` [PATCH v6 01/18] mm/mglru: rename the generation offset in lru_gen_folio_seq() Kairui Song via B4 Relay
2026-11-23 18:52   ` Kairui Song
2026-11-23 20:22   ` + mm-mglru-rename-the-generation-offset-in-lru_gen_folio_seq.patch added to mm-new branch Andrew Morton
2026-11-25  1:25   ` [PATCH v6 01/18] mm/mglru: rename the generation offset in lru_gen_folio_seq() SJ Park
2026-11-25 20:35   ` [to-be-updated] mm-mglru-rename-the-generation-offset-in-lru_gen_folio_seq.patch removed from -mm tree Andrew Morton
2026-11-23 18:52 ` [PATCH v6 02/18] mm/memcontrol: allow update of LRU statistic without holding LRU lock Kairui Song via B4 Relay
2026-11-23 18:52   ` Kairui Song
2026-11-23 20:22   ` + mm-memcontrol-allow-update-of-lru-statistic-without-holding-lru-lock.patch added to mm-new branch Andrew Morton
2026-11-25  1:32   ` [PATCH v6 02/18] mm/memcontrol: allow update of LRU statistic without holding LRU lock SJ Park
2026-11-25  8:17   ` Ridong Chen
2026-11-25 20:35   ` [to-be-updated] mm-memcontrol-allow-update-of-lru-statistic-without-holding-lru-lock.patch removed from -mm tree Andrew Morton
2026-11-26  9:43   ` [PATCH v6 02/18] mm/memcontrol: allow update of LRU statistic without holding LRU lock Ridong Chen
2026-11-26 12:38     ` Kairui Song
2026-11-23 18:52 ` [PATCH v6 03/18] mm/memcontrol: avoid potential counter leak when reparenting local stats Kairui Song via B4 Relay
2026-11-23 18:52   ` Kairui Song
2026-11-23 20:22   ` + mm-memcontrol-avoid-potential-counter-leak-when-reparenting-local-stats.patch added to mm-new branch Andrew Morton
2026-11-24  2:07   ` [PATCH v6 03/18] mm/memcontrol: avoid potential counter leak when reparenting local stats KunWu Chan
2026-11-25  1:41   ` SJ Park
2026-11-25 20:35   ` [to-be-updated] mm-memcontrol-avoid-potential-counter-leak-when-reparenting-local-stats.patch removed from -mm tree Andrew Morton
2026-11-26  3:38   ` [PATCH v6 03/18] mm/memcontrol: avoid potential counter leak when reparenting local stats Ridong Chen
2026-11-23 18:52 ` [PATCH v6 04/18] mm/mglru: make generation page counters atomic Kairui Song via B4 Relay
2026-11-23 18:52   ` Kairui Song
2026-11-23 20:22   ` + mm-mglru-make-generation-page-counters-atomic.patch added to mm-new branch Andrew Morton
2026-11-25  1:45   ` [PATCH v6 04/18] mm/mglru: make generation page counters atomic SJ Park
2026-11-25 20:35   ` [to-be-updated] mm-mglru-make-generation-page-counters-atomic.patch removed from -mm tree Andrew Morton
2026-11-26  3:11   ` [PATCH v6 04/18] mm/mglru: make generation page counters atomic Ridong Chen
2026-11-23 18:52 ` [PATCH v6 05/18] mm/memcg: add folio-based lruvec live helper Kairui Song via B4 Relay
2026-11-23 18:52   ` Kairui Song
2026-11-23 20:23   ` + mm-memcg-add-folio-based-lruvec-live-helper.patch added to mm-new branch Andrew Morton
2026-11-25 20:35   ` [to-be-updated] mm-memcg-add-folio-based-lruvec-live-helper.patch removed from -mm tree Andrew Morton
2026-11-26  7:57   ` [PATCH v6 05/18] mm/memcg: add folio-based lruvec live helper Ridong Chen
2026-11-23 18:52 ` [PATCH v6 06/18] mm/mglru: skip the flags cmpxchg when nothing changes Kairui Song via B4 Relay
2026-11-23 18:52   ` Kairui Song
2026-11-23 20:23   ` + mm-mglru-skip-the-flags-cmpxchg-when-nothing-changes.patch added to mm-new branch Andrew Morton
2026-11-25 10:07   ` [PATCH v6 06/18] mm/mglru: skip the flags cmpxchg when nothing changes Vernon Yang
2026-11-25 20:35   ` [to-be-updated] mm-mglru-skip-the-flags-cmpxchg-when-nothing-changes.patch removed from -mm tree Andrew Morton
2026-11-23 18:52 ` [PATCH v6 07/18] mm/mglru: frequency guided workingset promotion (MGLRU-FG) Kairui Song via B4 Relay
2026-11-23 18:52   ` Kairui Song
2026-11-23 20:23   ` + mm-mglru-frequency-guided-workingset-promotion-mglru-fg.patch added to mm-new branch Andrew Morton
2026-11-25 20:35   ` [to-be-updated] mm-mglru-frequency-guided-workingset-promotion-mglru-fg.patch removed from -mm tree Andrew Morton
2026-11-30 14:42   ` [PATCH v6 07/18] mm/mglru: frequency guided workingset promotion (MGLRU-FG) Vernon Yang
2026-11-30 15:55     ` Kairui Song
2026-12-01  2:11       ` Vernon Yang
2026-11-23 18:53 ` [PATCH v6 08/18] mm/mglru: make folio lru referenced times count a generic API Kairui Song via B4 Relay
2026-11-23 18:53   ` Kairui Song
2026-11-23 20:23   ` + mm-mglru-make-folio-lru-referenced-times-count-a-generic-api.patch added to mm-new branch Andrew Morton
2026-11-25 10:15   ` [PATCH v6 08/18] mm/mglru: make folio lru referenced times count a generic API David Hildenbrand (Arm)
2026-11-25 12:36     ` Kairui Song
2026-11-27  1:48       ` Ridong Chen
2026-11-27  2:01         ` Kairui Song
2026-11-27  2:20           ` Kairui Song
2026-11-27  3:32             ` Ridong Chen
2026-11-27 19:41               ` Kairui Song
2026-11-28 12:47                 ` KunWu Chan
2026-11-25 20:36   ` [to-be-updated] mm-mglru-make-folio-lru-referenced-times-count-a-generic-api.patch removed from -mm tree Andrew Morton
2026-11-23 18:53 ` [PATCH v6 09/18] mm/mglru: move add/del LRU size accounting out of lru_gen_update_size() Kairui Song via B4 Relay
2026-11-23 18:53   ` Kairui Song
2026-11-23 20:23   ` + mm-mglru-move-add-del-lru-size-accounting-out-of-lru_gen_update_size.patch added to mm-new branch Andrew Morton
2026-11-25 20:36   ` [to-be-updated] mm-mglru-move-add-del-lru-size-accounting-out-of-lru_gen_update_size.patch removed from -mm tree Andrew Morton
2026-11-23 18:53 ` [PATCH v6 10/18] mm/mglru, gup: mark folios referenced via a fast helper Kairui Song via B4 Relay
2026-11-23 18:53   ` Kairui Song
2026-11-23 20:23   ` + mm-mglru-gup-mark-folios-referenced-via-a-fast-helper.patch added to mm-new branch Andrew Morton
2026-11-25 10:13   ` [PATCH v6 10/18] mm/mglru, gup: mark folios referenced via a fast helper David Hildenbrand (Arm)
2026-11-25 12:32     ` Kairui Song
2026-11-25 13:47   ` Vernon Yang
2026-11-26  7:16     ` Kairui Song
2026-11-26 15:01       ` Vernon Yang
2026-11-25 20:36   ` [to-be-updated] mm-mglru-gup-mark-folios-referenced-via-a-fast-helper.patch removed from -mm tree Andrew Morton
2026-11-23 18:53 ` [PATCH v6 11/18] mm/mglru, smaps: convert to LRU refs based operations for MGLRU Kairui Song via B4 Relay
2026-11-23 18:53   ` Kairui Song
2026-11-23 19:52   ` Zi Yan
2026-11-24 17:29     ` Kairui Song
2026-11-24 17:31       ` Zi Yan
2026-11-23 20:23   ` + mm-mglru-smaps-convert-to-lru-refs-based-operations-for-mglru.patch added to mm-new branch Andrew Morton
2026-11-25 20:36   ` [to-be-updated] mm-mglru-smaps-convert-to-lru-refs-based-operations-for-mglru.patch removed from -mm tree Andrew Morton
2026-11-23 18:53 ` [PATCH v6 12/18] mm/damon: convert to LRU refs based operations for MGLRU Kairui Song via B4 Relay
2026-11-23 18:53   ` Kairui Song
2026-11-23 20:23   ` + mm-damon-convert-to-lru-refs-based-operations-for-mglru.patch added to mm-new branch Andrew Morton
2026-11-25 10:16   ` [PATCH v6 12/18] mm/damon: convert to LRU refs based operations for MGLRU David Hildenbrand (Arm)
2026-11-25 20:36   ` [to-be-updated] mm-damon-convert-to-lru-refs-based-operations-for-mglru.patch removed from -mm tree Andrew Morton
2026-11-23 18:53 ` [PATCH v6 13/18] mm/khugepaged: convert to LRU refs based operations for MGLRU Kairui Song
2026-11-23 18:53   ` Kairui Song via B4 Relay
2026-11-23 20:23   ` + mm-khugepaged-convert-to-lru-refs-based-operations-for-mglru.patch added to mm-new branch Andrew Morton
2026-11-25 10:11   ` [PATCH v6 13/18] mm/khugepaged: convert to LRU refs based operations for MGLRU David Hildenbrand (Arm)
2026-11-25 13:51     ` Kairui Song
2026-11-25 20:36   ` [to-be-updated] mm-khugepaged-convert-to-lru-refs-based-operations-for-mglru.patch removed from -mm tree Andrew Morton
2026-11-23 18:53 ` [PATCH v6 14/18] mm/madvise: adapt for LRU refs based operations for MGLRU Kairui Song
2026-11-23 18:53   ` Kairui Song via B4 Relay
2026-11-23 20:23   ` + mm-madvise-adapt-for-lru-refs-based-operations-for-mglru.patch added to mm-new branch Andrew Morton
2026-11-25 10:10   ` [PATCH v6 14/18] mm/madvise: adapt for LRU refs based operations for MGLRU David Hildenbrand (Arm)
2026-12-01 18:28     ` Kairui Song
2026-12-02  1:23       ` Baoquan He
2026-11-25 20:36   ` [to-be-updated] mm-madvise-adapt-for-lru-refs-based-operations-for-mglru.patch removed from -mm tree Andrew Morton
2026-11-23 18:53 ` [PATCH v6 15/18] mm/huge_memory: mark folio as accessed more accurately on split Kairui Song
2026-11-23 18:53   ` Kairui Song via B4 Relay
2026-11-23 20:17   ` Zi Yan
2026-11-24 17:24     ` Kairui Song
2026-11-24 17:30       ` Zi Yan
2026-11-23 20:23   ` + mm-huge_memory-mark-folio-as-accessed-more-accurately-on-split.patch added to mm-new branch Andrew Morton
2026-11-25 10:09   ` [PATCH v6 15/18] mm/huge_memory: mark folio as accessed more accurately on split David Hildenbrand (Arm)
2026-11-25 13:12     ` Kairui Song
2026-11-25 20:36   ` [to-be-updated] mm-huge_memory-mark-folio-as-accessed-more-accurately-on-split.patch removed from -mm tree Andrew Morton
2026-11-23 18:53 ` [PATCH v6 16/18] mm/mglru: make PG_workingset helpers work based on folio LRU refs Kairui Song
2026-11-23 18:53   ` Kairui Song via B4 Relay
2026-11-23 20:23   ` + mm-mglru-make-pg_workingset-helpers-work-based-on-folio-lru-refs.patch added to mm-new branch Andrew Morton
2026-11-25 20:36   ` [to-be-updated] mm-mglru-make-pg_workingset-helpers-work-based-on-folio-lru-refs.patch removed from -mm tree Andrew Morton
2026-11-23 18:53 ` [PATCH v6 17/18] mm/mglru: folio LRU refs based active/inactive number accounting Kairui Song
2026-11-23 18:53   ` Kairui Song via B4 Relay
2026-11-23 19:28   ` sashiko-bot
2026-11-24 16:47     ` Kairui Song
2026-11-23 20:23   ` + mm-mglru-folio-lru-refs-based-active-inactive-number-accounting.patch added to mm-new branch Andrew Morton
2026-11-25 10:02   ` [PATCH v6 17/18] mm/mglru: folio LRU refs based active/inactive number accounting Barry Song
2026-11-30 18:01     ` Kairui Song
2026-11-25 10:17   ` David Hildenbrand (Arm)
2026-11-25 20:36   ` [to-be-updated] mm-mglru-folio-lru-refs-based-active-inactive-number-accounting.patch removed from -mm tree Andrew Morton
2026-11-23 18:53 ` [PATCH v6 18/18] mm/mglru: make folio_inc_lru_refs lruvec lockless Kairui Song
2026-11-23 18:53   ` Kairui Song via B4 Relay
2026-11-23 20:23   ` + mm-mglru-make-folio_inc_lru_refs-lruvec-lockless.patch added to mm-new branch Andrew Morton
2026-11-25 20:36   ` [to-be-updated] mm-mglru-make-folio_inc_lru_refs-lruvec-lockless.patch removed from -mm tree Andrew Morton
2026-11-23 19:28 ` [PATCH v6 00/18] mm/mglru: frequency guided promotion (MGLRU-FG) and flag cleanup sashiko-bot
2026-11-23 20:22 ` Andrew Morton
  -- strict thread matches above, loose matches on Subject: below --
2026-12-01 20:18 [PATCH v7 07/19] mm/mglru: frequency guided workingset promotion (MGLRU-FG) Kairui Song
2026-12-02  1:51 ` + mm-mglru-frequency-guided-workingset-promotion-mglru-fg.patch added to mm-new branch Andrew Morton

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.