mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: <xu.xin16@zte.com.cn>
To: <akpm@linux-foundation.org>, <david@kernel.org>, <ljs@kernel.org>
Cc: <hughd@google.com>, <linux-mm@kvack.org>,
	<linux-kernel@vger.kernel.org>, <michel@lespinasse.org>,
	<corbet@lwn.net>, <wang.yaxin@zte.com.cn>, <xu.xin16@zte.com.cn>
Subject: [PATCH v5 1/5] mm/rmap: add tracepoint for rmap_walk
Date: Tue, 19 May 2026 22:09:09 +0800 (CST)	[thread overview]
Message-ID: <20260519220909868loJhTdEdfN7gGPtr_wH-y@zte.com.cn> (raw)
In-Reply-To: <20260519220536792dMIKRMurt3vZ5lXC5pwh8@zte.com.cn>

From: xu xin <xu.xin16@zte.com.cn>

Add trace_rmap_walk_start() and trace_rmap_walk_end() to bracket
reverse mapping walks.  Unlike manual clock sampling, these
tracepoints record no timestamp; latency can be computed offline
by tools (e.g., perf, trace-cmd) using the event timestamps.

When tracepoints are disabled, the only cost is a static branch
check (no clock read, no duration calculation), making them
suitable for production use.

The information (folio type, locked state) helps diagnose
performance issues in KSM, anonymous, and file-backed rmap walks.

'# cat /sys/kernel/tracing/trace
'# tracer: nop
'#
'# entries-in-buffer/entries-written: 408/408   #P:4
'#
'#                     _-----=> irqs-off/BH-disabled
'#                    / _----=> need-resched
'#                   | / _---=> hardirq/softirq
'#                   || / _--=> preempt-depth
'#                   ||| / _-=> migrate-disable
'#                   |||| /     delay
'#TASK-PID     CPU#  |||||  TIMESTAMP  FUNCTION
'#   | |         |   |||||     |         |
rmap-215     [002] .....   163.530676: rmap_walk_start: folio=00000000ae4eb941 rwc=0000000030d943e6 page_type=ksm locked=false
rmap-215     [002] .....   163.532446: rmap_walk_end: folio=00000000ae4eb941 rwc=0000000030d943e6 page_type=ksm locked=false
rmap-215     [002] .....   163.533201: rmap_walk_start: folio=00000000ae4eb941 rwc=000000003c9e8513 page_type=ksm locked=false
rmap-215     [002] .....   163.533597: rmap_walk_end: folio=00000000ae4eb941 rwc=000000003c9e8513 page_type=ksm locked=false
rmap-215     [002] .....   163.533899: rmap_walk_start: folio=00000000ae4eb941 rwc=0000000030d943e6 page_type=ksm locked=false
rmap-215     [002] .....   163.534053: rmap_walk_end: folio=00000000ae4eb941 rwc=0000000030d943e6 page_type=ksm locked=false

Signed-off-by: xu xin <xu.xin16@zte.com.cn>
---
 include/trace/events/rmap.h | 73 +++++++++++++++++++++++++++++++++++++
 mm/rmap.c                   |  9 +++++
 2 files changed, 82 insertions(+)
 create mode 100644 include/trace/events/rmap.h

