linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: Quanmin Yan <yanquanmin1@huawei.com>
To: <sj@kernel.org>
Cc: <akpm@linux-foundation.org>, <damon@lists.linux.dev>,
	<linux-kernel@vger.kernel.org>, <linux-mm@kvack.org>,
	<yanquanmin1@huawei.com>, <wangkefeng.wang@huawei.com>,
	<zuoze1@huawei.com>
Subject: [RFC PATCH -next 11/16] mm/damon: add addr_unit for DAMON_RECLAIM and LRU_SORT
Date: Wed, 13 Aug 2025 13:07:01 +0800	[thread overview]
Message-ID: <20250813050706.1564229-12-yanquanmin1@huawei.com> (raw)
In-Reply-To: <20250813050706.1564229-1-yanquanmin1@huawei.com>

In module DAMON_RECLAIM and DAMON_LRU_SORT, the damon_ctx is
independent of the core, necessitating dedicated addr_unit
integration for these features.
Additionally, if the input monitor_region_start and monitor_region_end
are both 0 while addr_unit is set to a non-zero valuethe default
system RAM range should be divided by addr_unit.

Signed-off-by: Quanmin Yan <yanquanmin1@huawei.com>
---
 include/linux/damon.h     |  4 +++-
 mm/damon/core.c           | 14 ++++++++++----
 mm/damon/lru_sort.c       | 16 +++++++++++++---
 mm/damon/modules-common.c |  5 ++++-
 mm/damon/modules-common.h |  2 +-
 mm/damon/reclaim.c        | 16 +++++++++++++---
 mm/damon/stat.c           |  2 +-
 7 files changed, 45 insertions(+), 14 deletions(-)

diff --git a/include/linux/damon.h b/include/linux/damon.h
index b85c6c669cd0..1b7b4cf1a3c5 100644
--- a/include/linux/damon.h
+++ b/include/linux/damon.h
@@ -942,7 +942,9 @@ int damon_call(struct damon_ctx *ctx, struct damon_call_control *control);
 int damos_walk(struct damon_ctx *ctx, struct damos_walk_control *control);
 
 int damon_set_region_biggest_system_ram_default(struct damon_target *t,
-				unsigned long *start, unsigned long *end);
+						unsigned long *start,
+						unsigned long *end,
+						unsigned long addr_unit);
 
 #endif	/* CONFIG_DAMON */
 
diff --git a/mm/damon/core.c b/mm/damon/core.c
index 1a8d3009d606..803c30f64b94 100644
--- a/mm/damon/core.c
+++ b/mm/damon/core.c
@@ -2714,6 +2714,7 @@ static bool damon_find_biggest_system_ram(unsigned long *start,
  * @t:		The monitoring target to set the region.
  * @start:	The pointer to the start address of the region.
  * @end:	The pointer to the end address of the region.
+ * @addr_unit:	Scale factor for core to ops address conversion.
  *
  * This function sets the region of @t as requested by @start and @end.  If the
  * values of @start and @end are zero, however, this function finds the biggest
@@ -2724,16 +2725,21 @@ static bool damon_find_biggest_system_ram(unsigned long *start,
  * Return: 0 on success, negative error code otherwise.
  */
 int damon_set_region_biggest_system_ram_default(struct damon_target *t,
-			unsigned long *start, unsigned long *end)
+						unsigned long *start,
+						unsigned long *end,
+						unsigned long addr_unit)
 {
 	struct damon_addr_range addr_range;
 
 	if (*start > *end)
 		return -EINVAL;
 
-	if (!*start && !*end &&
-		!damon_find_biggest_system_ram(start, end))
-		return -EINVAL;
+	if (!*start && !*end) {
+		if (!damon_find_biggest_system_ram(start, end) || !addr_unit)
+			return -EINVAL;
+		*start /= addr_unit;
+		*end /= addr_unit;
+	}
 
 	addr_range.start = *start;
 	addr_range.end = *end;
diff --git a/mm/damon/lru_sort.c b/mm/damon/lru_sort.c
index 151a9de5ad8b..8107d08c5e4b 100644
--- a/mm/damon/lru_sort.c
+++ b/mm/damon/lru_sort.c
@@ -111,6 +111,14 @@ 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_LRU_SORT to ops address conversion.
+ *
+ * This parameter is used to convert to the actual physical address.
+ */
+static unsigned long addr_unit __read_mostly = 1;
+module_param(addr_unit, ulong, 0600);
+
 /*
  * PID of the DAMON thread
  *
@@ -194,7 +202,8 @@ static int damon_lru_sort_apply_parameters(void)
 	unsigned int hot_thres, cold_thres;
 	int err;
 
-	err = damon_modules_new_paddr_ctx_target(&param_ctx, &param_target);
+	err = damon_modules_new_paddr_ctx_target(&param_ctx, &param_target,
+			addr_unit);
 	if (err)
 		return err;
 
@@ -221,7 +230,8 @@ static int damon_lru_sort_apply_parameters(void)
 
 	err = damon_set_region_biggest_system_ram_default(param_target,
 					&monitor_region_start,
-					&monitor_region_end);
+					&monitor_region_end,
+					addr_unit);
 	if (err)
 		goto out;
 	err = damon_commit_ctx(ctx, param_ctx);
@@ -323,7 +333,7 @@ MODULE_PARM_DESC(enabled,
 
 static int __init damon_lru_sort_init(void)
 {
-	int err = damon_modules_new_paddr_ctx_target(&ctx, &target);
+	int err = damon_modules_new_paddr_ctx_target(&ctx, &target, 1);
 
 	if (err)
 		goto out;
diff --git a/mm/damon/modules-common.c b/mm/damon/modules-common.c
index 86d58f8c4f63..613b7cc99368 100644
--- a/mm/damon/modules-common.c
+++ b/mm/damon/modules-common.c
@@ -13,9 +13,10 @@
  * Allocate, set, and return a DAMON context for the physical address space.
  * @ctxp:	Pointer to save the point to the newly created context
  * @targetp:	Pointer to save the point to the newly created target
+ * @addr_unit:	Scale factor for modules to ops address conversion.
  */
 int damon_modules_new_paddr_ctx_target(struct damon_ctx **ctxp,
-		struct damon_target **targetp)
+		struct damon_target **targetp, unsigned long addr_unit)
 {
 	struct damon_ctx *ctx;
 	struct damon_target *target;
@@ -24,6 +25,8 @@ int damon_modules_new_paddr_ctx_target(struct damon_ctx **ctxp,
 	if (!ctx)
 		return -ENOMEM;
 
+	ctx->addr_unit = addr_unit;
+
 	if (damon_select_ops(ctx, DAMON_OPS_PADDR)) {
 		damon_destroy_ctx(ctx);
 		return -EINVAL;
diff --git a/mm/damon/modules-common.h b/mm/damon/modules-common.h
index f103ad556368..c7048a449321 100644
--- a/mm/damon/modules-common.h
+++ b/mm/damon/modules-common.h
@@ -46,4 +46,4 @@
 			0400);
 
 int damon_modules_new_paddr_ctx_target(struct damon_ctx **ctxp,
-		struct damon_target **targetp);
+		struct damon_target **targetp, unsigned long addr_unit);
diff --git a/mm/damon/reclaim.c b/mm/damon/reclaim.c
index 3c71b4596676..0e11b121d693 100644
--- a/mm/damon/reclaim.c
+++ b/mm/damon/reclaim.c
@@ -128,6 +128,14 @@ 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 is used to convert to the actual physical address.
+ */
+static unsigned long addr_unit __read_mostly = 1;
+module_param(addr_unit, ulong, 0600);
+
 /*
  * Skip anonymous pages reclamation.
  *
@@ -190,7 +198,8 @@ static int damon_reclaim_apply_parameters(void)
 	struct damos_filter *filter;
 	int err;
 
-	err = damon_modules_new_paddr_ctx_target(&param_ctx, &param_target);
+	err = damon_modules_new_paddr_ctx_target(&param_ctx, &param_target,
+			addr_unit);
 	if (err)
 		return err;
 
@@ -229,7 +238,8 @@ static int damon_reclaim_apply_parameters(void)
 
 	err = damon_set_region_biggest_system_ram_default(param_target,
 					&monitor_region_start,
-					&monitor_region_end);
+					&monitor_region_end,
+					addr_unit);
 	if (err)
 		goto out;
 	err = damon_commit_ctx(ctx, param_ctx);
@@ -327,7 +337,7 @@ MODULE_PARM_DESC(enabled,
 
 static int __init damon_reclaim_init(void)
 {
-	int err = damon_modules_new_paddr_ctx_target(&ctx, &target);
+	int err = damon_modules_new_paddr_ctx_target(&ctx, &target, 1);
 
 	if (err)
 		goto out;
diff --git a/mm/damon/stat.c b/mm/damon/stat.c
index 87bcd8866d4b..ae7377e7409f 100644
--- a/mm/damon/stat.c
+++ b/mm/damon/stat.c
@@ -181,7 +181,7 @@ static struct damon_ctx *damon_stat_build_ctx(void)
 	if (!target)
 		goto free_out;
 	damon_add_target(ctx, target);
-	if (damon_set_region_biggest_system_ram_default(target, &start, &end))
+	if (damon_set_region_biggest_system_ram_default(target, &start, &end, ctx->addr_unit))
 		goto free_out;
 	return ctx;
 free_out:
-- 
2.34.1



  parent reply	other threads:[~2025-08-13  3:53 UTC|newest]

Thread overview: 51+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-08-13  5:06 [RFC PATCH -next 00/16] mm/damon: support ARM32 with LPAE Quanmin Yan
2025-08-13  5:06 ` [RFC PATCH -next 01/16] mm/damon/core: add damon_ctx->addr_unit Quanmin Yan
2025-08-13  5:06 ` [RFC PATCH -next 02/16] mm/damon/paddr: support addr_unit for access monitoring Quanmin Yan
2025-08-13  5:06 ` [RFC PATCH -next 03/16] mm/damon/paddr: support addr_unit for DAMOS_PAGEOUT Quanmin Yan
2025-08-19  6:18   ` SeongJae Park
2025-08-19  6:26     ` SeongJae Park
2025-08-19 14:18       ` Quanmin Yan
2025-08-19 15:53         ` SeongJae Park
2025-08-13  5:06 ` [RFC PATCH -next 04/16] mm/damon/paddr: support addr_unit for DAMOS_LRU_[DE]PRIO Quanmin Yan
2025-08-19  6:19   ` SeongJae Park
2025-08-19  6:26     ` SeongJae Park
2025-08-13  5:06 ` [RFC PATCH -next 05/16] mm/damon/paddr: support addr_unit for MIGRATE_{HOT,COLD} Quanmin Yan
2025-08-19  6:21   ` SeongJae Park
2025-08-19  6:27     ` SeongJae Park
2025-08-13  5:06 ` [RFC PATCH -next 06/16] mm/damon/paddr: support addr_unit for DAMOS_STAT Quanmin Yan
2025-08-19  6:22   ` SeongJae Park
2025-08-19  6:27     ` SeongJae Park
2025-08-13  5:06 ` [RFC PATCH -next 07/16] mm/damon/sysfs: implement addr_unit file under context dir Quanmin Yan
2025-08-19  6:24   ` SeongJae Park
2025-08-19 14:45     ` Quanmin Yan
2025-08-19 15:56       ` SeongJae Park
2025-08-13  5:06 ` [RFC PATCH -next 08/16] Docs/mm/damon/design: document 'address unit' parameter Quanmin Yan
2025-08-13  5:06 ` [RFC PATCH -next 09/16] Docs/admin-guide/mm/damon/usage: document addr_unit file Quanmin Yan
2025-08-13  5:07 ` [RFC PATCH -next 10/16] Docs/ABI/damon: " Quanmin Yan
2025-08-13  5:07 ` Quanmin Yan [this message]
2025-08-13 16:36   ` [RFC PATCH -next 11/16] mm/damon: add addr_unit for DAMON_RECLAIM and LRU_SORT SeongJae Park
2025-08-14 12:59     ` Quanmin Yan
2025-08-14 16:11       ` SeongJae Park
2025-08-19 14:59         ` Quanmin Yan
2025-08-13  5:07 ` [RFC PATCH -next 12/16] mm/damon: add damon_ctx->min_region and damon_target->min_region Quanmin Yan
2025-08-13 16:49   ` SeongJae Park
2025-08-19 14:52     ` Quanmin Yan
2025-08-13  5:07 ` [RFC PATCH -next 13/16] mm/damon/sysfs: ensure valid addr_unit setting in damon_sysfs_apply_inputs() Quanmin Yan
2025-08-13 17:02   ` SeongJae Park
2025-08-20  8:45     ` Quanmin Yan
2025-08-13  5:07 ` [RFC PATCH -next 14/16] mm/damon/core: convert sz to byte units when updating state Quanmin Yan
2025-08-13 17:08   ` SeongJae Park
2025-08-20 10:10     ` Quanmin Yan
2025-08-13  5:07 ` [RFC PATCH -next 15/16] mm/damon: the byte statistics data type in damos_stat uses unsigned long long Quanmin Yan
2025-08-13 17:10   ` SeongJae Park
2025-08-20  9:54     ` Quanmin Yan
2025-08-20 19:57       ` SeongJae Park
2025-08-13  5:07 ` [RFC PATCH -next 16/16] mm/damon/core: handle quota->esz overflow issues Quanmin Yan
2025-08-13 17:15   ` SeongJae Park
2025-08-20 10:06     ` Quanmin Yan
2025-08-13 17:25 ` [RFC PATCH -next 00/16] mm/damon: support ARM32 with LPAE SeongJae Park
2025-08-14  0:57   ` SeongJae Park
2025-08-14 14:07     ` Quanmin Yan
2025-08-14 16:04       ` SeongJae Park
2025-08-20 10:19         ` Quanmin Yan
2025-08-13 17:28 ` 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=20250813050706.1564229-12-yanquanmin1@huawei.com \
    --to=yanquanmin1@huawei.com \
    --cc=akpm@linux-foundation.org \
    --cc=damon@lists.linux.dev \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=sj@kernel.org \
    --cc=wangkefeng.wang@huawei.com \
    --cc=zuoze1@huawei.com \
    /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