[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20250213014438.145611-2-sj@kernel.org>
Date: Wed, 12 Feb 2025 17:44:31 -0800
From: SeongJae Park <sj@...nel.org>
To:
Cc: SeongJae Park <sj@...nel.org>,
Andrew Morton <akpm@...ux-foundation.org>,
damon@...ts.linux.dev,
kernel-team@...a.com,
linux-kernel@...r.kernel.org,
linux-mm@...ck.org
Subject: [RFC PATCH 1/8] mm/damon: add data structure for monitoring intervals auto-tuning
Add data structures for using DAMON sampling and aggregation intervals
automatic tuning aiming specific amount of access events per snapshot.
Specificaslly, define a data structure to define the tuning goal, namely
target ratio of positive access check samples, link it to monitoring
attributes data structure so that DAMON kernel API users can make the
request, and update parameters setup DAMON function to respect the new
data.
Signed-off-by: SeongJae Park <sj@...nel.org>
---
include/linux/damon.h | 27 +++++++++++++++++++++++++++
mm/damon/core.c | 22 ++++++++++++++++++++++
2 files changed, 49 insertions(+)
diff --git a/include/linux/damon.h b/include/linux/damon.h
index 0adfc2f4ca75..4368ba1a942f 100644
--- a/include/linux/damon.h
+++ b/include/linux/damon.h
@@ -651,12 +651,38 @@ struct damon_call_control {
bool canceled;
};
+/**
+ * struct damon_intervals_goal - Monitoring intervals auto-tuning goal.
+ *
+ * @samples_bp: Positive access check samples ratio to achieve.
+ * @aggrs: Number of aggregations to acheive @samples_bp within.
+ * @min_sample_us: Minimum resulting sampling interval in microseconds.
+ * @max_sample_us: Maximum resulting sampling interval in microseconds.
+ *
+ * DAMON automatically tunes &damon_attrs->sample_interval and
+ * &damon_attrs->aggr_interval aiming the ratio in bp (1/10,000) of access
+ * check samples that shown positive result (was accessed) to total samples
+ * within @aggrs aggregations be same to @samples_bp. The logic increases
+ * &damon_attrs->aggr_interval and &damon_attrs->sampling_interval in same
+ * ratio if the current positive access samples ratio is lower than the target
+ * for each @aggrs aggregations, and vice versa.
+ *
+ * If @aggrs is zero, the tuning is disabled and hence this struct is ignored.
+ */
+struct damon_intervals_goal {
+ unsigned long samples_bp;
+ unsigned long aggrs;
+ unsigned long min_sample_us;
+ unsigned long max_sample_us;
+};
+
/**
* struct damon_attrs - Monitoring attributes for accuracy/overhead control.
*
* @sample_interval: The time between access samplings.
* @aggr_interval: The time between monitor results aggregations.
* @ops_update_interval: The time between monitoring operations updates.
+ * @intervals_goal: Intervals auto-tuning goal.
* @min_nr_regions: The minimum number of adaptive monitoring
* regions.
* @max_nr_regions: The maximum number of adaptive monitoring
@@ -676,6 +702,7 @@ struct damon_attrs {
unsigned long sample_interval;
unsigned long aggr_interval;
unsigned long ops_update_interval;
+ struct damon_intervals_goal intervals_goal;
unsigned long min_nr_regions;
unsigned long max_nr_regions;
};
diff --git a/mm/damon/core.c b/mm/damon/core.c
index 38f545fea585..2fad800271a4 100644
--- a/mm/damon/core.c
+++ b/mm/damon/core.c
@@ -614,6 +614,25 @@ static void damon_update_monitoring_results(struct damon_ctx *ctx,
r, old_attrs, new_attrs);
}
+/*
+ * damon_valid_intervals_goal() - return if the intervals goal of @attrs is
+ * valid.
+ */
+static bool damon_valid_intervals_goal(struct damon_attrs *attrs)
+{
+ struct damon_intervals_goal *goal = &attrs->intervals_goal;
+
+ /* tuning is disabled */
+ if (!goal->aggrs)
+ return true;
+ if (goal->min_sample_us > goal->max_sample_us)
+ return false;
+ if (attrs->sample_interval < goal->min_sample_us ||
+ goal->max_sample_us < attrs->sample_interval)
+ return false;
+ return true;
+}
+
/**
* damon_set_attrs() - Set attributes for the monitoring.
* @ctx: monitoring context
@@ -634,6 +653,9 @@ int damon_set_attrs(struct damon_ctx *ctx, struct damon_attrs *attrs)
attrs->sample_interval : 1;
struct damos *s;
+ if (!damon_valid_intervals_goal(attrs))
+ return -EINVAL;
+
if (attrs->min_nr_regions < 3)
return -EINVAL;
if (attrs->min_nr_regions > attrs->max_nr_regions)
--
2.39.5
Powered by blists - more mailing lists