]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
mm/damon/reclaim: support addr_unit for DAMON_RECLAIM
authorQuanmin Yan <yanquanmin1@huawei.com>
Wed, 10 Sep 2025 11:32:21 +0000 (19:32 +0800)
committerAndrew Morton <akpm@linux-foundation.org>
Sun, 21 Sep 2025 21:22:33 +0000 (14:22 -0700)
Implement a sysfs file to expose addr_unit for DAMON_RECLAIM users.
During parameter application, use the configured addr_unit parameter to
perform the necessary initialization.  Similar to the core layer, prevent
setting addr_unit to zero.

It is worth noting that when monitor_region_start and monitor_region_end
are unset (i.e., 0), their values will later be set to biggest_system_ram.
At that point, addr_unit may not be the default value 1.  Although we
could divide the biggest_system_ram value by addr_unit, changing addr_unit
without setting monitor_region_start/end should be considered a user
misoperation.  And biggest_system_ram is only within the 0~ULONG_MAX
range, system can clearly work correctly with addr_unit=1.  Therefore, if
monitor_region_start/end are unset, always silently reset addr_unit to 1.

Link: https://lkml.kernel.org/r/20250910113221.1065764-3-yanquanmin1@huawei.com
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>
mm/damon/reclaim.c

index fb7c982a0018c2e5a2f8abcb4104e2119c4da440..590f9d6c55ef2314a9330ae493a9a23f1a90d63b 100644 (file)
@@ -128,6 +128,13 @@ module_param(monitor_region_start, ulong, 0600);
 static unsigned long monitor_region_end __read_mostly;
 module_param(monitor_region_end, ulong, 0600);
 
+/*
+ * Scale factor for DAMON_RECLAIM to ops address conversion.
+ *
+ * This parameter must not be set to 0.
+ */
+static unsigned long addr_unit __read_mostly = 1;
+
 /*
  * Skip anonymous pages reclamation.
  *
@@ -194,6 +201,15 @@ static int damon_reclaim_apply_parameters(void)
        if (err)
                return err;
 
+       /*
+        * If monitor_region_start/end are unset, always silently
+        * reset addr_unit to 1.
+        */
+       if (!monitor_region_start && !monitor_region_end)
+               addr_unit = 1;
+       param_ctx->addr_unit = addr_unit;
+       param_ctx->min_sz_region = max(DAMON_MIN_REGION / addr_unit, 1);
+
        if (!damon_reclaim_mon_attrs.aggr_interval) {
                err = -EINVAL;
                goto out;
@@ -294,6 +310,30 @@ static int damon_reclaim_turn(bool on)
        return damon_call(ctx, &call_control);
 }
 
+static int damon_reclaim_addr_unit_store(const char *val,
+               const struct kernel_param *kp)
+{
+       unsigned long input_addr_unit;
+       int err = kstrtoul(val, 0, &input_addr_unit);
+
+       if (err)
+               return err;
+       if (!input_addr_unit)
+               return -EINVAL;
+
+       addr_unit = input_addr_unit;
+       return 0;
+}
+
+static const struct kernel_param_ops addr_unit_param_ops = {
+       .set = damon_reclaim_addr_unit_store,
+       .get = param_get_ulong,
+};
+
+module_param_cb(addr_unit, &addr_unit_param_ops, &addr_unit, 0600);
+MODULE_PARM_DESC(addr_unit,
+       "Scale factor for DAMON_RECLAIM to ops address conversion (default: 1)");
+
 static int damon_reclaim_enabled_store(const char *val,
                const struct kernel_param *kp)
 {