Skip to contentSkip to conversation

mm/damon: add trace events for auto-tuned monitoring intervals and DAMOS quota

PATCH In review SeongJae Park 2 participants 5 messages Jul 4, 2025 – Jul 9, 2025

Subsystems (3)
lore
Share & tools
lore

SeongJae Park

author maintainer
#0 lore raw

cover mm/damon: add trace events for auto-tuned monitoring intervals and DAMOS quota

The aim-oriented auto-tuning features for monitoring intervals and DAMOS quota are important and recommended. Add tracepoints for observabilities of those tuned values and the tuning itself.

SeongJae Park (2):
mm/damon: add trace event for auto-tuned monitoring intervals mm/damon: add trace event for effective size quota

 include/trace/events/damon.h | 43 ++++++++++++++++++++++++++++++++++++
 mm/damon/core.c              | 21 +++++++++++++++++-
 2 files changed, 63 insertions(+), 1 deletion(-)

base-commit: 09cf52aa7503a7126edc3af797e116a7ec49e572

Signature · 1 line
2.39.5
author maintainer
#1 lore raw

PATCH 1/2 mm/damon: add trace event for auto-tuned monitoring intervals

Aim-oriented monitoring intervals auto-tuning is an important and recommended feature for DAMON users. Add a trace event for the observability of the tuned intervals and tuning itself.

---
 include/trace/events/damon.h | 17 +++++++++++++++++
 mm/damon/core.c              |  1 +
 2 files changed, 18 insertions(+)
include/trace/events/damon.h +17 -0
index da4bd9fd1162..32c611076023 100644
@@ -48,6 +48,23 @@ TRACE_EVENT_CONDITION(damos_before_apply,
 			__entry->nr_accesses, __entry->age)
 );
 
+TRACE_EVENT(damon_monitor_intervals_tune,
+
+	TP_PROTO(unsigned long sample_us),
+
+	TP_ARGS(sample_us),
+
+	TP_STRUCT__entry(
+		__field(unsigned long, sample_us)
+	),
+
+	TP_fast_assign(
+		__entry->sample_us = sample_us;
+	),
+
+	TP_printk("sample_us=%lu", __entry->sample_us)
+);
+
 TRACE_EVENT(damon_aggregated,
 
 	TP_PROTO(unsigned int target_id, struct damon_region *r,
mm/damon/core.c +1 -0
index 979b29e16ef4..57a1ace4d10d 100644
@@ -1490,6 +1490,7 @@ static void kdamond_tune_intervals(struct damon_ctx *c)
 			new_attrs.sample_interval);
 	new_attrs.aggr_interval = new_attrs.sample_interval *
 		c->attrs.aggr_samples;
+	trace_damon_monitor_intervals_tune(new_attrs.sample_interval);
 	damon_set_attrs(c, &new_attrs);
 }
 
Signature · 1 line
2.39.5
author maintainer
#2 lore raw

PATCH 2/2 mm/damon: add trace event for effective size quota

In reply to SeongJae Park

Aim-oriented DAMOS quota auto-tuning is an important and recommended feature for DAMOS users. Add a trace event for the observability of the tuned quota and tuning itself.

---
 include/trace/events/damon.h | 26 ++++++++++++++++++++++++++
 mm/damon/core.c              | 20 +++++++++++++++++++-
 2 files changed, 45 insertions(+), 1 deletion(-)
include/trace/events/damon.h +26 -0
index 32c611076023..36b2cdf47dce 100644
@@ -9,6 +9,32 @@
 #include <linux/types.h>
 #include <linux/tracepoint.h>
 
