Linux-mm Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: "David Hildenbrand (Arm)" <david@kernel.org>
To: xu.xin16@zte.com.cn, akpm@linux-foundation.org, ljs@kernel.org
Cc: hughd@google.com, linux-mm@kvack.org,
	linux-kernel@vger.kernel.org, michel@lespinasse.org
Subject: Re: [PATCH v4 1/5] mm/rmap: add tracepoint for rmap_walk
Date: Wed, 13 May 2026 14:03:05 +0200	[thread overview]
Message-ID: <fcb056b2-9910-43eb-8009-430f88230b35@kernel.org> (raw)
In-Reply-To: <20260503203911259NKHEr5gDy3PbvnSc077a7@zte.com.cn>

On 5/3/26 14:39, xu.xin16@zte.com.cn wrote:
> From: xu xin <xu.xin16@zte.com.cn>
> 
> Add a new tracepoint rmap_walk in mm/rmap.c to monitor reverse mapping
> traversal. The tracepoint records the duration (in nanoseconds), the
> type of the folio (KSM, anonymous, or file-backed), and the addresses
> of the folio and rmap_walk_control structures. The type determination
> is performed inside the tracepoint to keep the function itself
> lightweight.
> 
> '# 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     [001] .....   692.237079: rmap_walk: folio=000000000029ddcb rwc=00000000dac4cda0 duration_ns=828682 page_type=ksm locked=false
> rmap-215     [001] .....   692.239480: rmap_walk: folio=0000000092a21fd3 rwc=00000000986376ff duration_ns=905966 page_type=ksm locked=false
> rmap-230     [003] .....   692.583619: rmap_walk: folio=0000000037a237b6 rwc=0000000080fbbb0a duration_ns=107892 page_type=ksm locked=false
> rmap-230     [003] .....   692.584104: rmap_walk: folio=0000000031bdbf8b rwc=00000000b39c973a duration_ns=330886 page_type=ksm locked=false
> rmap-244     [003] .....   692.708706: rmap_walk: folio=000000009105fa6b rwc=0000000037d46cd7 duration_ns=987826 page_type=file locked=false
> rmap-244     [003] .....   692.709198: rmap_walk: folio=000000009105fa6b rwc=0000000093942e2c duration_ns=161733 page_type=file locked=false
> rmap-244     [003] .....   692.709606: rmap_walk: folio=000000009105fa6b rwc=0000000037d46cd7 duration_ns=54428 page_type=file locked=false
> rmap-244     [003] .....   692.709658: rmap_walk: folio=000000009105fa6b rwc=0000000093942e2c duration_ns=27192 page_type=file locked=false
> 
> Signed-off-by: xu xin <xu.xin16@zte.com.cn>
> ---
>  include/trace/events/rmap.h | 49 +++++++++++++++++++++++++++++++++++++
>  mm/rmap.c                   | 14 +++++++++++
>  2 files changed, 63 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..987fa204d65d
> --- /dev/null
> +++ b/include/trace/events/rmap.h
> @@ -0,0 +1,49 @@
> +/* 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,
> +
> +	TP_PROTO(struct folio *folio, struct rmap_walk_control *rwc, u64 duration_ns, bool locked),
> +
> +	TP_ARGS(folio, rwc, duration_ns, locked),
> +
> +	TP_STRUCT__entry(
> +		__field(unsigned long, folio_addr)
> +		__field(unsigned long, rwc_addr)
> +		__field(u64, duration_ns)
> +		__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;
> +		__entry->duration_ns = duration_ns;
> +		__assign_str(page_type);
> +		__entry->locked = locked;
> +	),
> +
> +	TP_printk("folio=%p rwc=%p duration_ns=%llu page_type=%s locked=%s",
> +		(void *)(unsigned long)__entry->folio_addr,
> +		(void *)(unsigned long)__entry->rwc_addr,
> +		__entry->duration_ns,
> +		__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..14bf8483f38b 100644
> --- a/mm/rmap.c
> +++ b/mm/rmap.c
> @@ -75,11 +75,13 @@
>  #include <linux/userfaultfd_k.h>
>  #include <linux/mm_inline.h>
>  #include <linux/oom.h>
> +#include <linux/sched/clock.h>
> 
>  #include <asm/tlb.h>
> 
>  #define CREATE_TRACE_POINTS
>  #include <trace/events/migrate.h>
> +#include <trace/events/rmap.h>
> 
>  #include "internal.h"
>  #include "swap.h"
> @@ -3098,23 +3100,35 @@ static void rmap_walk_file(struct folio *folio,
> 
>  void rmap_walk(struct folio *folio, struct rmap_walk_control *rwc)
>  {
> +	u64 ts_start, delta_ns;
> +	ts_start = local_clock();
> +
>  	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);
> +
> +	delta_ns = local_clock() - ts_start;
> +	trace_rmap_walk(folio, rwc, delta_ns, false);
>  }
> 
>  /* Like rmap_walk, but caller holds relevant rmap lock */
>  void rmap_walk_locked(struct folio *folio, struct rmap_walk_control *rwc)
>  {
> +	u64 ts_start, delta_ns;
> +	ts_start = local_clock();
> +
>  	/* 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);
> +
> +	delta_ns = local_clock() - ts_start;
> +	trace_rmap_walk(folio, rwc, delta_ns, true);
>  }
> 
>  #ifdef CONFIG_HUGETLB_PAGE

Doing the clock stuff manually is nasty.

We could have a trace_rmap_walk_start() + trace_rmap_walk_stop().

But I wonder right now, whether we really need that information in the tree?

For local debugging (what you did) having this OOT patch is probably fine.

-- 
Cheers,

David


  reply	other threads:[~2026-05-13 12:03 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-05-03 12:35 [PATCH v4 0/5] KSM: Optimizations for rmap_walk_ksm xu.xin16
2026-05-03 12:39 ` [PATCH v4 1/5] mm/rmap: add tracepoint for rmap_walk xu.xin16
2026-05-13 12:03   ` David Hildenbrand (Arm) [this message]
2026-05-03 12:42 ` [PATCH v4 2/5] tools/testing: add rmap walk latency benchmark for KSM, anonymous and file pages xu.xin16
2026-05-03 12:48 ` [PATCH v4 3/5] ksm: add vm_pgoff into ksm_rmap_item xu.xin16
2026-05-13 11:59   ` David Hildenbrand (Arm)
2026-05-03 12:50 ` [PATCH v4 4/5] ksm: Optimize rmap_walk_ksm by passing a suitable address range xu.xin16
2026-05-13 12:10   ` David Hildenbrand (Arm)
2026-05-03 12:51 ` [PATCH v4 5/5] ksm: add mremap selftests for ksm_rmap_walk xu.xin16
2026-05-13 12:10   ` David Hildenbrand (Arm)
2026-05-03 14:59 ` [PATCH v4 0/5] KSM: Optimizations for rmap_walk_ksm Andrew Morton

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=fcb056b2-9910-43eb-8009-430f88230b35@kernel.org \
    --to=david@kernel.org \
    --cc=akpm@linux-foundation.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=xu.xin16@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