Skip to contentSkip to conversation

mm/mglru: add tracepoints for scan and aging paths

PATCH In review Ridong Chen 4 participants 19 messages Sep 11 – Oct 19

Subsystems (4)
lore
Share & tools
lore
#0 lore raw

v2 cover mm/mglru: add tracepoints for scan and aging paths

From: Ridong Chen <[email protected]>

Background
==========

MGLRU currently has no tracepoints of its own. The scan and evict paths reuse the classic-LRU tracepoints (trace_mm_vmscan_lru_isolate() and trace_mm_vmscan_lru_shrink_inactive()), which predate MGLRU and carry no generation, sequence, memcg or swappiness context. A trace of a running system therefore cannot tell which memcg a given scan belongs to, how far reclaim has progressed through the generations, or when a new generation is created - so how MGLRU actually operates is effectively invisible.

Implementation
==============

Patch 1 is a cleanup that factors the per-generation page-count summation into a helper, lru_gen_seq_nr_pages(), reused by patch 3.

Patch 2 adds mm_mglru_scan_folios on the scan path, and patch 3 adds mm_mglru_inc_max_seq on the aging path. Both carry the memcg id and the generation window (min_seq/max_seq), live at MGLRU-specific layers with no classic-LRU counterpart, and are guarded so the hot paths stay zero-cost when disabled.

Effect
======

Paired, the two tracepoints make the full aging-to-eviction window observable per memcg: aging advances max_seq (the leading edge), scanning consumes the oldest generations, and the min_seq/max_seq pair on each event shows how the generation window moves over time.

A sample trace, with the classic-LRU tracepoints left enabled to show how they interleave:

mm_vmscan_lru_isolate: classzone=4 order=0 nr_requested=36 nr_scanned=31 nr_skipped=0 nr_taken=29 lru=inactive_file
mm_mglru_scan_folios: memcg_id=73 classzone=4 order=0 nr_requested=36 nr_scanned=31 nr_sorted=2 nr_skipped=0 nr_taken=29 lru=inactive_file max_seq=3 tier=3 min_seq=0
mm_vmscan_lru_shrink_inactive: nid=0 nr_scanned=31 nr_reclaimed=29 nr_dirty=0 nr_writeback=0 nr_congested=0 nr_immediate=0 nr_activate_anon=0 nr_activate_file=0 nr_ref_keep=0 nr_unmap_fail=0 priority=5 flags=RECLAIM_WB_FILE|RECLAIM_WB_ASYNC
mm_mglru_inc_max_seq: memcg_id=73 max_seq=4 anon_min_seq=1 file_min_seq=1 nr_anon={0x0,0x0,0x1,0x0} nr_file={0x0,0x427,0x6,0x4a}
mm_vmscan_lru_isolate: classzone=4 order=0 nr_requested=5 nr_scanned=5 nr_skipped=0 nr_taken=1 lru=inactive_file
mm_mglru_scan_folios: memcg_id=73 classzone=4 order=0 nr_requested=5 nr_scanned=5 nr_sorted=4 nr_skipped=0 nr_taken=1 lru=inactive_file max_seq=4 tier=3 min_seq=1
mm_vmscan_lru_shrink_inactive: nid=0 nr_scanned=5 nr_reclaimed=1 nr_dirty=0 nr_writeback=0 nr_congested=0 nr_immediate=0 nr_activate_anon=0 nr_activate_file=0 nr_ref_keep=0 nr_unmap_fail=0 priority=5 flags=RECLAIM_WB_FILE|RECLAIM_WB_ASYNC

The mm_mglru_scan_folios lines carry the memcg id and the generation window (max_seq/min_seq) that the bare mm_vmscan_lru_isolate lines above them cannot - those cannot even say which memcg they came from. The mm_mglru_inc_max_seq line then shows a new generation being created (max_seq 3 -> 4) with the per-generation page counts for both types.

---
v2: address Sashiko AI review [1] - pass struct lruvec * into the tracepoints
and do the memcg lookup inside TP_fast_assign.

[1] https://sashiko.dev/#/patchset/[email protected]?part=2

Ridong Chen (3):
mm/mglru: factor out lru_gen_seq_nr_pages()
mm/mglru: add tracepoint for scan_folios()
mm/mglru: add tracepoint for inc_max_seq()

 include/trace/events/vmscan.h | 101 ++++++++++++++++++++++++++++++++++
 mm/vmscan.c                   |  53 +++++++++++++++---
 2 files changed, 146 insertions(+), 8 deletions(-)
Signature · 1 line
2.34.1
#1 lore raw

PATCH v2 1/3 mm/mglru: factor out lru_gen_seq_nr_pages()

From: Ridong Chen <[email protected]>

Both lruvec_evictable_size() and the debugfs lru_gen_seq_show() compute the number of pages in a generation the same way: sum lrugen->nr_pages over all zones for a given (gen, type) and clamp each term to >= 0.

Factor that out into lru_gen_seq_nr_pages() so the open-coded zone loop lives in one place. No functional change.

A follow-up patch adds a tracepoint that needs the same per-generation page count, and will reuse this helper instead of open-coding it again.

Assisted-by Claude:claude-opus-4-8
---
 mm/vmscan.c | 24 ++++++++++++++++--------
 1 file changed, 16 insertions(+), 8 deletions(-)
mm/vmscan.c +16 -8
index 40d3f1b48a74..2554a6513aa8 100644
@@ -2813,6 +2813,18 @@ static int get_nr_gens(struct lruvec *lruvec, int type)
 	return lruvec->lrugen.max_seq - lruvec->lrugen.min_seq[type] + 1;
 }
 
