linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: Stefan Roesch <shr@devkernel.io>
To: kernel-team@fb.com
Cc: shr@devkernel.io, akpm@linux-foundation.org, david@redhat.com,
	hannes@cmpxchg.org, riel@surriel.com,
	linux-kernel@vger.kernel.org, linux-mm@kvack.org
Subject: [PATCH v2 3/4] mm/ksm: add tracepoint for ksm advisor
Date: Fri, 27 Oct 2023 17:09:44 -0700	[thread overview]
Message-ID: <20231028000945.2428830-4-shr@devkernel.io> (raw)
In-Reply-To: <20231028000945.2428830-1-shr@devkernel.io>

This adds a new tracepoint for the ksm advisor. It reports the last scan
time, the new setting of the pages_to_scan parameter and the average cpu
percent usage of the ksmd background thread for the last scan.

Signed-off-by: Stefan Roesch <shr@devkernel.io>
---
 include/trace/events/ksm.h | 33 +++++++++++++++++++++++++++++++++
 mm/ksm.c                   |  1 +
 2 files changed, 34 insertions(+)

diff --git a/include/trace/events/ksm.h b/include/trace/events/ksm.h
index b5ac35c1d0e8..e728647b5d26 100644
--- a/include/trace/events/ksm.h
+++ b/include/trace/events/ksm.h
@@ -245,6 +245,39 @@ TRACE_EVENT(ksm_remove_rmap_item,
 			__entry->pfn, __entry->rmap_item, __entry->mm)
 );
 
+/**
+ * ksm_advisor - called after the advisor has run
+ *
+ * @scan_time:		scan time in seconds
+ * @pages_to_scan:	new pages_to_scan value
+ * @cpu_percent:	cpu usage in percent
+ *
+ * Allows to trace the ksm advisor.
+ */
+TRACE_EVENT(ksm_advisor,
+
+	TP_PROTO(s64 scan_time, unsigned long pages_to_scan,
+		 unsigned int cpu_percent),
+
+	TP_ARGS(scan_time, pages_to_scan, cpu_percent),
+
+	TP_STRUCT__entry(
+		__field(s64,		scan_time)
+		__field(unsigned long,	pages_to_scan)
+		__field(unsigned int,	cpu_percent)
+	),
+
+	TP_fast_assign(
+		__entry->scan_time	= scan_time;
+		__entry->pages_to_scan	= pages_to_scan;
+		__entry->cpu_percent	= cpu_percent;
+	),
+
+	TP_printk("ksm scan time %lld pages_to_scan %lu cpu percent %u",
+			__entry->scan_time, __entry->pages_to_scan,
+			__entry->cpu_percent)
+);
+
 #endif /* _TRACE_KSM_H */
 
 /* This part must be outside protection */
diff --git a/mm/ksm.c b/mm/ksm.c
index 042ecaeb0beb..b2a519083d66 100644
--- a/mm/ksm.c
+++ b/mm/ksm.c
@@ -442,6 +442,7 @@ static void scan_time_advisor(unsigned long scan_time)
 	advisor_ctx.cpu_time = cpu_time;
 
 	ksm_thread_pages_to_scan = pages;
+	trace_ksm_advisor(scan_time, pages, cpu_percent);
 }
 
 static void run_advisor(void)
-- 
2.39.3



  parent reply	other threads:[~2023-10-28  0:13 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-10-28  0:09 [PATCH v2 0/4] mm/ksm: Add ksm advisor Stefan Roesch
2023-10-28  0:09 ` [PATCH v2 1/4] mm/ksm: add " Stefan Roesch
2023-10-28  7:33   ` kernel test robot
2023-11-20 10:51   ` David Hildenbrand
2023-11-22 17:20     ` Stefan Roesch
2023-11-24 15:37       ` David Hildenbrand
2023-11-24 15:39   ` David Hildenbrand
2023-10-28  0:09 ` [PATCH v2 2/4] mm/ksm: add sysfs knobs for advisor Stefan Roesch
2023-11-20 10:32   ` David Hildenbrand
2023-11-22 17:42     ` Stefan Roesch
2023-11-22 17:43     ` Stefan Roesch
2023-11-20 10:53   ` David Hildenbrand
2023-11-22 17:41     ` Stefan Roesch
2023-10-28  0:09 ` Stefan Roesch [this message]
2023-10-28  0:09 ` [PATCH v2 4/4] mm/ksm: document ksm advisor and its sysfs knobs Stefan Roesch

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=20231028000945.2428830-4-shr@devkernel.io \
    --to=shr@devkernel.io \
    --cc=akpm@linux-foundation.org \
    --cc=david@redhat.com \
    --cc=hannes@cmpxchg.org \
    --cc=kernel-team@fb.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=riel@surriel.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;
as well as URLs for NNTP newsgroup(s).