[PATCH RFC 1/2] mm/mglru: add tracepoint for folio isolation

From: Ridong Chen

Date: Mon Sep 07 2026 - 00:28:49 EST


From: Ridong Chen <chenridong@xxxxxxxxxx>

MGLRU's scan_folios() and evict_folios() emit the classic-LRU
tracepoints trace_mm_vmscan_lru_isolate() and
trace_mm_vmscan_lru_shrink_inactive(). Those predate MGLRU and are
indistinguishable from the classic-LRU path: they carry no generation,
sequence, memcg or swappiness context, so a trace of an MGLRU run cannot
tell which memcg a given scan/evict belongs to, nor how far reclaim has
progressed through the generations.

Add mm_mglru_isolate_folios, emitted once per isolate_folios() call with
the memcg id, the type actually scanned, the effective swappiness, the
scanned/isolated counts, and the anon/file min_seq and max_seq. The
min_seq/max_seq triplet ties each isolation to the generation layout it
ran against, which the classic-LRU tracepoints cannot express.

This is emitted at the isolate_folios() layer, which is MGLRU-specific
and has no classic-LRU counterpart, so it neither changes nor duplicates
the existing scan/evict tracepoints.

Assisted-by: Claude:claude-opus-4-8
Signed-off-by: Ridong Chen <chenridong@xxxxxxxxxx>
---
include/trace/events/vmscan.h | 47 +++++++++++++++++++++++++++++++++++
mm/vmscan.c | 9 ++++++-
2 files changed, 55 insertions(+), 1 deletion(-)

diff --git a/include/trace/events/vmscan.h b/include/trace/events/vmscan.h
index 8a872990b4be..a0e3cf75294b 100644
--- a/include/trace/events/vmscan.h
+++ b/include/trace/events/vmscan.h
@@ -392,6 +392,53 @@ TRACE_EVENT(mm_vmscan_lru_isolate,
__print_symbolic(__entry->lru, LRU_NAMES))
);

+TRACE_EVENT(mm_mglru_isolate_folios,
+
+ TP_PROTO(u64 memcg_id,
+ int type,
+ int swappiness,
+ unsigned long nr_scanned,
+ unsigned long nr_isolated,
+ unsigned long anon_min_seq,
+ unsigned long file_min_seq,
+ unsigned long max_seq),
+
+ TP_ARGS(memcg_id, type, swappiness, nr_scanned, nr_isolated,
+ anon_min_seq, file_min_seq, max_seq),
+
+ TP_STRUCT__entry(
+ __field(u64, memcg_id)
+ __field(int, type)
+ __field(int, swappiness)
+ __field(unsigned long, nr_scanned)
+ __field(unsigned long, nr_isolated)
+ __field(unsigned long, anon_min_seq)
+ __field(unsigned long, file_min_seq)
+ __field(unsigned long, max_seq)
+ ),
+
+ TP_fast_assign(
+ __entry->memcg_id = memcg_id;
+ __entry->type = type;
+ __entry->swappiness = swappiness;
+ __entry->nr_scanned = nr_scanned;
+ __entry->nr_isolated = nr_isolated;
+ __entry->anon_min_seq = anon_min_seq;
+ __entry->file_min_seq = file_min_seq;
+ __entry->max_seq = max_seq;
+ ),
+
+ TP_printk("memcg_id=%llu type=%s swappiness=%d nr_scanned=%lu nr_isolated=%lu anon_min_seq=%lu file_min_seq=%lu max_seq=%lu",
+ __entry->memcg_id,
+ __entry->type ? "file" : "anon",
+ __entry->swappiness,
+ __entry->nr_scanned,
+ __entry->nr_isolated,
+ __entry->anon_min_seq,
+ __entry->file_min_seq,
+ __entry->max_seq)
+);
+
TRACE_EVENT(mm_vmscan_write_folio,

TP_PROTO(struct folio *folio),
diff --git a/mm/vmscan.c b/mm/vmscan.c
index 8409ea4bbf37..771fe6827939 100644
--- a/mm/vmscan.c
+++ b/mm/vmscan.c
@@ -4843,6 +4843,7 @@ static int isolate_folios(unsigned long nr_to_scan, struct lruvec *lruvec,
bool type_fallback_allowed = !is_single_type_reclaim(swappiness);
int type = get_type_to_scan(lruvec, swappiness);
int total_scanned = 0, scanned, tier;
+ struct lru_gen_folio *lrugen = &lruvec->lrugen;
bool tried = false;

retry:
@@ -4854,7 +4855,7 @@ static int isolate_folios(unsigned long nr_to_scan, struct lruvec *lruvec,
if (*isolated) {
*isolate_type = type;
*isolate_scanned = scanned;
- return total_scanned;
+ goto done;
}

/*
@@ -4876,6 +4877,12 @@ static int isolate_folios(unsigned long nr_to_scan, struct lruvec *lruvec,
goto retry;
}

+done:
+ trace_mm_mglru_isolate_folios(mem_cgroup_id(lruvec_memcg(lruvec)),
+ type, swappiness, total_scanned, *isolated,
+ lrugen->min_seq[LRU_GEN_ANON],
+ lrugen->min_seq[LRU_GEN_FILE],
+ lrugen->max_seq);
return total_scanned;
}

--
2.34.1