]> www.infradead.org Git - users/jedix/linux-maple.git/commitdiff
mm/damon: add a min_sz_region parameter to damon_set_region_biggest_system_ram_default()
authorQuanmin Yan <yanquanmin1@huawei.com>
Mon, 20 Oct 2025 13:01:24 +0000 (21:01 +0800)
committerAndrew Morton <akpm@linux-foundation.org>
Wed, 22 Oct 2025 01:51:44 +0000 (18:51 -0700)
Patch series "mm/damon: fixes for address alignment issues in
DAMON_LRU_SORT and DAMON_RECLAIM", v2.

In DAMON_LRU_SORT and DAMON_RECLAIM, damon_set_regions() will apply
DAMON_MIN_REGION as the core address alignment, and the monitoring target
address ranges would be aligned on DAMON_MIN_REGION * addr_unit.  When
users 1) set addr_unit to a value larger than 1, and 2) set the monitoring
target address range as not aligned on DAMON_MIN_REGION * addr_unit, it
will cause DAMON_LRU_SORT and DAMON_RECLAIM to operate on unexpectedly
large physical address ranges.

For example, if the user sets the monitoring target address range to [4,
8) and addr_unit as 1024, the aimed monitoring target address range is [4
KiB, 8 KiB).  Assuming DAMON_MIN_REGION is 4096, so resulting target
address range will be [0, 4096) in the DAMON core layer address system,
and [0, 4 MiB) in the physical address space, which is an unexpected
range.

To fix the issue, add a min_sz_region parameter to
damon_set_region_biggest_system_ram_default() and use it when calling
damon_set_regions(), replacing the direct use of DAMON_MIN_REGION.

This patch (of 2):

In DAMON_LRU_SORT, damon_set_regions() will apply DAMON_MIN_REGION as the
core address alignment, and the monitoring target address ranges would be
aligned on DAMON_MIN_REGION * addr_unit.  When users 1) set addr_unit to a
value larger than 1, and 2) set the monitoring target address range as not
aligned on DAMON_MIN_REGION * addr_unit, it will cause DAMON_LRU_SORT to
operate on unexpectedly large physical address ranges.

For example, if the user sets the monitoring target address range to [4,
8) and addr_unit as 1024, the aimed monitoring target address range is [4
KiB, 8 KiB).  Assuming DAMON_MIN_REGION is 4096, so resulting target
address range will be [0, 4096) in the DAMON core layer address system,
and [0, 4 MiB) in the physical address space, which is an unexpected
range.

To fix the issue, add a min_sz_region parameter to
damon_set_region_biggest_system_ram_default() and use it when calling
damon_set_regions(), replacing the direct use of DAMON_MIN_REGION.

Link: https://lkml.kernel.org/r/20251020130125.2875164-1-yanquanmin1@huawei.com
Link: https://lkml.kernel.org/r/20251020130125.2875164-2-yanquanmin1@huawei.com
Fixes: 2e0fe9245d6b ("mm/damon/lru_sort: support addr_unit for DAMON_LRU_SORT")
Signed-off-by: Quanmin Yan <yanquanmin1@huawei.com>
Reviewed-by: SeongJae Park <sj@kernel.org>
Cc: Kefeng Wang <wangkefeng.wang@huawei.com>
Cc: ze zuo <zuoze1@huawei.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
include/linux/damon.h
mm/damon/core.c
mm/damon/lru_sort.c
mm/damon/reclaim.c
mm/damon/stat.c

index 0edf41d36ea1f854bfaef7d2c53c901b895b111c..9ee026c2db53e2ec46476a8684aab9500b246051 100644 (file)
@@ -961,7 +961,8 @@ int damon_call(struct damon_ctx *ctx, struct damon_call_control *control);
 int damos_walk(struct damon_ctx *ctx, struct damos_walk_control *control);
 
 int damon_set_region_biggest_system_ram_default(struct damon_target *t,
-                               unsigned long *start, unsigned long *end);
+                               unsigned long *start, unsigned long *end,
+                               unsigned long min_sz_region);
 
 #endif /* CONFIG_DAMON */
 
index a9c11d2d37b076a48469fc922b14303178428017..82546d138a5af1097109768b3e7767b763b906e2 100644 (file)
@@ -2818,6 +2818,7 @@ static bool damon_find_biggest_system_ram(unsigned long *start,
  * @t:         The monitoring target to set the region.
  * @start:     The pointer to the start address of the region.
  * @end:       The pointer to the end address of the region.
+ * @min_sz_region:     Minimum region size.
  *
  * This function sets the region of @t as requested by @start and @end.  If the
  * values of @start and @end are zero, however, this function finds the biggest
@@ -2828,7 +2829,8 @@ static bool damon_find_biggest_system_ram(unsigned long *start,
  * Return: 0 on success, negative error code otherwise.
  */
 int damon_set_region_biggest_system_ram_default(struct damon_target *t,
-                       unsigned long *start, unsigned long *end)
+                       unsigned long *start, unsigned long *end,
+                       unsigned long min_sz_region)
 {
        struct damon_addr_range addr_range;
 
@@ -2841,7 +2843,7 @@ int damon_set_region_biggest_system_ram_default(struct damon_target *t,
 
        addr_range.start = *start;
        addr_range.end = *end;
-       return damon_set_regions(t, &addr_range, 1, DAMON_MIN_REGION);
+       return damon_set_regions(t, &addr_range, 1, min_sz_region);
 }
 
 /*
index 42b9a656f9ded0978b0e2a9da899bda0401b21c1..49b4bc294f4e1eb626e7128ca47eaa0a6b0d9c95 100644 (file)
@@ -242,7 +242,8 @@ static int damon_lru_sort_apply_parameters(void)
 
        err = damon_set_region_biggest_system_ram_default(param_target,
                                        &monitor_region_start,
-                                       &monitor_region_end);
+                                       &monitor_region_end,
+                                       param_ctx->min_sz_region);
        if (err)
                goto out;
        err = damon_commit_ctx(ctx, param_ctx);
index 7ba3d0f9a19ace8bfd960d8f7c6ad30d52fb9da9..e30811cafe90cd465efd77ee4340c6109a5a6b9d 100644 (file)
@@ -250,7 +250,8 @@ static int damon_reclaim_apply_parameters(void)
 
        err = damon_set_region_biggest_system_ram_default(param_target,
                                        &monitor_region_start,
-                                       &monitor_region_end);
+                                       &monitor_region_end,
+                                       DAMON_MIN_REGION);
        if (err)
                goto out;
        err = damon_commit_ctx(ctx, param_ctx);
index d8010968bbedd12a7751ff8c6f091a0da4c5bccd..6c4503d2aee3f0f008f419ab79c446ed1db8a088 100644 (file)
@@ -187,7 +187,8 @@ static struct damon_ctx *damon_stat_build_ctx(void)
        if (!target)
                goto free_out;
        damon_add_target(ctx, target);
-       if (damon_set_region_biggest_system_ram_default(target, &start, &end))
+       if (damon_set_region_biggest_system_ram_default(target, &start, &end,
+                                                       ctx->min_sz_region))
                goto free_out;
        return ctx;
 free_out: