]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
samples/damon: support automatic node address detection
authorYunjeong Mun <yunjeong.mun@sk.com>
Mon, 7 Jul 2025 23:59:18 +0000 (08:59 +0900)
committerAndrew Morton <akpm@linux-foundation.org>
Sun, 20 Jul 2025 01:59:47 +0000 (18:59 -0700)
This patch adds a new knob `detect_node_addresses`, which determines
whether the physical address range is set manually using the existing
knobs or automatically by the mtier module.  When `detect_node_addresses`
set to 'Y', mtier automatically converts node0 and node1 to their physical
addresses.  If set to 'N', it uses the existing 'node#_start_addr' and
'node#_end_addr' to define regions as before.

Link: https://lkml.kernel.org/r/20250707235919.513-1-yunjeong.mun@sk.com
Signed-off-by: Yunjeong Mun <yunjeong.mun@sk.com>
Suggested-by: Honggyu Kim <honggyu.kim@sk.com>
Reviewed-by: SeongJae Park <sj@kernel.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
samples/damon/mtier.c

index 42e14df16f44afe1e45098655a3166b077f1bca5..7ebd352138e4f21a51079eba5278a5e361575c47 100644 (file)
@@ -47,8 +47,29 @@ static bool enabled __read_mostly;
 module_param_cb(enabled, &enabled_param_ops, &enabled, 0600);
 MODULE_PARM_DESC(enabled, "Enable or disable DAMON_SAMPLE_MTIER");
 
+static bool detect_node_addresses __read_mostly;
+module_param(detect_node_addresses, bool, 0600);
+
 static struct damon_ctx *ctxs[2];
 
+struct region_range {
+       phys_addr_t start;
+       phys_addr_t end;
+};
+
+static int nid_to_phys(int target_node, struct region_range *range)
+{
+       if (!node_online(target_node)) {
+               pr_err("NUMA node %d is not online\n", target_node);
+               return -EINVAL;
+       }
+
+       range->start = PFN_PHYS(node_start_pfn(target_node));
+       range->end  = PFN_PHYS(node_end_pfn(target_node));
+
+       return 0;
+}
+
 static struct damon_ctx *damon_sample_mtier_build_ctx(bool promote)
 {
        struct damon_ctx *ctx;
@@ -58,6 +79,8 @@ static struct damon_ctx *damon_sample_mtier_build_ctx(bool promote)
        struct damos *scheme;
        struct damos_quota_goal *quota_goal;
        struct damos_filter *filter;
+       struct region_range addr;
+       int ret;
 
        ctx = damon_new_ctx();
        if (!ctx)
@@ -87,9 +110,17 @@ static struct damon_ctx *damon_sample_mtier_build_ctx(bool promote)
        if (!target)
                goto free_out;
        damon_add_target(ctx, target);
-       region = damon_new_region(
-                       promote ? node1_start_addr : node0_start_addr,
-                       promote ? node1_end_addr : node0_end_addr);
+
+       if (detect_node_addresses) {
+               ret = promote ? nid_to_phys(1, &addr) : nid_to_phys(0, &addr);
+               if (ret)
+                       goto free_out;
+       } else {
+               addr.start = promote ? node1_start_addr : node0_start_addr;
+               addr.end = promote ? node1_end_addr : node0_end_addr;
+       }
+
+       region = damon_new_region(addr.start, addr.end);
        if (!region)
                goto free_out;
        damon_add_region(region, target);