diff mbox series

[v3,3/4] mm/ksm: add tracepoint for ksm advisor

Message ID 20231204234906.1237478-4-shr@devkernel.io (mailing list archive)
State New
Headers show
Series mm/ksm: Add ksm advisor | expand

Commit Message

Stefan Roesch Dec. 4, 2023, 11:49 p.m. UTC
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(+)

Comments

David Hildenbrand Dec. 12, 2023, 1:45 p.m. UTC | #1
On 05.12.23 00:49, Stefan Roesch wrote:
> 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 b5ac35c1d0e88..e728647b5d268 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 18b7185bbc65b..b8065c5d5f833 100644
> --- a/mm/ksm.c
> +++ b/mm/ksm.c
> @@ -455,6 +455,7 @@ static void scan_time_advisor(void)
>   	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)

Acked-by: David Hildenbrand <david@redhat.com>
diff mbox series

Patch

diff --git a/include/trace/events/ksm.h b/include/trace/events/ksm.h
index b5ac35c1d0e88..e728647b5d268 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 18b7185bbc65b..b8065c5d5f833 100644
--- a/mm/ksm.c
+++ b/mm/ksm.c
@@ -455,6 +455,7 @@  static void scan_time_advisor(void)
 	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)