* [PATCH v5 0/4] skip empty PUD subtrees during aging with a PUD-level Bloom filter
@ 2026-11-23 8:57 Baoquan He
2026-11-23 8:57 ` [PATCH v5 1/4] mm/mglru: add MM_WALK_EMPTY stats and tracepoint Baoquan He
` (4 more replies)
0 siblings, 5 replies; 7+ messages in thread
From: Baoquan He @ 2026-11-23 8:57 UTC (permalink / raw)
To: linux-mm
Cc: david, akpm, kasong, baohua, qi.zheng, shakeel.butt,
axelrasmussen, yuanchu, weixugc, baolin.wang, baoquan.he
Problem
=======
MGLRU's aging walks every PUD of every mm in the mm_list. For a PUD whose
512 PMDs all fail the existing PMD-level Bloom filter, the walker still
descends into the PUD and iterates all 512 PMD entries. When an mm has no
pages on a given node this is structural waste: lru_gen_use_mm() sets
mm->lru_gen.bitmap to -1 (all nodes) on every context switch, so the aging
walker of *every* node, e.g kswapd, direct reclaim, proactive aging walks
the same mm.
On a 2-node KVM guest with the workload pinned to node 0, node 1's aging
walks of those mms scan 1,362 leaf entries per walk while finding no young
folio for node 1's lruvec, and 94% of those walks are entirely empty.
Approach
========
Add a PUD-level Bloom filter, one level above the existing PMD filter.
The walker now:
1. Tests the PUD filter before descending into a PUD subtree.
2. If the PUD had nothing young for this lruvec last generation, skips the
whole 1 GiB region -- avoiding 512 PMD lookups.
3. walk_pmd_range() reports whether it found anything young;
walk_pud_range() records that in the double-buffered PUD filter.
4. The rmap feedback path marks hot PUDs, so regions whose hotness is only
observed by eviction are re-examined promptly. This is done for both
mapping types: lru_gen_look_around() covers PTE-mapped folios, and
folio_referenced_one() covers PMD-mapped ones, which never reach
lru_gen_look_around().
5. force_scan walks bypass the PUD test, so manual aging and newly added
mms always rescan and re-populate the filter.
The filter key is (mm, PUD-aligned address), as suggested by Kairui. It is
a stable identity of the range on both sides of the interface: the aging
walk computes it from args->mm and addr, the rmap path from vma->vm_mm and
the address. So the feedback path needs no page-table walk at all.
The double-buffered filter flips each generation and force_scan bypasses
it, so a missed re-mark costs at most one generation, and reclaim is still
safe for a wrongly skipped subtree because folio_referenced() consults the
PTE young bits, not the filter.
Change log
==========
v4 -> v5:
- Rebased onto the latest mm-new commit 7d1a16abe4cc.
- Drop MM_LEAF_ASSOCIATED: an empty walk is now "MM_LEAF_TOTAL > 0 and
MM_LEAF_YOUNG == 0". MM_LEAF_YOUNG already means the young leaves of
this lruvec, which is what the PUD filter needs, so the second counter
added nothing. The debugfs columns and the tracepoint field are renamed
to match. (Sashiko)
Test
====
8 GiB KVM guest, 4 vCPU, two 4 GiB NUMA nodes, 7.4.0-rc3 with the series.
"base" below is the same kernel with the filter disabled (patch 1 only):
same .config, same workload. Each result directory records its own cmdline
and per-node meminfo, so a wrong configuration would show.
1) Cross-node empty walks. 16 workers x 128 MiB pinned to node 0
(numactl --membind=0), so node 1 owns none of these pages. 100 aging
passes, both nodes aged, 3 runs, median:
base filter change
node 1 leaf entries scanned 1,243 107 -91%
walks with leaves 17 0.67 -96%
PUDs skipped 0 51
node 0 leaf entries scanned 12,926 13,155 +1.8%
young leaves 9,228 9,167 -0.7%
worker RSS delta 0% 0%
The base's own three runs spread 9,133 to 9,248 young leaves on node 0,
so node 0 keeps its young leaves. The filter marks young leaves in
exactly the same place it did before; what it drops is the walk into
PUDs that had nothing young.
forced pass, node 1 leaf/walk
before the filtered passes 1,359-1,371 1,363-1,370
after them 1,361-1,371 1,363-1,370
A forced pass bypasses the filter, so it costs the same on both kernels
and the same before and after 100 filtered passes: the filter is a
cache, not a state.
2) Correctness, 11 checks, all pass: a cold PUD is skipped; touching it
does not revive it; force_scan re-marks it and the next pass walks it
again; a munmap + mmap at the same address shows no stale suppression; a
1 GiB range migrated from node 0 to node 1 is re-scanned by node 1 after
one forced pass; no premature reclaim in any of them; dmesg clean.
3) A PUD that holds only PMD-mapped huge pages. 1 GiB is mapped with
THP=always (AnonHugePages = 1 GiB, 262,144 of 262,144 pages resident) and
aged until its PUD is skipped (S +4 over 3 passes). The memcg is then
put under reclaim pressure (memory.max below the current usage) and the
range is touched again, so folio_referenced() runs on PMD-mapped folios.
The next normal aging pass walks the range again:
leaf_total 1560, leaf_young 387
4) Reclaim pressure. Four 512 MiB workers in a memory.max=2G/swap.max=1G
memcg, at the limit so reclaim never stops; each flips a 256 MiB half
every second. Both nodes are aged every 0.5 s for 600 s. Rates per
second, because some runs stopped early on both kernels:
base filter
pgscan_anon 23.7-27.4k/s (3) 34.6-35.3k/s (2)
pgsteal_anon 3.95-4.10k/s 3.74-4.63k/s
pswpout 3.94-4.10k/s 3.74-4.61k/s
refault_anon 3.95-4.10k/s 3.74-4.63k/s
oom_kill 0 0
hot half resident 262,140-262,144 262,144
node 1 walks w/ leaves 2,812-4,544 4
Evictions, swap-out, refaults and residency are the same. The scanner
examines 26-49% more folios with the filter: a folio under a skipped PUD
is not promoted that generation, so it sits in an older generation a
little longer and takes more scanning to reach. Extra scanning, not
extra reclaim. The per-walk statistics cannot cause it, nothing outside
lru_gen_seq_show() reads them.
5) Aging cost on a single node. Per pass, 200 passes, perf stat and the
median wall time around the same fork-free debugfs write:
shape base filter change
2 procs x 32 GiB VA, 0.2% touched
time per pass 1,577-1,596 1,278-1,392 us -15%
instructions per pass 5.79M 4.27M -26%
20 procs x 3 GiB VA, 2% touched
time per pass 9,889-10,097 9,563-9,775 us -4%
instructions per pass 29.6M 28.1M -5%
20 procs x 64 MiB, fully touched
time per pass 10,294-10,579 10,167-10,411 us -2%
instructions per pass 30.06M 30.05M 0%
The leaf counters are the same in all three rows; only the skips differ.
The wide shape has 34 PUD regions per mm and skips all of them, so it is
1.5M instructions lighter per pass, about 22,000 per skipped PUD, which
is the 512 PMD-level Bloom tests it no longer runs. With 5 and 1 PUD
regions per mm there is little to skip, so the other two cost nothing.
Baoquan He (4):
mm/mglru: add MM_WALK_EMPTY stats and tracepoint
mm/mglru: add PUD-level Bloom filter state and generic helpers
mm/mglru: skip cold PUD subtrees during aging
mm/mglru: count PUD subtrees skipped by the PUD-level filter
include/linux/mmzone.h | 20 ++++-
mm/rmap.c | 5 +-
mm/trace_vmscan.h | 30 ++++++++
mm/vmscan.c | 169 +++++++++++++++++++++++++++++++++--------
4 files changed, 189 insertions(+), 35 deletions(-)
base-commit: 7d1a16abe4cc5dccd21e3d6262e44433a5885d27
--
2.52.0
^ permalink raw reply [flat|nested] 7+ messages in thread
* [PATCH v5 1/4] mm/mglru: add MM_WALK_EMPTY stats and tracepoint
2026-11-23 8:57 [PATCH v5 0/4] skip empty PUD subtrees during aging with a PUD-level Bloom filter Baoquan He
@ 2026-11-23 8:57 ` Baoquan He
2026-11-23 8:57 ` [PATCH v5 2/4] mm/mglru: add PUD-level Bloom filter state and generic helpers Baoquan He
` (3 subsequent siblings)
4 siblings, 0 replies; 7+ messages in thread
From: Baoquan He @ 2026-11-23 8:57 UTC (permalink / raw)
To: linux-mm
Cc: david, akpm, kasong, baohua, qi.zheng, shakeel.butt,
axelrasmussen, yuanchu, weixugc, baolin.wang, baoquan.he,
Baoquan He
From: Baoquan He <hebaoquan@kylinos.cn>
Add per-walk counters to measure empty aging walks, which traverse an mm's
page tables but find no young leaf for the current lruvec (node+memcg).
These are common on multi-NUMA node systems because lru_gen_use_mm() marks
an mm for all nodes at every context switch.
New counters (accumulated in mm_state->stats[]):
MM_WALK_TOTAL - page-table walks completed
MM_WALK_EMPTY - walks that found no young leaf for this lruvec
MM_LEAF_EMPTY_WALKS - leaf entries scanned during empty walks
A walk is empty when MM_LEAF_TOTAL > 0 and MM_LEAF_YOUNG == 0.
MM_LEAF_YOUNG already counts only the young leaves whose folio is in this
lruvec, which is the condition the PUD-level filter of the following
patches uses.
The new tracepoint mm_vmscan_lru_gen_walk() fires after each walk, and the
debugfs lru_gen output ("TYFAWEE") exposes the counters.
Signed-off-by: Baoquan He <hebaoquan@kylinos.cn>
---
include/linux/mmzone.h | 3 +++
mm/trace_vmscan.h | 28 ++++++++++++++++++++++++++++
mm/vmscan.c | 32 ++++++++++++++++++++++++++++----
3 files changed, 59 insertions(+), 4 deletions(-)
diff --git a/include/linux/mmzone.h b/include/linux/mmzone.h
index 6a2ad0cff795..8aabe0f23e60 100644
--- a/include/linux/mmzone.h
+++ b/include/linux/mmzone.h
@@ -579,6 +579,9 @@ enum {
MM_LEAF_YOUNG, /* young leaf entries */
MM_NONLEAF_FOUND, /* non-leaf entries found in Bloom filters */
MM_NONLEAF_ADDED, /* non-leaf entries added to Bloom filters */
+ MM_WALK_TOTAL, /* page-table walks completed */
+ MM_WALK_EMPTY, /* walks that found no young leaf for this lruvec */
+ MM_LEAF_EMPTY_WALKS, /* leaf entries scanned during empty walks */
NR_MM_STATS
};
diff --git a/mm/trace_vmscan.h b/mm/trace_vmscan.h
index 9dafdb5bd3ce..b0c2af65c1ea 100644
--- a/mm/trace_vmscan.h
+++ b/mm/trace_vmscan.h
@@ -508,6 +508,34 @@ TRACE_EVENT(mm_mglru_aging,
__print_array(__entry->nr_anon, MAX_NR_GENS, sizeof(unsigned long)),
__print_array(__entry->nr_file, MAX_NR_GENS, sizeof(unsigned long)))
);
+TRACE_EVENT(mm_vmscan_lru_gen_walk,
+
+ TP_PROTO(int nid, unsigned long seq, int leaf_total,
+ int leaf_young, bool empty),
+
+ TP_ARGS(nid, seq, leaf_total, leaf_young, empty),
+
+ TP_STRUCT__entry(
+ __field(int, nid)
+ __field(unsigned long, seq)
+ __field(int, leaf_total)
+ __field(int, leaf_young)
+ __field(bool, empty)
+ ),
+
+ TP_fast_assign(
+ __entry->nid = nid;
+ __entry->seq = seq;
+ __entry->leaf_total = leaf_total;
+ __entry->leaf_young = leaf_young;
+ __entry->empty = empty;
+ ),
+
+ TP_printk("nid=%d seq=%lu leaf_total=%d leaf_young=%d empty=%d",
+ __entry->nid, __entry->seq, __entry->leaf_total,
+ __entry->leaf_young, __entry->empty)
+);
+
#endif /* CONFIG_LRU_GEN */
TRACE_EVENT(mm_vmscan_write_folio,
diff --git a/mm/vmscan.c b/mm/vmscan.c
index bc7579d47f9b..a0cbbbb2ff00 100644
--- a/mm/vmscan.c
+++ b/mm/vmscan.c
@@ -4158,8 +4158,32 @@ static bool try_to_inc_max_seq(struct lruvec *lruvec, unsigned long seq,
do {
success = iterate_mm_list(walk, &mm);
- if (mm)
+ if (mm) {
+ bool empty = false;
+
walk_mm(mm, walk);
+ /*
+ * A walk that traversed page tables but found no young
+ * leaf for this lruvec (node+memcg) is pure waste: the
+ * PUD-level filter will skip it next generation.
+ * MM_LEAF_YOUNG only counts leaves whose folio belongs
+ * to this lruvec, so it is the condition the filter
+ * uses as well.
+ */
+ if (walk->mm_stats[MM_LEAF_TOTAL]) {
+ walk->mm_stats[MM_WALK_TOTAL]++;
+ if (walk->mm_stats[MM_LEAF_YOUNG] == 0) {
+ walk->mm_stats[MM_WALK_EMPTY]++;
+ walk->mm_stats[MM_LEAF_EMPTY_WALKS] +=
+ walk->mm_stats[MM_LEAF_TOTAL];
+ empty = true;
+ }
+ }
+ trace_mm_vmscan_lru_gen_walk(
+ lruvec_pgdat(lruvec)->node_id, walk->seq,
+ walk->mm_stats[MM_LEAF_TOTAL],
+ walk->mm_stats[MM_LEAF_YOUNG], empty);
+ }
} while (mm);
done:
if (success) {
@@ -5804,14 +5828,14 @@ static void lru_gen_seq_show_full(struct seq_file *m, struct lruvec *lruvec,
seq_puts(m, " ");
for (i = 0; i < NR_MM_STATS; i++) {
- const char *s = "xxxx";
+ const char *s = "xxxxxxxx";
unsigned long n = 0;
if (seq == max_seq && NR_HIST_GENS == 1) {
- s = "TYFA";
+ s = "TYFAWEE";
n = READ_ONCE(mm_state->stats[hist][i]);
} else if (seq != max_seq && NR_HIST_GENS > 1) {
- s = "tyfa";
+ s = "tyfawee";
n = READ_ONCE(mm_state->stats[hist][i]);
}
--
2.52.0
^ permalink raw reply related [flat|nested] 7+ messages in thread
* [PATCH v5 2/4] mm/mglru: add PUD-level Bloom filter state and generic helpers
2026-11-23 8:57 [PATCH v5 0/4] skip empty PUD subtrees during aging with a PUD-level Bloom filter Baoquan He
2026-11-23 8:57 ` [PATCH v5 1/4] mm/mglru: add MM_WALK_EMPTY stats and tracepoint Baoquan He
@ 2026-11-23 8:57 ` Baoquan He
2026-11-23 8:57 ` [PATCH v5 3/4] mm/mglru: skip cold PUD subtrees during aging Baoquan He
` (2 subsequent siblings)
4 siblings, 0 replies; 7+ messages in thread
From: Baoquan He @ 2026-11-23 8:57 UTC (permalink / raw)
To: linux-mm
Cc: david, akpm, kasong, baohua, qi.zheng, shakeel.butt,
axelrasmussen, yuanchu, weixugc, baolin.wang, baoquan.he,
Baoquan He
From: Baoquan He <hebaoquan@kylinos.cn>
Generalize the Bloom filter state and helpers so that another filter level
can reuse the same hash, double-buffering and reset logic.
Replace the PMD-level filter array with a two-dimensional filters array
indexed by level, and add BLOOM_FILTER_PUD and BLOOM_FILTER_PMD. The
PUD-level filters work one level up: when all PMDs under a PUD fail the
PMD-level filter, the whole PMD iteration can be skipped. Cross-node
empty walks are the case where this wastes the most time.
test_bloom_filter(), update_bloom_filter() and reset_bloom_filter() take
the level and use mm_state->filters[level][gen] directly.
No behavior change yet, and no PUD-level bitmap is allocated.
Signed-off-by: Baoquan He <hebaoquan@kylinos.cn>
---
include/linux/mmzone.h | 10 ++++++++--
mm/vmscan.c | 39 ++++++++++++++++++++++-----------------
2 files changed, 30 insertions(+), 19 deletions(-)
diff --git a/include/linux/mmzone.h b/include/linux/mmzone.h
index 8aabe0f23e60..f057c98d1f97 100644
--- a/include/linux/mmzone.h
+++ b/include/linux/mmzone.h
@@ -588,6 +588,12 @@ enum {
/* double-buffering Bloom filters */
#define NR_BLOOM_FILTERS 2
+enum bloom_filter_level {
+ BLOOM_FILTER_PUD,
+ BLOOM_FILTER_PMD,
+ BLOOM_FILTER_LEVELS,
+};
+
struct lru_gen_mm_state {
/* synced with max_seq after each iteration */
unsigned long seq;
@@ -595,8 +601,8 @@ struct lru_gen_mm_state {
struct list_head *head;
/* where the last iteration ended before */
struct list_head *tail;
- /* Bloom filters flip after each iteration */
- unsigned long *filters[NR_BLOOM_FILTERS];
+ /* Bloom filters flip after each iteration, indexed by level */
+ unsigned long *filters[BLOOM_FILTER_LEVELS][NR_BLOOM_FILTERS];
/* the mm stats for debugging */
unsigned long stats[NR_HIST_GENS][NR_MM_STATS];
};
diff --git a/mm/vmscan.c b/mm/vmscan.c
index a0cbbbb2ff00..7d20ee1b6c10 100644
--- a/mm/vmscan.c
+++ b/mm/vmscan.c
@@ -2819,14 +2819,14 @@ static void get_item_key(void *item, int *key)
key[1] = hash >> BLOOM_FILTER_SHIFT;
}
-static bool test_bloom_filter(struct lru_gen_mm_state *mm_state, unsigned long seq,
- void *item)
+static bool test_bloom_filter(struct lru_gen_mm_state *mm_state, int level,
+ unsigned long seq, void *item)
{
int key[2];
unsigned long *filter;
int gen = filter_gen_from_seq(seq);
- filter = READ_ONCE(mm_state->filters[gen]);
+ filter = READ_ONCE(mm_state->filters[level][gen]);
if (!filter)
return true;
@@ -2835,14 +2835,14 @@ static bool test_bloom_filter(struct lru_gen_mm_state *mm_state, unsigned long s
return test_bit(key[0], filter) && test_bit(key[1], filter);
}
-static void update_bloom_filter(struct lru_gen_mm_state *mm_state, unsigned long seq,
- void *item)
+static void update_bloom_filter(struct lru_gen_mm_state *mm_state, int level,
+ unsigned long seq, void *item)
{
int key[2];
unsigned long *filter;
int gen = filter_gen_from_seq(seq);
- filter = READ_ONCE(mm_state->filters[gen]);
+ filter = READ_ONCE(mm_state->filters[level][gen]);
if (!filter)
return;
@@ -2854,12 +2854,13 @@ static void update_bloom_filter(struct lru_gen_mm_state *mm_state, unsigned long
set_bit(key[1], filter);
}
-static void reset_bloom_filter(struct lru_gen_mm_state *mm_state, unsigned long seq)
+static void reset_bloom_filter(struct lru_gen_mm_state *mm_state, int level,
+ unsigned long seq)
{
unsigned long *filter;
int gen = filter_gen_from_seq(seq);
- filter = mm_state->filters[gen];
+ filter = mm_state->filters[level][gen];
if (filter) {
bitmap_clear(filter, 0, BIT(BLOOM_FILTER_SHIFT));
return;
@@ -2867,7 +2868,7 @@ static void reset_bloom_filter(struct lru_gen_mm_state *mm_state, unsigned long
filter = bitmap_zalloc(BIT(BLOOM_FILTER_SHIFT),
__GFP_HIGH | __GFP_NOMEMALLOC | __GFP_NOWARN);
- WRITE_ONCE(mm_state->filters[gen], filter);
+ WRITE_ONCE(mm_state->filters[level][gen], filter);
}
/******************************************************************************
@@ -3110,7 +3111,7 @@ static bool iterate_mm_list(struct lru_gen_mm_walk *walk, struct mm_struct **ite
spin_unlock(&mm_list->lock);
if (mm && first)
- reset_bloom_filter(mm_state, walk->seq + 1);
+ reset_bloom_filter(mm_state, BLOOM_FILTER_PMD, walk->seq + 1);
if (*iter)
mmdrop(*iter);
@@ -3761,7 +3762,8 @@ static void walk_pmd_range(pud_t *pud, unsigned long start, unsigned long end,
walk_pmd_range_locked(pud, addr, vma, args, bitmap, &first);
}
- if (!walk->force_scan && !test_bloom_filter(mm_state, walk->seq, pmd + i))
+ if (!walk->force_scan &&
+ !test_bloom_filter(mm_state, BLOOM_FILTER_PMD, walk->seq, pmd + i))
continue;
walk->mm_stats[MM_NONLEAF_FOUND]++;
@@ -3772,7 +3774,7 @@ static void walk_pmd_range(pud_t *pud, unsigned long start, unsigned long end,
walk->mm_stats[MM_NONLEAF_ADDED]++;
/* carry over to the next generation */
- update_bloom_filter(mm_state, walk->seq + 1, pmd + i);
+ update_bloom_filter(mm_state, BLOOM_FILTER_PMD, walk->seq + 1, pmd + i);
}
walk_pmd_range_locked(pud, -1, vma, args, bitmap, &first);
@@ -4434,8 +4436,8 @@ bool lru_gen_look_around(struct page_vma_mapped_walk *pvmw, unsigned int nr)
/* feedback from rmap walkers to page table walkers */
if (mm_state && suitable_to_scan(i, young))
- update_bloom_filter(mm_state, READ_ONCE(lruvec->lrugen.max_seq),
- pvmw->pmd);
+ update_bloom_filter(mm_state, BLOOM_FILTER_PMD,
+ READ_ONCE(lruvec->lrugen.max_seq), pvmw->pmd);
mem_cgroup_put(memcg);
@@ -6151,6 +6153,7 @@ void lru_gen_init_memcg(struct mem_cgroup *memcg)
void lru_gen_exit_memcg(struct mem_cgroup *memcg)
{
int i;
+ int level;
int nid;
struct lru_gen_mm_list *mm_list = get_mm_list(memcg);
@@ -6168,9 +6171,11 @@ void lru_gen_exit_memcg(struct mem_cgroup *memcg)
if (!mm_state)
continue;
- for (i = 0; i < NR_BLOOM_FILTERS; i++) {
- bitmap_free(mm_state->filters[i]);
- mm_state->filters[i] = NULL;
+ for (level = 0; level < BLOOM_FILTER_LEVELS; level++) {
+ for (i = 0; i < NR_BLOOM_FILTERS; i++) {
+ bitmap_free(mm_state->filters[level][i]);
+ mm_state->filters[level][i] = NULL;
+ }
}
}
}
--
2.52.0
^ permalink raw reply related [flat|nested] 7+ messages in thread
* [PATCH v5 3/4] mm/mglru: skip cold PUD subtrees during aging
2026-11-23 8:57 [PATCH v5 0/4] skip empty PUD subtrees during aging with a PUD-level Bloom filter Baoquan He
2026-11-23 8:57 ` [PATCH v5 1/4] mm/mglru: add MM_WALK_EMPTY stats and tracepoint Baoquan He
2026-11-23 8:57 ` [PATCH v5 2/4] mm/mglru: add PUD-level Bloom filter state and generic helpers Baoquan He
@ 2026-11-23 8:57 ` Baoquan He
2026-11-23 17:59 ` Lorenzo Stoakes (ARM)
2026-11-23 8:58 ` [PATCH v5 4/4] mm/mglru: count PUD subtrees skipped by the PUD-level filter Baoquan He
2026-11-23 17:57 ` [PATCH v5 0/4] skip empty PUD subtrees during aging with a PUD-level Bloom filter Lorenzo Stoakes (ARM)
4 siblings, 1 reply; 7+ messages in thread
From: Baoquan He @ 2026-11-23 8:57 UTC (permalink / raw)
To: linux-mm
Cc: david, akpm, kasong, baohua, qi.zheng, shakeel.butt,
axelrasmussen, yuanchu, weixugc, baolin.wang, baoquan.he,
Baoquan He, Kairui Song
From: Baoquan He <hebaoquan@kylinos.cn>
The aging walks into every PUD and runs the PMD-level Bloom filter on each
PMD. Add a coarser PUD-level filter one level up:
- walk_pmd_range() reports whether the subtree held anything young for
this lruvec. That is the same condition which already carries a PMD
over into the next generation: a young PMD entry, a huge page owned by
this lruvec, or PTEs with enough young ones to pass suitable_to_scan().
- walk_pud_range() records that in the PUD filter, and
- on subsequent generations, skips the whole PUD subtree when the filter
says it had nothing young last generation.
The filter key is (mm, PUD-aligned address): a stable identity for the
range that does not depend on the lifetime of a page table page, and that
the rmap path can compute without walking page tables.
The filter flips each generation and force_scan bypasses it, so a missed
re-mark costs at most one generation. To keep hot regions marked, the
rmap feedback path reports the covering PUD as well: lru_gen_look_around()
for PTE-mapped folios, folio_referenced_one() for PMD-mapped ones.
Without the second one a PUD that holds only transparent huge pages stays
skipped after one cold generation.
Suggested-by: Kairui Song <ryncsn@gmail.com>
Signed-off-by: Baoquan He <hebaoquan@kylinos.cn>
---
include/linux/mmzone.h | 6 +++
mm/rmap.c | 5 ++-
mm/vmscan.c | 99 ++++++++++++++++++++++++++++++++++++------
3 files changed, 96 insertions(+), 14 deletions(-)
diff --git a/include/linux/mmzone.h b/include/linux/mmzone.h
index f057c98d1f97..07e6c887e21a 100644
--- a/include/linux/mmzone.h
+++ b/include/linux/mmzone.h
@@ -677,6 +677,7 @@ struct lru_gen_memcg {
void lru_gen_init_pgdat(struct pglist_data *pgdat);
void lru_gen_init_lruvec(struct lruvec *lruvec);
bool lru_gen_look_around(struct page_vma_mapped_walk *pvmw, unsigned int nr);
+void lru_gen_mark_pud(struct mm_struct *mm, struct folio *folio, unsigned long addr);
void lru_gen_init_memcg(struct mem_cgroup *memcg);
void lru_gen_exit_memcg(struct mem_cgroup *memcg);
@@ -702,6 +703,11 @@ static inline bool lru_gen_look_around(struct page_vma_mapped_walk *pvmw,
return false;
}
+static inline void lru_gen_mark_pud(struct mm_struct *mm, struct folio *folio,
+ unsigned long addr)
+{
+}
+
static inline void lru_gen_init_memcg(struct mem_cgroup *memcg)
{
}
diff --git a/mm/rmap.c b/mm/rmap.c
index 65646ed6fc45..ea5ada45c09f 100644
--- a/mm/rmap.c
+++ b/mm/rmap.c
@@ -1004,8 +1004,11 @@ static bool folio_referenced_one(struct folio *folio,
referenced++;
} else if (IS_ENABLED(CONFIG_TRANSPARENT_HUGEPAGE)) {
if (pmdp_clear_flush_young_notify(vma, address,
- pvmw.pmd))
+ pvmw.pmd)) {
referenced++;
+ if (lru_gen_enabled() && !lru_gen_switching())
+ lru_gen_mark_pud(vma->vm_mm, folio, address);
+ }
} else {
/* unexpected pmd-mapped folio? */
WARN_ON_ONCE(1);
diff --git a/mm/vmscan.c b/mm/vmscan.c
index 7d20ee1b6c10..517f5fbecdbf 100644
--- a/mm/vmscan.c
+++ b/mm/vmscan.c
@@ -2794,9 +2794,18 @@ static bool __maybe_unused seq_is_valid(struct lruvec *lruvec)
* walk_pmd_range(); the eviction also report them when walking the rmap
* in lru_gen_look_around().
*
+ * A second pair of filters works one level above the first pair, over a whole
+ * 1 GiB subtree (a PUD): BLOOM_FILTER_PUD next to BLOOM_FILTER_PMD. A false
+ * positive at the PMD level only costs a PTE walk when the PUD level also
+ * passes. A false positive at the PUD level is rare, because it holds far
+ * fewer keys, but it costs 512 PMD walks. So both levels keep the same m and
+ * k, even though the PUD level holds much fewer keys.
+ *
* For future optimizations:
- * 1. It's not necessary to keep both filters all the time. The spare one can be
- * freed after the RCU grace period and reallocated if needed again.
+ * 1. It's not necessary to keep both filters of a level all the time.
+ * The spare one can be freed after the RCU grace period and reallocated
+ * if needed again. Now: two levels of double buffering take 16 KiB
+ * per lruvec.
* 2. And when reallocating, it's worth scaling its size according to the number
* of inserted entries in the other filter, to reduce the memory overhead on
* small systems and false positives on large systems.
@@ -3110,8 +3119,10 @@ static bool iterate_mm_list(struct lru_gen_mm_walk *walk, struct mm_struct **ite
spin_unlock(&mm_list->lock);
- if (mm && first)
+ if (mm && first) {
reset_bloom_filter(mm_state, BLOOM_FILTER_PMD, walk->seq + 1);
+ reset_bloom_filter(mm_state, BLOOM_FILTER_PUD, walk->seq + 1);
+ }
if (*iter)
mmdrop(*iter);
@@ -3623,11 +3634,12 @@ static bool walk_pte_range(pmd_t *pmd, unsigned long start, unsigned long end,
return suitable_to_scan(total, young);
}
-static void walk_pmd_range_locked(pud_t *pud, unsigned long addr, struct vm_area_struct *vma,
+static bool walk_pmd_range_locked(pud_t *pud, unsigned long addr, struct vm_area_struct *vma,
struct mm_walk *args, unsigned long *bitmap, unsigned long *first)
{
int i;
bool dirty;
+ bool young = false;
pmd_t *pmd;
spinlock_t *ptl;
struct folio *last = NULL;
@@ -3641,13 +3653,13 @@ static void walk_pmd_range_locked(pud_t *pud, unsigned long addr, struct vm_area
if (*first == -1) {
*first = addr;
bitmap_zero(bitmap, MIN_LRU_BATCH);
- return;
+ return false;
}
i = addr == -1 ? 0 : pmd_index(addr) - pmd_index(*first);
if (i && i <= MIN_LRU_BATCH) {
__set_bit(i - 1, bitmap);
- return;
+ return false;
}
pmd = pmd_offset(pud, *first);
@@ -3697,6 +3709,7 @@ static void walk_pmd_range_locked(pud_t *pud, unsigned long addr, struct vm_area
dirty = true;
walk->mm_stats[MM_LEAF_YOUNG]++;
+ young = true;
next:
i = i > MIN_LRU_BATCH ? 0 : find_next_bit(bitmap, MIN_LRU_BATCH, i) + 1;
} while (i <= MIN_LRU_BATCH);
@@ -3707,12 +3720,15 @@ static void walk_pmd_range_locked(pud_t *pud, unsigned long addr, struct vm_area
spin_unlock(ptl);
done:
*first = -1;
+
+ return young;
}
-static void walk_pmd_range(pud_t *pud, unsigned long start, unsigned long end,
+static bool walk_pmd_range(pud_t *pud, unsigned long start, unsigned long end,
struct mm_walk *args)
{
int i;
+ bool young = false;
pmd_t *pmd;
unsigned long next;
unsigned long addr;
@@ -3750,7 +3766,8 @@ static void walk_pmd_range(pud_t *pud, unsigned long start, unsigned long end,
walk->mm_stats[MM_LEAF_TOTAL]++;
if (pfn != -1)
- walk_pmd_range_locked(pud, addr, vma, args, bitmap, &first);
+ young |= walk_pmd_range_locked(pud, addr, vma, args,
+ bitmap, &first);
continue;
}
@@ -3772,15 +3789,18 @@ static void walk_pmd_range(pud_t *pud, unsigned long start, unsigned long end,
continue;
walk->mm_stats[MM_NONLEAF_ADDED]++;
+ young = true;
/* carry over to the next generation */
update_bloom_filter(mm_state, BLOOM_FILTER_PMD, walk->seq + 1, pmd + i);
}
- walk_pmd_range_locked(pud, -1, vma, args, bitmap, &first);
+ young |= walk_pmd_range_locked(pud, -1, vma, args, bitmap, &first);
if (i < PTRS_PER_PMD && get_next_vma(PUD_MASK, PMD_SIZE, args, &start, &end))
goto restart;
+
+ return young;
}
static int walk_pud_range(p4d_t *p4d, unsigned long start, unsigned long end,
@@ -3791,6 +3811,7 @@ static int walk_pud_range(p4d_t *p4d, unsigned long start, unsigned long end,
unsigned long addr;
unsigned long next;
struct lru_gen_mm_walk *walk = args->private;
+ struct lru_gen_mm_state *mm_state = get_mm_state(walk->lruvec);
VM_WARN_ON_ONCE(p4d_leaf(*p4d));
@@ -3798,13 +3819,29 @@ static int walk_pud_range(p4d_t *p4d, unsigned long start, unsigned long end,
restart:
for (i = pud_index(start), addr = start; addr != end; i++, addr = next) {
pud_t val = pudp_get(pud + i);
+ void *pud_key;
next = pud_addr_end(addr, end);
if (!pud_present(val) || WARN_ON_ONCE(pud_leaf(val)))
continue;
- walk_pmd_range(pud + i, addr, next, args);
+ /*
+ * Use (mm, PUD-aligned address) as the filter key instead of
+ * the page table pointer. It is stable across the aging walk
+ * and the rmap feedback path, and avoids walking the page
+ * tables in lru_gen_look_around().
+ */
+ pud_key = (void *)((unsigned long)args->mm ^ (addr & PUD_MASK));
+
+ /* Skip a subtree that had nothing young for this lruvec last gen */
+ if (!walk->force_scan &&
+ !test_bloom_filter(mm_state, BLOOM_FILTER_PUD, walk->seq, pud_key))
+ continue;
+
+ if (walk_pmd_range(pud + i, addr, next, args))
+ update_bloom_filter(mm_state, BLOOM_FILTER_PUD, walk->seq + 1,
+ pud_key);
if (need_resched() || walk->batched >= MAX_LRU_BATCH) {
end = (addr | ~PUD_MASK) + 1;
@@ -4334,6 +4371,39 @@ static void lru_gen_age_node(struct pglist_data *pgdat, struct scan_control *sc)
* the PTE table to the Bloom filter. This forms a feedback loop between the
* eviction and the aging.
*/
+/*
+ * Mark the PUD covering addr as young for lruvec, so that the PUD-level filter
+ * walks that 1 GiB subtree in the next generation.
+ */
+static void lru_gen_update_pud_filter(struct lruvec *lruvec, struct mm_struct *mm,
+ unsigned long addr)
+{
+ struct lru_gen_mm_state *mm_state = get_mm_state(lruvec);
+ unsigned long max_seq;
+
+ if (!mm_state)
+ return;
+
+ max_seq = READ_ONCE(lruvec->lrugen.max_seq);
+ update_bloom_filter(mm_state, BLOOM_FILTER_PUD, max_seq,
+ (void *)((unsigned long)mm ^ (addr & PUD_MASK)));
+}
+
+/*
+ * Same for a PMD-mapped folio: folio_referenced_one() takes the
+ * pmdp_clear_flush_young_notify() branch for those and never reaches
+ * lru_gen_look_around(), so without this a PUD holding only THPs stays
+ * suppressed once it has been skipped for one generation.
+ */
+void lru_gen_mark_pud(struct mm_struct *mm, struct folio *folio, unsigned long addr)
+{
+ struct mem_cgroup *memcg = get_mem_cgroup_from_folio(folio);
+
+ lru_gen_update_pud_filter(mem_cgroup_lruvec(memcg, folio_pgdat(folio)),
+ mm, addr);
+ mem_cgroup_put(memcg);
+}
+
bool lru_gen_look_around(struct page_vma_mapped_walk *pvmw, unsigned int nr)
{
int i;
@@ -4435,9 +4505,12 @@ bool lru_gen_look_around(struct page_vma_mapped_walk *pvmw, unsigned int nr)
lazy_mmu_mode_disable();
/* feedback from rmap walkers to page table walkers */
- if (mm_state && suitable_to_scan(i, young))
- update_bloom_filter(mm_state, BLOOM_FILTER_PMD,
- READ_ONCE(lruvec->lrugen.max_seq), pvmw->pmd);
+ if (mm_state && suitable_to_scan(i, young)) {
+ unsigned long max_seq = READ_ONCE(lruvec->lrugen.max_seq);
+
+ update_bloom_filter(mm_state, BLOOM_FILTER_PMD, max_seq, pvmw->pmd);
+ lru_gen_update_pud_filter(lruvec, vma->vm_mm, pvmw->address);
+ }
mem_cgroup_put(memcg);
--
2.52.0
^ permalink raw reply related [flat|nested] 7+ messages in thread
* [PATCH v5 4/4] mm/mglru: count PUD subtrees skipped by the PUD-level filter
2026-11-23 8:57 [PATCH v5 0/4] skip empty PUD subtrees during aging with a PUD-level Bloom filter Baoquan He
` (2 preceding siblings ...)
2026-11-23 8:57 ` [PATCH v5 3/4] mm/mglru: skip cold PUD subtrees during aging Baoquan He
@ 2026-11-23 8:58 ` Baoquan He
2026-11-23 17:57 ` [PATCH v5 0/4] skip empty PUD subtrees during aging with a PUD-level Bloom filter Lorenzo Stoakes (ARM)
4 siblings, 0 replies; 7+ messages in thread
From: Baoquan He @ 2026-11-23 8:58 UTC (permalink / raw)
To: linux-mm
Cc: david, akpm, kasong, baohua, qi.zheng, shakeel.butt,
axelrasmussen, yuanchu, weixugc, baolin.wang, baoquan.he,
Baoquan He
From: Baoquan He <hebaoquan@kylinos.cn>
Add MM_PUD_EMPTY_SKIPPED, incremented in walk_pud_range() whenever a PUD
subtree is skipped by the filter. Like the other per-walk counters it is
shown in the debugfs lru_gen output (the "S" column of TYFAWEES) and in
the mm_vmscan_lru_gen_walk tracepoint, so the avoided cost can be measured
directly.
Signed-off-by: Baoquan He <hebaoquan@kylinos.cn>
---
include/linux/mmzone.h | 1 +
mm/trace_vmscan.h | 10 ++++++----
mm/vmscan.c | 13 ++++++++-----
3 files changed, 15 insertions(+), 9 deletions(-)
diff --git a/include/linux/mmzone.h b/include/linux/mmzone.h
index 07e6c887e21a..a1437728180d 100644
--- a/include/linux/mmzone.h
+++ b/include/linux/mmzone.h
@@ -582,6 +582,7 @@ enum {
MM_WALK_TOTAL, /* page-table walks completed */
MM_WALK_EMPTY, /* walks that found no young leaf for this lruvec */
MM_LEAF_EMPTY_WALKS, /* leaf entries scanned during empty walks */
+ MM_PUD_EMPTY_SKIPPED, /* PUD subtrees skipped by the PUD-level filter */
NR_MM_STATS
};
diff --git a/mm/trace_vmscan.h b/mm/trace_vmscan.h
index b0c2af65c1ea..5a78b8ca3dac 100644
--- a/mm/trace_vmscan.h
+++ b/mm/trace_vmscan.h
@@ -511,9 +511,9 @@ TRACE_EVENT(mm_mglru_aging,
TRACE_EVENT(mm_vmscan_lru_gen_walk,
TP_PROTO(int nid, unsigned long seq, int leaf_total,
- int leaf_young, bool empty),
+ int leaf_young, bool empty, int pud_skipped),
- TP_ARGS(nid, seq, leaf_total, leaf_young, empty),
+ TP_ARGS(nid, seq, leaf_total, leaf_young, empty, pud_skipped),
TP_STRUCT__entry(
__field(int, nid)
@@ -521,6 +521,7 @@ TRACE_EVENT(mm_vmscan_lru_gen_walk,
__field(int, leaf_total)
__field(int, leaf_young)
__field(bool, empty)
+ __field(int, pud_skipped)
),
TP_fast_assign(
@@ -529,11 +530,12 @@ TRACE_EVENT(mm_vmscan_lru_gen_walk,
__entry->leaf_total = leaf_total;
__entry->leaf_young = leaf_young;
__entry->empty = empty;
+ __entry->pud_skipped = pud_skipped;
),
- TP_printk("nid=%d seq=%lu leaf_total=%d leaf_young=%d empty=%d",
+ TP_printk("nid=%d seq=%lu leaf_total=%d leaf_young=%d empty=%d pud_skipped=%d",
__entry->nid, __entry->seq, __entry->leaf_total,
- __entry->leaf_young, __entry->empty)
+ __entry->leaf_young, __entry->empty, __entry->pud_skipped)
);
#endif /* CONFIG_LRU_GEN */
diff --git a/mm/vmscan.c b/mm/vmscan.c
index 517f5fbecdbf..56e18ffd3383 100644
--- a/mm/vmscan.c
+++ b/mm/vmscan.c
@@ -3836,8 +3836,10 @@ static int walk_pud_range(p4d_t *p4d, unsigned long start, unsigned long end,
/* Skip a subtree that had nothing young for this lruvec last gen */
if (!walk->force_scan &&
- !test_bloom_filter(mm_state, BLOOM_FILTER_PUD, walk->seq, pud_key))
+ !test_bloom_filter(mm_state, BLOOM_FILTER_PUD, walk->seq, pud_key)) {
+ walk->mm_stats[MM_PUD_EMPTY_SKIPPED]++;
continue;
+ }
if (walk_pmd_range(pud + i, addr, next, args))
update_bloom_filter(mm_state, BLOOM_FILTER_PUD, walk->seq + 1,
@@ -4221,7 +4223,8 @@ static bool try_to_inc_max_seq(struct lruvec *lruvec, unsigned long seq,
trace_mm_vmscan_lru_gen_walk(
lruvec_pgdat(lruvec)->node_id, walk->seq,
walk->mm_stats[MM_LEAF_TOTAL],
- walk->mm_stats[MM_LEAF_YOUNG], empty);
+ walk->mm_stats[MM_LEAF_YOUNG], empty,
+ walk->mm_stats[MM_PUD_EMPTY_SKIPPED]);
}
} while (mm);
done:
@@ -5903,14 +5906,14 @@ static void lru_gen_seq_show_full(struct seq_file *m, struct lruvec *lruvec,
seq_puts(m, " ");
for (i = 0; i < NR_MM_STATS; i++) {
- const char *s = "xxxxxxxx";
+ const char *s = "xxxxxxxxx";
unsigned long n = 0;
if (seq == max_seq && NR_HIST_GENS == 1) {
- s = "TYFAWEE";
+ s = "TYFAWEES";
n = READ_ONCE(mm_state->stats[hist][i]);
} else if (seq != max_seq && NR_HIST_GENS > 1) {
- s = "tyfawee";
+ s = "tyfawees";
n = READ_ONCE(mm_state->stats[hist][i]);
}
--
2.52.0
^ permalink raw reply related [flat|nested] 7+ messages in thread
* Re: [PATCH v5 0/4] skip empty PUD subtrees during aging with a PUD-level Bloom filter
2026-11-23 8:57 [PATCH v5 0/4] skip empty PUD subtrees during aging with a PUD-level Bloom filter Baoquan He
` (3 preceding siblings ...)
2026-11-23 8:58 ` [PATCH v5 4/4] mm/mglru: count PUD subtrees skipped by the PUD-level filter Baoquan He
@ 2026-11-23 17:57 ` Lorenzo Stoakes (ARM)
4 siblings, 0 replies; 7+ messages in thread
From: Lorenzo Stoakes (ARM) @ 2026-11-23 17:57 UTC (permalink / raw)
To: Baoquan He
Cc: linux-mm, david, akpm, kasong, baohua, qi.zheng, shakeel.butt,
axelrasmussen, yuanchu, weixugc, baolin.wang
(Got a script set up to detect things not cc'd now)
On Mon, Nov 23, 2026 at 04:57:56PM +0800, Baoquan He wrote:
> mm/rmap.c | 5 +-
MEMORY MANAGEMENT - RMAP (REVERSE MAPPING)
...
M: Lorenzo Stoakes <ljs@kernel.org>
Please cc- me on rmap stuff, thanks ;)
--
Cheers, Lorenzo
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH v5 3/4] mm/mglru: skip cold PUD subtrees during aging
2026-11-23 8:57 ` [PATCH v5 3/4] mm/mglru: skip cold PUD subtrees during aging Baoquan He
@ 2026-11-23 17:59 ` Lorenzo Stoakes (ARM)
0 siblings, 0 replies; 7+ messages in thread
From: Lorenzo Stoakes (ARM) @ 2026-11-23 17:59 UTC (permalink / raw)
To: Baoquan He
Cc: linux-mm, david, akpm, kasong, baohua, qi.zheng, shakeel.butt,
axelrasmussen, yuanchu, weixugc, baolin.wang, Baoquan He,
Kairui Song
On Mon, Nov 23, 2026 at 04:57:59PM +0800, Baoquan He wrote:
> diff --git a/mm/rmap.c b/mm/rmap.c
> index 65646ed6fc45..ea5ada45c09f 100644
> --- a/mm/rmap.c
> +++ b/mm/rmap.c
> @@ -1004,8 +1004,11 @@ static bool folio_referenced_one(struct folio *folio,
> referenced++;
> } else if (IS_ENABLED(CONFIG_TRANSPARENT_HUGEPAGE)) {
> if (pmdp_clear_flush_young_notify(vma, address,
> - pvmw.pmd))
> + pvmw.pmd)) {
> referenced++;
> + if (lru_gen_enabled() && !lru_gen_switching())
Could this be abstracted a little bette? This looks to be embedding an expression
specific to lrugen in rmap?
> + lru_gen_mark_pud(vma->vm_mm, folio, address);
--
Cheers, Lorenzo
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2026-11-23 17:59 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-23 8:57 [PATCH v5 0/4] skip empty PUD subtrees during aging with a PUD-level Bloom filter Baoquan He
2026-11-23 8:57 ` [PATCH v5 1/4] mm/mglru: add MM_WALK_EMPTY stats and tracepoint Baoquan He
2026-11-23 8:57 ` [PATCH v5 2/4] mm/mglru: add PUD-level Bloom filter state and generic helpers Baoquan He
2026-11-23 8:57 ` [PATCH v5 3/4] mm/mglru: skip cold PUD subtrees during aging Baoquan He
2026-11-23 17:59 ` Lorenzo Stoakes (ARM)
2026-11-23 8:58 ` [PATCH v5 4/4] mm/mglru: count PUD subtrees skipped by the PUD-level filter Baoquan He
2026-11-23 17:57 ` [PATCH v5 0/4] skip empty PUD subtrees during aging with a PUD-level Bloom filter Lorenzo Stoakes (ARM)
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox