Re: [PATCH v7 00/19] mm/mglru: frequency guided promotion (MGLRU-FG) and flag cleanup
From: Andrew Morton
Date: Tue Dec 01 2026 - 22:26:13 EST
On Wed, 02 Dec 2026 04:18:40 +0800 Kairui Song <kasong@xxxxxxxxxxx> wrote:
> This series implements MGLRU-FG following the idea proposed at LSF/MM/BPF
> this year [1], based on current mm-new. Depending on the workload, it
> improves the performance or reduces IO by roughly 10% to over 50%,
> fixes multiple long-standing issues with MGLRU metrics, and drops one
> page flag.
>
I gave this a 2-hour workout on 64 vCPU QEMU. Everything checks out.
It might have found one thing:
: The test gives a 128 MiB cgroup a 4 MiB file that it reads repeatedly
: and a 512 MiB file whose reads force reclaim. The 4 MiB file is the
: hotset: 1,024 pages we expect to survive the cold-file scans.
:
: With three hot-file reads per scan, the kernel before the series (A)
: kept all 1,024 pages after warmup. The 19-patch kernel (B) sometimes
: evicted every one: in 6 of 10 cycles in one run and 3 of 10 in another.
: Reading the hot file then took about 2.4-3.2 ms on B versus about 1.3
: ms on A. B also scanned more pages.
:
: The result depends on access rate: with one hot-file read per scan, B
: kept the pages and A mostly lost them. So the series helped one
: workload but regressed this more frequently read one. The trace points
: to hot pages being selected for eviction, but the run did not establish
: a safe correction or isolate which of the 19 patches causes it.
And it proposed a little GUP speedup:
From: Andrew Morton <akpm@xxxxxxxxxxxxxxxxxxxx>
Subject: mm/mglru: skip refs decoding for already referenced GUP folios
Date: Tue, 01 Dec 2026 17:59:24 -0800
GUP-fast calls folio_inc_lru_refs_fast() for every folio it pins. After
its first reference, a folio with PG_referenced set still incurs the
generation decode, refs decode and static-key test on every pin. The
v7 GUP helper is measurably slower than the preceding queue endpoint
in this repeated-pin workload.
Test PG_referenced first. If set, both the MGLRU refs count and the
classical LRU referenced state are already nonzero, so the helper has
nothing to change. Otherwise, check the remaining MGLRU refs bits and
atomically set PG_referenced only when needed. Reevaluate all tests
after a failed cmpxchg. This retains the original behavior for MGLRU
on, off and during switching, including a folio still on a generation
list after the static key turns off.
In fresh 7.4.0-rc4 guests with the 19 v7 patches, GUP_FAST_BENCHMARK
pinned 16 MiB of 4 KiB pages in 64-page batches for 8192 calls per
thread. Across two interleaved baseline/fix pairs, the single-thread
median kernel get time fell from 52.9/53.8 to 49.3/50.1 us per call.
The 64-CPU medians fell from 88.3/85.7 to 79.8/85.8 us, with wider
run-to-run variation. GUP selftests passed 60/60 with MGLRU enabled
and 60/60 with it disabled; MADV selftests passed 24/24 with MGLRU
disabled. No kernel warnings were observed.
Link: https://patch.msgid.link/20261202-mglru-fg-v7-10-5965a96d86d0@xxxxxxxxxxx
Cc: Kairui Song <kasong@xxxxxxxxxxx>
Cc: linux-mm@xxxxxxxxx
include/linux/mm_inline.h | 15 +++++----------
1 file changed, 5 insertions(+), 10 deletions(-)
--- a/include/linux/mm_inline.h
+++ b/include/linux/mm_inline.h
@@ -538,21 +538,16 @@
static __always_inline void folio_inc_lru_refs_fast(struct folio *folio)
{
unsigned long new_flags, old_flags = READ_ONCE(*folio_flags(folio, 0));
- unsigned int refs;
- bool has_gen;
BUILD_BUG_ON(LRU_REFS_REFERENCED >= LRU_REFS_ACTIVATED);
do {
- has_gen = lru_get_gen_flags(old_flags) >= 0;
- refs = lru_get_refs_flags(old_flags);
- if (has_gen || lru_gen_enabled()) {
- if (refs)
- break;
- } else if (refs & LRU_REFS_REFERENCED) {
+ if (old_flags & BIT(PG_referenced))
break;
+ if (lru_get_gen_flags(old_flags) >= 0 || lru_gen_enabled()) {
+ if (old_flags & LRU_REFS_FLAGS)
+ break;
}
- new_flags = old_flags;
- lru_set_refs_flags(&new_flags, refs | LRU_REFS_REFERENCED);
+ new_flags = old_flags | BIT(PG_referenced);
} while (!try_cmpxchg(folio_flags(folio, 0), &old_flags, new_flags));
}