linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 0/2] mm/damon: add addr_unit for DAMON_LRU_SORT and DAMON_RECLAIM
@ 2025-09-10 11:32 Quanmin Yan
  2025-09-10 11:32 ` [PATCH 1/2] mm/damon/lru_sort: support addr_unit for DAMON_LRU_SORT Quanmin Yan
  2025-09-10 11:32 ` [PATCH 2/2] mm/damon/reclaim: support addr_unit for DAMON_RECLAIM Quanmin Yan
  0 siblings, 2 replies; 5+ messages in thread
From: Quanmin Yan @ 2025-09-10 11:32 UTC (permalink / raw)
  To: sj
  Cc: akpm, damon, linux-kernel, linux-mm, yanquanmin1,
	wangkefeng.wang, zuoze1

In DAMON_LRU_SORT and DAMON_RECLAIM, damon_ctx is independent
of the core. Add addr_unit to these modules to support systems
like ARM32 with LPAE.

Quanmin Yan (2):
  mm/damon/lru_sort: support addr_unit for DAMON_LRU_SORT
  mm/damon/reclaim: support addr_unit for DAMON_RECLAIM

 mm/damon/lru_sort.c | 40 ++++++++++++++++++++++++++++++++++++++++
 mm/damon/reclaim.c  | 40 ++++++++++++++++++++++++++++++++++++++++
 2 files changed, 80 insertions(+)

-- 
2.43.0



^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PATCH 1/2] mm/damon/lru_sort: support addr_unit for DAMON_LRU_SORT
  2025-09-10 11:32 [PATCH 0/2] mm/damon: add addr_unit for DAMON_LRU_SORT and DAMON_RECLAIM Quanmin Yan
@ 2025-09-10 11:32 ` Quanmin Yan
  2025-09-11  2:19   ` SeongJae Park
  2025-09-10 11:32 ` [PATCH 2/2] mm/damon/reclaim: support addr_unit for DAMON_RECLAIM Quanmin Yan
  1 sibling, 1 reply; 5+ messages in thread
From: Quanmin Yan @ 2025-09-10 11:32 UTC (permalink / raw)
  To: sj
  Cc: akpm, damon, linux-kernel, linux-mm, yanquanmin1,
	wangkefeng.wang, zuoze1

Implement a sysfs file to expose addr_unit for DAMON_LRU_SORT
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.

Signed-off-by: Quanmin Yan <yanquanmin1@huawei.com>
---
 mm/damon/lru_sort.c | 40 ++++++++++++++++++++++++++++++++++++++++
 1 file changed, 40 insertions(+)

diff --git a/mm/damon/lru_sort.c b/mm/damon/lru_sort.c
index b5a5ed16a7a5..14d31009c09e 100644
--- a/mm/damon/lru_sort.c
+++ b/mm/damon/lru_sort.c
@@ -111,6 +111,13 @@ 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 must not be set to 0.
+ */
+static unsigned long addr_unit __read_mostly = 1;
+
 /*
  * PID of the DAMON thread
  *
@@ -198,6 +205,15 @@ static int damon_lru_sort_apply_parameters(void)
 	if (err)
 		return err;
 
+	/*
+	 * If monitor_region_start/end are unset, always silently
+	 * reset addr_unit to 1.
+	 */
+	if (!monitor_region_start && !monitor_region_end)
+		addr_unit = 1;
+	param_ctx->addr_unit = addr_unit;
+	param_ctx->min_sz_region = max(DAMON_MIN_REGION / addr_unit, 1);
+
 	if (!damon_lru_sort_mon_attrs.sample_interval) {
 		err = -EINVAL;
 		goto out;
@@ -290,6 +306,30 @@ static int damon_lru_sort_turn(bool on)
 	return damon_call(ctx, &call_control);
 }
 
+static int damon_lru_sort_addr_unit_store(const char *val,
+		const struct kernel_param *kp)
+{
+	unsigned long input_addr_unit;
+	int err = kstrtoul(val, 0, &input_addr_unit);
+
+	if (err)
+		return err;
+	if (!input_addr_unit)
+		return -EINVAL;
+
+	addr_unit = input_addr_unit;
+	return 0;
+}
+
+static const struct kernel_param_ops addr_unit_param_ops = {
+	.set = damon_lru_sort_addr_unit_store,
+	.get = param_get_ulong,
+};
+
+module_param_cb(addr_unit, &addr_unit_param_ops, &addr_unit, 0600);
+MODULE_PARM_DESC(addr_unit,
+	"Scale factor for DAMON_LRU_SORT to ops address conversion (default: 1)");
+
 static int damon_lru_sort_enabled_store(const char *val,
 		const struct kernel_param *kp)
 {
-- 
2.43.0



^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PATCH 2/2] mm/damon/reclaim: support addr_unit for DAMON_RECLAIM
  2025-09-10 11:32 [PATCH 0/2] mm/damon: add addr_unit for DAMON_LRU_SORT and DAMON_RECLAIM Quanmin Yan
  2025-09-10 11:32 ` [PATCH 1/2] mm/damon/lru_sort: support addr_unit for DAMON_LRU_SORT Quanmin Yan
@ 2025-09-10 11:32 ` Quanmin Yan
  2025-09-11  2:20   ` SeongJae Park
  1 sibling, 1 reply; 5+ messages in thread
From: Quanmin Yan @ 2025-09-10 11:32 UTC (permalink / raw)
  To: sj
  Cc: akpm, damon, linux-kernel, linux-mm, yanquanmin1,
	wangkefeng.wang, zuoze1

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.

Signed-off-by: Quanmin Yan <yanquanmin1@huawei.com>
---
 mm/damon/reclaim.c | 40 ++++++++++++++++++++++++++++++++++++++++
 1 file changed, 40 insertions(+)

diff --git a/mm/damon/reclaim.c b/mm/damon/reclaim.c
index fb7c982a0018..590f9d6c55ef 100644
--- a/mm/damon/reclaim.c
+++ b/mm/damon/reclaim.c
@@ -128,6 +128,13 @@ 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 must not be set to 0.
+ */
+static unsigned long addr_unit __read_mostly = 1;
+
 /*
  * Skip anonymous pages reclamation.
  *
@@ -194,6 +201,15 @@ static int damon_reclaim_apply_parameters(void)
 	if (err)
 		return err;
 
+	/*
+	 * If monitor_region_start/end are unset, always silently
+	 * reset addr_unit to 1.
+	 */
+	if (!monitor_region_start && !monitor_region_end)
+		addr_unit = 1;
+	param_ctx->addr_unit = addr_unit;
+	param_ctx->min_sz_region = max(DAMON_MIN_REGION / addr_unit, 1);
+
 	if (!damon_reclaim_mon_attrs.aggr_interval) {
 		err = -EINVAL;
 		goto out;
@@ -294,6 +310,30 @@ static int damon_reclaim_turn(bool on)
 	return damon_call(ctx, &call_control);
 }
 
+static int damon_reclaim_addr_unit_store(const char *val,
+		const struct kernel_param *kp)
+{
+	unsigned long input_addr_unit;
+	int err = kstrtoul(val, 0, &input_addr_unit);
+
+	if (err)
+		return err;
+	if (!input_addr_unit)
+		return -EINVAL;
+
+	addr_unit = input_addr_unit;
+	return 0;
+}
+
+static const struct kernel_param_ops addr_unit_param_ops = {
+	.set = damon_reclaim_addr_unit_store,
+	.get = param_get_ulong,
+};
+
+module_param_cb(addr_unit, &addr_unit_param_ops, &addr_unit, 0600);
+MODULE_PARM_DESC(addr_unit,
+	"Scale factor for DAMON_RECLAIM to ops address conversion (default: 1)");
+
 static int damon_reclaim_enabled_store(const char *val,
 		const struct kernel_param *kp)
 {
-- 
2.43.0



^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH 1/2] mm/damon/lru_sort: support addr_unit for DAMON_LRU_SORT
  2025-09-10 11:32 ` [PATCH 1/2] mm/damon/lru_sort: support addr_unit for DAMON_LRU_SORT Quanmin Yan
@ 2025-09-11  2:19   ` SeongJae Park
  0 siblings, 0 replies; 5+ messages in thread
From: SeongJae Park @ 2025-09-11  2:19 UTC (permalink / raw)
  To: Quanmin Yan
  Cc: SeongJae Park, akpm, damon, linux-kernel, linux-mm,
	wangkefeng.wang, zuoze1

On Wed, 10 Sep 2025 19:32:20 +0800 Quanmin Yan <yanquanmin1@huawei.com> wrote:

> Implement a sysfs file to expose addr_unit for DAMON_LRU_SORT
> 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.

Sounds fair to me.

> 
> Signed-off-by: Quanmin Yan <yanquanmin1@huawei.com>

Reviewed-by: SeongJae Park <sj@kernel.org>


Thanks,
SJ

[...]


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH 2/2] mm/damon/reclaim: support addr_unit for DAMON_RECLAIM
  2025-09-10 11:32 ` [PATCH 2/2] mm/damon/reclaim: support addr_unit for DAMON_RECLAIM Quanmin Yan
@ 2025-09-11  2:20   ` SeongJae Park
  0 siblings, 0 replies; 5+ messages in thread
From: SeongJae Park @ 2025-09-11  2:20 UTC (permalink / raw)
  To: Quanmin Yan
  Cc: SeongJae Park, akpm, damon, linux-kernel, linux-mm,
	wangkefeng.wang, zuoze1

On Wed, 10 Sep 2025 19:32:21 +0800 Quanmin Yan <yanquanmin1@huawei.com> wrote:

> 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.

Again, sounds fair to me.  Also this kind of information is helpful at
reviewing.  Thank you Quanmin :)

> 
> Signed-off-by: Quanmin Yan <yanquanmin1@huawei.com>

Reviewed-by: SeongJae Park <sj@kernel.org>


Thanks,
SJ

[...]


^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2025-09-11  2:20 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2025-09-10 11:32 [PATCH 0/2] mm/damon: add addr_unit for DAMON_LRU_SORT and DAMON_RECLAIM Quanmin Yan
2025-09-10 11:32 ` [PATCH 1/2] mm/damon/lru_sort: support addr_unit for DAMON_LRU_SORT Quanmin Yan
2025-09-11  2:19   ` SeongJae Park
2025-09-10 11:32 ` [PATCH 2/2] mm/damon/reclaim: support addr_unit for DAMON_RECLAIM Quanmin Yan
2025-09-11  2:20   ` SeongJae Park

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox