Skip to contentSkip to conversation

mm/damon: advance DAMOS-based LRU sorting

RFC PATCH New SeongJae Park 1 participant 12 messages Jun 28, 2025

Subsystems (4)
lore
Share & tools
lore

SeongJae Park

author maintainer
#0 lore raw

cover mm/damon: advance DAMOS-based LRU sorting

DAMOS_LRU_[DE]PRIO actions were added to DAMOS for more access-aware LRU lists sorting. For simple usage, a specialized kernel module, namely DAMON_LRU_SORT, has also introduced. After the introduction of DAMON_LRU_SORT, DAMON got a few important new features, including the aim-based quota auto-tuning, young page filter, and monitoring intervals auto-tuning. But DAMOS-based LRU sorting had no many updates. Now we show some rooms to advance for DAMOS-based LRU sorting.

DAMON sysfs interface users can utilize all the features, but DAMON_LRU_SORT is not updated for such modern features. Also, even in case of DAMON sysfs interface usage, there is no good quota auto-tuning goal metric for LRU sorting. Since it is a sort of balancing of active and inactive pages, a metric that represents the size ratio between the active and the inactive pages could be useful. Also, internal behaviors of DAMOS_LRU_[DE]PRIO are not very symmetric.

Advance DAMOS-based LRU sorting by introducing a new DAMOS quota auto-tuning target metric for [in]active memory size ratio, making DAMOS_LRU_[DE]PRIO behavior more intuitive and symmetric. Also update DAMON_LRU_SORT module to be able to fully utilize the modern features including the [in]active memory size ratio, young page filter, and monitoring intervals auto-tuning.

With these changes, for example, users can now ask DAMON to "find hot/cold memory regions with auto-tuned monitoring intervals, do one more page level access check for found hot/cold memory, and move pages of those to active or inactive LRU lists accordingly, aiming 50:50 active to inactive memory ratio."

Plan for none-RFC Version
-------------------------

I'm planning to do more tests and add the results by the final version.

Patches Sequence
----------------

First four patches extend DAMOS quota auto-tuning to support [in]active memory ratio target metric type. The patches introduce new metrics (patch 1), DAMON sysfs support
(patch 2), and add the document (patch 3).

Following patch (patch 4) makes DAMOS_LRU_PRIO action to directly move target pages to active LRU list, instead of marking accessed and incrementally be moved to active lists.

Following seven patches (patches 5-11) updates DAMON_LRU_SORT to support modern DAMON features. Patch 5 makes it to use not only access frequency but also age at under-quota regions prioritization. Patch 6-11 add the support and document it for young page filtering, active:inactive memory ratio based quota auto-tuning, and monitoring intervals auto-tuning, respectively.

SeongJae Park (11):
mm/damon/core: introduce [in]active memory ratio damos quota goal
metric
mm/damon/sysfs-schemes: support DAMOS_QUOTA_[IN]ACTIVE_MEM_BP Docs/mm/damon/design: document DAMOS_QUOTA_[IN]ACTIVE_MEM_BP mm/damon/paddr: activate DAMOS_LRU_PRIO targets instead of marking
accessed
mm/damon/lru_sort: consider age for quota prioritization mm/damon/lru_sort: support young page filters Docs/admin-guide/mm/damon/lru_sort: document filter_young_pages mm/damon/lru_sort: support active:inactive memory ratio based
auto-tuning
Docs/admin-guide/mm/damon/lru_sort: document active_mem_bp parameter mm/damon/lru_sort: add monitoring intervals auto-tuning parameter Docs/admin-guide/mm/damon/lru_sort: document intervals autotuning

 .../admin-guide/mm/damon/lru_sort.rst         |  37 ++++++
 Documentation/mm/damon/design.rst             |   4 +
 include/linux/damon.h                         |   4 +
 mm/damon/core.c                               |  22 ++++
 mm/damon/lru_sort.c                           | 110 +++++++++++++++++-
 mm/damon/paddr.c                              |  18 ++-
 mm/damon/sysfs-schemes.c                      |   8 ++
 7 files changed, 189 insertions(+), 14 deletions(-)

base-commit: cd5e995caa32062e89e340acb4acbcbe09ad709e

Signature · 1 line
2.39.5
author maintainer
#1 lore raw

RFC PATCH 1/11 mm/damon/core: introduce [in]active memory ratio damos quota goal metric

DAMOS_LRU_[DE]PRIO are DAMOS actions for making balance of active and inactive memory size. There is no appripriate DAMOS quota auto-tuning target metric for the use case. Add two new DAMOS quota goal metrics for the purpose, namely DAMOS_QUOTA_[IN]ACTIVE_MEM_BP. Those weill represent the ratio of [in]active memory to total (inactive + active) memory. Hence, users will be able to ask DAMON to, for example, "find hot and cold memory, and move pages of those to active and inactive LRU lists, adjusting the hot/cold thresholds aiming 50:50 active:inactive memory ratio."

---
 include/linux/damon.h |  4 ++++
 mm/damon/core.c       | 22 ++++++++++++++++++++++
 2 files changed, 26 insertions(+)
include/linux/damon.h +4 -0
index 517f48ffe782..c2fc6c8cbbe4 100644
@@ -179,6 +179,8 @@ enum damos_action {
  * @DAMOS_QUOTA_SOME_MEM_PSI_US:	System level some memory PSI in us.
  * @DAMOS_QUOTA_NODE_MEM_USED_BP:	MemUsed ratio of a node.
  * @DAMOS_QUOTA_NODE_MEM_FREE_BP:	MemFree ratio of a node.
+ * @DAMOS_QUOTA_ACTIVE_MEM_BP:		Active to [in]active memory ratio.
+ * @DAMOS_QUOTA_INACTIVE_MEM_BP:	Inactive to [in]active memory ratio.
  * @NR_DAMOS_QUOTA_GOAL_METRICS:	Number of DAMOS quota goal metrics.
  *
  * Metrics equal to larger than @NR_DAMOS_QUOTA_GOAL_METRICS are unsupported.
@@ -188,6 +190,8 @@ enum damos_quota_goal_metric {
 	DAMOS_QUOTA_SOME_MEM_PSI_US,
 	DAMOS_QUOTA_NODE_MEM_USED_BP,
 	DAMOS_QUOTA_NODE_MEM_FREE_BP,
+	DAMOS_QUOTA_ACTIVE_MEM_BP,
+	DAMOS_QUOTA_INACTIVE_MEM_BP,
 	NR_DAMOS_QUOTA_GOAL_METRICS,
 };
 
mm/damon/core.c +22 -0
index 02493d71460c..88ffc826a118 100644
@@ -2027,6 +2027,23 @@ static __kernel_ulong_t damos_get_node_mem_bp(
 }
 #endif
 
+/*
+ * Returns LRU-active memory to LRU-inactive memory size ratio.
+ */
+static unsigned int damos_get_in_active_mem_bp(bool active_ratio)
+{
+	unsigned long active, inactive, total;
+
+	/* This should align with /proc/meminfo output */
+	active = global_node_page_state(NR_LRU_BASE + LRU_ACTIVE_ANON) +
+		global_node_page_state(NR_LRU_BASE + LRU_ACTIVE_FILE);
+	inactive = global_node_page_state(NR_LRU_BASE + LRU_INACTIVE_ANON) +
+		global_node_page_state(NR_LRU_BASE + LRU_INACTIVE_FILE);
+	total = active + inactive;
+	if (active_ratio)
+		return active * 10000 / total;
+	return inactive * 10000 / total;
+}
 
 static void damos_set_quota_goal_current_value(struct damos_quota_goal *goal)
 {
@@ -2046,6 +2063,11 @@ static void damos_set_quota_goal_current_value(struct damos_quota_goal *goal)
 	case DAMOS_QUOTA_NODE_MEM_FREE_BP:
 		goal->current_value = damos_get_node_mem_bp(goal);
 		break;
+	case DAMOS_QUOTA_ACTIVE_MEM_BP:
+	case DAMOS_QUOTA_INACTIVE_MEM_BP:
+		goal->current_value = damos_get_in_active_mem_bp(
+				goal->metric == DAMOS_QUOTA_ACTIVE_MEM_BP);
+		break;
 	default:
 		break;
 	}
Signature · 1 line
2.39.5
author maintainer
#2 lore raw

RFC PATCH 2/11 mm/damon/sysfs-schemes: support DAMOS_QUOTA_[IN]ACTIVE_MEM_BP

In reply to SeongJae Park

Add support of DAMOS_QUOTA_[IN]ACTIVE_MEM_BP on DAMON sysfs interface. Users can use [in]active_mem_bp keyword input to the target_metric sysfs file to use the new DAMOS quota auto-tune target metrics.

---
 mm/damon/sysfs-schemes.c | 8 ++++++++
 1 file changed, 8 insertions(+)
mm/damon/sysfs-schemes.c +8 -0
index e026eed16c2e..e8dcad65292b 100644
@@ -1029,6 +1029,14 @@ struct damos_sysfs_qgoal_metric_name damos_sysfs_qgoal_metric_names[] = {
 		.metric = DAMOS_QUOTA_NODE_MEM_FREE_BP,
 		.name = "node_mem_free_bp",
 	},
+	{
+		.metric = DAMOS_QUOTA_ACTIVE_MEM_BP,
+		.name = "active_mem_bp",
+	},
+	{
+		.metric = DAMOS_QUOTA_INACTIVE_MEM_BP,
+		.name = "inactive_mem_bp",
+	},
 };
 
 static ssize_t target_metric_show(struct kobject *kobj,
Signature · 1 line
2.39.5
author maintainer
#3 lore raw

RFC PATCH 3/11 Docs/mm/damon/design: document DAMOS_QUOTA_[IN]ACTIVE_MEM_BP

In reply to SeongJae Park

Update design document for newly added DAMOS_QUOTA_[IN]ACTIVE_MEM_BP metrics. Note that API document is automatically updated by kernel-doc comment, and the usage document points to the design document which uses keywords same to that for sysfs inputs. Hence updating only design document is sufficient.

---
 Documentation/mm/damon/design.rst | 4 ++++
 1 file changed, 4 insertions(+)
Documentation/mm/damon/design.rst +4 -0
index 2290ebefc648..ce8c389f0c68 100644
@@ -570,6 +570,10 @@ tries to make ``current_value`` of ``target_metric`` be same to
   set by users at the initial time.  In other words, DAMOS does self-feedback.
 - ``node_mem_used_bp``: Specific NUMA node's used memory ratio in bp (1/10,000).
 - ``node_mem_free_bp``: Specific NUMA node's free memory ratio in bp (1/10,000).
+- ``active_mem_bp``: Active to active + inactive (LRU) memory size ratio in bp
+  (1/10,000).
+- ``inactive_mem_bp``: Inactive to active + inactive (LRU) memory size ratio in
+  bp (1/10,000).
 
 ``nid`` is optionally required for only ``node_mem_used_bp`` and
 ``node_mem_free_bp`` to point the specific NUMA node.
Signature · 1 line
2.39.5
author maintainer
#4 lore raw

RFC PATCH 4/11 mm/damon/paddr: activate DAMOS_LRU_PRIO targets instead of marking accessed

In reply to SeongJae Park

DAMOS_LRU_DEPRIOD directly deactivate the pages, while DAMOS_LRU_PRIO calls folio_mark_accessed(), which does incremental activation. The incremental activation was assumed to be useful for making sure the pages of the hot memory region are really hot. After the introduction of DAMOS_LRU_PRIO, the young page filter has added. Users can use the young page filter to make sure the page is eligible to be activated. Meanwhile, the asymmetric behavior of DAMOS_LRU_[DE]PRIO can confuse users.

Directly activate given pages for DAMOS_LRU_PRIO, to eliminate the unnecessary incremental activation steps, and be symmetric with DAMOS_LRU_DEPRIO for easier usages.

---
 mm/damon/paddr.c | 18 ++++++++----------
 1 file changed, 8 insertions(+), 10 deletions(-)
mm/damon/paddr.c +8 -10
index d4261da48b0a..34d4b3017043 100644
@@ -474,8 +474,8 @@ static unsigned long damon_pa_pageout(struct damon_region *r, struct damos *s,
 	return applied * PAGE_SIZE;
 }
 
-static inline unsigned long damon_pa_mark_accessed_or_deactivate(
-		struct damon_region *r, struct damos *s, bool mark_accessed,
+static inline unsigned long damon_pa_de_activate(
+		struct damon_region *r, struct damos *s, bool activate,
 		unsigned long *sz_filter_passed)
 {
 	unsigned long addr, applied = 0;
@@ -494,8 +494,8 @@ static inline unsigned long damon_pa_mark_accessed_or_deactivate(
 		else
 			*sz_filter_passed += folio_size(folio);
 
-		if (mark_accessed)
-			folio_mark_accessed(folio);
+		if (activate)
+			folio_activate(folio);
 		else
 			folio_deactivate(folio);
 		applied += folio_nr_pages(folio);
@@ -507,18 +507,16 @@ static inline unsigned long damon_pa_mark_accessed_or_deactivate(
 	return applied * PAGE_SIZE;
 }
 
-static unsigned long damon_pa_mark_accessed(struct damon_region *r,
+static unsigned long damon_pa_activate_pages(struct damon_region *r,
 	struct damos *s, unsigned long *sz_filter_passed)
 {
-	return damon_pa_mark_accessed_or_deactivate(r, s, true,
-			sz_filter_passed);
+	return damon_pa_de_activate(r, s, true, sz_filter_passed);
 }
 
 static unsigned long damon_pa_deactivate_pages(struct damon_region *r,
 	struct damos *s, unsigned long *sz_filter_passed)
 {
-	return damon_pa_mark_accessed_or_deactivate(r, s, false,
-			sz_filter_passed);
+	return damon_pa_de_activate(r, s, false, sz_filter_passed);
 }
 
 static unsigned int __damon_pa_migrate_folio_list(
@@ -803,7 +801,7 @@ static unsigned long damon_pa_apply_scheme(struct damon_ctx *ctx,
 	case DAMOS_PAGEOUT:
 		return damon_pa_pageout(r, scheme, sz_filter_passed);
 	case DAMOS_LRU_PRIO:
-		return damon_pa_mark_accessed(r, scheme, sz_filter_passed);
+		return damon_pa_activate_pages(r, scheme, sz_filter_passed);
 	case DAMOS_LRU_DEPRIO:
 		return damon_pa_deactivate_pages(r, scheme, sz_filter_passed);
 	case DAMOS_MIGRATE_HOT:
Signature · 1 line
2.39.5
author maintainer
#5 lore raw

RFC PATCH 5/11 mm/damon/lru_sort: consider age for quota prioritization

In reply to SeongJae Park

DAMON_LRU_SORT is doing under-quota access pattern based regions prioritization using only access frequency. Age of regions is another useful information for distinguishing hot and cold regions. Use it for the prioritization, too.

---
 mm/damon/lru_sort.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
mm/damon/lru_sort.c +1 -1
index 4af8fd4a390b..7513ebc6aeef 100644
@@ -71,7 +71,7 @@ static struct damos_quota damon_lru_sort_quota = {
 	/* Within the quota, mark hotter regions accessed first. */
 	.weight_sz = 0,
 	.weight_nr_accesses = 1,
-	.weight_age = 0,
+	.weight_age = 1,
 };
 DEFINE_DAMON_MODULES_DAMOS_TIME_QUOTA(damon_lru_sort_quota);
 
Signature · 1 line
2.39.5
author maintainer
#6 lore raw

RFC PATCH 6/11 mm/damon/lru_sort: support young page filters

In reply to SeongJae Park

DAMON monitors access pattern in the region level, and hence there could be some page level mismatches. A few hot pages could be located in cold region, and vice versa. Young page filter can be useful for doing additional page level access check before applying some DAMOS action.

DAMON_LRU_SORT is not using young page filters, though. Add a parameter for using it.

---
 mm/damon/lru_sort.c | 41 +++++++++++++++++++++++++++++++++++++++++
 1 file changed, 41 insertions(+)
mm/damon/lru_sort.c +41 -0
index 7513ebc6aeef..3ccde23a8566 100644
@@ -41,6 +41,21 @@ static bool enabled __read_mostly;
 static bool commit_inputs __read_mostly;
 module_param(commit_inputs, bool, 0600);
 
+/*
+ * Filter [none-]young pages accordingly for LRU [de]prioritizations.
+ *
+ * If this is set, check page level access (youngness) once again before each
+ * LRU [de]prioritization operation.  LRU prioritization operation is skipped
+ * if the page has not accessed since the last check (not young).  LRU
+ * deprioritization operation is skipped if the page has accessed since the
+ * last check (young).  The feature is enabled or disabled if this parameter is
+ * set as ``Y`` or ``N``, respectively.
+ *
+ * Disabled by default.
+ */
+static bool filter_young_pages __read_mostly;
+module_param(filter_young_pages, bool, 0600);
+
 /*
  * Access frequency threshold for hot memory regions identification in permil.
  *
@@ -186,6 +201,28 @@ static struct damos *damon_lru_sort_new_cold_scheme(unsigned int cold_thres)
 	return damon_lru_sort_new_scheme(&pattern, DAMOS_LRU_DEPRIO);
 }
 
+static int damon_lru_sort_add_filters(struct damos *hot_scheme,
+		struct damos *cold_scheme)
+{
+	struct damos_filter *filter;
+
+	if (!filter_young_pages)
+		return 0;
+
+	/* disallow prioritizing not-young pages */
+	filter = damos_new_filter(DAMOS_FILTER_TYPE_YOUNG, false, false);
+	if (!filter)
+		return -ENOMEM;
+	damos_add_filter(hot_scheme, filter);
+
+	/* disabllow de-prioritizing young pages */
+	filter = damos_new_filter(DAMOS_FILTER_TYPE_YOUNG, true, false);
+	if (!filter)
+		return -ENOMEM;
+	damos_add_filter(cold_scheme, filter);
+	return 0;
+}
+
 static int damon_lru_sort_apply_parameters(void)
 {
 	struct damon_ctx *param_ctx;
@@ -219,6 +256,10 @@ static int damon_lru_sort_apply_parameters(void)
 	damon_set_schemes(param_ctx, &hot_scheme, 1);
 	damon_add_scheme(param_ctx, cold_scheme);
 
+	err = damon_lru_sort_add_filters(hot_scheme, cold_scheme);
+	if (err)
+		goto out;
+
 	err = damon_set_region_biggest_system_ram_default(param_target,
 					&monitor_region_start,
 					&monitor_region_end);
Signature · 1 line
2.39.5
author maintainer
#7 lore raw

RFC PATCH 7/11 Docs/admin-guide/mm/damon/lru_sort: document filter_young_pages

In reply to SeongJae Park

Document the new DAMON_LRU_SORT parameter, filter_young_pages. It can be used to use page level access re-check for the LRU sorting.

---
 Documentation/admin-guide/mm/damon/lru_sort.rst | 14 ++++++++++++++
 1 file changed, 14 insertions(+)
Documentation/admin-guide/mm/damon/lru_sort.rst +14 -0
index 7b0775d281b4..18fa73a59f62 100644
@@ -79,6 +79,20 @@ of parametrs except ``enabled`` again.  Once the re-reading is done, this
 parameter is set as ``N``.  If invalid parameters are found while the
 re-reading, DAMON_LRU_SORT will be disabled.
 
+filter_young_pages
+------------------
+
+Filter [none-]young pages accordingly for LRU [de]prioritizations.
+
+If this is set, check page level access (youngness) once again before each
+LRU [de]prioritization operation.  LRU prioritization operation is skipped
+if the page has not accessed since the last check (not young).  LRU
+deprioritization operation is skipped if the page has accessed since the
+last check (young).  The feature is enabled or disabled if this parameter is
+set as ``Y`` or ``N``, respectively.
+
+Disabled by default.
+
 hot_thres_access_freq
 ---------------------
 
Signature · 1 line
2.39.5
author maintainer
#8 lore raw

RFC PATCH 8/11 mm/damon/lru_sort: support active:inactive memory ratio based auto-tuning

In reply to SeongJae Park

Doing DAMOS_LRU_[DE]PRIO with DAMOS_QUOTA_[IN]ACTIVE_MEM_BP based quota auto-tuning can be useful. For example, users can ask DAMON to "find hot/cold pages and activate/deactivate those aiming 50:50 active:inactive memory size." But DAMON_LRU_SORT has no interface to do that. Add a module parameter for setting the target ratio.

---
 mm/damon/lru_sort.c | 37 +++++++++++++++++++++++++++++++++++++
 1 file changed, 37 insertions(+)
mm/damon/lru_sort.c +37 -0
index 3ccde23a8566..99c5a22cf3f2 100644
@@ -41,6 +41,20 @@ static bool enabled __read_mostly;
 static bool commit_inputs __read_mostly;
 module_param(commit_inputs, bool, 0600);
 
+/*
+ * Desired active to [in]active memory ratio in bp (1/10,000).
+ *
+ * While keeping the caps that set by other quotas, DAMON_LRU_SORT
+ * automatically increases and decreases the effective level of the quota
+ * aiming the LRU [de]prioritizations of the hot and cold memory resulting in
+ * this active to [in]active memory ratio.  Value zero means disabling this
+ * auto-tuning feature.
+ *
+ * Disabled by default.
+ */
+static unsigned long active_mem_bp __read_mostly;
+module_param(active_mem_bp, ulong, 0600);
+
 /*
  * Filter [none-]young pages accordingly for LRU [de]prioritizations.
  *
@@ -201,6 +215,26 @@ static struct damos *damon_lru_sort_new_cold_scheme(unsigned int cold_thres)
 	return damon_lru_sort_new_scheme(&pattern, DAMOS_LRU_DEPRIO);
 }
 
+static int damon_lru_sort_add_quota_goals(struct damos *hot_scheme,
+		struct damos *cold_scheme)
+{
+	struct damos_quota_goal *goal;
+
+	if (!active_mem_bp)
+		return 0;
+	goal = damos_new_quota_goal(DAMOS_QUOTA_ACTIVE_MEM_BP, active_mem_bp);
+	if (!goal)
+		return -ENOMEM;
+	damos_add_quota_goal(&hot_scheme->quota, goal);
+	/* aim 0.2 % goal conflict, to keep little ping pong */
+	goal = damos_new_quota_goal(DAMOS_QUOTA_INACTIVE_MEM_BP,
+			10000 - active_mem_bp + 2);
+	if (!goal)
+		return -ENOMEM;
+	damos_add_quota_goal(&hot_scheme->quota, goal);
+	return 0;
+}
+
 static int damon_lru_sort_add_filters(struct damos *hot_scheme,
 		struct damos *cold_scheme)
 {
@@ -256,6 +290,9 @@ static int damon_lru_sort_apply_parameters(void)
 	damon_set_schemes(param_ctx, &hot_scheme, 1);
 	damon_add_scheme(param_ctx, cold_scheme);
 
+	err = damon_lru_sort_add_quota_goals(hot_scheme, cold_scheme);
+	if (err)
+		goto out;
 	err = damon_lru_sort_add_filters(hot_scheme, cold_scheme);
 	if (err)
 		goto out;
Signature · 1 line
2.39.5
author maintainer
#9 lore raw

RFC PATCH 9/11 Docs/admin-guide/mm/damon/lru_sort: document active_mem_bp parameter

In reply to SeongJae Park

Document a newly added DAMON_LRU_SORT parameter for doing auto-tuning aiming an active to inactive memory size ratio.

---
 Documentation/admin-guide/mm/damon/lru_sort.rst | 12 ++++++++++++
 1 file changed, 12 insertions(+)
Documentation/admin-guide/mm/damon/lru_sort.rst +12 -0
index 18fa73a59f62..ca4e071b3159 100644
@@ -79,6 +79,18 @@ of parametrs except ``enabled`` again.  Once the re-reading is done, this
 parameter is set as ``N``.  If invalid parameters are found while the
 re-reading, DAMON_LRU_SORT will be disabled.
 
+active_mem_bp
+-------------
+
+Desired active to [in]active memory ratio in bp (1/10,000).
+
+While keeping the caps that set by other quotas, DAMON_LRU_SORT automatically
+increases and decreases the effective level of the quota aiming the LRU
+[de]prioritizations of the hot and cold memory resulting in this active to
+[in]active memory ratio.  Value zero means disabling this auto-tuning feature.
+
+Disabled by default.
+
 filter_young_pages
 ------------------
 
Signature · 1 line
2.39.5
author maintainer
#10 lore raw

RFC PATCH 10/11 mm/damon/lru_sort: add monitoring intervals auto-tuning parameter

In reply to SeongJae Park

DAMON monitoring intervals tuning was crucial for every DAMON use case. Now there are a tuning guideline and an automated intervals tuning feature. DAMON_LRU_SORT is still using manual control of intervals. Add a module parameter for utilizing the auto-tuning feature with a suggested auto-tuning parameters.

---
 mm/damon/lru_sort.c | 30 +++++++++++++++++++++++++++---
 1 file changed, 27 insertions(+), 3 deletions(-)
mm/damon/lru_sort.c +27 -3
index 99c5a22cf3f2..1e9e19f15b33 100644
@@ -55,6 +55,20 @@ module_param(commit_inputs, bool, 0600);
 static unsigned long active_mem_bp __read_mostly;
 module_param(active_mem_bp, ulong, 0600);
 
+/*
+ * Auto-tune monitoring intervals.
+ *
+ * If this parameter is set as ``Y``, DAMON_LRU_SORT automatically tune
+ * 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 minimu, and 10 seconds in maximum.
+ * Setting this as ``Y`` disables the auto-tuning.
+ *
+ * Disabled by default.
+ */
+static bool autotune_monitoring_intervals __read_mostly;
+module_param(autotune_monitoring_intervals, bool, 0600);
+
 /*
  * Filter [none-]young pages accordingly for LRU [de]prioritizations.
  *
@@ -261,6 +275,7 @@ static int damon_lru_sort_apply_parameters(void)
 {
 	struct damon_ctx *param_ctx;
 	struct damon_target *param_target;
+	struct damon_attrs attrs;
 	struct damos *hot_scheme, *cold_scheme;
 	unsigned int hot_thres, cold_thres;
 	int err;
@@ -269,18 +284,27 @@ static int damon_lru_sort_apply_parameters(void)
 	if (err)
 		return err;
 
-	err = damon_set_attrs(ctx, &damon_lru_sort_mon_attrs);
+	attrs = damon_lru_sort_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(ctx, &attrs);
 	if (err)
 		goto out;
 
 	err = -ENOMEM;
-	hot_thres = damon_max_nr_accesses(&damon_lru_sort_mon_attrs) *
+	hot_thres = damon_max_nr_accesses(&attrs) *
 		hot_thres_access_freq / 1000;
 	hot_scheme = damon_lru_sort_new_hot_scheme(hot_thres);
 	if (!hot_scheme)
 		goto out;
 
-	cold_thres = cold_min_age / damon_lru_sort_mon_attrs.aggr_interval;
+	cold_thres = cold_min_age / attrs.aggr_interval;
 	cold_scheme = damon_lru_sort_new_cold_scheme(cold_thres);
 	if (!cold_scheme) {
 		damon_destroy_scheme(hot_scheme);
Signature · 1 line
2.39.5
author maintainer
#11 lore raw

RFC PATCH 11/11 Docs/admin-guide/mm/damon/lru_sort: document intervals autotuning

In reply to SeongJae Park

Document a newly added DAMON_LRU_SORT module parameter for using monitoring intervals auto-tuning feature of DAMON.

---
 Documentation/admin-guide/mm/damon/lru_sort.rst | 11 +++++++++++
 1 file changed, 11 insertions(+)
Documentation/admin-guide/mm/damon/lru_sort.rst +11 -0
index ca4e071b3159..f9dfa8255dda 100644
@@ -91,6 +91,17 @@ increases and decreases the effective level of the quota aiming the LRU
 
 Disabled by default.
 
+Auto-tune monitoring intervals
+------------------------------
+
+If this parameter is set as ``Y``, DAMON_LRU_SORT automatically tune 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 minimu, and 10 seconds in maximum.  Setting this as
+``Y`` disables the auto-tuning.
+
+Disabled by default.
+
 filter_young_pages
 ------------------
 
Signature · 1 line
2.39.5