[PATCH v4 8/9] mm/mglru: add tracepoint for scan_folios()
flat view
HOTtoday
From: Ridong Chen <ridong.chen@linux.dev>
Date: 2026-10-19 04:24:07
Also in:
bpf, cgroups, linux-mm, lkml
Subsystem:
memory management, memory management - mglru (multi-gen lru), memory management - reclaim, the rest · Maintainers:
Andrew Morton, Johannes Weiner, Linus Torvalds
From: Ridong Chen <redacted> 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 context the classic tracepoint lacks: the node id and memcg id of the lruvec, and the max_seq, tier and min_seq of the type being scanned. Now that struct scan_control is visible to the trace header, pass sc, lruvec, type and tier straight in and derive everything else in TP_fast_assign(), so nothing is computed at the call site when the event is disabled. The int fields are grouped at the end of the entry to avoid padding on 64-bit. scan_folios() is the MGLRU-specific layer where folios are actually scanned, so it has no classic-LRU counterpart. The existing tracepoint is left unchanged. Assisted-by: LLM Signed-off-by: Ridong Chen <redacted> --- mm/trace_vmscan.h | 66 +++++++++++++++++++++++++++++++++++++++++++++++ mm/vmscan.c | 2 ++ 2 files changed, 68 insertions(+)
diff --git a/mm/trace_vmscan.h b/mm/trace_vmscan.h
index b2ad83e5f25e..8148b8224422 100644
--- a/mm/trace_vmscan.h
+++ b/mm/trace_vmscan.h@@ -392,6 +392,72 @@ TRACE_EVENT(mm_vmscan_lru_isolate, __print_symbolic(__entry->lru, LRU_NAMES)) ); +#ifdef CONFIG_LRU_GEN +TRACE_EVENT(mm_mglru_scan_folios, + + TP_PROTO(struct lruvec *lruvec, + struct scan_control *sc, + unsigned long nr_requested, + unsigned long nr_scanned, + unsigned long nr_sorted, + unsigned long nr_skipped, + unsigned long nr_taken, + int type, + int tier), + + TP_ARGS(lruvec, sc, nr_requested, nr_scanned, nr_sorted, nr_skipped, + nr_taken, type, tier), + + TP_STRUCT__entry( + __field(u64, memcg_id) + __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(unsigned long, max_seq) + __field(unsigned long, min_seq) + __field(int, nid) + __field(int, highest_zoneidx) + __field(int, order) + __field(int, lru) + __field(int, tier) + ), + + TP_fast_assign( + __entry->memcg_id = mem_cgroup_id(lruvec_memcg(lruvec)); + __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->max_seq = lruvec->lrugen.max_seq; + __entry->min_seq = lruvec->lrugen.min_seq[type]; + __entry->nid = lruvec_pgdat(lruvec)->node_id; + __entry->highest_zoneidx = sc->reclaim_idx; + __entry->order = sc->order; + __entry->lru = type ? LRU_INACTIVE_FILE : LRU_INACTIVE_ANON; + __entry->tier = tier; + ), + + TP_printk("nid=%d 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->nid, + __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) +); + +#endif /* CONFIG_LRU_GEN */ + TRACE_EVENT(mm_vmscan_write_folio, TP_PROTO(struct folio *folio),
diff --git a/mm/vmscan.c b/mm/vmscan.c
index 5d699decaa28..d459678c5ee5 100644
--- a/mm/vmscan.c
+++ b/mm/vmscan.c@@ -4847,6 +4847,8 @@ static int scan_folios(unsigned long nr_to_scan, struct lruvec *lruvec, trace_mm_vmscan_lru_isolate(sc, nr_to_scan, scanned, skipped, isolated, type ? LRU_INACTIVE_FILE : LRU_INACTIVE_ANON); + trace_mm_mglru_scan_folios(lruvec, sc, nr_to_scan, scanned, sorted, + skipped, isolated, type, tier); *isolatedp = isolated; return scanned;
--
2.34.1