[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20250701085417.1734-3-yunjeong.mun@sk.com>
Date: Tue, 1 Jul 2025 17:54:17 +0900
From: Yunjeong Mun <yunjeong.mun@...com>
To: sj@...nel.org
Cc: akpm@...ux-foundation.org,
damon@...ts.linux.dev,
linux-mm@...ck.org,
linux-kernel@...r.kernel.org,
kernel_team@...ynix.com,
honggyu.kim@...com
Subject: [RFC PATCH 2/2] samples/damon: add `migrate_hot` and `migrate_cold` knobs
This patch introduces two new konbs for promotion/demotion:
`migrate_hot` and `migrate_cold`. It receives node ids for migration in
a comma-separated format as `<src,dst>`. The usage is as follows:
# demote pages from nid 0 to nid 1
$ echo 0,1 > /sys/module/mtier/parameters/migrate_cold
# promote pages from nid 1 to nid 0
$ echo 1,0 > /sys/module/mtier/parameters/migrate_hot
Susggested-by: Honggyu Kim <honggyu.kim@...com>
Signed-off-by: Yunjeong Mun <yunjeong.mun@...com>
---
samples/damon/mtier.c | 68 +++++++++++++++++++++++++++++++++++++++++--
1 file changed, 66 insertions(+), 2 deletions(-)
diff --git a/samples/damon/mtier.c b/samples/damon/mtier.c
index ba6938a89c21..55d2edb84d7e 100644
--- a/samples/damon/mtier.c
+++ b/samples/damon/mtier.c
@@ -11,6 +11,7 @@
#include <linux/init.h>
#include <linux/kernel.h>
#include <linux/module.h>
+#include <linux/string.h>
static unsigned long node0_mem_used_bp __read_mostly = 9970;
module_param(node0_mem_used_bp, ulong, 0600);
@@ -18,6 +19,32 @@ module_param(node0_mem_used_bp, ulong, 0600);
static unsigned long node0_mem_free_bp __read_mostly = 50;
module_param(node0_mem_free_bp, ulong, 0600);
+static int get_migrate_hot(
+ char *val, const struct kernel_param *kp);
+
+static const struct kernel_param_ops migrate_hot_ops = {
+ .set = param_set_charp,
+ .get = get_migrate_hot,
+};
+
+static char *migrate_hot __read_mostly = "";
+module_param_cb(migrate_hot, &migrate_hot_ops, &migrate_hot, 0600);
+MODULE_PARM_DESC(migrate_hot,
+ "Specify source and destination node id as a comma-seperated pair");
+
+static int get_migrate_cold(
+ char *val, const struct kernel_param *kp);
+
+static const struct kernel_param_ops migrate_cold_ops = {
+ .set = param_set_charp,
+ .get = get_migrate_cold,
+};
+
+static char *migrate_cold __read_mostly = "";
+module_param_cb(migrate_cold, &migrate_cold_ops, &migrate_cold, 0600);
+MODULE_PARM_DESC(migrate_cold,
+ "Specify source and destination node id as a comma-seperated pair");
+
static int damon_sample_mtier_enable_store(
const char *val, const struct kernel_param *kp);
@@ -37,6 +64,30 @@ struct region_range {
phys_addr_t end;
};
+static int parse_migrate_node(int *src, int *dst, bool promote) {
+ char *comma;
+ char buf[32];
+
+ if (promote)
+ strscpy(buf, migrate_hot, sizeof(buf));
+ else
+ strscpy(buf, migrate_cold, sizeof(buf));
+
+ comma = strchr(buf, ',');
+ if (!comma)
+ return -EINVAL;
+
+ *comma = '\0';
+ comma++;
+
+ if (kstrtoint(buf, 0, src))
+ return -EINVAL;
+ if (kstrtoint(comma, 0, dst))
+ return -EINVAL;
+
+ return 0;
+}
+
static int numa_info_init(int target_node, struct region_range *range) {
if (!node_online(target_node)) {
@@ -64,6 +115,7 @@ static struct damon_ctx *damon_sample_mtier_build_ctx(bool promote)
struct damos_quota_goal *quota_goal;
struct damos_filter *filter;
struct region_range addr;
+ int src, dst;
ctx = damon_new_ctx();
if (!ctx)
@@ -94,8 +146,10 @@ static struct damon_ctx *damon_sample_mtier_build_ctx(bool promote)
goto free_out;
damon_add_target(ctx, target);
- int ret = promote ? numa_info_init(1, &addr) : numa_info_init(0, &addr);
- if (ret)
+ if (parse_migrate_node(&src, &dst, promote))
+ goto free_out;
+
+ if (numa_info_init(src, &addr))
goto free_out;
region = damon_new_region(addr.start, addr.end);
@@ -171,6 +225,16 @@ static void damon_sample_mtier_stop(void)
damon_destroy_ctx(ctxs[1]);
}
+static int get_migrate_hot(char *buf, const struct kernel_param *kp)
+{
+ return scnprintf(buf, PAGE_SIZE, "%s", migrate_hot);
+}
+
+static int get_migrate_cold(char *buf, const struct kernel_param *kp)
+{
+ return scnprintf(buf, PAGE_SIZE, "%s", migrate_cold);
+}
+
static int damon_sample_mtier_enable_store(
const char *val, const struct kernel_param *kp)
{
--
2.34.1
Powered by blists - more mailing lists