mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] mm/damon: add damos_node_eligible_mem_bp tracepoint
@ 2026-10-03 20:27 Ravi Jonnalagadda
  2026-10-04  8:01 ` SJ Park
  2026-10-04  9:16 ` Steven Rostedt
  0 siblings, 2 replies; 3+ messages in thread
From: Ravi Jonnalagadda @ 2026-10-03 20:27 UTC (permalink / raw)
  To: Andrew Morton, SJ Park
  Cc: Ravi Jonnalagadda, damon, linux-mm, linux-kernel,
	linux-trace-kernel, Steven Rostedt, Masami Hiramatsu,
	Jonathan Corbet, Bijan Tabatabai, Ajay Joshi, Honggyu Kim,
	Yunjeong Mun, Akinobu Mita, Lian Wang, Kunwu Chan

Add a tracepoint for DAMOS_QUOTA_NODE_ELIGIBLE_MEM_BP quota goal
evaluation.  The tracepoint fires once per quota-score computation when
the goal metric is DAMOS_QUOTA_NODE_ELIGIBLE_MEM_BP, exposing
context_idx, scheme_idx, nid, target_value, and current_value.
current_value is reported as the quota tuning sees it, after the goal's
complement setting is applied.

The DAMOS_QUOTA_NODE_ELIGIBLE_MEM_BP metric expresses node memory
occupancy as basis points of eligible bytes.  This information is not
exposed through any existing external interface (perf stat, /proc, or
sysfs), so the tracepoint is the only way for userspace to observe the
target and current eligible-memory basis point values at quota-scoring
time.

Link: https://lore.kernel.org/linux-mm/20260428030520.701-1-ravis.opensrc@gmail.com/
Signed-off-by: Ravi Jonnalagadda <ravis.opensrc@gmail.com>
---
 include/trace/events/damon.h | 31 +++++++++++++++++++++++++++++++
 mm/damon/core.c              | 16 ++++++++++++++++
 2 files changed, 47 insertions(+)

diff --git a/include/trace/events/damon.h b/include/trace/events/damon.h
index 8851727ae162..2c7249cc7c88 100644
--- a/include/trace/events/damon.h
+++ b/include/trace/events/damon.h
@@ -74,6 +74,37 @@ TRACE_EVENT(damos_esz,
 			__entry->esz)
 );
 
+/* Per-tick DAMOS_QUOTA_NODE_ELIGIBLE_MEM_BP goal evaluation. */
+TRACE_EVENT(damos_node_eligible_mem_bp,
+
+	TP_PROTO(unsigned int context_idx, unsigned int scheme_idx,
+		int nid,
+		unsigned long target_value, unsigned long current_value),
+
+	TP_ARGS(context_idx, scheme_idx, nid, target_value, current_value),
+
+	TP_STRUCT__entry(
+		__field(unsigned int, context_idx)
+		__field(unsigned int, scheme_idx)
+		__field(int, nid)
+		__field(unsigned long, target_value)
+		__field(unsigned long, current_value)
+	),
+
+	TP_fast_assign(
+		__entry->context_idx = context_idx;
+		__entry->scheme_idx = scheme_idx;
+		__entry->nid = nid;
+		__entry->target_value = target_value;
+		__entry->current_value = current_value;
+	),
+
+	TP_printk("ctx_idx=%u scheme_idx=%u nid=%d target_value=%lu current_value=%lu",
+			__entry->context_idx, __entry->scheme_idx,
+			__entry->nid,
+			__entry->target_value, __entry->current_value)
+);
+
 TRACE_EVENT_CONDITION(damos_before_apply,
 
 	TP_PROTO(unsigned int context_idx, unsigned int scheme_idx,
diff --git a/mm/damon/core.c b/mm/damon/core.c
index b63e60ef8990..6ddd15dc4f55 100644
--- a/mm/damon/core.c
+++ b/mm/damon/core.c
@@ -3294,6 +3294,22 @@ static unsigned long damos_quota_score(struct damon_ctx *c, struct damos *s)
 		highest_score = max(highest_score,
 				mult_frac(goal->current_value, 10000,
 					goal->target_value));
+
+		if (goal->metric == DAMOS_QUOTA_NODE_ELIGIBLE_MEM_BP &&
+		    trace_damos_node_eligible_mem_bp_enabled()) {
+			unsigned int cidx = 0, sidx = 0;
+			struct damos *siter;
+
+			damon_for_each_scheme(siter, c) {
+				if (siter == s)
+					break;
+				sidx++;
+			}
+			trace_damos_node_eligible_mem_bp(cidx, sidx,
+					goal->nid,
+					goal->target_value,
+					goal->current_value);
+		}
 	}
 
 	return highest_score;

base-commit: 763ad0211c7b587344f03bc4d1299810aeb736f4
-- 
2.54.0 (Apple Git-157)


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] mm/damon: add damos_node_eligible_mem_bp tracepoint
  2026-10-03 20:27 [PATCH] mm/damon: add damos_node_eligible_mem_bp tracepoint Ravi Jonnalagadda
@ 2026-10-04  8:01 ` SJ Park
  2026-10-04  9:16 ` Steven Rostedt
  1 sibling, 0 replies; 3+ messages in thread
From: SJ Park @ 2026-10-04  8:01 UTC (permalink / raw)
  To: Ravi Jonnalagadda
  Cc: SJ Park, Andrew Morton, damon, linux-mm, linux-kernel,
	linux-trace-kernel, Steven Rostedt, Masami Hiramatsu,
	Jonathan Corbet, Bijan Tabatabai, Ajay Joshi, Honggyu Kim,
	Yunjeong Mun, Akinobu Mita, Lian Wang, Kunwu Chan

Hi Ravi,

On Sat,  3 Oct 2026 13:27:27 -0700 Ravi Jonnalagadda <ravis.opensrc@gmail.com> wrote:

> Add a tracepoint for DAMOS_QUOTA_NODE_ELIGIBLE_MEM_BP quota goal
> evaluation.  The tracepoint fires once per quota-score computation when
> the goal metric is DAMOS_QUOTA_NODE_ELIGIBLE_MEM_BP, exposing
> context_idx, scheme_idx, nid, target_value, and current_value.
> current_value is reported as the quota tuning sees it, after the goal's
> complement setting is applied.
> 
> The DAMOS_QUOTA_NODE_ELIGIBLE_MEM_BP metric expresses node memory
> occupancy as basis points of eligible bytes.  This information is not
> exposed through any existing external interface (perf stat, /proc, or
> sysfs), so the tracepoint is the only way for userspace to observe the
> target and current eligible-memory basis point values at quota-scoring
> time.

Thank you for this patch!

We have damos_esz tracepoint.  Have you considered using it?  It doesn't expose
the current value, though.  I thought it wouldn't be real problem in most
cases, but I can show it could be problematic for node_eligible_mem_bp case, as
the metric value is not straightforward to see without using DAMON.

If you really need to know the current_value, I'm open to add a new tracepoint.
But I think it has no reason to make it only eligible_mem_bp specific.  How
about adding more general purpose tracepoint, and/or update the current_value
file [1] under the goal sysfs directory to show the current current_value for
all goal types?

[1] https://origin.kernel.org/doc/html/latest/admin-guide/mm/damon/usage.html#sysfs-schemes-quota-goals


Thanks,
SJ

[...]

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] mm/damon: add damos_node_eligible_mem_bp tracepoint
  2026-10-03 20:27 [PATCH] mm/damon: add damos_node_eligible_mem_bp tracepoint Ravi Jonnalagadda
  2026-10-04  8:01 ` SJ Park
@ 2026-10-04  9:16 ` Steven Rostedt
  1 sibling, 0 replies; 3+ messages in thread
From: Steven Rostedt @ 2026-10-04  9:16 UTC (permalink / raw)
  To: Ravi Jonnalagadda
  Cc: Andrew Morton, SJ Park, damon, linux-mm, linux-kernel,
	linux-trace-kernel, Masami Hiramatsu, Jonathan Corbet,
	Bijan Tabatabai, Ajay Joshi, Honggyu Kim, Yunjeong Mun,
	Akinobu Mita, Lian Wang, Kunwu Chan

On Sat,  3 Oct 2026 13:27:27 -0700
Ravi Jonnalagadda <ravis.opensrc@gmail.com> wrote:

> Add a tracepoint for DAMOS_QUOTA_NODE_ELIGIBLE_MEM_BP quota goal
> evaluation.  The tracepoint fires once per quota-score computation when
> the goal metric is DAMOS_QUOTA_NODE_ELIGIBLE_MEM_BP, exposing
> context_idx, scheme_idx, nid, target_value, and current_value.
> current_value is reported as the quota tuning sees it, after the goal's
> complement setting is applied.
> 
> The DAMOS_QUOTA_NODE_ELIGIBLE_MEM_BP metric expresses node memory
> occupancy as basis points of eligible bytes.  This information is not
> exposed through any existing external interface (perf stat, /proc, or
> sysfs), so the tracepoint is the only way for userspace to observe the
> target and current eligible-memory basis point values at quota-scoring
> time.
> 
> Link: https://lore.kernel.org/linux-mm/20260428030520.701-1-ravis.opensrc@gmail.com/
> Signed-off-by: Ravi Jonnalagadda <ravis.opensrc@gmail.com>
> ---
>  include/trace/events/damon.h | 31 +++++++++++++++++++++++++++++++
>  mm/damon/core.c              | 16 ++++++++++++++++
>  2 files changed, 47 insertions(+)
> 
> diff --git a/include/trace/events/damon.h b/include/trace/events/damon.h
> index 8851727ae162..2c7249cc7c88 100644
> --- a/include/trace/events/damon.h
> +++ b/include/trace/events/damon.h
> @@ -74,6 +74,37 @@ TRACE_EVENT(damos_esz,
>  			__entry->esz)
>  );
>  
> +/* Per-tick DAMOS_QUOTA_NODE_ELIGIBLE_MEM_BP goal evaluation. */
> +TRACE_EVENT(damos_node_eligible_mem_bp,
> +
> +	TP_PROTO(unsigned int context_idx, unsigned int scheme_idx,
> +		int nid,
> +		unsigned long target_value, unsigned long current_value),
> +
> +	TP_ARGS(context_idx, scheme_idx, nid, target_value, current_value),
> +
> +	TP_STRUCT__entry(
> +		__field(unsigned int, context_idx)
> +		__field(unsigned int, scheme_idx)
> +		__field(int, nid)

Can you move the nid after the two unsigned long values below. This
creates a structure, and on 64bit machines, this adds a 4 byte padding
in the middle of the ring buffer.

> +		__field(unsigned long, target_value)
> +		__field(unsigned long, current_value)
> +	),
> +
> +	TP_fast_assign(
> +		__entry->context_idx = context_idx;
> +		__entry->scheme_idx = scheme_idx;
> +		__entry->nid = nid;
> +		__entry->target_value = target_value;
> +		__entry->current_value = current_value;
> +	),
> +
> +	TP_printk("ctx_idx=%u scheme_idx=%u nid=%d target_value=%lu current_value=%lu",
> +			__entry->context_idx, __entry->scheme_idx,
> +			__entry->nid,
> +			__entry->target_value, __entry->current_value)
> +);
> +
>  TRACE_EVENT_CONDITION(damos_before_apply,
>  
>  	TP_PROTO(unsigned int context_idx, unsigned int scheme_idx,
> diff --git a/mm/damon/core.c b/mm/damon/core.c
> index b63e60ef8990..6ddd15dc4f55 100644
> --- a/mm/damon/core.c
> +++ b/mm/damon/core.c
> @@ -3294,6 +3294,22 @@ static unsigned long damos_quota_score(struct damon_ctx *c, struct damos *s)
>  		highest_score = max(highest_score,
>  				mult_frac(goal->current_value, 10000,
>  					goal->target_value));
> +
> +		if (goal->metric == DAMOS_QUOTA_NODE_ELIGIBLE_MEM_BP &&
> +		    trace_damos_node_eligible_mem_bp_enabled()) {

If you move the trace_damos_node_eligible_mem_bp_enabled() before the
goal->metric check, you will save yourself a branch when tracing is
off. As the trace_*_enabled() is a static branch (nop or jmp) it has no
cmp branch, but the above will keep the goal->metric still exposed. By
swapping the two compares, the goal->metric check will be hidder behind
the 'nop' when tracing is disabled.

-- Steve


> +			unsigned int cidx = 0, sidx = 0;
> +			struct damos *siter;
> +
> +			damon_for_each_scheme(siter, c) {
> +				if (siter == s)
> +					break;
> +				sidx++;
> +			}
> +			trace_damos_node_eligible_mem_bp(cidx, sidx,
> +					goal->nid,
> +					goal->target_value,
> +					goal->current_value);
> +		}
>  	}
>  
>  	return highest_score;
> 
> base-commit: 763ad0211c7b587344f03bc4d1299810aeb736f4


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2026-10-04  9:24 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-10-03 20:27 [PATCH] mm/damon: add damos_node_eligible_mem_bp tracepoint Ravi Jonnalagadda
2026-10-04  8:01 ` SJ Park
2026-10-04  9:16 ` Steven Rostedt

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®