diff --git a/include/trace/events/rmap.h b/include/trace/events/rmap.h
new file mode 100644
index 000000000000..275e77849698
--- /dev/null
+++ b/include/trace/events/rmap.h
@@ -0,0 +1,73 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+#undef TRACE_SYSTEM
+#define TRACE_SYSTEM rmap
+
+#if !defined(_TRACE_RMAP_H) || defined(TRACE_HEADER_MULTI_READ)
+#define _TRACE_RMAP_H
+
+#include <linux/tracepoint.h>
+#include <linux/rmap.h>
+
+#define GET_RMAP_PAGE_TYPE(folio) (folio_test_ksm(folio) ? "ksm" : \
+		(folio_test_anon(folio) ? "anon" : "file"))
+
+TRACE_EVENT(rmap_walk_start,
+
+	TP_PROTO(struct folio *folio, struct rmap_walk_control *rwc, bool locked),
+
+	TP_ARGS(folio, rwc, locked),
+
+	TP_STRUCT__entry(
+		__field(unsigned long, folio_addr)
+		__field(unsigned long, rwc_addr)
+		__string(page_type, GET_RMAP_PAGE_TYPE(folio))
+		__field(bool, locked)
+	),
+
+	TP_fast_assign(
+		__entry->folio_addr = (unsigned long)folio;
+		__entry->rwc_addr = (unsigned long)rwc;
+		__assign_str(page_type);
+		__entry->locked = locked;
+	),
+
+	TP_printk("folio=%p rwc=%p page_type=%s locked=%s",
+		(void *)(unsigned long)__entry->folio_addr,
+		(void *)(unsigned long)__entry->rwc_addr,
+		__get_str(page_type),
+		__entry->locked ? "true" : "false")
+);
+
+TRACE_EVENT(rmap_walk_end,
+
+	TP_PROTO(struct folio *folio, struct rmap_walk_control *rwc, bool locked),
+
+	TP_ARGS(folio, rwc, locked),
+
+	TP_STRUCT__entry(
+		__field(unsigned long, folio_addr)
+		__field(unsigned long, rwc_addr)
+		__string(page_type, GET_RMAP_PAGE_TYPE(folio))
+		__field(bool, locked)
+	),
+
+	TP_fast_assign(
+		__entry->folio_addr = (unsigned long)folio;
+		__entry->rwc_addr = (unsigned long)rwc;
+		__assign_str(page_type);
+		__entry->locked = locked;
+	),
+
+	TP_printk("folio=%p rwc=%p page_type=%s locked=%s",
+		(void *)(unsigned long)__entry->folio_addr,
+		(void *)(unsigned long)__entry->rwc_addr,
+		__get_str(page_type),
+		__entry->locked ? "true" : "false")
+);
+
+
+#endif /* _TRACE_RMAP_H */
+
+/* This part must be outside protection */
+#include <trace/define_trace.h>
+
diff --git a/mm/rmap.c b/mm/rmap.c
index 78b7fb5f367c..52f795f768e1 100644
--- a/mm/rmap.c
+++ b/mm/rmap.c
@@ -80,6 +80,7 @@

 #define CREATE_TRACE_POINTS
 #include <trace/events/migrate.h>
+#include <trace/events/rmap.h>

 #include "internal.h"
 #include "swap.h"
@@ -3098,23 +3099,31 @@ static void rmap_walk_file(struct folio *folio,

 void rmap_walk(struct folio *folio, struct rmap_walk_control *rwc)
 {
+	trace_rmap_walk_start(folio, rwc, false);
+
 	if (unlikely(folio_test_ksm(folio)))
 		rmap_walk_ksm(folio, rwc);
 	else if (folio_test_anon(folio))
 		rmap_walk_anon(folio, rwc, false);
 	else
 		rmap_walk_file(folio, rwc, false);
+
+	trace_rmap_walk_end(folio, rwc, false);
 }

 /* Like rmap_walk, but caller holds relevant rmap lock */
 void rmap_walk_locked(struct folio *folio, struct rmap_walk_control *rwc)
 {
+	trace_rmap_walk_start(folio, rwc, true);
+
 	/* no ksm support for now */
 	VM_BUG_ON_FOLIO(folio_test_ksm(folio), folio);
 	if (folio_test_anon(folio))
 		rmap_walk_anon(folio, rwc, true);
 	else
 		rmap_walk_file(folio, rwc, true);
+
+	trace_rmap_walk_end(folio, rwc, true);
 }

 #ifdef CONFIG_HUGETLB_PAGE
-- 
2.25.1

  reply	other threads:[~2026-05-19 14:09 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-05-19 14:05 [PATCH v5 0/5] KSM: performance optimizations for rmap_walk_ksm xu.xin16
2026-05-19 14:09 ` xu.xin16 [this message]
2026-05-19 14:11 ` [PATCH v5 2/5] tools/testing: add rmap walk latency benchmark xu.xin16
2026-05-19 14:12 ` [PATCH v5 3/5] ksm: add pgoff into ksm_rmap_item xu.xin16
2026-05-19 14:14 ` [PATCH v5 4/5] ksm: Optimize rmap_walk_ksm by passing a suitable pgoff xu.xin16
2026-05-19 14:18 ` [PATCH v5 5/5] ksm: add mremap selftests for ksm_rmap_walk xu.xin16
2026-05-19 17:01 ` [PATCH v5 0/5] KSM: performance optimizations for rmap_walk_ksm Andrew Morton
2026-05-20  6:26   ` xu.xin16
2026-05-20  6:37   ` xu.xin16

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=20260519220909868loJhTdEdfN7gGPtr_wH-y@zte.com.cn \
    --to=xu.xin16@zte.com.cn \
    --cc=akpm@linux-foundation.org \
    --cc=corbet@lwn.net \
    --cc=david@kernel.org \
    --cc=hughd@google.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=ljs@kernel.org \
    --cc=michel@lespinasse.org \
    --cc=wang.yaxin@zte.com.cn \
    /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

all inboxes | Powered by JetHome®