Skip to contentSkip to conversation

mm-damon-core-merge-regions-after-applying-damos-schemes.patch removed from -mm tree

merged mm-stable Andrew Morton 1 participant 1 message May 29

lore
Share & tools
lore

Andrew Morton

author tree notice Applied
#0 lore raw

The quilt patch titled
Subject: mm/damon/core: merge regions after applying DAMOS schemes
has been removed from the -mm tree. Its filename was
mm-damon-core-merge-regions-after-applying-damos-schemes.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: merge regions after applying DAMOS schemes
Date: Mon, 27 Apr 2026 18:33:51 -0700

damos_apply_scheme() could split the given region if applying the scheme's action to the entire region can result in violating the quota-set upper limit. Keeping regions that are created by such split operations is unnecessary overhead.

The overhead would be negligible in the common case because such split operations could happen only up to the number of installed schemes per scheme apply interval. The following commit could make the impact larger, though. The following commit will allow the action-failed region to be charged in a different ratio. If both the ratio and the remaining quota is quite small while the region to apply the scheme is quite large and the action is nearly always failing, a high number of split operations could happen.

Remove the unnecessary overhead by merging regions after applying schemes is done for each region. The merge operation is made only if it will not lose monitoring information and keep min_nr_regions constraint. In the worst case, the max_nr_regions could still be violated until the next per-aggregation interval merge operation is made.

Cc Brendan Higgins <[email protected]>
Cc David Hildenbrand <[email protected]>
Cc Jonathan Corbet <[email protected]>
Cc Liam R. Howlett <[email protected]>
Cc Lorenzo Stoakes <[email protected]>
Cc Michal Hocko <[email protected]>
Cc Mike Rapoport <[email protected]>
Cc Shuah Khan <[email protected]>
Cc Suren Baghdasaryan <[email protected]>
Cc Vlastimil Babka <[email protected]>

---

 mm/damon/core.c |   59 ++++++++++++++++++++++++++++++++++++++++++----
 1 file changed, 55 insertions(+), 4 deletions(-)
mm/damon/core.c renamed from mm/damon/core.c~mm-damon-core-merge-regions-after-applying-damos-schemes +55 -4
@@ -2183,6 +2183,58 @@ static void damon_do_apply_schemes(struc
 }
 
 /*
+ * damos_apply_target() - Apply DAMOS schemes to a given target.
+ * @c:			monitoring context to apply its DAMOS schemes to..
+ * @t:			monitoring target to apply the schemes to.
+ * @max_region_sz:	maximum region size for @c.
+ *
+ * This function could split regions for keeping the quota.  To minimize
+ * overhead from the split operations increased number of regions, this
+ * function will also merge regions after the schemes applying attempt is done,
+ * for each region.  The merge operation is made only when it doesn't lose the
+ * monitoring information and not violating @max_region_sz.
+ *
+ * Hence, after this function is called, the total number of regions could
+ * be increased or reduced.  The increase could make max_nr_regions temporarily
+ * be violated, until the next per-aggregation interval regions merge operation
+ * is executed.  The decrease will not violate min_nr_regions though, since it
+ * keeps @max_region_sz.
+ */
+static void damos_apply_target(struct damon_ctx *c, struct damon_target *t,
+		unsigned long max_region_sz)
+{
+	struct damon_region *r;
+
+	damon_for_each_region(r, t) {
+		struct damon_region *prev_r;
+
+		damon_do_apply_schemes(c, t, r);
+		/*
+		 * damon_do_apply_scheems() could split the region for the
+		 * quota.  Keeping the new slices is an overhead.  Merge back
+		 * the slices into the previous region if it doesn't lose any
+		 * information and not violating the max_region_sz.
+		 */
+		if (damon_first_region(t) == r)
+			continue;
+		prev_r = damon_prev_region(r);
+		if (prev_r->ar.end != r->ar.start)
+			continue;
+		if (prev_r->age != r->age)
+			continue;
+		if (prev_r->last_nr_accesses != r->last_nr_accesses)
+			continue;
+		if (prev_r->nr_accesses != r->nr_accesses)
+			continue;
+		if (r->ar.end - prev_r->ar.start > max_region_sz)
+			continue;
+		prev_r->ar.end = r->ar.end;
+		damon_destroy_region(r, t);
+		r = prev_r;
+	}
+}
+
+/*
  * damon_feed_loop_next_input() - get next input to achieve a target score.
  * @last_input	The last input.
  * @score	Current score that made with @last_input.
@@ -2674,9 +2726,9 @@ static void damos_trace_stat(struct damo
 static void kdamond_apply_schemes(struct damon_ctx *c)
 {
 	struct damon_target *t;
-	struct damon_region *r;
 	struct damos *s;
 	bool has_schemes_to_apply = false;
+	unsigned long max_region_sz;
 
 	damon_for_each_scheme(s, c) {
 		if (time_before(c->passed_sample_intervals, s->next_apply_sis))
@@ -2693,13 +2745,12 @@ static void kdamond_apply_schemes(struct
 	if (!has_schemes_to_apply)
 		return;
 
+	max_region_sz = damon_region_sz_limit(c);
 	mutex_lock(&c->walk_control_lock);
 	damon_for_each_target(t, c) {
 		if (c->ops.target_valid && c->ops.target_valid(t) == false)
 			continue;
-
-		damon_for_each_region(r, t)
-			damon_do_apply_schemes(c, t, r);
+		damos_apply_target(c, t, max_region_sz);
 	}
 
 	damon_for_each_scheme(s, c) {

_

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

mm-damon-ops-common-call-folio_test_lru-after-folio_get.patch mm-damon-reclaim-handle-ctx-allocation-failure.patch mm-damonn-lru_sort-handle-ctx-allocation-failure.patch mm-damon-core-introduce-struct-damon_probe.patch mm-damon-core-embed-damon_probe-objects-in-damon_ctx.patch mm-damon-core-introduce-damon_filter.patch mm-damon-core-commit-probes.patch mm-damon-core-introduce-damon_region-probe_hits.patch mm-damon-core-introduce-damon_ops-apply_probes.patch mm-damon-core-do-data-attributes-monitoring.patch mm-damon-paddr-support-data-attributes-monitoring.patch mm-damon-sysfs-implement-probes-dir.patch mm-damon-sysfs-implement-probe-dir.patch mm-damon-sysfs-implement-filters-directory.patch mm-damon-sysfs-implement-filter-dir.patch mm-damon-sysfs-implement-filter-dir-files.patch mm-damon-sysfs-setup-probes-on-damon-core-api-parameters.patch mm-damon-sysfs-schemes-implement-tried_regions-r-probes.patch mm-damon-sysfs-schemes-implement-probe-dir.patch mm-damon-sysfs-schemes-implement-probe-hits-file.patch mm-damon-trace-probe_hits.patch selftests-damon-sysfssh-test-probes-dir.patch docs-mm-damon-design-document-data-attributes-monitoring.patch docs-admin-guide-mm-damon-usage-document-data-attributes-monitoring.patch mm-damon-core-introduce-damon_filter_type_memcg.patch mm-damon-paddr-support-damon_filter_type_memcg.patch mm-damon-sysfs-add-filters-f-path-file.patch mm-damon-sysfs-schemes-move-memcg_path_to_id-to-sysfs-common.patch mm-damon-sysfs-setup-damon_filter-memcg_id-from-path.patch docs-mm-damon-design-update-for-memcg-damon-filter.patch docs-admin-guide-mm-damon-usage-update-for-memcg-damon-filter.patch mm-damon-core-safely-handle-no-region-case-in-damon_set_regions.patch mm-damon-core-do-not-use-region-out-of-a-loop-in-damon_set_regions.patch samples-damon-mtier-replace-damon_add_region-with-damon_set_regions.patch mm-damon-tests-vaddr-kunit-replace-damon_add_region-with-damon_set_regions.patch mm-damon-core-hide-damon_add_region.patch mm-damon-core-hide-damon_insert_region.patch mm-damon-core-hide-damon_destroy_region.patch mm-damon-core-add-kdamond_call-debug_sanity-check.patch mm-damon-core-remove-damon_verify_nr_regions.patch mm-damon-tests-core-kunit-add-damon_set_regions-test-cases.patch selftests-damon-sysfspy-stop-kdamonds-before-failing.patch selftests-damon-sysfssh-test-monitoring-intervals-goal-dir.patch selftests-damon-sysfssh-test-addr_unit-file-existence.patch selftests-damon-sysfssh-test-pause-file-existence.patch mm-damon-core-trace-esz-at-first-setup.patch