Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

mm/damon/reclaim: support addr_unit for DAMON_RECLAIM

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>

authored by

Quanmin Yan and committed by
Andrew Morton
7db551fc 2e0fe924

+40
+40
mm/damon/reclaim.c
··· 129 129 module_param(monitor_region_end, ulong, 0600); 130 130 131 131 /* 132 + * Scale factor for DAMON_RECLAIM to ops address conversion. 133 + * 134 + * This parameter must not be set to 0. 135 + */ 136 + static unsigned long addr_unit __read_mostly = 1; 137 + 138 + /* 132 139 * Skip anonymous pages reclamation. 133 140 * 134 141 * If this parameter is set as ``Y``, DAMON_RECLAIM does not reclaim anonymous ··· 200 193 err = damon_modules_new_paddr_ctx_target(&param_ctx, &param_target); 201 194 if (err) 202 195 return err; 196 + 197 + /* 198 + * If monitor_region_start/end are unset, always silently 199 + * reset addr_unit to 1. 200 + */ 201 + if (!monitor_region_start && !monitor_region_end) 202 + addr_unit = 1; 203 + param_ctx->addr_unit = addr_unit; 204 + param_ctx->min_sz_region = max(DAMON_MIN_REGION / addr_unit, 1); 203 205 204 206 if (!damon_reclaim_mon_attrs.aggr_interval) { 205 207 err = -EINVAL; ··· 309 293 kdamond_pid = ctx->kdamond->pid; 310 294 return damon_call(ctx, &call_control); 311 295 } 296 + 297 + static int damon_reclaim_addr_unit_store(const char *val, 298 + const struct kernel_param *kp) 299 + { 300 + unsigned long input_addr_unit; 301 + int err = kstrtoul(val, 0, &input_addr_unit); 302 + 303 + if (err) 304 + return err; 305 + if (!input_addr_unit) 306 + return -EINVAL; 307 + 308 + addr_unit = input_addr_unit; 309 + return 0; 310 + } 311 + 312 + static const struct kernel_param_ops addr_unit_param_ops = { 313 + .set = damon_reclaim_addr_unit_store, 314 + .get = param_get_ulong, 315 + }; 316 + 317 + module_param_cb(addr_unit, &addr_unit_param_ops, &addr_unit, 0600); 318 + MODULE_PARM_DESC(addr_unit, 319 + "Scale factor for DAMON_RECLAIM to ops address conversion (default: 1)"); 312 320 313 321 static int damon_reclaim_enabled_store(const char *val, 314 322 const struct kernel_param *kp)