Skip to contentSkip to conversation

mm/damon/reclaim: support monitoring intervals auto-tuning

RFC PATCH In review SeongJae Park 1 participant 4 messages Apr 14

Subsystems (4)
lore
Share & tools
lore

SeongJae Park

author maintainer
#0 lore raw

cover mm/damon/reclaim: support monitoring intervals auto-tuning

The monitoring intervals auto-tuning feature of DAMON has proven to be useful in multiple environments. Add a new DAMON_RECLAIM parameter for supporting the feature, and update the document for the new parameter.

SeongJae Park (2):
mm/damon/reclaim: add autotune_monitoring_intervals parameter Docs/admin-guide/mm/damon/reclaim: update for
autotune_monitoring_intervals

 .../admin-guide/mm/damon/reclaim.rst          | 11 +++++++
 mm/damon/reclaim.c                            | 33 ++++++++++++++++---
 2 files changed, 39 insertions(+), 5 deletions(-)

base-commit: 02f9b1619307bbcf7028704a50f6b31909f360ce

Signature · 1 line
2.47.3
author maintainer
#1 lore raw

RFC PATCH 1/2 mm/damon/reclaim: add autotune_monitoring_intervals parameter

DAMON's monitoring intervals auto-tuning feature has proven to be useful in multiple environments. DAMON_RECLAIM is still asking users to do the manual tuning of the intervals. Add a module parameter for utilizing the auto-tuning feature with the suggested default setup.

---
 mm/damon/reclaim.c | 33 ++++++++++++++++++++++++++++-----
 1 file changed, 28 insertions(+), 5 deletions(-)
mm/damon/reclaim.c +28 -5
index 4fc4a54b5e546..89998d28628c4 100644
@@ -91,6 +91,20 @@ module_param(quota_mem_pressure_us, ulong, 0600);
 static unsigned long quota_autotune_feedback __read_mostly;
 module_param(quota_autotune_feedback, ulong, 0600);
 
+/*
+ * Auto-tune monitoring intervals.
+ *
+ * If this parameter is set as ``Y``, DAMON_RECLAIM automatically tunes DAMON's
+ * sampling and aggregation intervals.  The auto-tuning aims to capture
+ * meaningful amount of access events in each DAMON-snapshot, while keeping the
+ * sampling intervals 5 milliseconds in minimum, and 10 seconds in maximum.
+ * Setting this as ``N`` disables the auto-tuning.
+ *
+ * Disabled by default.
+ */
+static bool autotune_monitoring_intervals __read_mostly;
+module_param(autotune_monitoring_intervals, bool, 0600);
+
 static struct damos_watermarks damon_reclaim_wmarks = {
 	.metric = DAMOS_WMARK_FREE_MEM_RATE,
 	.interval = 5000000,	/* 5 seconds */
@@ -159,7 +173,7 @@ DEFINE_DAMON_MODULES_DAMOS_STATS_PARAMS(damon_reclaim_stat,
 static struct damon_ctx *ctx;
 static struct damon_target *target;
 
-static struct damos *damon_reclaim_new_scheme(void)
+static struct damos *damon_reclaim_new_scheme(unsigned long aggr_interval)
 {
 	struct damos_access_pattern pattern = {
 		/* Find regions having PAGE_SIZE or larger size */
@@ -169,8 +183,7 @@ static struct damos *damon_reclaim_new_scheme(void)
 		.min_nr_accesses = 0,
 		.max_nr_accesses = 0,
 		/* for min_age or more micro-seconds */
-		.min_age_region = min_age /
-			damon_reclaim_mon_attrs.aggr_interval,
+		.min_age_region = min_age / aggr_interval,
 		.max_age_region = UINT_MAX,
 	};
 
@@ -191,6 +204,7 @@ static int damon_reclaim_apply_parameters(void)
 {
 	struct damon_ctx *param_ctx;
 	struct damon_target *param_target;
+	struct damon_attrs attrs;
 	struct damos *scheme;
 	struct damos_quota_goal *goal;
 	struct damos_filter *filter;
@@ -208,12 +222,21 @@ static int damon_reclaim_apply_parameters(void)
 		goto out;
 	}
 
-	err = damon_set_attrs(param_ctx, &damon_reclaim_mon_attrs);
+	attrs = damon_reclaim_mon_attrs;
+	if (autotune_monitoring_intervals) {
+		attrs.sample_interval = 5000;
+		attrs.aggr_interval = 100000;
+		attrs.intervals_goal.access_bp = 40;
+		attrs.intervals_goal.aggrs = 3;
+		attrs.intervals_goal.min_sample_us = 5000;
+		attrs.intervals_goal.max_sample_us = 10 * 1000 * 1000;
+	}
+	err = damon_set_attrs(param_ctx, &attrs);
 	if (err)
 		goto out;
 
 	err = -ENOMEM;
-	scheme = damon_reclaim_new_scheme();
+	scheme = damon_reclaim_new_scheme(attrs.aggr_interval);
 	if (!scheme)
 		goto out;
 	damon_set_schemes(param_ctx, &scheme, 1);
Signature · 1 line
2.47.3
author maintainer
#2 lore raw

Re: (sashiko review) [RFC PATCH 1/2] mm/damon/reclaim: add autotune_monitoring_intervals parameter

TL; DR: Sashiko found not clearly documented behaviors. I will make those clearly documented in the commit message in the next revision.

Forwarding full sashiko review in a reply format with my inline comments below, for sharing details of my view and doing followup discussions via mails if needed.

Quoted 42 lines
# review url: https://sashiko.dev/#/patchset/[email protected]
# start of sashiko.dev inline review
commit 7929f87e52de2f1dff34abf2ede4e58298280466
Author: SeongJae Park <[email protected]>

mm/damon/reclaim: add autotune_monitoring_intervals parameter

This commit adds a new module parameter, autotune_monitoring_intervals, to DAMON_RECLAIM. It enables the auto-tuning feature for sampling and aggregation intervals with suggested default values.

Quoted 4 lines
mm/damon/reclaim.c +0 -0
index 86da147786583..bcba2f719898d 100644

[ ... ]

Quoted 10 lines
mm/damon/reclaim.c +1 -1
@@ -160,7 +174,7 @@ DEFINE_DAMON_MODULES_DAMOS_STATS_PARAMS(damon_reclaim_stat,
 static struct damon_ctx *ctx;
 static struct damon_target *target;
 
-static struct damos *damon_reclaim_new_scheme(void)
+static struct damos *damon_reclaim_new_scheme(unsigned long aggr_interval)
 {
 	struct damos_access_pattern pattern = {
 		/* Find regions having PAGE_SIZE or larger size */

mm/damon/reclaim.c static struct damos *damon_reclaim_new_scheme(void) · line 187

Quoted 6 lines
mm/damon/reclaim.c +1 -2
@@ -170,8 +184,7 @@ static struct damos *damon_reclaim_new_scheme(void)
 		.min_nr_accesses = 0,
 		.max_nr_accesses = 0,
 		/* for min_age or more micro-seconds */
-		.min_age_region = min_age /
-			damon_reclaim_mon_attrs.aggr_interval,
+		.min_age_region = min_age / aggr_interval,

How does time-based page reclaim behave when the aggregation interval changes dynamically?

The min_age_region value is calculated statically once at scheme creation. If autotune_monitoring_intervals is enabled, the DAMON core dynamically modifies ctx->attrs.aggr_interval at runtime.

Quoted 8 lines

While the core scales existing regions' age counters via damon_age_for_new_attrs() so absolute time is preserved in the new units, the scheme's min_age_region threshold remains static and is not updated.

If the auto-tuner increases aggr_interval, the age counter grows slower, but it still needs to reach the exact same static min_age_region value. Does this cause the effective absolute time required for a page to be reclaimed to become much longer than the user originally configured?

Yes, and this is the intended behavior. Modern users are expected to be less depend on the static age threshold and use the aim-oriented quota tuning using quota_mem_pressure_us like parameter.

Nonetheless, I think this is better to be more clearly documented. I will clarify this in the commit message in the next revision.

Quoted 18 lines
Quoted 3 lines
mm/damon/reclaim.c +0 -0
 		.max_age_region = UINT_MAX,
 	};

[ ... ]

mm/damon/reclaim.c static int damon_reclaim_apply_parameters(void) · line 229

Quoted 9 lines
mm/damon/reclaim.c +4 -1
@@ -209,12 +223,21 @@ static int damon_reclaim_apply_parameters(void)
 		goto out;
 	}
 
-	err = damon_set_attrs(param_ctx, &damon_reclaim_mon_attrs);
+	attrs = damon_reclaim_mon_attrs;
+	if (autotune_monitoring_intervals) {
+		attrs.sample_interval = 5000;
+		attrs.aggr_interval = 100000;

Does this silently discard user-configured module parameters?

Quoted 3 lines

If an administrator explicitly tuned sample_interval or aggr_interval via module parameters or sysfs prior to enabling the autotune feature, it appears their configured values are overwritten here without warning.

Yes, and this is an intended behavior.

Nonetheless, I think this is better to be more clearly documented. I will clarify this in the commit message in the next revision.

Quoted 11 lines

mm/damon/reclaim.c static int damon_reclaim_apply_parameters(void) · line 234

Quoted 7 lines
mm/damon/reclaim.c +6 -0
+		attrs.intervals_goal.access_bp = 40;
+		attrs.intervals_goal.aggrs = 3;
+		attrs.intervals_goal.min_sample_us = 5000;
+		attrs.intervals_goal.max_sample_us = 10 * 1000 * 1000;
+	}
+	err = damon_set_attrs(param_ctx, &attrs);
# end of sashiko.dev inline review
# review url: https://sashiko.dev/#/patchset/[email protected]

Thanks,
SJ

# hkml [1] generated a draft of this mail.  You can regenerate
# this using below command:
#
#     hkml patch sashiko_dev --for_forwarding \
#             [email protected]
#
# [1] https://github.com/sjp38/hackermail
author maintainer
#3 lore raw

RFC PATCH 2/2 Docs/admin-guide/mm/damon/reclaim: update for autotune_monitoring_intervals

In reply to SeongJae Park

Update DAMON_RECLAIM usage document for the newly added monitoring intervals auto-tuning enablement parameter.

---
 Documentation/admin-guide/mm/damon/reclaim.rst | 11 +++++++++++
 1 file changed, 11 insertions(+)
Documentation/admin-guide/mm/damon/reclaim.rst +11 -0
index 01a34c215b66f..b14a065586271 100644
@@ -85,6 +85,17 @@ identifies the region as cold, and reclaims it.
 
 120 seconds by default.
 
+autotune_monitoring_intervals
+-----------------------------
+
+If this parameter is set as ``Y``, DAMON_RECLAIM automatically tunes DAMON's
+sampling and aggregation intervals.  The auto-tuning aims to capture meaningful
+amount of access events in each DAMON-snapshot, while keeping the sampling
+interval 5 milliseconds in minimum, and 10 seconds in maximum.  Setting this as
+``N`` disables the auto-tuning.
+
+Disabled by default.
+
 quota_ms
 --------
 
Signature · 1 line
2.47.3