linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: Yunjeong Mun <yunjeong.mun@sk.com>
To: sj@kernel.org
Cc: akpm@linux-foundation.org, damon@lists.linux.dev,
	linux-mm@kvack.org, linux-kernel@vger.kernel.org,
	kernel_team@skhynix.com, honggyu.kim@sk.com
Subject: [RFC PATCH 2/2] samples/damon: add `migrate_hot` and `migrate_cold` knobs
Date: Tue,  1 Jul 2025 17:54:17 +0900	[thread overview]
Message-ID: <20250701085417.1734-3-yunjeong.mun@sk.com> (raw)
In-Reply-To: <20250701085417.1734-1-yunjeong.mun@sk.com>

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@sk.com>
Signed-off-by: Yunjeong Mun <yunjeong.mun@sk.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



  parent reply	other threads:[~2025-07-01  8:54 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-07-01  8:54 [RFC PATCH 0/2] samples/damon: improve expression of target region in mtier Yunjeong Mun
2025-07-01  8:54 ` [RFC PATCH 1/2] samples/damon: convert node id to physical address Yunjeong Mun
2025-07-01 23:54   ` SeongJae Park
2025-07-03  5:18     ` Yunjeong Mun
2025-07-03  5:24       ` SeongJae Park
2025-07-01  8:54 ` Yunjeong Mun [this message]
2025-07-02  0:08   ` [RFC PATCH 2/2] samples/damon: add `migrate_hot` and `migrate_cold` knobs SeongJae Park
2025-07-03  5:18     ` Yunjeong Mun
2025-07-03  5:28       ` SeongJae Park
2025-07-01 23:45 ` [RFC PATCH 0/2] samples/damon: improve expression of target region in mtier SeongJae Park

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20250701085417.1734-3-yunjeong.mun@sk.com \
    --to=yunjeong.mun@sk.com \
    --cc=akpm@linux-foundation.org \
    --cc=damon@lists.linux.dev \
    --cc=honggyu.kim@sk.com \
    --cc=kernel_team@skhynix.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=sj@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox