Skip to contentSkip to conversation

mm-damon-core-split-regions-for-min_nr_regions.patch removed from -mm tree

merged mm-stable Andrew Morton 1 participant 1 message Mar 24

lore
Share & tools
lore

Andrew Morton

author tree notice Applied
#0 lore raw

The quilt patch titled
Subject: mm/damon/core: split regions for min_nr_regions
has been removed from the -mm tree. Its filename was
mm-damon-core-split-regions-for-min_nr_regions.patch

This patch was dropped because it was merged into the mm-stable branch of git://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm

------------------------------------------------------
From: SeongJae Park <[email protected]>
Subject: mm/damon/core: split regions for min_nr_regions
Date: Sat, 28 Feb 2026 14:28:25 -0800

Patch series "mm/damon: strictly respect min_nr_regions".

DAMON core respects min_nr_regions only at merge operation. DAMON API callers are therefore responsible to respect or ignore that. Only vaddr ops is respecting that, but only for initial start time. DAMON sysfs interface allows users to setup the initial regions that DAMON core also respects. But, again, it works for only the initial time. Users setting the regions for min_nr_regions can be difficult and inefficient, when the min_nr_regions value is high. There was actually a report [1] from a user. The use case was page granular access monitoring with a large aggregation interval.

Make the following three changes for resolving the issue. First (patch 1), make DAMON core split regions at the beginning and every aggregation interval, to respect the min_nr_regions. Second (patch 2), drop the vaddr's split operations and related code that are no more needed. Third (patch 3), add a kunit test for the newly introduced function.

This patch (of 3):

DAMON core layer respects the min_nr_regions parameter by setting the maximum size of each region as total monitoring region size divided by the parameter value. And the limit is applied by preventing merge of regions that result in a region larger than the maximum size. The limit is updated per ops update interval, because vaddr updates the monitoring regions on the ops update callback.

It does nothing for the beginning state. That's because the users can set the initial monitoring regions as they want. That is, if the users really care about the min_nr_regions, they are supposed to set the initial

monitoring regions to have more than min_nr_regions regions.  The virtual
address space operation set, vaddr, has an exceptional case.  Users can
ask the ops set to configure the initial regions on its own.  For the

case, vaddr sets up the initial regions to meet the min_nr_regions. So, vaddr has exceptional support, but basically users are required to set the regions on their own if they want min_nr_regions to be respected.

When 'min_nr_regions' is high, such initial setup is difficult. If DAMON sysfs interface is used for that, the memory for saving the initial setup is also a waste.

Even if the user forgives the setup, DAMON will eventually make more than min_nr_regions regions by splitting operations. But it will take time. If the aggregation interval is long, the delay could be problematic. There was actually a report [1] of the case. The reporter wanted to do page granular monitoring with a large aggregation interval.

Also, DAMON is doing nothing for online changes on monitoring regions and min_nr_regions. For example, the user can remove a monitoring region or increase min_nr_regions while DAMON is running.

Split regions larger than the size at the beginning of the kdamond main loop, to fix the initial setup issue. Also do the split every aggregation interval, for online changes. This means the behavior is slightly changed. It is difficult to imagine a use case that actually depends on the old behavior, though. So this change is arguably fine.

Note that the size limit is aligned by damon_ctx->min_region_sz and cannot be zero. That is, if min_nr_region is larger than the total size of monitoring regions divided by ->min_region_sz, that cannot be respected.

---

 mm/damon/core.c |   45 +++++++++++++++++++++++++++++++++++++++------
 1 file changed, 39 insertions(+), 6 deletions(-)
mm/damon/core.c renamed from mm/damon/core.c~mm-damon-core-split-regions-for-min_nr_regions +39 -6
@@ -1316,6 +1316,40 @@ static unsigned long damon_region_sz_lim
 	return sz;
 }
 
+static void damon_split_region_at(struct damon_target *t,
+				  struct damon_region *r, unsigned long sz_r);
+
+/*
+ * damon_apply_min_nr_regions() - Make effect of min_nr_regions parameter.
+ * @ctx:	monitoring context.
+ *
+ * This function implement min_nr_regions (minimum number of damon_region
+ * objects in the given monitoring context) behavior.  It first calculates
+ * maximum size of each region for enforcing the min_nr_regions as total size
+ * of the regions divided by the min_nr_regions.  After that, this function
+ * splits regions to ensure all regions are equal to or smaller than the size
+ * limit.  Finally, this function returns the maximum size limit.
+ *
+ * Returns: maximum size of each region for convincing min_nr_regions.
+ */
+static unsigned long damon_apply_min_nr_regions(struct damon_ctx *ctx)
+{
+	unsigned long max_region_sz = damon_region_sz_limit(ctx);
+	struct damon_target *t;
+	struct damon_region *r, *next;
+
+	max_region_sz = ALIGN(max_region_sz, ctx->min_region_sz);
+	damon_for_each_target(t, ctx) {
+		damon_for_each_region_safe(r, next, t) {
+			while (damon_sz_region(r) > max_region_sz) {
+				damon_split_region_at(t, r, max_region_sz);
+				r = damon_next_region(r);
+			}
+		}
+	}
+	return max_region_sz;
+}
+
 static int kdamond_fn(void *data);
 
 /*
@@ -1672,9 +1706,6 @@ static void kdamond_tune_intervals(struc
 	damon_set_attrs(c, &new_attrs);
 }
 
-static void damon_split_region_at(struct damon_target *t,
-				  struct damon_region *r, unsigned long sz_r);
-
 static bool __damos_valid_target(struct damon_region *r, struct damos *s)
 {
 	unsigned long sz;
@@ -2763,7 +2794,7 @@ static int kdamond_fn(void *data)
 	if (!ctx->regions_score_histogram)
 		goto done;
 
-	sz_limit = damon_region_sz_limit(ctx);
+	sz_limit = damon_apply_min_nr_regions(ctx);
 
 	while (!kdamond_need_stop(ctx)) {
 		/*
@@ -2788,10 +2819,13 @@ static int kdamond_fn(void *data)
 		if (ctx->ops.check_accesses)
 			max_nr_accesses = ctx->ops.check_accesses(ctx);
 
-		if (ctx->passed_sample_intervals >= next_aggregation_sis)
+		if (ctx->passed_sample_intervals >= next_aggregation_sis) {
 			kdamond_merge_regions(ctx,
 					max_nr_accesses / 10,
 					sz_limit);
+			/* online updates might be made */
+			sz_limit = damon_apply_min_nr_regions(ctx);
+		}
 
 		/*
 		 * do kdamond_call() and kdamond_apply_schemes() after
@@ -2850,7 +2884,6 @@ static int kdamond_fn(void *data)
 				sample_interval;
 			if (ctx->ops.update)
 				ctx->ops.update(ctx);
-			sz_limit = damon_region_sz_limit(ctx);
 		}
 	}
 done:

_

Patches currently in -mm which might be from [email protected] are

mm-damon-add-config_damon_debug_sanity.patch mm-damon-core-add-damon_new_region-debug_sanity-check.patch mm-damon-core-add-damon_del_region-debug_sanity-check.patch mm-damon-core-add-damon_nr_regions-debug_sanity-check.patch mm-damon-core-add-damon_merge_two_regions-debug_sanity-check.patch mm-damon-core-add-damon_merge_regions_of-debug_sanity-check.patch mm-damon-core-add-damon_split_region_at-debug_sanity-check.patch mm-damon-core-add-damon_reset_aggregated-debug_sanity-check.patch mm-damon-tests-kunitconifg-enable-damon_debug_sanity.patch selftests-damon-config-enable-damon_debug_sanity.patch mm-damon-tests-core-kunit-add-a-test-for-damon_commit_ctx.patch docs-mm-damon-design-document-the-power-of-two-limitation-for-addr_unit.patch mm-damon-core-remove-damos_set_next_apply_sis-duplicates.patch mm-damon-core-use-time_before-for-next_apply_sis.patch mm-damon-core-use-time_after_eq-in-kdamond_fn.patch mm-damon-core-use-mult_frac.patch mm-damon-tests-core-kunit-add-a-test-for-damon_is_last_region.patch mm-damon-core-clarify-damon_set_attrs-usages.patch mm-damon-document-non-zero-length-damon_region-assumption.patch docs-admin-guide-mm-damn-lru_sort-fix-intervals-autotune-parameter-name.patch docs-mm-damon-maintainer-profile-use-flexible-review-cadence.patch docs-mm-damon-index-fix-typo-autoamted-automated.patch mm-damon-core-introduce-damos_quota_goal_tuner.patch mm-damon-core-allow-quota-goals-set-zero-effective-size-quota.patch mm-damon-core-introduce-damos_quota_goal_tuner_temporal.patch mm-damon-sysfs-schemes-implement-quotas-goal_tuner-file.patch docs-mm-damon-design-document-the-goal-based-quota-tuner-selections.patch docs-admin-guide-mm-damon-usage-document-goal_tuner-sysfs-file.patch docs-abi-damon-update-for-goal_tuner.patch mm-damon-tests-core-kunit-test-goal_tuner-commit.patch selftests-damon-_damon_sysfs-support-goal_tuner-setup.patch selftests-damon-drgn_dump_damon_status-support-quota-goal_tuner-dumping.patch selftests-damon-sysfspy-test-goal_tuner-commit.patch mm-damon-core-fix-wrong-end-address-assignment-on-walk_system_ram.patch mm-damon-core-support-addr_unit-on-damon_find_biggest_system_ram.patch mm-damon-core-support-addr_unit-on-damon_find_biggest_system_ram-fix.patch mm-damon-core-receive-addr_unit-on-damon_set_region_biggest_system_ram_default.patch mm-damon-core-receive-addr_unit-on-damon_set_region_biggest_system_ram_default-fix.patch mm-damon-reclaim-respect-addr_unit-on-default-monitoring-region-setup.patch mm-damon-lru_sort-respect-addr_unit-on-default-monitoring-region-setup.patch