linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
* [PATCH mm-unstable] samples/damon/mtier: fix wrong DAMON attrs setting
@ 2025-05-10 22:09 SeongJae Park
  0 siblings, 0 replies; only message in thread
From: SeongJae Park @ 2025-05-10 22:09 UTC (permalink / raw)
  To: Andrew Morton; +Cc: SeongJae Park, damon, kernel-team, linux-kernel, linux-mm

When intervals auto-tuning is enabled, DAMON monitoring attributes
should be set with damon_set_attrs().  Because damon_set_attrs() is the
only place that sets attrs->aggr_samples, not calling damon_set_attrs()
can result in divide-by-zero from damon_get_intervals_score().

mtier, which is a DAMON's sample module that merged in mm-unstable as of
this writing, is not calling the function while enabling the
auto-tuning.  Fix the problem by properly calling damon_set_attrs().

Fixes: 3a1fff3fe05b ("samples/damon: implement a DAMON module for memory tiering") # mm-unstable
Signed-off-by: SeongJae Park <sj@kernel.org>
---
 samples/damon/mtier.c | 13 ++++++++++++-
 1 file changed, 12 insertions(+), 1 deletion(-)

diff --git a/samples/damon/mtier.c b/samples/damon/mtier.c
index 3390b7d30c26..36d2cd933f5a 100644
--- a/samples/damon/mtier.c
+++ b/samples/damon/mtier.c
@@ -41,6 +41,7 @@ static struct damon_ctx *ctxs[2];
 static struct damon_ctx *damon_sample_mtier_build_ctx(bool promote)
 {
 	struct damon_ctx *ctx;
+	struct damon_attrs attrs;
 	struct damon_target *target;
 	struct damon_region *region;
 	struct damos *scheme;
@@ -50,14 +51,24 @@ static struct damon_ctx *damon_sample_mtier_build_ctx(bool promote)
 	ctx = damon_new_ctx();
 	if (!ctx)
 		return NULL;
+	attrs = (struct damon_attrs) {
+		.sample_interval = 5 * USEC_PER_MSEC,
+		.aggr_interval = 100 * USEC_PER_MSEC,
+		.ops_update_interval = 60 * USEC_PER_MSEC * MSEC_PER_SEC,
+		.min_nr_regions = 10,
+		.max_nr_regions = 1000,
+	};
+
 	/*
 	 * auto-tune sampling and aggregation interval aiming 4% DAMON-observed
 	 * accesses ratio, keeping sampling interval in [5ms, 10s] range.
 	 */
-	ctx->attrs.intervals_goal = (struct damon_intervals_goal) {
+	attrs.intervals_goal = (struct damon_intervals_goal) {
 		.access_bp = 400, .aggrs = 3,
 		.min_sample_us = 5000, .max_sample_us = 10000000,
 	};
+	if (damon_set_attrs(ctx, &attrs))
+		goto free_out;
 	if (damon_select_ops(ctx, DAMON_OPS_PADDR))
 		goto free_out;
 

base-commit: 882bfccd259e3961b81219834715a70a23f9ea71
-- 
2.39.5


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2025-05-10 22:09 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2025-05-10 22:09 [PATCH mm-unstable] samples/damon/mtier: fix wrong DAMON attrs setting SeongJae Park

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox