Linux-mm Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: Ridong Chen <ridong.chen@linux.dev>
To: Steven Rostedt <rostedt@goodmis.org>,
	Masami Hiramatsu <mhiramat@kernel.org>,
	Andrew Morton <akpm@linux-foundation.org>,
	Johannes Weiner <hannes@cmpxchg.org>
Cc: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>,
	David Hildenbrand <david@kernel.org>,
	Michal Hocko <mhocko@kernel.org>, Qi Zheng <qi.zheng@linux.dev>,
	Shakeel Butt <shakeel.butt@linux.dev>,
	Lorenzo Stoakes <ljs@kernel.org>,
	Kairui Song <kasong@tencent.com>, Barry Song <baohua@kernel.org>,
	Axel Rasmussen <axelrasmussen@google.com>,
	Yuanchu Xie <yuanchu@google.com>, Wei Xu <weixugc@google.com>,
	linux-kernel@vger.kernel.org, linux-trace-kernel@vger.kernel.org,
	linux-mm@kvack.org, Ridong Chen <ridong.chen@linux.dev>,
	Ridong Chen <chenridong@xiaomi.com>
Subject: [PATCH RFC 1/2] mm/mglru: add tracepoint for folio isolation
Date: Mon,  7 Sep 2026 12:24:46 +0800	[thread overview]
Message-ID: <20260907042447.2450663-2-ridong.chen@linux.dev> (raw)
In-Reply-To: <20260907042447.2450663-1-ridong.chen@linux.dev>

From: Ridong Chen <chenridong@xiaomi.com>

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@xiaomi.com>
---
 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



  reply	other threads:[~2026-09-07  4:25 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-09-07  4:24 [PATCH RFC 0/2] mm/mglru: add tracepoints for aging and isolation Ridong Chen
2026-09-07  4:24 ` Ridong Chen [this message]
2026-09-09  6:40   ` [PATCH RFC 1/2] mm/mglru: add tracepoint for folio isolation Barry Song
2026-09-09 12:00     ` Ridong Chen
2026-09-09 12:11       ` Barry Song
2026-09-09 12:41         ` Ridong Chen
2026-09-07  4:24 ` [PATCH RFC 2/2] mm/mglru: add tracepoint for inc_max_seq Ridong Chen
2026-09-09  6:45   ` Barry Song
2026-09-09 12:43     ` Ridong Chen
2026-09-08 13:45 ` [PATCH RFC 0/2] mm/mglru: add tracepoints for aging and isolation Steven Rostedt
2026-09-09 11:37   ` Ridong Chen

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20260907042447.2450663-2-ridong.chen@linux.dev \
    --to=ridong.chen@linux.dev \
    --cc=akpm@linux-foundation.org \
    --cc=axelrasmussen@google.com \
    --cc=baohua@kernel.org \
    --cc=chenridong@xiaomi.com \
    --cc=david@kernel.org \
    --cc=hannes@cmpxchg.org \
    --cc=kasong@tencent.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=linux-trace-kernel@vger.kernel.org \
    --cc=ljs@kernel.org \
    --cc=mathieu.desnoyers@efficios.com \
    --cc=mhiramat@kernel.org \
    --cc=mhocko@kernel.org \
    --cc=qi.zheng@linux.dev \
    --cc=rostedt@goodmis.org \
    --cc=shakeel.butt@linux.dev \
    --cc=weixugc@google.com \
    --cc=yuanchu@google.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox