Skip to contentSkip to conversation

skip empty PUD subtrees during aging with a PUD-level Bloom filter

PATCH New Baoquan He 1 participant 5 messages Nov 27

Subsystems (5)
lore
Share & tools
lore

Baoquan He

author reviewer
#0 lore raw

v6 cover skip empty PUD subtrees during aging with a PUD-level Bloom filter

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
==========
v5 -> v6:
- Rebased to latest mm-new.

- Keep the "is MGLRU in use" test inside lru_gen_mark_pud(), so the rmap side is one plain call and rmap does not carry an MGLRU expression. Suggested by by Lorenzo.

- In the non-leaf PMD branch of walk_pmd_range(), keep the result of walk_pmd_range_locked(). That call can flush the huge pages batched by an earlier iteration, and if it does and no later PMD is young, the PUD was left out of the filter and the 1 GiB subtree was skipped on the next pass. (Sashiko)

v4 -> v5:
- Drop MM_LEAF_ASSOCIATED: an empty walk is now "MM_LEAF_TOTAL > 0 and MM_LEAF_YOUNG == 0". (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

The filter's scan, steal, swap-out, refault and residency are the same as base's within run-to-run noise: base's own two runs span 38.8M-48.7M on pgscan. The filter still skips the cold node 1 PUDs (walks with leaves 4,000 -> 4), but reclaim costs nothing measurable.

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              |   4 +-
 mm/trace_vmscan.h      |  30 +++++++
 mm/vmscan.c            | 184 +++++++++++++++++++++++++++++++++--------
 4 files changed, 202 insertions(+), 36 deletions(-)

base-commit: 5bd93e4b0b357e9d0a13199887aacbf04d1ce216

Signature · 1 line
2.52.0
author reviewer
#1 lore raw

PATCH v6 1/4 mm/mglru: add MM_WALK_EMPTY stats and tracepoint

From: Baoquan He <[email protected]>

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.

---
 include/linux/mmzone.h |  3 +++
 mm/trace_vmscan.h      | 28 ++++++++++++++++++++++++++++
 mm/vmscan.c            | 32 ++++++++++++++++++++++++++++----
 3 files changed, 59 insertions(+), 4 deletions(-)
include/linux/mmzone.h +3 -0
index 14c58bbd1606..12cba15a02fa 100644
@@ -631,6 +631,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
 };
 
mm/trace_vmscan.h +28 -0
index 9dafdb5bd3ce..b0c2af65c1ea 100644
@@ -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,
mm/vmscan.c +28 -4
index 81797b71228f..c755d4914d76 100644
@@ -4375,8 +4375,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) {
@@ -6010,14 +6034,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]);
 		}
 
Signature · 1 line
2.52.0
author reviewer
#2 lore raw

PATCH v6 2/4 mm/mglru: add PUD-level Bloom filter state and generic helpers

In reply to Baoquan He

From: Baoquan He <[email protected]>

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.

---
 include/linux/mmzone.h | 10 ++++++++--
 mm/vmscan.c            | 39 ++++++++++++++++++++++-----------------
 2 files changed, 30 insertions(+), 19 deletions(-)
include/linux/mmzone.h +8 -2
index 12cba15a02fa..98b60cd6b534 100644
@@ -640,6 +640,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;
@@ -647,8 +653,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];
 };
mm/vmscan.c +22 -17
index c755d4914d76..9861cc35062f 100644
@@ -3068,14 +3068,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;
 
@@ -3084,14 +3084,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;
 
@@ -3103,12 +3103,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;
@@ -3116,7 +3117,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);
 }
 
 /******************************************************************************
@@ -3359,7 +3360,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);
@@ -4010,7 +4011,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]++;
@@ -4021,7 +4023,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);
@@ -4651,8 +4653,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);
 
@@ -6357,6 +6359,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);
 
@@ -6374,9 +6377,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;
+			}
 		}
 	}
 }
Signature · 1 line
2.52.0
author reviewer
#3 lore raw

PATCH v6 3/4 mm/mglru: skip cold PUD subtrees during aging

In reply to Baoquan He

From: Baoquan He <[email protected]>

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.

---
 include/linux/mmzone.h |   6 +++
 mm/rmap.c              |   4 +-
 mm/vmscan.c            | 114 ++++++++++++++++++++++++++++++++++++-----
 3 files changed, 109 insertions(+), 15 deletions(-)
include/linux/mmzone.h +6 -0
index 98b60cd6b534..832809cbeeb0 100644
@@ -731,6 +731,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);
@@ -756,6 +757,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)
 {
 }
mm/rmap.c +3 -1
index fe354fa6cc43..6459aee862e2 100644
@@ -1005,8 +1005,10 @@ 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++;
+				lru_gen_mark_pud(vma->vm_mm, folio, address);
+			}
 		} else {
 			/* unexpected pmd-mapped folio? */
 			WARN_ON_ONCE(1);
mm/vmscan.c +100 -14

222 lines not on this page · raw message

Signature · 1 line
2.52.0
author reviewer
#4 lore raw

PATCH v6 4/4 mm/mglru: count PUD subtrees skipped by the PUD-level filter

In reply to Baoquan He

From: Baoquan He <[email protected]>

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.

---
 include/linux/mmzone.h |  1 +
 mm/trace_vmscan.h      | 10 ++++++----
 mm/vmscan.c            | 13 ++++++++-----
 3 files changed, 15 insertions(+), 9 deletions(-)
include/linux/mmzone.h +1 -0
index 832809cbeeb0..49eb833aa786 100644
@@ -634,6 +634,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
 };
 
mm/trace_vmscan.h +6 -4
index b0c2af65c1ea..5a78b8ca3dac 100644
@@ -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 */
mm/vmscan.c +8 -5
index db89b5f5f0db..4d0f82c6cc59 100644
@@ -4091,8 +4091,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,
@@ -4444,7 +4446,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:
@@ -6122,14 +6125,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]);
 		}
 
Signature · 1 line
2.52.0