+/* the number of pages in a generation, summed over zones and clamped to >= 0 */
+static unsigned long lru_gen_seq_nr_pages(struct lru_gen_folio *lrugen, int gen, int type)
+{
+	int zone;
+	unsigned long size = 0;
+
+	for (zone = 0; zone < MAX_NR_ZONES; zone++)
+		size += max(READ_ONCE(lrugen->nr_pages[gen][type][zone]), 0L);
+
+	return size;
+}
+
 static bool __maybe_unused seq_is_valid(struct lruvec *lruvec)
 {
 	int type;
@@ -4239,7 +4251,7 @@ static void set_initial_priority(struct pglist_data *pgdat, struct scan_control
 
 static unsigned long lruvec_evictable_size(struct lruvec *lruvec, int swappiness)
 {
-	int gen, type, zone;
+	int gen, type;
 	unsigned long seq, total = 0;
 	struct lru_gen_folio *lrugen = &lruvec->lrugen;
 	DEFINE_MAX_SEQ(lruvec);
@@ -4248,8 +4260,7 @@ static unsigned long lruvec_evictable_size(struct lruvec *lruvec, int swappiness
 	for_each_evictable_type(type, swappiness) {
 		for (seq = min_seq[type]; seq <= max_seq; seq++) {
 			gen = lru_gen_from_seq(seq);
-			for (zone = 0; zone < MAX_NR_ZONES; zone++)
-				total += max(READ_ONCE(lrugen->nr_pages[gen][type][zone]), 0L);
+			total += lru_gen_seq_nr_pages(lrugen, gen, type);
 		}
 	}
 
@@ -5738,19 +5749,16 @@ static int lru_gen_seq_show(struct seq_file *m, void *v)
 		seq = 0;
 
 	for (; seq <= max_seq; seq++) {
-		int type, zone;
+		int type;
 		int gen = lru_gen_from_seq(seq);
 		unsigned long birth = READ_ONCE(lruvec->lrugen.timestamps[gen]);
 
 		seq_printf(m, " %10lu %10u", seq, jiffies_to_msecs(jiffies - birth));
 
 		for (type = 0; type < ANON_AND_FILE; type++) {
-			unsigned long size = 0;
+			unsigned long size = lru_gen_seq_nr_pages(lrugen, gen, type);
 			char mark = full && seq < min_seq[type] ? 'x' : ' ';
 
-			for (zone = 0; zone < MAX_NR_ZONES; zone++)
-				size += max(READ_ONCE(lrugen->nr_pages[gen][type][zone]), 0L);
-
 			seq_printf(m, " %10lu%c", size, mark);
 		}
 
Signature · 1 line
2.34.1
reviewer Reviewed-by on v2 1/3
#2 lore raw

Re: [PATCH v2 1/3] mm/mglru: factor out lru_gen_seq_nr_pages()

Quoted 9 lines · Ridong Chen

From: Ridong Chen <[email protected]>

Both lruvec_evictable_size() and the debugfs lru_gen_seq_show() compute the number of pages in a generation the same way: sum lrugen->nr_pages over all zones for a given (gen, type) and clamp each term to >= 0.

Factor that out into lru_gen_seq_nr_pages() so the open-coded zone loop lives in one place. No functional change.

Quoted 6 lines

A follow-up patch adds a tracepoint that needs the same per-generation page count, and will reuse this helper instead of open-coding it again.

Assisted-by Claude:claude-opus-4-8

---

LGTM.

reviewer Reviewed-by on v2 1/3
#3 lore raw

Re: [PATCH v2 1/3] mm/mglru: factor out lru_gen_seq_nr_pages()

In reply to Ridong Chen
Quoted 23 lines · Ridong Chen

From: Ridong Chen <[email protected]>

Both lruvec_evictable_size() and the debugfs lru_gen_seq_show() compute the number of pages in a generation the same way: sum lrugen->nr_pages over all zones for a given (gen, type) and clamp each term to >= 0.

Factor that out into lru_gen_seq_nr_pages() so the open-coded zone loop lives in one place. No functional change.

A follow-up patch adds a tracepoint that needs the same per-generation page count, and will reuse this helper instead of open-coding it again.

Assisted-by Claude:claude-opus-4-8
---
 mm/vmscan.c | 24 ++++++++++++++++--------
 1 file changed, 16 insertions(+), 8 deletions(-)
mm/vmscan.c +0 -0
index 40d3f1b48a74..2554a6513aa8 100644

mm/vmscan.c static int get_nr_gens(struct lruvec *lruvec, int type) · line 2816

Quoted 4 lines
mm/vmscan.c +1 -0
@@ -2813,6 +2813,18 @@ static int get_nr_gens(struct lruvec *lruvec, int type)
 	return lruvec->lrugen.max_seq - lruvec->lrugen.min_seq[type] + 1;
 }
 
+/* the number of pages in a generation, summed over zones and clamped to >= 0 */
      ^

The first letter should be capitalized?

Other than the nit, LGTM,

Quoted 58 lines
mm/vmscan.c +15 -8
+static unsigned long lru_gen_seq_nr_pages(struct lru_gen_folio *lrugen, int gen, int type)
+{
+	int zone;
+	unsigned long size = 0;
+
+	for (zone = 0; zone < MAX_NR_ZONES; zone++)
+		size += max(READ_ONCE(lrugen->nr_pages[gen][type][zone]), 0L);
+
+	return size;
+}
+
 static bool __maybe_unused seq_is_valid(struct lruvec *lruvec)
 {
 	int type;
@@ -4239,7 +4251,7 @@ static void set_initial_priority(struct pglist_data *pgdat, struct scan_control
 
 static unsigned long lruvec_evictable_size(struct lruvec *lruvec, int swappiness)
 {
-	int gen, type, zone;
+	int gen, type;
 	unsigned long seq, total = 0;
 	struct lru_gen_folio *lrugen = &lruvec->lrugen;
 	DEFINE_MAX_SEQ(lruvec);
@@ -4248,8 +4260,7 @@ static unsigned long lruvec_evictable_size(struct lruvec *lruvec, int swappiness
 	for_each_evictable_type(type, swappiness) {
 		for (seq = min_seq[type]; seq <= max_seq; seq++) {
 			gen = lru_gen_from_seq(seq);
-			for (zone = 0; zone < MAX_NR_ZONES; zone++)
-				total += max(READ_ONCE(lrugen->nr_pages[gen][type][zone]), 0L);
+			total += lru_gen_seq_nr_pages(lrugen, gen, type);
 		}
 	}
 
@@ -5738,19 +5749,16 @@ static int lru_gen_seq_show(struct seq_file *m, void *v)
 		seq = 0;
 
 	for (; seq <= max_seq; seq++) {
-		int type, zone;
+		int type;
 		int gen = lru_gen_from_seq(seq);
 		unsigned long birth = READ_ONCE(lruvec->lrugen.timestamps[gen]);
 
 		seq_printf(m, " %10lu %10u", seq, jiffies_to_msecs(jiffies - birth));
 
 		for (type = 0; type < ANON_AND_FILE; type++) {
-			unsigned long size = 0;
+			unsigned long size = lru_gen_seq_nr_pages(lrugen, gen, type);
 			char mark = full && seq < min_seq[type] ? 'x' : ' ';
 
-			for (zone = 0; zone < MAX_NR_ZONES; zone++)
-				size += max(READ_ONCE(lrugen->nr_pages[gen][type][zone]), 0L);
-
 			seq_printf(m, " %10lu%c", size, mark);
 		}
 
Signature · 1 line
2.34.1
#4 lore raw

PATCH v2 2/3 mm/mglru: add tracepoint for scan_folios()

In reply to Ridong Chen

From: Ridong Chen <[email protected]>

MGLRU's scan_folios() emits the classic-LRU tracepoint trace_mm_vmscan_lru_isolate(), which predates MGLRU. It reports the scan/isolate counts and the LRU type, but carries no generation or memcg context, so a trace of an MGLRU run cannot tell which memcg a given scan belongs to, nor how far reclaim has progressed through the generations.

Add mm_mglru_scan_folios next to it, reporting the same counters plus nr_sorted (folios moved to a younger generation by sort_folio()) and the MGLRU context the classic tracepoint lacks: the memcg id, and the max_seq, tier and min_seq of the type being scanned.

scan_folios() is the MGLRU-specific layer where folios are actually scanned, so it has no classic-LRU counterpart. That the classic trace_mm_vmscan_lru_isolate() has lived here stably shows this is a long-lived place to hook, and the new tracepoint can be enabled on its own to observe the MGLRU-specific information. The existing tracepoint is left unchanged.

Assisted-by Claude:claude-opus-4-8
---
 include/trace/events/vmscan.h | 63 +++++++++++++++++++++++++++++++++++
 mm/vmscan.c                   |  6 ++++
 2 files changed, 69 insertions(+)
include/trace/events/vmscan.h +63 -0
index 8a872990b4be..5defa8f6719c 100644
@@ -392,6 +392,69 @@ TRACE_EVENT(mm_vmscan_lru_isolate,
 		__print_symbolic(__entry->lru, LRU_NAMES))
 );
 
+TRACE_EVENT(mm_mglru_scan_folios,
+
+	TP_PROTO(struct lruvec *lruvec,
+		int highest_zoneidx,
+		int order,
+		unsigned long nr_requested,
+		unsigned long nr_scanned,
+		unsigned long nr_sorted,
+		unsigned long nr_skipped,
+		unsigned long nr_taken,
+		int lru,
+		unsigned long max_seq,
+		int tier,
+		unsigned long min_seq),
+
+	TP_ARGS(lruvec, highest_zoneidx, order, nr_requested, nr_scanned,
+		nr_sorted, nr_skipped, nr_taken, lru, max_seq, tier, min_seq),
+
+	TP_STRUCT__entry(
+		__field(u64, memcg_id)
+		__field(int, highest_zoneidx)
+		__field(int, order)
+		__field(unsigned long, nr_requested)
+		__field(unsigned long, nr_scanned)
+		__field(unsigned long, nr_sorted)
+		__field(unsigned long, nr_skipped)
+		__field(unsigned long, nr_taken)
+		__field(int, lru)
+		__field(unsigned long, max_seq)
+		__field(int, tier)
+		__field(unsigned long, min_seq)
+	),
+
+	TP_fast_assign(
+		__entry->memcg_id = mem_cgroup_id(lruvec_memcg(lruvec));
+		__entry->highest_zoneidx = highest_zoneidx;
+		__entry->order = order;
+		__entry->nr_requested = nr_requested;
+		__entry->nr_scanned = nr_scanned;
+		__entry->nr_sorted = nr_sorted;
+		__entry->nr_skipped = nr_skipped;
+		__entry->nr_taken = nr_taken;
+		__entry->lru = lru;
+		__entry->max_seq = max_seq;
+		__entry->tier = tier;
+		__entry->min_seq = min_seq;
+	),
+
+	TP_printk("memcg_id=%llu classzone=%d order=%d nr_requested=%lu nr_scanned=%lu nr_sorted=%lu nr_skipped=%lu nr_taken=%lu lru=%s max_seq=%lu tier=%d min_seq=%lu",
+		__entry->memcg_id,
+		__entry->highest_zoneidx,
+		__entry->order,
+		__entry->nr_requested,
+		__entry->nr_scanned,
+		__entry->nr_sorted,
+		__entry->nr_skipped,
+		__entry->nr_taken,
+		__print_symbolic(__entry->lru, LRU_NAMES),
+		__entry->max_seq,
+		__entry->tier,
+		__entry->min_seq)
+);
+
 TRACE_EVENT(mm_vmscan_write_folio,
 
 	TP_PROTO(struct folio *folio),
mm/vmscan.c +6 -0
index 2554a6513aa8..67f59aa73fb9 100644
@@ -4876,6 +4876,12 @@ static int scan_folios(unsigned long nr_to_scan, struct lruvec *lruvec,
 	trace_mm_vmscan_lru_isolate(sc->reclaim_idx, sc->order, nr_to_scan,
 				scanned, skipped, isolated,
 				type ? LRU_INACTIVE_FILE : LRU_INACTIVE_ANON);
+	trace_mm_mglru_scan_folios(lruvec,
+				   sc->reclaim_idx, sc->order, nr_to_scan,
+				   scanned, sorted, skipped, isolated,
+				   type ? LRU_INACTIVE_FILE : LRU_INACTIVE_ANON,
+				   lrugen->max_seq, tier,
+				   lrugen->min_seq[type]);
 
 	*isolatedp = isolated;
 	return scanned;
Signature · 1 line
2.34.1
reviewer
#5 lore raw

Re: [PATCH v2 2/3] mm/mglru: add tracepoint for scan_folios()

Quoted 36 lines · Ridong Chen

From: Ridong Chen <[email protected]>

MGLRU's scan_folios() emits the classic-LRU tracepoint trace_mm_vmscan_lru_isolate(), which predates MGLRU. It reports the scan/isolate counts and the LRU type, but carries no generation or memcg context, so a trace of an MGLRU run cannot tell which memcg a given scan belongs to, nor how far reclaim has progressed through the generations.

Add mm_mglru_scan_folios next to it, reporting the same counters plus nr_sorted (folios moved to a younger generation by sort_folio()) and the MGLRU context the classic tracepoint lacks: the memcg id, and the max_seq, tier and min_seq of the type being scanned.

scan_folios() is the MGLRU-specific layer where folios are actually scanned, so it has no classic-LRU counterpart. That the classic trace_mm_vmscan_lru_isolate() has lived here stably shows this is a long-lived place to hook, and the new tracepoint can be enabled on its own to observe the MGLRU-specific information. The existing tracepoint is left unchanged.

Assisted-by Claude:claude-opus-4-8
---
  include/trace/events/vmscan.h | 63 +++++++++++++++++++++++++++++++++++
  mm/vmscan.c                   |  6 ++++
  2 files changed, 69 insertions(+)
include/trace/events/vmscan.h +0 -0
index 8a872990b4be..5defa8f6719c 100644
@@ -392,6 +392,69 @@ TRACE_EVENT(mm_vmscan_lru_isolate,
  		__print_symbolic(__entry->lru, LRU_NAMES))
  );
 

[snip]

Quoted 5 lines
mm/vmscan.c +0 -0
index 2554a6513aa8..67f59aa73fb9 100644

mm/vmscan.c static int scan_folios(unsigned long nr_to_scan, struct lruvec *lruvec, · line 4884

Quoted 9 lines
mm/vmscan.c +6 -0
@@ -4876,6 +4876,12 @@ static int scan_folios(unsigned long nr_to_scan, struct lruvec *lruvec,
  	trace_mm_vmscan_lru_isolate(sc->reclaim_idx, sc->order, nr_to_scan,
  				scanned, skipped, isolated,
  				type ? LRU_INACTIVE_FILE : LRU_INACTIVE_ANON);
+	trace_mm_mglru_scan_folios(lruvec,
+				   sc->reclaim_idx, sc->order, nr_to_scan,
+				   scanned, sorted, skipped, isolated,
+				   type ? LRU_INACTIVE_FILE : LRU_INACTIVE_ANON,
+				   lrugen->max_seq, tier,
+				   lrugen->min_seq[type]);

Both tracepoints will print some duplicated content, and I'm not sure it's worth a new tracepoint just to trace max_seq and min_seq.

Anyway, I'm not against this patch, but I'd like to hear others' opinions.

#6 lore raw

Re: [PATCH v2 2/3] mm/mglru: add tracepoint for scan_folios()

Quoted 59 lines · Baolin Wang
Quoted 35 lines · Ridong Chen

From: Ridong Chen <[email protected]>

MGLRU's scan_folios() emits the classic-LRU tracepoint trace_mm_vmscan_lru_isolate(), which predates MGLRU. It reports the scan/isolate counts and the LRU type, but carries no generation or memcg context, so a trace of an MGLRU run cannot tell which memcg a given scan belongs to, nor how far reclaim has progressed through the generations.

Add mm_mglru_scan_folios next to it, reporting the same counters plus nr_sorted (folios moved to a younger generation by sort_folio()) and the MGLRU context the classic tracepoint lacks: the memcg id, and the max_seq, tier and min_seq of the type being scanned.

scan_folios() is the MGLRU-specific layer where folios are actually scanned, so it has no classic-LRU counterpart. That the classic trace_mm_vmscan_lru_isolate() has lived here stably shows this is a long-lived place to hook, and the new tracepoint can be enabled on its own to observe the MGLRU-specific information. The existing tracepoint is left unchanged.

Assisted-by Claude:claude-opus-4-8

---
  include/trace/events/vmscan.h | 63 +++++++++++++++++++++++++++++++++++ mm/vmscan.c                   |  6 ++++

  2 files changed, 69 insertions(+)
include/trace/events/vmscan.h +0 -0
index 8a872990b4be..5defa8f6719c 100644
@@ -392,6 +392,69 @@ TRACE_EVENT(mm_vmscan_lru_isolate,
           __print_symbolic(__entry->lru, LRU_NAMES))
   );

[snip]

Quoted 5 lines
mm/vmscan.c +0 -0
index 2554a6513aa8..67f59aa73fb9 100644

mm/vmscan.c static int scan_folios(unsigned long nr_to_scan, struct · line 4885

Quoted 10 lines
mm/vmscan.c +6 -0
@@ -4876,6 +4876,12 @@ static int scan_folios(unsigned long nr_to_scan, struct 
 lruvec *lruvec,
       trace_mm_vmscan_lru_isolate(sc->reclaim_idx, sc->order, nr_to_scan,
                   scanned, skipped, isolated,
                   type ? LRU_INACTIVE_FILE : LRU_INACTIVE_ANON);
+    trace_mm_mglru_scan_folios(lruvec,
+                   sc->reclaim_idx, sc->order, nr_to_scan,
+                   scanned, sorted, skipped, isolated,
+                   type ? LRU_INACTIVE_FILE : LRU_INACTIVE_ANON,
+                   lrugen->max_seq, tier,
+                   lrugen->min_seq[type]);

Both tracepoints will print some duplicated content, and I'm not sure it's worth a new tracepoint just to trace max_seq and min_seq.

Quoted 1 line

Anyway, I'm not against this patch, but I'd like to hear others' opinions.

Thank you for your review.

Since the lruvec is per memcg and per node, we would like to know how the memcg scans and reclaims its lruvec.

I am also concerned that the content may be duplicated where we place it here. However, with Barry's suggestion, it is stable here. What is more, the trace is under the control of the trace event gate. It is convenient to control and would not lead to any regression when they are disabled.

As my cover letter mentions, with the current trace events, we don't know when the per-memcg lruvec ages, when it is scanned and reclaimed, or with what seq(gen). With this series, we can tell the memcg aging and reclaim actions.

Signature · 2 lines
Best regards
Ridong
reviewer
#7 lore raw

Re: [PATCH v2 2/3] mm/mglru: add tracepoint for scan_folios()

In reply to Ridong Chen
Quoted 1 line · Ridong Chen

From: Ridong Chen <[email protected]>

...snip...

Quoted 17 lines
---
 include/trace/events/vmscan.h | 63 +++++++++++++++++++++++++++++++++++
 mm/vmscan.c                   |  6 ++++
 2 files changed, 69 insertions(+)
include/trace/events/vmscan.h +4 -0
index 8a872990b4be..5defa8f6719c 100644
@@ -392,6 +392,69 @@ TRACE_EVENT(mm_vmscan_lru_isolate,
 		__print_symbolic(__entry->lru, LRU_NAMES))
 );
 
+TRACE_EVENT(mm_mglru_scan_folios,
+
+	TP_PROTO(struct lruvec *lruvec,
+		int highest_zoneidx,

include/trace/events/vmscan.h TRACE_EVENT(mm_vmscan_lru_isolate, · line 408

Quoted 10 lines
include/trace/events/vmscan.h +10 -0
+		int order,
+		unsigned long nr_requested,
+		unsigned long nr_scanned,
+		unsigned long nr_sorted,
+		unsigned long nr_skipped,
+		unsigned long nr_taken,
+		int lru,
+		unsigned long max_seq,
+		int tier,
+		unsigned long min_seq),

Do we need show nid? Guess phone vendor doesn't care about multi-NUMA system.

And I checked v1 thread, seems Steven suggested to move the two int to avoid extra padding.

Quoted 57 lines
include/trace/events/vmscan.h +49 -0
+
+	TP_ARGS(lruvec, highest_zoneidx, order, nr_requested, nr_scanned,
+		nr_sorted, nr_skipped, nr_taken, lru, max_seq, tier, min_seq),
+
+	TP_STRUCT__entry(
+		__field(u64, memcg_id)
+		__field(int, highest_zoneidx)
+		__field(int, order)
+		__field(unsigned long, nr_requested)
+		__field(unsigned long, nr_scanned)
+		__field(unsigned long, nr_sorted)
+		__field(unsigned long, nr_skipped)
+		__field(unsigned long, nr_taken)
+		__field(int, lru)
+		__field(unsigned long, max_seq)
+		__field(int, tier)
+		__field(unsigned long, min_seq)
+	),
+
+	TP_fast_assign(
+		__entry->memcg_id = mem_cgroup_id(lruvec_memcg(lruvec));
+		__entry->highest_zoneidx = highest_zoneidx;
+		__entry->order = order;
+		__entry->nr_requested = nr_requested;
+		__entry->nr_scanned = nr_scanned;
+		__entry->nr_sorted = nr_sorted;
+		__entry->nr_skipped = nr_skipped;
+		__entry->nr_taken = nr_taken;
+		__entry->lru = lru;
+		__entry->max_seq = max_seq;
+		__entry->tier = tier;
+		__entry->min_seq = min_seq;
+	),
+
+	TP_printk("memcg_id=%llu classzone=%d order=%d nr_requested=%lu nr_scanned=%lu nr_sorted=%lu nr_skipped=%lu nr_taken=%lu lru=%s max_seq=%lu tier=%d min_seq=%lu",
+		__entry->memcg_id,
+		__entry->highest_zoneidx,
+		__entry->order,
+		__entry->nr_requested,
+		__entry->nr_scanned,
+		__entry->nr_sorted,
+		__entry->nr_skipped,
+		__entry->nr_taken,
+		__print_symbolic(__entry->lru, LRU_NAMES),
+		__entry->max_seq,
+		__entry->tier,
+		__entry->min_seq)
+);
+
 TRACE_EVENT(mm_vmscan_write_folio,
 
 	TP_PROTO(struct folio *folio),
mm/vmscan.c +0 -0
index 2554a6513aa8..67f59aa73fb9 100644

mm/vmscan.c static int scan_folios(unsigned long nr_to_scan, struct lruvec *lruvec, · line 4884

Quoted 9 lines
mm/vmscan.c +6 -0
@@ -4876,6 +4876,12 @@ static int scan_folios(unsigned long nr_to_scan, struct lruvec *lruvec,
 	trace_mm_vmscan_lru_isolate(sc->reclaim_idx, sc->order, nr_to_scan,
 				scanned, skipped, isolated,
 				type ? LRU_INACTIVE_FILE : LRU_INACTIVE_ANON);
+	trace_mm_mglru_scan_folios(lruvec,
+				   sc->reclaim_idx, sc->order, nr_to_scan,
+				   scanned, sorted, skipped, isolated,
+				   type ? LRU_INACTIVE_FILE : LRU_INACTIVE_ANON,
+				   lrugen->max_seq, tier,
+				   lrugen->min_seq[type]);

And seems Steven also suggested to calculate lru, max_seq, min_seq in TP_fast_assign() in v1 which could be missed.

        TP_fast_assign(
                __entry->memcg_id = mem_cgroup_id(lruvec_memcg(lruvec));
                __entry->highest_zoneidx = sc->reclaim_idx;
                __entry->order = sc->order;
                __entry->nr_requested = nr_requested;
                __entry->nr_scanned = nr_scanned;
                __entry->nr_sorted = nr_sorted;
                __entry->nr_skipped = nr_skipped;
                __entry->nr_taken = nr_taken;
                __entry->lru = type ? LRU_INACTIVE_FILE : LRU_INACTIVE_ANON;
                __entry->max_seq = lrugen->max_seq;
                __entry->tier = tier;
                __entry->min_seq = lrugen->min_seq;
        ),
Quoted 6 lines
mm/vmscan.c +0 -0
 	*isolatedp = isolated;
 	return scanned;
Signature · 1 line
2.34.1
#8 lore raw

Re: [PATCH v2 2/3] mm/mglru: add tracepoint for scan_folios()

Quoted 16 lines · Baoquan He
Quoted 1 line · Ridong Chen

From: Ridong Chen <[email protected]>

...snip...

Quoted 13 lines
---
  include/trace/events/vmscan.h | 63 +++++++++++++++++++++++++++++++++++
  mm/vmscan.c                   |  6 ++++
  2 files changed, 69 insertions(+)
include/trace/events/vmscan.h +0 -0
index 8a872990b4be..5defa8f6719c 100644
@@ -392,6 +392,69 @@ TRACE_EVENT(mm_vmscan_lru_isolate,
  		__print_symbolic(__entry->lru, LRU_NAMES))
  );
 
Quoted 15 lines
Quoted 4 lines
include/trace/events/vmscan.h +4 -0
+TRACE_EVENT(mm_mglru_scan_folios,
+
+	TP_PROTO(struct lruvec *lruvec,
+		int highest_zoneidx,

include/trace/events/vmscan.h TRACE_EVENT(mm_vmscan_lru_isolate, · line 408

Quoted 10 lines
include/trace/events/vmscan.h +10 -0
+		int order,
+		unsigned long nr_requested,
+		unsigned long nr_scanned,
+		unsigned long nr_sorted,
+		unsigned long nr_skipped,
+		unsigned long nr_taken,
+		int lru,
+		unsigned long max_seq,
+		int tier,
+		unsigned long min_seq),

Thank you for your review.

Quoted 3 lines

Do we need show nid? Guess phone vendor doesn't care about multi-NUMA system.

Eh, nid is not an mglru-specific key. Since there are 12 elements here, it can't be added here.

Quoted 3 lines

And I checked v1 thread, seems Steven suggested to move the two int to avoid extra padding.

Yeah, I will update it. I updated v2 to fix Sashiko's issue, before Steven had any comment.

Quoted 61 lines
Quoted 61 lines
include/trace/events/vmscan.h +49 -0
+
+	TP_ARGS(lruvec, highest_zoneidx, order, nr_requested, nr_scanned,
+		nr_sorted, nr_skipped, nr_taken, lru, max_seq, tier, min_seq),
+
+	TP_STRUCT__entry(
+		__field(u64, memcg_id)
+		__field(int, highest_zoneidx)
+		__field(int, order)
+		__field(unsigned long, nr_requested)
+		__field(unsigned long, nr_scanned)
+		__field(unsigned long, nr_sorted)
+		__field(unsigned long, nr_skipped)
+		__field(unsigned long, nr_taken)
+		__field(int, lru)
+		__field(unsigned long, max_seq)
+		__field(int, tier)
+		__field(unsigned long, min_seq)
+	),
+
+	TP_fast_assign(
+		__entry->memcg_id = mem_cgroup_id(lruvec_memcg(lruvec));
+		__entry->highest_zoneidx = highest_zoneidx;
+		__entry->order = order;
+		__entry->nr_requested = nr_requested;
+		__entry->nr_scanned = nr_scanned;
+		__entry->nr_sorted = nr_sorted;
+		__entry->nr_skipped = nr_skipped;
+		__entry->nr_taken = nr_taken;
+		__entry->lru = lru;
+		__entry->max_seq = max_seq;
+		__entry->tier = tier;
+		__entry->min_seq = min_seq;
+	),
+
+	TP_printk("memcg_id=%llu classzone=%d order=%d nr_requested=%lu nr_scanned=%lu nr_sorted=%lu nr_skipped=%lu nr_taken=%lu lru=%s max_seq=%lu tier=%d min_seq=%lu",
+		__entry->memcg_id,
+		__entry->highest_zoneidx,
+		__entry->order,
+		__entry->nr_requested,
+		__entry->nr_scanned,
+		__entry->nr_sorted,
+		__entry->nr_skipped,
+		__entry->nr_taken,
+		__print_symbolic(__entry->lru, LRU_NAMES),
+		__entry->max_seq,
+		__entry->tier,
+		__entry->min_seq)
+);
+
  TRACE_EVENT(mm_vmscan_write_folio,
 
  	TP_PROTO(struct folio *folio),
mm/vmscan.c +1 -0
index 2554a6513aa8..67f59aa73fb9 100644
@@ -4876,6 +4876,12 @@ static int scan_folios(unsigned long nr_to_scan, struct lruvec *lruvec,
  	trace_mm_vmscan_lru_isolate(sc->reclaim_idx, sc->order, nr_to_scan,
  				scanned, skipped, isolated,
  				type ? LRU_INACTIVE_FILE : LRU_INACTIVE_ANON);
+	trace_mm_mglru_scan_folios(lruvec,
Quoted 9 lines

mm/vmscan.c static int scan_folios(unsigned long nr_to_scan, struct lruvec *lruvec, · line 4884

Quoted 5 lines
mm/vmscan.c +5 -0
+				   sc->reclaim_idx, sc->order, nr_to_scan,
+				   scanned, sorted, skipped, isolated,
+				   type ? LRU_INACTIVE_FILE : LRU_INACTIVE_ANON,
+				   lrugen->max_seq, tier,
+				   lrugen->min_seq[type]);

And seems Steven also suggested to calculate lru, max_seq, min_seq in TP_fast_assign() in v1 which could be missed.

Thanks, I will update it following Steven's suggestions.

Quoted 6 lines
         TP_fast_assign(
                 __entry->memcg_id = mem_cgroup_id(lruvec_memcg(lruvec));
                 __entry->highest_zoneidx = sc->reclaim_idx;
                 __entry->order = sc->order;
                 __entry->nr_requested = nr_requested;
                 __entry->nr_scanned = nr_scanned;
Quoted 9 lines
                 __entry->nr_sorted = nr_sorted;
                 __entry->nr_skipped = nr_skipped;
                 __entry->nr_taken = nr_taken;
                 __entry->lru = type ? LRU_INACTIVE_FILE : LRU_INACTIVE_ANON;
                 __entry->max_seq = lrugen->max_seq;
                 __entry->tier = tier;
                 __entry->min_seq = lrugen->min_seq;
         ),

However, 'sc' is an internal structure, so sc->order cannot be accessed in TP_fast_assign(), and I don't think it is worth making scan_control an external structure just for this.

Quoted 7 lines
Quoted 7 lines
mm/vmscan.c +0 -0
  	*isolatedp = isolated;
  	return scanned;
Signature · 1 line
2.34.1
Signature · 2 lines
Best regards
Ridong
reviewer
#9 lore raw

Re: [PATCH v2 2/3] mm/mglru: add tracepoint for scan_folios()

Quoted 34 lines · Ridong Chen
Quoted 21 lines · Baoquan He
Quoted 1 line · Ridong Chen

From: Ridong Chen <[email protected]>

...snip...

Quoted 18 lines
---
  include/trace/events/vmscan.h | 63 +++++++++++++++++++++++++++++++++++
  mm/vmscan.c                   |  6 ++++
  2 files changed, 69 insertions(+)
include/trace/events/vmscan.h +6 -0
index 8a872990b4be..5defa8f6719c 100644
@@ -392,6 +392,69 @@ TRACE_EVENT(mm_vmscan_lru_isolate,
  		__print_symbolic(__entry->lru, LRU_NAMES))
  );
+TRACE_EVENT(mm_mglru_scan_folios,
+
+	TP_PROTO(struct lruvec *lruvec,
+		int highest_zoneidx,
+		int order,
+		unsigned long nr_requested,
Quoted 9 lines

include/trace/events/vmscan.h TRACE_EVENT(mm_vmscan_lru_isolate, · line 408

Quoted 8 lines
include/trace/events/vmscan.h +8 -0
+		unsigned long nr_scanned,
+		unsigned long nr_sorted,
+		unsigned long nr_skipped,
+		unsigned long nr_taken,
+		int lru,
+		unsigned long max_seq,
+		int tier,
+		unsigned long min_seq),
Quoted 8 lines

Thank you for your review.

Quoted 3 lines

Do we need show nid? Guess phone vendor doesn't care about multi-NUMA system.

Eh, nid is not an mglru-specific key. Since there are 12 elements here, it can't be added here.

Hmm, we print memcg_id but not nid, it may not be so clear. How do you differentiate several lruvec-s on one memcg? I am not very familiar with trace mechanism, do we have a element number limit?

Imagine I only want to trace this function, now I can see memcg_id, zone_idex, while don't know node/lruvec, that's a little pitty. Just my personal opinion, I could miss anything.

Quoted 99 lines
Quoted 5 lines

And I checked v1 thread, seems Steven suggested to move the two int to avoid extra padding.

Yeah, I will update it. I updated v2 to fix Sashiko's issue, before Steven had any comment.

Quoted 60 lines
Quoted 60 lines
include/trace/events/vmscan.h +49 -0
+
+	TP_ARGS(lruvec, highest_zoneidx, order, nr_requested, nr_scanned,
+		nr_sorted, nr_skipped, nr_taken, lru, max_seq, tier, min_seq),
+
+	TP_STRUCT__entry(
+		__field(u64, memcg_id)
+		__field(int, highest_zoneidx)
+		__field(int, order)
+		__field(unsigned long, nr_requested)
+		__field(unsigned long, nr_scanned)
+		__field(unsigned long, nr_sorted)
+		__field(unsigned long, nr_skipped)
+		__field(unsigned long, nr_taken)
+		__field(int, lru)
+		__field(unsigned long, max_seq)
+		__field(int, tier)
+		__field(unsigned long, min_seq)
+	),
+
+	TP_fast_assign(
+		__entry->memcg_id = mem_cgroup_id(lruvec_memcg(lruvec));
+		__entry->highest_zoneidx = highest_zoneidx;
+		__entry->order = order;
+		__entry->nr_requested = nr_requested;
+		__entry->nr_scanned = nr_scanned;
+		__entry->nr_sorted = nr_sorted;
+		__entry->nr_skipped = nr_skipped;
+		__entry->nr_taken = nr_taken;
+		__entry->lru = lru;
+		__entry->max_seq = max_seq;
+		__entry->tier = tier;
+		__entry->min_seq = min_seq;
+	),
+
+	TP_printk("memcg_id=%llu classzone=%d order=%d nr_requested=%lu nr_scanned=%lu nr_sorted=%lu nr_skipped=%lu nr_taken=%lu lru=%s max_seq=%lu tier=%d min_seq=%lu",
+		__entry->memcg_id,
+		__entry->highest_zoneidx,
+		__entry->order,
+		__entry->nr_requested,
+		__entry->nr_scanned,
+		__entry->nr_sorted,
+		__entry->nr_skipped,
+		__entry->nr_taken,
+		__print_symbolic(__entry->lru, LRU_NAMES),
+		__entry->max_seq,
+		__entry->tier,
+		__entry->min_seq)
+);
+
  TRACE_EVENT(mm_vmscan_write_folio,
  	TP_PROTO(struct folio *folio),
mm/vmscan.c +1 -0
index 2554a6513aa8..67f59aa73fb9 100644
@@ -4876,6 +4876,12 @@ static int scan_folios(unsigned long nr_to_scan, struct lruvec *lruvec,
  	trace_mm_vmscan_lru_isolate(sc->reclaim_idx, sc->order, nr_to_scan,
  				scanned, skipped, isolated,
  				type ? LRU_INACTIVE_FILE : LRU_INACTIVE_ANON);
+	trace_mm_mglru_scan_folios(lruvec,
Quoted 9 lines

mm/vmscan.c static int scan_folios(unsigned long nr_to_scan, struct lruvec *lruvec, · line 4884

Quoted 5 lines
mm/vmscan.c +5 -0
+				   sc->reclaim_idx, sc->order, nr_to_scan,
+				   scanned, sorted, skipped, isolated,
+				   type ? LRU_INACTIVE_FILE : LRU_INACTIVE_ANON,
+				   lrugen->max_seq, tier,
+				   lrugen->min_seq[type]);

And seems Steven also suggested to calculate lru, max_seq, min_seq in TP_fast_assign() in v1 which could be missed.

Thanks, I will update it following Steven's suggestions.

Quoted 6 lines
         TP_fast_assign(
                 __entry->memcg_id = mem_cgroup_id(lruvec_memcg(lruvec));
                 __entry->highest_zoneidx = sc->reclaim_idx;
                 __entry->order = sc->order;
                 __entry->nr_requested = nr_requested;
                 __entry->nr_scanned = nr_scanned;
Quoted 9 lines
                 __entry->nr_sorted = nr_sorted;
                 __entry->nr_skipped = nr_skipped;
                 __entry->nr_taken = nr_taken;
                 __entry->lru = type ? LRU_INACTIVE_FILE : LRU_INACTIVE_ANON;
                 __entry->max_seq = lrugen->max_seq;
                 __entry->tier = tier;
                 __entry->min_seq = lrugen->min_seq;
         ),
Quoted 3 lines

However, 'sc' is an internal structure, so sc->order cannot be accessed in TP_fast_assign(), and I don't think it is worth making scan_control an external structure just for this.

Agree.

Quoted 12 lines
Quoted 7 lines
Quoted 7 lines
mm/vmscan.c +0 -0
  	*isolatedp = isolated;
  	return scanned;
Signature · 1 line
2.34.1
Signature · 2 lines
Best regards
Ridong
#10 lore raw

Re: [PATCH v2 2/3] mm/mglru: add tracepoint for scan_folios()

Quoted 41 lines · Baoquan He
Quoted 40 lines · Ridong Chen
Quoted 21 lines · Baoquan He
Quoted 1 line · Ridong Chen

From: Ridong Chen <[email protected]>

...snip...

Quoted 18 lines
---
   include/trace/events/vmscan.h | 63 +++++++++++++++++++++++++++++++++++
   mm/vmscan.c                   |  6 ++++
   2 files changed, 69 insertions(+)
include/trace/events/vmscan.h +6 -0
index 8a872990b4be..5defa8f6719c 100644
@@ -392,6 +392,69 @@ TRACE_EVENT(mm_vmscan_lru_isolate,
   		__print_symbolic(__entry->lru, LRU_NAMES))
   );
+TRACE_EVENT(mm_mglru_scan_folios,
+
+	TP_PROTO(struct lruvec *lruvec,
+		int highest_zoneidx,
+		int order,
+		unsigned long nr_requested,
Quoted 9 lines

include/trace/events/vmscan.h TRACE_EVENT(mm_vmscan_lru_isolate, · line 408

Quoted 8 lines
include/trace/events/vmscan.h +8 -0
+		unsigned long nr_scanned,
+		unsigned long nr_sorted,
+		unsigned long nr_skipped,
+		unsigned long nr_taken,
+		int lru,
+		unsigned long max_seq,
+		int tier,
+		unsigned long min_seq),

Thank you for your review.

Quoted 3 lines

Do we need show nid? Guess phone vendor doesn't care about multi-NUMA system.

Quoted 7 lines
Quoted 2 lines

Eh, nid is not an mglru-specific key. Since there are 12 elements here, it can't be added here.

Hmm, we print memcg_id but not nid, it may not be so clear. How do you differentiate several lruvec-s on one memcg? I am not very familiar with trace mechanism, do we have a element number limit?

Yes, it will fail to compile if there are more than 12 elements.

With AI's help, see

include/trace/bpf_probe.h

```
30 #define __CAST1(a,...) __CAST_TO_U64(a)
 31 #define __CAST2(a,...) __CAST_TO_U64(a), __CAST1(__VA_ARGS__)
 32 #define __CAST3(a,...) __CAST_TO_U64(a), __CAST2(__VA_ARGS__)
 33 #define __CAST4(a,...) __CAST_TO_U64(a), __CAST3(__VA_ARGS__)
 34 #define __CAST5(a,...) __CAST_TO_U64(a), __CAST4(__VA_ARGS__)
 35 #define __CAST6(a,...) __CAST_TO_U64(a), __CAST5(__VA_ARGS__)
 36 #define __CAST7(a,...) __CAST_TO_U64(a), __CAST6(__VA_ARGS__)
 37 #define __CAST8(a,...) __CAST_TO_U64(a), __CAST7(__VA_ARGS__)
 38 #define __CAST9(a,...) __CAST_TO_U64(a), __CAST8(__VA_ARGS__)
 39 #define __CAST10(a,...) __CAST_TO_U64(a), __CAST9(__VA_ARGS__)
 40 #define __CAST11(a,...) __CAST_TO_U64(a), __CAST10(__VA_ARGS__)
 41 #define __CAST12(a,...) __CAST_TO_U64(a), __CAST11(__VA_ARGS__)
/* tracepoints with more than 12 arguments will hit build error */
```
Quoted 4 lines

Imagine I only want to trace this function, now I can see memcg_id, zone_idex, while don't know node/lruvec, that's a little pitty. Just my personal opinion, I could miss anything.

Yeah, you are right. In my personal experience, I always enable trace_mm_vmscan_lru_isolate and trace_mm_vmscan_lru_shrink_inactive, which contain node_id. So we can see how the lruvec is scanned and shrunk, and we can get node_id from trace_mm_vmscan_lru_shrink_inactive. I am not arguing that this is exactly the 'correct' way to use these tracepoints, but I think it is a common usage.

I am open to that. If we want to record node_id, we have to remove an element. Maybe tier? But I would strongly recommend record memcg_id, we frequently need to check the reclaim behavior of a memcg, and most of our scenarios are non-NUMA.

Quoted 117 lines
Quoted 99 lines
Quoted 5 lines

And I checked v1 thread, seems Steven suggested to move the two int to avoid extra padding.

Yeah, I will update it. I updated v2 to fix Sashiko's issue, before Steven had any comment.

Quoted 60 lines
Quoted 60 lines
include/trace/events/vmscan.h +49 -0
+
+	TP_ARGS(lruvec, highest_zoneidx, order, nr_requested, nr_scanned,
+		nr_sorted, nr_skipped, nr_taken, lru, max_seq, tier, min_seq),
+
+	TP_STRUCT__entry(
+		__field(u64, memcg_id)
+		__field(int, highest_zoneidx)
+		__field(int, order)
+		__field(unsigned long, nr_requested)
+		__field(unsigned long, nr_scanned)
+		__field(unsigned long, nr_sorted)
+		__field(unsigned long, nr_skipped)
+		__field(unsigned long, nr_taken)
+		__field(int, lru)
+		__field(unsigned long, max_seq)
+		__field(int, tier)
+		__field(unsigned long, min_seq)
+	),
+
+	TP_fast_assign(
+		__entry->memcg_id = mem_cgroup_id(lruvec_memcg(lruvec));
+		__entry->highest_zoneidx = highest_zoneidx;
+		__entry->order = order;
+		__entry->nr_requested = nr_requested;
+		__entry->nr_scanned = nr_scanned;
+		__entry->nr_sorted = nr_sorted;
+		__entry->nr_skipped = nr_skipped;
+		__entry->nr_taken = nr_taken;
+		__entry->lru = lru;
+		__entry->max_seq = max_seq;
+		__entry->tier = tier;
+		__entry->min_seq = min_seq;
+	),
+
+	TP_printk("memcg_id=%llu classzone=%d order=%d nr_requested=%lu nr_scanned=%lu nr_sorted=%lu nr_skipped=%lu nr_taken=%lu lru=%s max_seq=%lu tier=%d min_seq=%lu",
+		__entry->memcg_id,
+		__entry->highest_zoneidx,
+		__entry->order,
+		__entry->nr_requested,
+		__entry->nr_scanned,
+		__entry->nr_sorted,
+		__entry->nr_skipped,
+		__entry->nr_taken,
+		__print_symbolic(__entry->lru, LRU_NAMES),
+		__entry->max_seq,
+		__entry->tier,
+		__entry->min_seq)
+);
+
   TRACE_EVENT(mm_vmscan_write_folio,
   	TP_PROTO(struct folio *folio),
mm/vmscan.c +1 -0
index 2554a6513aa8..67f59aa73fb9 100644
@@ -4876,6 +4876,12 @@ static int scan_folios(unsigned long nr_to_scan, struct lruvec *lruvec,
   	trace_mm_vmscan_lru_isolate(sc->reclaim_idx, sc->order, nr_to_scan,
   				scanned, skipped, isolated,
   				type ? LRU_INACTIVE_FILE : LRU_INACTIVE_ANON);
+	trace_mm_mglru_scan_folios(lruvec,
Quoted 9 lines

mm/vmscan.c static int scan_folios(unsigned long nr_to_scan, struct lruvec *lruvec, · line 4884

Quoted 5 lines
mm/vmscan.c +5 -0
+				   sc->reclaim_idx, sc->order, nr_to_scan,
+				   scanned, sorted, skipped, isolated,
+				   type ? LRU_INACTIVE_FILE : LRU_INACTIVE_ANON,
+				   lrugen->max_seq, tier,
+				   lrugen->min_seq[type]);

And seems Steven also suggested to calculate lru, max_seq, min_seq in TP_fast_assign() in v1 which could be missed.

Thanks, I will update it following Steven's suggestions.

Quoted 6 lines
          TP_fast_assign(
                  __entry->memcg_id = mem_cgroup_id(lruvec_memcg(lruvec));
                  __entry->highest_zoneidx = sc->reclaim_idx;
                  __entry->order = sc->order;
                  __entry->nr_requested = nr_requested;
                  __entry->nr_scanned = nr_scanned;
Quoted 9 lines
                  __entry->nr_sorted = nr_sorted;
                  __entry->nr_skipped = nr_skipped;
                  __entry->nr_taken = nr_taken;
                  __entry->lru = type ? LRU_INACTIVE_FILE : LRU_INACTIVE_ANON;
                  __entry->max_seq = lrugen->max_seq;
                  __entry->tier = tier;
                  __entry->min_seq = lrugen->min_seq;
          ),
Quoted 3 lines

However, 'sc' is an internal structure, so sc->order cannot be accessed in TP_fast_assign(), and I don't think it is worth making scan_control an external structure just for this.

Agree.

Quoted 12 lines
Quoted 7 lines
Quoted 7 lines
mm/vmscan.c +0 -0
   	*isolatedp = isolated;
   	return scanned;
Signature · 1 line
2.34.1
Signature · 2 lines
Best regards
Ridong
Signature · 2 lines
Best regards
Ridong
reviewer
#11 lore raw

Re: [PATCH v2 2/3] mm/mglru: add tracepoint for scan_folios()

Quoted 40 lines · Ridong Chen
Quoted 37 lines · Baoquan He
Quoted 36 lines · Ridong Chen
Quoted 21 lines · Baoquan He
Quoted 1 line · Ridong Chen

From: Ridong Chen <[email protected]>

...snip...

Quoted 18 lines
---
   include/trace/events/vmscan.h | 63 +++++++++++++++++++++++++++++++++++
   mm/vmscan.c                   |  6 ++++
   2 files changed, 69 insertions(+)
include/trace/events/vmscan.h +6 -0
index 8a872990b4be..5defa8f6719c 100644
@@ -392,6 +392,69 @@ TRACE_EVENT(mm_vmscan_lru_isolate,
   		__print_symbolic(__entry->lru, LRU_NAMES))
   );
+TRACE_EVENT(mm_mglru_scan_folios,
+
+	TP_PROTO(struct lruvec *lruvec,
+		int highest_zoneidx,
+		int order,
+		unsigned long nr_requested,
Quoted 9 lines

include/trace/events/vmscan.h TRACE_EVENT(mm_vmscan_lru_isolate, · line 408

Quoted 8 lines
include/trace/events/vmscan.h +8 -0
+		unsigned long nr_scanned,
+		unsigned long nr_sorted,
+		unsigned long nr_skipped,
+		unsigned long nr_taken,
+		int lru,
+		unsigned long max_seq,
+		int tier,
+		unsigned long min_seq),

Thank you for your review.

Quoted 8 lines
Quoted 8 lines
Quoted 6 lines
Quoted 3 lines

Do we need show nid? Guess phone vendor doesn't care about multi-NUMA system.

Eh, nid is not an mglru-specific key. Since there are 12 elements here, it can't be added here.

Hmm, we print memcg_id but not nid, it may not be so clear. How do you

                               ^~~~ typo, s/not/no/
Quoted 37 lines
Quoted 3 lines

differentiate several lruvec-s on one memcg? I am not very familiar with trace mechanism, do we have a element number limit?

Yes, it will fail to compile if there are more than 12 elements.

With AI's help, see

include/trace/bpf_probe.h

```
30 #define __CAST1(a,...) __CAST_TO_U64(a)
 31 #define __CAST2(a,...) __CAST_TO_U64(a), __CAST1(__VA_ARGS__)
 32 #define __CAST3(a,...) __CAST_TO_U64(a), __CAST2(__VA_ARGS__)
 33 #define __CAST4(a,...) __CAST_TO_U64(a), __CAST3(__VA_ARGS__)
 34 #define __CAST5(a,...) __CAST_TO_U64(a), __CAST4(__VA_ARGS__)
 35 #define __CAST6(a,...) __CAST_TO_U64(a), __CAST5(__VA_ARGS__)
 36 #define __CAST7(a,...) __CAST_TO_U64(a), __CAST6(__VA_ARGS__)
 37 #define __CAST8(a,...) __CAST_TO_U64(a), __CAST7(__VA_ARGS__)
 38 #define __CAST9(a,...) __CAST_TO_U64(a), __CAST8(__VA_ARGS__)
 39 #define __CAST10(a,...) __CAST_TO_U64(a), __CAST9(__VA_ARGS__)
 40 #define __CAST11(a,...) __CAST_TO_U64(a), __CAST10(__VA_ARGS__)
 41 #define __CAST12(a,...) __CAST_TO_U64(a), __CAST11(__VA_ARGS__)
/* tracepoints with more than 12 arguments will hit build error */
```
Quoted 4 lines

Imagine I only want to trace this function, now I can see memcg_id, zone_idex, while don't know node/lruvec, that's a little pitty. Just my personal opinion, I could miss anything.

Yeah, you are right. In my personal experience, I always enable trace_mm_vmscan_lru_isolate and trace_mm_vmscan_lru_shrink_inactive, which contain node_id. So we can see how the lruvec is scanned and shrunk, and we can get node_id from trace_mm_vmscan_lru_shrink_inactive. I am not arguing that this is exactly the 'correct' way to use these tracepoints, but I think it is a common usage.

Quoted 3 lines

I am open to that. If we want to record node_id, we have to remove an element. Maybe tier? But I would strongly recommend record memcg_id, we frequently need to check the reclaim behavior of a memcg, and most of our

Sorry, that's my typo which could cause misunderstanding. I meant "we print memcg_id but no nid, it may not be so clear". I agree with you that memcg_id is undispensable.

Quoted 1 line

scenarios are non-NUMA.

Understood, mobile phone mostly is non-NUMA, while server is different. About adding nid, I cousulted AI too, it says it's doable.

It says The 12-argument limit only counts the TP_PROTO arguments (that's the BPF __CAST12/bpf_trace_run12 path), not the __entry fields in TP_STRUCT__entry. And nid doesn't have to be a 13th argument at all. We already pass lruvec, so nid can be derived from it in TP_fast_assign with lruvec_pgdat(lruvec)->node_id.

e.g. for mm_mglru_scan_folios:

TP_STRUCT__entry(
__field(u64, memcg_id)
__field(int, nid)
__field(int, highest_zoneidx)
__field(int, order)
__field(unsigned long, nr_requested)
__field(unsigned long, nr_scanned)
__field(unsigned long, nr_sorted)
__field(unsigned long, nr_skipped)
__field(unsigned long, nr_taken)
__field(int, lru)
__field(unsigned long, max_seq)
__field(int, tier)
__field(unsigned long, min_seq)
),

   TP_fast_assign(                                                                                    
      __entry->memcg_id = mem_cgroup_id(lruvec_memcg(lruvec));                                        
      __entry->nid      = lruvec_pgdat(lruvec)->node_id;                                              
      __entry->highest_zoneidx = highest_zoneidx;                                                     
      ...                                                                                             
   ),                                                                                                 

TP_printk("memcg_id=%llu nid=%d classzone=%d order=%d ...",

      __entry->memcg_id,                                                                              
      __entry->nid,                                                                                   
      __entry->highest_zoneidx,                                                                       
      ...)                                                                                            

lruvec_pgdat() comes from include/linux/mmzone.h, which vmscan.h already pulls in via linux/mm.h, so no extra include is needed. The same pattern applies to mm_mglru_inc_max_seq in patch 3 if you want nid there too. I didn't try it though, please feel free to give it a shot.

Thanks
Baoquan

Quoted 124 lines
Quoted 119 lines
Quoted 101 lines
Quoted 7 lines

And I checked v1 thread, seems Steven suggested to move the two int to avoid extra padding.

Yeah, I will update it. I updated v2 to fix Sashiko's issue, before Steven had any comment.

Quoted 60 lines
Quoted 60 lines
include/trace/events/vmscan.h +49 -0
+
+	TP_ARGS(lruvec, highest_zoneidx, order, nr_requested, nr_scanned,
+		nr_sorted, nr_skipped, nr_taken, lru, max_seq, tier, min_seq),
+
+	TP_STRUCT__entry(
+		__field(u64, memcg_id)
+		__field(int, highest_zoneidx)
+		__field(int, order)
+		__field(unsigned long, nr_requested)
+		__field(unsigned long, nr_scanned)
+		__field(unsigned long, nr_sorted)
+		__field(unsigned long, nr_skipped)
+		__field(unsigned long, nr_taken)
+		__field(int, lru)
+		__field(unsigned long, max_seq)
+		__field(int, tier)
+		__field(unsigned long, min_seq)
+	),
+
+	TP_fast_assign(
+		__entry->memcg_id = mem_cgroup_id(lruvec_memcg(lruvec));
+		__entry->highest_zoneidx = highest_zoneidx;
+		__entry->order = order;
+		__entry->nr_requested = nr_requested;
+		__entry->nr_scanned = nr_scanned;
+		__entry->nr_sorted = nr_sorted;
+		__entry->nr_skipped = nr_skipped;
+		__entry->nr_taken = nr_taken;
+		__entry->lru = lru;
+		__entry->max_seq = max_seq;
+		__entry->tier = tier;
+		__entry->min_seq = min_seq;
+	),
+
+	TP_printk("memcg_id=%llu classzone=%d order=%d nr_requested=%lu nr_scanned=%lu nr_sorted=%lu nr_skipped=%lu nr_taken=%lu lru=%s max_seq=%lu tier=%d min_seq=%lu",
+		__entry->memcg_id,
+		__entry->highest_zoneidx,
+		__entry->order,
+		__entry->nr_requested,
+		__entry->nr_scanned,
+		__entry->nr_sorted,
+		__entry->nr_skipped,
+		__entry->nr_taken,
+		__print_symbolic(__entry->lru, LRU_NAMES),
+		__entry->max_seq,
+		__entry->tier,
+		__entry->min_seq)
+);
+
   TRACE_EVENT(mm_vmscan_write_folio,
   	TP_PROTO(struct folio *folio),
mm/vmscan.c +1 -0
index 2554a6513aa8..67f59aa73fb9 100644
@@ -4876,6 +4876,12 @@ static int scan_folios(unsigned long nr_to_scan, struct lruvec *lruvec,
   	trace_mm_vmscan_lru_isolate(sc->reclaim_idx, sc->order, nr_to_scan,
   				scanned, skipped, isolated,
   				type ? LRU_INACTIVE_FILE : LRU_INACTIVE_ANON);
+	trace_mm_mglru_scan_folios(lruvec,
Quoted 9 lines

mm/vmscan.c static int scan_folios(unsigned long nr_to_scan, struct lruvec *lruvec, · line 4884

Quoted 5 lines
mm/vmscan.c +5 -0
+				   sc->reclaim_idx, sc->order, nr_to_scan,
+				   scanned, sorted, skipped, isolated,
+				   type ? LRU_INACTIVE_FILE : LRU_INACTIVE_ANON,
+				   lrugen->max_seq, tier,
+				   lrugen->min_seq[type]);

And seems Steven also suggested to calculate lru, max_seq, min_seq in TP_fast_assign() in v1 which could be missed.

Thanks, I will update it following Steven's suggestions.

Quoted 6 lines
          TP_fast_assign(
                  __entry->memcg_id = mem_cgroup_id(lruvec_memcg(lruvec));
                  __entry->highest_zoneidx = sc->reclaim_idx;
                  __entry->order = sc->order;
                  __entry->nr_requested = nr_requested;
                  __entry->nr_scanned = nr_scanned;
Quoted 9 lines
                  __entry->nr_sorted = nr_sorted;
                  __entry->nr_skipped = nr_skipped;
                  __entry->nr_taken = nr_taken;
                  __entry->lru = type ? LRU_INACTIVE_FILE : LRU_INACTIVE_ANON;
                  __entry->max_seq = lrugen->max_seq;
                  __entry->tier = tier;
                  __entry->min_seq = lrugen->min_seq;
          ),
Quoted 3 lines

However, 'sc' is an internal structure, so sc->order cannot be accessed in TP_fast_assign(), and I don't think it is worth making scan_control an external structure just for this.

Agree.

Quoted 12 lines
Quoted 7 lines
Quoted 7 lines
mm/vmscan.c +0 -0
   	*isolatedp = isolated;
   	return scanned;
Signature · 1 line
2.34.1
Signature · 2 lines
Best regards
Ridong
Signature · 2 lines
Best regards
Ridong
#12 lore raw

Re: [PATCH v2 2/3] mm/mglru: add tracepoint for scan_folios()

Quoted 138 lines · Baoquan He
Quoted 40 lines · Ridong Chen
Quoted 37 lines · Baoquan He
Quoted 36 lines · Ridong Chen
Quoted 21 lines · Baoquan He
Quoted 1 line · Ridong Chen

From: Ridong Chen <[email protected]>

...snip...

Quoted 18 lines
---
    include/trace/events/vmscan.h | 63 +++++++++++++++++++++++++++++++++++
    mm/vmscan.c                   |  6 ++++
    2 files changed, 69 insertions(+)
include/trace/events/vmscan.h +6 -0
index 8a872990b4be..5defa8f6719c 100644
@@ -392,6 +392,69 @@ TRACE_EVENT(mm_vmscan_lru_isolate,
    		__print_symbolic(__entry->lru, LRU_NAMES))
    );
+TRACE_EVENT(mm_mglru_scan_folios,
+
+	TP_PROTO(struct lruvec *lruvec,
+		int highest_zoneidx,
+		int order,
+		unsigned long nr_requested,
Quoted 9 lines

include/trace/events/vmscan.h TRACE_EVENT(mm_vmscan_lru_isolate, · line 408

Quoted 8 lines
include/trace/events/vmscan.h +8 -0
+		unsigned long nr_scanned,
+		unsigned long nr_sorted,
+		unsigned long nr_skipped,
+		unsigned long nr_taken,
+		int lru,
+		unsigned long max_seq,
+		int tier,
+		unsigned long min_seq),

Thank you for your review.

Quoted 8 lines
Quoted 8 lines
Quoted 6 lines
Quoted 3 lines

Do we need show nid? Guess phone vendor doesn't care about multi-NUMA system.

Eh, nid is not an mglru-specific key. Since there are 12 elements here, it can't be added here.

Hmm, we print memcg_id but not nid, it may not be so clear. How do you

                                ^~~~ typo, s/not/no/
Quoted 37 lines
Quoted 3 lines

differentiate several lruvec-s on one memcg? I am not very familiar with trace mechanism, do we have a element number limit?

Yes, it will fail to compile if there are more than 12 elements.

With AI's help, see

include/trace/bpf_probe.h

```
30 #define __CAST1(a,...) __CAST_TO_U64(a)
  31 #define __CAST2(a,...) __CAST_TO_U64(a), __CAST1(__VA_ARGS__)
  32 #define __CAST3(a,...) __CAST_TO_U64(a), __CAST2(__VA_ARGS__)
  33 #define __CAST4(a,...) __CAST_TO_U64(a), __CAST3(__VA_ARGS__)
  34 #define __CAST5(a,...) __CAST_TO_U64(a), __CAST4(__VA_ARGS__)
  35 #define __CAST6(a,...) __CAST_TO_U64(a), __CAST5(__VA_ARGS__)
  36 #define __CAST7(a,...) __CAST_TO_U64(a), __CAST6(__VA_ARGS__)
  37 #define __CAST8(a,...) __CAST_TO_U64(a), __CAST7(__VA_ARGS__)
  38 #define __CAST9(a,...) __CAST_TO_U64(a), __CAST8(__VA_ARGS__)
  39 #define __CAST10(a,...) __CAST_TO_U64(a), __CAST9(__VA_ARGS__)
  40 #define __CAST11(a,...) __CAST_TO_U64(a), __CAST10(__VA_ARGS__)
  41 #define __CAST12(a,...) __CAST_TO_U64(a), __CAST11(__VA_ARGS__)
/* tracepoints with more than 12 arguments will hit build error */
```
Quoted 4 lines

Imagine I only want to trace this function, now I can see memcg_id, zone_idex, while don't know node/lruvec, that's a little pitty. Just my personal opinion, I could miss anything.

Yeah, you are right. In my personal experience, I always enable trace_mm_vmscan_lru_isolate and trace_mm_vmscan_lru_shrink_inactive, which contain node_id. So we can see how the lruvec is scanned and shrunk, and we can get node_id from trace_mm_vmscan_lru_shrink_inactive. I am not arguing that this is exactly the 'correct' way to use these tracepoints, but I think it is a common usage.

Quoted 3 lines

I am open to that. If we want to record node_id, we have to remove an element. Maybe tier? But I would strongly recommend record memcg_id, we frequently need to check the reclaim behavior of a memcg, and most of our

Sorry, that's my typo which could cause misunderstanding. I meant "we print memcg_id but no nid, it may not be so clear". I agree with you that memcg_id is undispensable.

Quoted 1 line

scenarios are non-NUMA.

Understood, mobile phone mostly is non-NUMA, while server is different. About adding nid, I cousulted AI too, it says it's doable.

It says The 12-argument limit only counts the TP_PROTO arguments (that's the BPF __CAST12/bpf_trace_run12 path), not the __entry fields in TP_STRUCT__entry. And nid doesn't have to be a 13th argument at all. We already pass lruvec, so nid can be derived from it in TP_fast_assign with lruvec_pgdat(lruvec)->node_id.

e.g. for mm_mglru_scan_folios:

    TP_STRUCT__entry(
       __field(u64, memcg_id)
       __field(int, nid)
       __field(int, highest_zoneidx)
       __field(int, order)
       __field(unsigned long, nr_requested)
       __field(unsigned long, nr_scanned)
       __field(unsigned long, nr_sorted)
       __field(unsigned long, nr_skipped)
       __field(unsigned long, nr_taken)
       __field(int, lru)
       __field(unsigned long, max_seq)
       __field(int, tier)
       __field(unsigned long, min_seq)
    ),
                                                                                                       
    TP_fast_assign(
       __entry->memcg_id = mem_cgroup_id(lruvec_memcg(lruvec));
       __entry->nid      = lruvec_pgdat(lruvec)->node_id;
       __entry->highest_zoneidx = highest_zoneidx;
       ...
    ),
                                                                                                       
    TP_printk("memcg_id=%llu nid=%d classzone=%d order=%d ...",
       __entry->memcg_id,
       __entry->nid,
       __entry->highest_zoneidx,
       ...)
Quoted 5 lines

lruvec_pgdat() comes from include/linux/mmzone.h, which vmscan.h already pulls in via linux/mm.h, so no extra include is needed. The same pattern applies to mm_mglru_inc_max_seq in patch 3 if you want nid there too. I didn't try it though, please feel free to give it a shot.

Good. It works, I just tested it. Will add nid.

Quoted 125 lines
Quoted 125 lines
Quoted 120 lines
Quoted 102 lines
Quoted 8 lines

And I checked v1 thread, seems Steven suggested to move the two int to avoid extra padding.

Yeah, I will update it. I updated v2 to fix Sashiko's issue, before Steven had any comment.

Quoted 60 lines
Quoted 60 lines
include/trace/events/vmscan.h +49 -0
+
+	TP_ARGS(lruvec, highest_zoneidx, order, nr_requested, nr_scanned,
+		nr_sorted, nr_skipped, nr_taken, lru, max_seq, tier, min_seq),
+
+	TP_STRUCT__entry(
+		__field(u64, memcg_id)
+		__field(int, highest_zoneidx)
+		__field(int, order)
+		__field(unsigned long, nr_requested)
+		__field(unsigned long, nr_scanned)
+		__field(unsigned long, nr_sorted)
+		__field(unsigned long, nr_skipped)
+		__field(unsigned long, nr_taken)
+		__field(int, lru)
+		__field(unsigned long, max_seq)
+		__field(int, tier)
+		__field(unsigned long, min_seq)
+	),
+
+	TP_fast_assign(
+		__entry->memcg_id = mem_cgroup_id(lruvec_memcg(lruvec));
+		__entry->highest_zoneidx = highest_zoneidx;
+		__entry->order = order;
+		__entry->nr_requested = nr_requested;
+		__entry->nr_scanned = nr_scanned;
+		__entry->nr_sorted = nr_sorted;
+		__entry->nr_skipped = nr_skipped;
+		__entry->nr_taken = nr_taken;
+		__entry->lru = lru;
+		__entry->max_seq = max_seq;
+		__entry->tier = tier;
+		__entry->min_seq = min_seq;
+	),
+
+	TP_printk("memcg_id=%llu classzone=%d order=%d nr_requested=%lu nr_scanned=%lu nr_sorted=%lu nr_skipped=%lu nr_taken=%lu lru=%s max_seq=%lu tier=%d min_seq=%lu",
+		__entry->memcg_id,
+		__entry->highest_zoneidx,
+		__entry->order,
+		__entry->nr_requested,
+		__entry->nr_scanned,
+		__entry->nr_sorted,
+		__entry->nr_skipped,
+		__entry->nr_taken,
+		__print_symbolic(__entry->lru, LRU_NAMES),
+		__entry->max_seq,
+		__entry->tier,
+		__entry->min_seq)
+);
+
    TRACE_EVENT(mm_vmscan_write_folio,
    	TP_PROTO(struct folio *folio),
mm/vmscan.c +1 -0
index 2554a6513aa8..67f59aa73fb9 100644
@@ -4876,6 +4876,12 @@ static int scan_folios(unsigned long nr_to_scan, struct lruvec *lruvec,
    	trace_mm_vmscan_lru_isolate(sc->reclaim_idx, sc->order, nr_to_scan,
    				scanned, skipped, isolated,
    				type ? LRU_INACTIVE_FILE : LRU_INACTIVE_ANON);
+	trace_mm_mglru_scan_folios(lruvec,
Quoted 9 lines

mm/vmscan.c static int scan_folios(unsigned long nr_to_scan, struct lruvec *lruvec, · line 4884

Quoted 5 lines
mm/vmscan.c +5 -0
+				   sc->reclaim_idx, sc->order, nr_to_scan,
+				   scanned, sorted, skipped, isolated,
+				   type ? LRU_INACTIVE_FILE : LRU_INACTIVE_ANON,
+				   lrugen->max_seq, tier,
+				   lrugen->min_seq[type]);

And seems Steven also suggested to calculate lru, max_seq, min_seq in TP_fast_assign() in v1 which could be missed.

Thanks, I will update it following Steven's suggestions.

Quoted 6 lines
           TP_fast_assign(
                   __entry->memcg_id = mem_cgroup_id(lruvec_memcg(lruvec));
                   __entry->highest_zoneidx = sc->reclaim_idx;
                   __entry->order = sc->order;
                   __entry->nr_requested = nr_requested;
                   __entry->nr_scanned = nr_scanned;
Quoted 9 lines
                   __entry->nr_sorted = nr_sorted;
                   __entry->nr_skipped = nr_skipped;
                   __entry->nr_taken = nr_taken;
                   __entry->lru = type ? LRU_INACTIVE_FILE : LRU_INACTIVE_ANON;
                   __entry->max_seq = lrugen->max_seq;
                   __entry->tier = tier;
                   __entry->min_seq = lrugen->min_seq;
           ),
Quoted 3 lines

However, 'sc' is an internal structure, so sc->order cannot be accessed in TP_fast_assign(), and I don't think it is worth making scan_control an external structure just for this.

Agree.

Quoted 12 lines
Quoted 7 lines
Quoted 7 lines
mm/vmscan.c +0 -0
    	*isolatedp = isolated;
    	return scanned;
Signature · 1 line
2.34.1
Signature · 2 lines
Best regards
Ridong
Signature · 2 lines
Best regards
Ridong
Signature · 2 lines
Best regards
Ridong
maintainer
#13 lore raw

Re: [PATCH v2 2/3] mm/mglru: add tracepoint for scan_folios()

In reply to Baoquan He
Quoted 5 lines · On Wed, 16 Sep 2026 10:14:31 +0800 Baoquan He <[email protected]> wrote:
Quoted 3 lines

However, 'sc' is an internal structure, so sc->order cannot be accessed in TP_fast_assign(), and I don't think it is worth making scan_control an external structure just for this.

Agree.

Or what you can do is to move include/trace/events/vmscan.h to mm/trace_mm.h (or whatever you want to call it) and struct scan_control into "vmscan.h" and then you can use internal structures within the trace event.

Up to you, but this is what other subsystems have done.

-- Steve

reviewer
#14 lore raw

Re: [PATCH v2 2/3] mm/mglru: add tracepoint for scan_folios()

Quoted 7 lines · Steven Rostedt
Quoted 4 lines · On Wed, 16 Sep 2026 10:14:31 +0800 Baoquan He <[email protected]> wrote:
Quoted 3 lines

However, 'sc' is an internal structure, so sc->order cannot be accessed in TP_fast_assign(), and I don't think it is worth making scan_control an external structure just for this.

Quoted 6 lines
Quoted 1 line

Agree.

Or what you can do is to move include/trace/events/vmscan.h to mm/trace_mm.h (or whatever you want to call it) and struct scan_control into "vmscan.h" and then you can use internal structures within the trace event.

Sounds very reasonable, thanks for the valuable input.

Quoted 2 lines

Up to you, but this is what other subsystems have done.

Yeah, leave this to Ridong to decide.

#15 lore raw

Re: [PATCH v2 2/3] mm/mglru: add tracepoint for scan_folios()

Quoted 15 lines · Baoquan He
Quoted 7 lines · Steven Rostedt
Quoted 4 lines · On Wed, 16 Sep 2026 10:14:31 +0800 Baoquan He <[email protected]> wrote:
Quoted 3 lines

However, 'sc' is an internal structure, so sc->order cannot be accessed in TP_fast_assign(), and I don't think it is worth making scan_control an external structure just for this.

Quoted 6 lines
Quoted 1 line

Agree.

Or what you can do is to move include/trace/events/vmscan.h to mm/trace_mm.h (or whatever you want to call it) and struct scan_control into "vmscan.h" and then you can use internal structures within the trace event.

Quoted 6 lines

Sounds very reasonable, thanks for the valuable input.

Quoted 2 lines

Up to you, but this is what other subsystems have done.

Yeah, leave this to Ridong to decide.

Thank you for the suggestion.

I think it is worth doing. And we can also use that for other tracepoints that are using sc->*.

I will give this approach a try.

Signature · 2 lines
Best regards
Ridong
#16 lore raw

PATCH v2 3/3 mm/mglru: add tracepoint for inc_max_seq()

In reply to Ridong Chen

From: Ridong Chen <[email protected]>

Aging in MGLRU advances max_seq via inc_max_seq(), creating a new youngest generation. There is currently no tracepoint on this path, so the moment a new generation is created, and how the min_seq of each type trails behind it, cannot be observed as it happens.

Add mm_mglru_inc_max_seq, emitted right after max_seq is bumped, with the memcg id, the new max_seq, the anon and file min_seq, and the number of pages in each generation for both types, summed over zones the same way the debugfs lru_gen file reports them. The nr_anon/nr_file arrays are indexed by generation slot, so the emitted max_seq/min_seq say which slot holds which seq. They are printed with __print_array(), so the output is hex and its length follows MAX_NR_GENS automatically. Paired with the mm_mglru_scan_folios tracepoint it makes the full aging-to-eviction window observable per memcg.

Assisted-by Claude:claude-opus-4-8
---
 include/trace/events/vmscan.h | 38 +++++++++++++++++++++++++++++++++++
 mm/vmscan.c                   | 23 +++++++++++++++++++++
 2 files changed, 61 insertions(+)
include/trace/events/vmscan.h +38 -0
index 5defa8f6719c..a20c6b2e062f 100644
@@ -455,6 +455,44 @@ TRACE_EVENT(mm_mglru_scan_folios,
 		__entry->min_seq)
 );
 
+TRACE_EVENT(mm_mglru_inc_max_seq,
+
+	TP_PROTO(struct lruvec *lruvec,
+		unsigned long max_seq,
+		unsigned long anon_min_seq,
+		unsigned long file_min_seq,
+		unsigned long *nr_anon,
+		unsigned long *nr_file),
+
+	TP_ARGS(lruvec, max_seq, anon_min_seq, file_min_seq, nr_anon, nr_file),
+
+	TP_STRUCT__entry(
+		__field(u64, memcg_id)
+		__field(unsigned long, max_seq)
+		__field(unsigned long, anon_min_seq)
+		__field(unsigned long, file_min_seq)
+		__array(unsigned long, nr_anon, MAX_NR_GENS)
+		__array(unsigned long, nr_file, MAX_NR_GENS)
+	),
+
+	TP_fast_assign(
+		__entry->memcg_id = mem_cgroup_id(lruvec_memcg(lruvec));
+		__entry->max_seq = max_seq;
+		__entry->anon_min_seq = anon_min_seq;
+		__entry->file_min_seq = file_min_seq;
+		memcpy(__entry->nr_anon, nr_anon, sizeof(__entry->nr_anon));
+		memcpy(__entry->nr_file, nr_file, sizeof(__entry->nr_file));
+	),
+
+	TP_printk("memcg_id=%llu max_seq=%lu anon_min_seq=%lu file_min_seq=%lu nr_anon=%s nr_file=%s",
+		__entry->memcg_id,
+		__entry->max_seq,
+		__entry->anon_min_seq,
+		__entry->file_min_seq,
+		__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_write_folio,
 
 	TP_PROTO(struct folio *folio),
mm/vmscan.c +23 -0
index 67f59aa73fb9..d1495a7d469d 100644
@@ -4100,6 +4100,27 @@ static void try_to_inc_min_seq(struct lruvec *lruvec, int swappiness)
 	}
 }
 
+static void trace_inc_max_seq(struct lruvec *lruvec)
+{
+	int type, gen;
+	unsigned long nr[ANON_AND_FILE][MAX_NR_GENS];
+	struct lru_gen_folio *lrugen;
+
+	if (!trace_mm_mglru_inc_max_seq_enabled())
+		return;
+
+	lrugen = &lruvec->lrugen;
+	for (type = 0; type < ANON_AND_FILE; type++)
+		for (gen = 0; gen < MAX_NR_GENS; gen++)
+			nr[type][gen] = lru_gen_seq_nr_pages(lrugen, gen, type);
+
+	trace_mm_mglru_inc_max_seq(lruvec,
+				   lrugen->max_seq,
+				   lrugen->min_seq[LRU_GEN_ANON],
+				   lrugen->min_seq[LRU_GEN_FILE],
+				   nr[LRU_GEN_ANON], nr[LRU_GEN_FILE]);
+}
+
 static bool inc_max_seq(struct lruvec *lruvec, unsigned long seq, int swappiness)
 {
 	bool success;
@@ -4159,6 +4180,8 @@ static bool inc_max_seq(struct lruvec *lruvec, unsigned long seq, int swappiness
 	WRITE_ONCE(lrugen->timestamps[next], jiffies);
 	/* make sure preceding modifications appear */
 	smp_store_release(&lrugen->max_seq, lrugen->max_seq + 1);
+
+	trace_inc_max_seq(lruvec);
 unlock:
 	lruvec_unlock_irq(lruvec);
 
Signature · 1 line
2.34.1
reviewer Reviewed-by on v2 3/3
#17 lore raw

Re: [PATCH v2 3/3] mm/mglru: add tracepoint for inc_max_seq()

Quoted 17 lines · Ridong Chen

From: Ridong Chen <[email protected]>

Aging in MGLRU advances max_seq via inc_max_seq(), creating a new youngest generation. There is currently no tracepoint on this path, so the moment a new generation is created, and how the min_seq of each type trails behind it, cannot be observed as it happens.

Add mm_mglru_inc_max_seq, emitted right after max_seq is bumped, with the memcg id, the new max_seq, the anon and file min_seq, and the number of pages in each generation for both types, summed over zones the same way the debugfs lru_gen file reports them. The nr_anon/nr_file arrays are indexed by generation slot, so the emitted max_seq/min_seq say which slot holds which seq. They are printed with __print_array(), so the output is hex and its length follows MAX_NR_GENS automatically. Paired with the mm_mglru_scan_folios tracepoint it makes the full aging-to-eviction window observable per memcg.

Quoted 3 lines
Assisted-by Claude:claude-opus-4-8

---

Make sense to me.

#18 lore raw
In reply to Ridong Chen
Quoted 56 lines · Ridong Chen

From: Ridong Chen <[email protected]>

Background
==========

MGLRU currently has no tracepoints of its own. The scan and evict paths reuse the classic-LRU tracepoints (trace_mm_vmscan_lru_isolate() and trace_mm_vmscan_lru_shrink_inactive()), which predate MGLRU and carry no generation, sequence, memcg or swappiness context. A trace of a running system therefore cannot tell which memcg a given scan belongs to, how far reclaim has progressed through the generations, or when a new generation is created - so how MGLRU actually operates is effectively invisible.

Implementation
==============

Patch 1 is a cleanup that factors the per-generation page-count summation into a helper, lru_gen_seq_nr_pages(), reused by patch 3.

Patch 2 adds mm_mglru_scan_folios on the scan path, and patch 3 adds mm_mglru_inc_max_seq on the aging path. Both carry the memcg id and the generation window (min_seq/max_seq), live at MGLRU-specific layers with no classic-LRU counterpart, and are guarded so the hot paths stay zero-cost when disabled.

Effect
======

Paired, the two tracepoints make the full aging-to-eviction window observable per memcg: aging advances max_seq (the leading edge), scanning consumes the oldest generations, and the min_seq/max_seq pair on each event shows how the generation window moves over time.

A sample trace, with the classic-LRU tracepoints left enabled to show how they interleave:

mm_vmscan_lru_isolate: classzone=4 order=0 nr_requested=36 nr_scanned=31 nr_skipped=0 nr_taken=29 lru=inactive_file
mm_mglru_scan_folios: memcg_id=73 classzone=4 order=0 nr_requested=36 nr_scanned=31 nr_sorted=2 nr_skipped=0 nr_taken=29 lru=inactive_file max_seq=3 tier=3 min_seq=0
mm_vmscan_lru_shrink_inactive: nid=0 nr_scanned=31 nr_reclaimed=29 nr_dirty=0 nr_writeback=0 nr_congested=0 nr_immediate=0 nr_activate_anon=0 nr_activate_file=0 nr_ref_keep=0 nr_unmap_fail=0 priority=5 flags=RECLAIM_WB_FILE|RECLAIM_WB_ASYNC
mm_mglru_inc_max_seq: memcg_id=73 max_seq=4 anon_min_seq=1 file_min_seq=1 nr_anon={0x0,0x0,0x1,0x0} nr_file={0x0,0x427,0x6,0x4a}
mm_vmscan_lru_isolate: classzone=4 order=0 nr_requested=5 nr_scanned=5 nr_skipped=0 nr_taken=1 lru=inactive_file
mm_mglru_scan_folios: memcg_id=73 classzone=4 order=0 nr_requested=5 nr_scanned=5 nr_sorted=4 nr_skipped=0 nr_taken=1 lru=inactive_file max_seq=4 tier=3 min_seq=1
mm_vmscan_lru_shrink_inactive: nid=0 nr_scanned=5 nr_reclaimed=1 nr_dirty=0 nr_writeback=0 nr_congested=0 nr_immediate=0 nr_activate_anon=0 nr_activate_file=0 nr_ref_keep=0 nr_unmap_fail=0 priority=5 flags=RECLAIM_WB_FILE|RECLAIM_WB_ASYNC

The mm_mglru_scan_folios lines carry the memcg id and the generation window (max_seq/min_seq) that the bare mm_vmscan_lru_isolate lines above them cannot - those cannot even say which memcg they came from. The mm_mglru_inc_max_seq line then shows a new generation being created (max_seq 3 -> 4) with the per-generation page counts for both types.

---
v2: address Sashiko AI review [1] - pass struct lruvec * into the tracepoints
and do the memcg lookup inside TP_fast_assign.

[1] https://sashiko.dev/#/patchset/[email protected]?part=2

Quoted 9 lines

Ridong Chen (3):
mm/mglru: factor out lru_gen_seq_nr_pages()
mm/mglru: add tracepoint for scan_folios()
mm/mglru: add tracepoint for inc_max_seq()

  include/trace/events/vmscan.h | 101 ++++++++++++++++++++++++++++++++++
  mm/vmscan.c                   |  53 +++++++++++++++---
  2 files changed, 146 insertions(+), 8 deletions(-)

Hi Steven, Baolin and Baoquan,

Thanks again for reviewing v2.

Following Steven's suggestion in this thread, I first moved the vmscan trace header under mm/ and exposed struct scan_control to it in a separate RFC series. Patches [2/3] and [3/3] of v2 have now been reworked on top of that and posted together with it as one series:

[PATCH v4 0/9] mm/vmscan: move tracepoints to mm/ and add MGLRU tracepoints
https://lore.kernel.org/all/[email protected]/

The two MGLRU tracepoints are [8/9] and [9/9] there. Compared with v2:

- Both events now take only lruvec/sc plus the local counters, and derive everything else (memcg id, order, reclaim_idx, lru, max_seq, min_seq and the per-generation page counts) in TP_fast_assign() (Steven).
- Add nid, derived from lruvec_pgdat(lruvec) (Baoquan).
- Group the int fields at the end of the entry to avoid padding on 64-bit (Steven).
- Drop v2 [1/3] "mm/mglru: factor out lru_gen_seq_nr_pages()": the per-generation page count is now summed inside TP_fast_assign(), so the helper has no user left.

Since [8/9] and [9/9] changed substantially, I did not carry over your Reviewed-by tags. I would really appreciate it if you could take another look at v4.

Signature · 2 lines
Best regards
Ridong