+TRACE_EVENT_CONDITION(damos_esz,
+
+	TP_PROTO(unsigned int context_idx, unsigned int scheme_idx,
+		unsigned long esz, bool do_trace),
+
+	TP_ARGS(context_idx, scheme_idx, esz, do_trace),
+
+	TP_CONDITION(do_trace),
+
+	TP_STRUCT__entry(
+		__field(unsigned int, context_idx)
+		__field(unsigned int, scheme_idx)
+		__field(unsigned long, esz)
+	),
+
+	TP_fast_assign(
+		__entry->context_idx = context_idx;
+		__entry->scheme_idx = scheme_idx;
+		__entry->esz = esz;
+	),
+
+	TP_printk("ctx_idx=%u scheme_idx=%u esz=%lu",
+			__entry->context_idx, __entry->scheme_idx,
+			__entry->esz)
+);
+
 TRACE_EVENT_CONDITION(damos_before_apply,
 
 	TP_PROTO(unsigned int context_idx, unsigned int scheme_idx,
mm/damon/core.c +19 -1
index 57a1ace4d10d..6019b8ec4bba 100644
@@ -2011,12 +2011,26 @@ static void damos_set_effective_quota(struct damos_quota *quota)
 	quota->esz = esz;
 }
 
+static void damos_trace_esz(struct damon_ctx *c, struct damos *s,
+		struct damos_quota *quota)
+{
+	unsigned int cidx = 0, sidx;
+	struct damos *siter;
+
+	damon_for_each_scheme(siter, c) {
+		if (siter == s)
+			break;
+		sidx++;
+	}
+	trace_damos_esz(cidx, sidx, quota->esz, true);
+}
+
 static void damos_adjust_quota(struct damon_ctx *c, struct damos *s)
 {
 	struct damos_quota *quota = &s->quota;
 	struct damon_target *t;
 	struct damon_region *r;
-	unsigned long cumulated_sz;
+	unsigned long cumulated_sz, cached_esz;
 	unsigned int score, max_score = 0;
 
 	if (!quota->ms && !quota->sz && list_empty(&quota->goals))
@@ -2030,7 +2044,11 @@ static void damos_adjust_quota(struct damon_ctx *c, struct damos *s)
 		quota->total_charged_sz += quota->charged_sz;
 		quota->charged_from = jiffies;
 		quota->charged_sz = 0;
+		if (trace_damos_esz_enabled())
+			cached_esz = quota->esz;
 		damos_set_effective_quota(quota);
+		if (trace_damos_esz_enabled() && quota->esz != cached_esz)
+			damos_trace_esz(c, s, quota);
 	}
 
 	if (!c->ops.get_scheme_score)
Signature · 1 line
2.39.5
maintainer
#3 lore raw

Re: [PATCH 2/2] mm/damon: add trace event for effective size quota

Quoted 16 lines · On Fri, 4 Jul 2025 15:14:08 -0700 SeongJae Park <[email protected]> wrote:

Aim-oriented DAMOS quota auto-tuning is an important and recommended feature for DAMOS users. Add a trace event for the observability of the tuned quota and tuning itself.

---
 include/trace/events/damon.h | 26 ++++++++++++++++++++++++++
 mm/damon/core.c              | 20 +++++++++++++++++++-
 2 files changed, 45 insertions(+), 1 deletion(-)
include/trace/events/damon.h +0 -0
index 32c611076023..36b2cdf47dce 100644
@@ -9,6 +9,32 @@
 #include <linux/types.h>

include/trace/events/damon.h line 19

Quoted 10 lines
include/trace/events/damon.h +8 -0
 #include <linux/tracepoint.h>
 
+TRACE_EVENT_CONDITION(damos_esz,
+
+	TP_PROTO(unsigned int context_idx, unsigned int scheme_idx,
+		unsigned long esz, bool do_trace),
+
+	TP_ARGS(context_idx, scheme_idx, esz, do_trace),
+
+	TP_CONDITION(do_trace),

Please explain to me why you are using a conditional here?

Quoted 31 lines
include/trace/events/damon.h +18 -0
+
+	TP_STRUCT__entry(
+		__field(unsigned int, context_idx)
+		__field(unsigned int, scheme_idx)
+		__field(unsigned long, esz)
+	),
+
+	TP_fast_assign(
+		__entry->context_idx = context_idx;
+		__entry->scheme_idx = scheme_idx;
+		__entry->esz = esz;
+	),
+
+	TP_printk("ctx_idx=%u scheme_idx=%u esz=%lu",
+			__entry->context_idx, __entry->scheme_idx,
+			__entry->esz)
+);
+
 TRACE_EVENT_CONDITION(damos_before_apply,
 
 	TP_PROTO(unsigned int context_idx, unsigned int scheme_idx,
mm/damon/core.c +2 -0
index 57a1ace4d10d..6019b8ec4bba 100644
@@ -2011,12 +2011,26 @@ static void damos_set_effective_quota(struct damos_quota *quota)
 	quota->esz = esz;
 }
 
+static void damos_trace_esz(struct damon_ctx *c, struct damos *s,
+		struct damos_quota *quota)

mm/damon/core.c static void damos_set_effective_quota(struct damos_quota *quota) · line 2025

Quoted 10 lines
mm/damon/core.c +10 -0
+{
+	unsigned int cidx = 0, sidx;
+	struct damos *siter;
+
+	damon_for_each_scheme(siter, c) {
+		if (siter == s)
+			break;
+		sidx++;
+	}
+	trace_damos_esz(cidx, sidx, quota->esz, true);

It's set to true, so it's not even a conditional anymore. The compiler will likely optimize it out!

-- Steve

Quoted 24 lines
mm/damon/core.c +7 -1
+}
+
 static void damos_adjust_quota(struct damon_ctx *c, struct damos *s)
 {
 	struct damos_quota *quota = &s->quota;
 	struct damon_target *t;
 	struct damon_region *r;
-	unsigned long cumulated_sz;
+	unsigned long cumulated_sz, cached_esz;
 	unsigned int score, max_score = 0;
 
 	if (!quota->ms && !quota->sz && list_empty(&quota->goals))
@@ -2030,7 +2044,11 @@ static void damos_adjust_quota(struct damon_ctx *c, struct damos *s)
 		quota->total_charged_sz += quota->charged_sz;
 		quota->charged_from = jiffies;
 		quota->charged_sz = 0;
+		if (trace_damos_esz_enabled())
+			cached_esz = quota->esz;
 		damos_set_effective_quota(quota);
+		if (trace_damos_esz_enabled() && quota->esz != cached_esz)
+			damos_trace_esz(c, s, quota);
 	}
 
 	if (!c->ops.get_scheme_score)
author maintainer
#4 lore raw

Re: [PATCH 2/2] mm/damon: add trace event for effective size quota

Hi Steven,

Quoted 21 lines · On Wed, 9 Jul 2025 12:21:23 -0400 Steven Rostedt <[email protected]> wrote:
Quoted 18 lines · On Fri, 4 Jul 2025 15:14:08 -0700 SeongJae Park <[email protected]> wrote:

Aim-oriented DAMOS quota auto-tuning is an important and recommended feature for DAMOS users. Add a trace event for the observability of the tuned quota and tuning itself.

---
 include/trace/events/damon.h | 26 ++++++++++++++++++++++++++
 mm/damon/core.c              | 20 +++++++++++++++++++-
 2 files changed, 45 insertions(+), 1 deletion(-)
include/trace/events/damon.h +0 -0
index 32c611076023..36b2cdf47dce 100644
@@ -9,6 +9,32 @@
 #include <linux/types.h>
 #include <linux/tracepoint.h>
 
Quoted 10 lines

include/trace/events/damon.h line 19

Quoted 8 lines
include/trace/events/damon.h +8 -0
+TRACE_EVENT_CONDITION(damos_esz,
+
+	TP_PROTO(unsigned int context_idx, unsigned int scheme_idx,
+		unsigned long esz, bool do_trace),
+
+	TP_ARGS(context_idx, scheme_idx, esz, do_trace),
+
+	TP_CONDITION(do_trace),

Please explain to me why you are using a conditional here?

There is no reason to make this conditional. Maybe I was out of my mind.

[...]

Quoted 6 lines
Quoted 6 lines
mm/damon/core.c +0 -0
@@ -2011,12 +2011,26 @@ static void damos_set_effective_quota(struct damos_quota *quota)
 	quota->esz = esz;
 }
 
Quoted 15 lines

mm/damon/core.c static void damos_set_effective_quota(struct damos_quota *quota) · line 2025

Quoted 12 lines
mm/damon/core.c +12 -0
+static void damos_trace_esz(struct damon_ctx *c, struct damos *s,
+		struct damos_quota *quota)
+{
+	unsigned int cidx = 0, sidx;
+	struct damos *siter;
+
+	damon_for_each_scheme(siter, c) {
+		if (siter == s)
+			break;
+		sidx++;
+	}
+	trace_damos_esz(cidx, sidx, quota->esz, true);

It's set to true, so it's not even a conditional anymore. The compiler will likely optimize it out!

You're right.

Andrew, could you please add below fixup patch?

Thanks,
SJ

=================== >8 ======================
From 13975534cad603410837c5eca299f0a24ad802a1 Mon Sep 17 00:00:00 2001
From: SeongJae Park <[email protected]>
Date: Wed, 9 Jul 2025 11:22:39 -0700
Subject: [PATCH] mm/damon: make damos_esz unconditional trace event

It has no reason to be conditional. Make it unconditional trace event.

Fixes 9a365a71b830 ("mm/damon: add trace event for effective size quota") # mm-unstable
---
 include/trace/events/damon.h | 8 +++-----
 mm/damon/core.c              | 2 +-
 2 files changed, 4 insertions(+), 6 deletions(-)
include/trace/events/damon.h +3 -5
index 2e4d7d281fa7..fc2c61ccc887 100644
@@ -9,14 +9,12 @@
 #include <linux/types.h>
 #include <linux/tracepoint.h>
 
-TRACE_EVENT_CONDITION(damos_esz,
+TRACE_EVENT(damos_esz,
 
 	TP_PROTO(unsigned int context_idx, unsigned int scheme_idx,
-		unsigned long esz, bool do_trace),
+		unsigned long esz),
 
-	TP_ARGS(context_idx, scheme_idx, esz, do_trace),
-
-	TP_CONDITION(do_trace),
+	TP_ARGS(context_idx, scheme_idx, esz),
 
 	TP_STRUCT__entry(
 		__field(unsigned int, context_idx)
mm/damon/core.c +1 -1
index 0f7d8b37c91d..775e097b6538 100644
@@ -2223,7 +2223,7 @@ static void damos_trace_esz(struct damon_ctx *c, struct damos *s,
 			break;
 		sidx++;
 	}
-	trace_damos_esz(cidx, sidx, quota->esz, true);
+	trace_damos_esz(cidx, sidx, quota->esz);
 }
 
 static void damos_adjust_quota(struct damon_ctx *c, struct damos *s)
Signature · 1 line
2.39.5