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
Signed-off-by: Ridong Chen <[email protected]>
---
 include/trace/events/vmscan.h | 63 +++++++++++++++++++++++++++++++++++
 mm/vmscan.c                   |  6 ++++
 2 files changed, 69 insertions(+)

diff --git a/include/trace/events/vmscan.h b/include/trace/events/vmscan.h
index 8a872990b4be..c39dfacef033 100644
--- a/include/trace/events/vmscan.h
+++ b/include/trace/events/vmscan.h
@@ -392,6 +392,69 @@ TRACE_EVENT(mm_vmscan_lru_isolate,
                __print_symbolic(__entry->lru, LRU_NAMES))
 );
 
+TRACE_EVENT(mm_mglru_scan_folios,
+
+       TP_PROTO(u64 memcg_id,
+               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(memcg_id, 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 = memcg_id;
+               __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),
diff --git a/mm/vmscan.c b/mm/vmscan.c
index 2554a6513aa8..bd1b9ecf2e84 100644
--- a/mm/vmscan.c
+++ b/mm/vmscan.c
@@ -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(mem_cgroup_id(lruvec_memcg(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;
-- 
2.34.1


Reply via email to