From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mxhk.zte.com.cn (mxhk.zte.com.cn [160.30.148.35]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 430AB27E049 for ; Tue, 19 May 2026 14:09:25 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=160.30.148.35 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779199768; cv=none; b=a9hgQGgFK2ygw62TqVzPoG9X799DwhHrWuxMZQgmM3MXG/KDf+peW0k+0ckP/lYd3H7D2ivuzXRaNMl2LklABPdsqPA5EniftJKenloOlk3Ln0C7teZl716hbkmOFwaYWiSdmYple8SiKxvA00damdd2/aRoCuwoUP4mNXK11TI= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779199768; c=relaxed/simple; bh=b0b4bgurnFDiklxzNbq/L+LkWtXi27qpk9tZG7NfXmE=; h=Message-ID:In-Reply-To:References:Date:Mime-Version:From:To:Cc: Subject:Content-Type; b=ePoFERCaqXjWUOyX4VpXWckJKSw8TyDncfmvqKYbuuPkTfr4BiSLhRLr6l84v7FJS2XwWKunr8UdaMqpCec4MBlJGTABp3HlMO7BMcweqemMMYjIGmj7vqhRIWvI6f2kSFj4FSgsM1nqqt7MPcy5tg2HEQl8uKL4wHZ3qd3j0OU= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=zte.com.cn; spf=pass smtp.mailfrom=zte.com.cn; arc=none smtp.client-ip=160.30.148.35 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=zte.com.cn Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=zte.com.cn Received: from mse-fl1.zte.com.cn (unknown [10.5.228.132]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange x25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mxhk.zte.com.cn (FangMail) with ESMTPS id 4gKc3w6sNvz8Xrkn; Tue, 19 May 2026 22:09:16 +0800 (CST) Received: from xaxapp02.zte.com.cn ([10.88.97.241]) by mse-fl1.zte.com.cn with SMTP id 64JE97kl056524; Tue, 19 May 2026 22:09:07 +0800 (+08) (envelope-from xu.xin16@zte.com.cn) Received: from mapi (xaxapp05[null]) by mapi (Zmail) with MAPI id mid32; Tue, 19 May 2026 22:09:09 +0800 (CST) X-Zmail-TransId: 2afc6a0c6f055d7-efb5a X-Mailer: Zmail v1.0 Message-ID: <20260519220909868loJhTdEdfN7gGPtr_wH-y@zte.com.cn> In-Reply-To: <20260519220536792dMIKRMurt3vZ5lXC5pwh8@zte.com.cn> References: 20260519220536792dMIKRMurt3vZ5lXC5pwh8@zte.com.cn Date: Tue, 19 May 2026 22:09:09 +0800 (CST) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 From: To: , , Cc: , , , , , , Subject: =?UTF-8?B?W1BBVENIIHY1IDEvNV0gbW0vcm1hcDogYWRkIHRyYWNlcG9pbnQgZm9yIHJtYXBfd2Fsaw==?= Content-Type: text/plain; charset="UTF-8" X-MAIL:mse-fl1.zte.com.cn 64JE97kl056524 X-TLS: YES X-ENVELOPE-SENDER: xu.xin16@zte.com.cn X-SOURCE-IP: 10.5.228.132 unknown Tue, 19 May 2026 22:09:16 +0800 X-CLEAN: YES X-Fangmail-Anti-Spam-Filtered: true X-Fangmail-MID-QID: 6A0C6F0C.000/4gKc3w6sNvz8Xrkn From: xu xin 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 --- 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 +#include + +#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 + 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 +#include #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