Skip to contentSkip to conversation

mm/damon/reclaim,lru_sort: monitor all system rams by default

PATCH Applied SeongJae Park 2 participants 17 messages Apr 29

Subsystems (4)
lore
Share & tools
lore

SeongJae Park

author maintainer
#0 lore raw

cover mm/damon/reclaim,lru_sort: monitor all system rams by default

DAMON_RECLAIM and DAMON_LRU_SORT set the biggest 'System RAM' resource of the system as the default monitoring target address range. The main intention behind the design is to minimize the overhead coming from monitoring of non-System RAM areas.

This could result in an odd setup when there are multiple discrete System RAMs of considerable sizes. For example, there are System RAMs each having 500 GiB size. In this case, only the first 500 GiB will be set as the monitoring region by default. This is particularly common on NUMA systems. Hence the modules allow users to set the monitoring target address range using the module parameters if the default setup doesn't work for them. In other words, the current design trades ease of setup for lower overhead.

However, because DAMON utilizes the sampling based access check and the adaptive regions adjustment mechanisms, the overhead from the monitoring of non-System RAM areas should be negligible in most setups. Meanwhile, the setup complexity is causing real headaches for users who need to run those modules on various types of systems. That is, the current tradeoff is not a good deal.

Set the physical address range that can cover all System RAM areas of the system as the default monitoring regions for DAMON_RECLAIM and DAMON_LRU_SORT.

Technically speaking, this is changing documented behavior. However, it makes no sense to believe there is a real use case that really depends on the old weird default behavior. If the old default behavior was working for them in the reasonable way, this change will only add a negligible amount of monitoring overhead. If it didn't work, the users may already be using manual monitoring regions setup, and they will not be affected by this change.

Patches Sequence
================

Patch 1 introduces a new core function that will be used for the new default monitoring target region setup. Patch 2 and 3 update DAMON_RECLAIM and DAMON_LRU_SORT to use the new function instead of the old one, respectively. Patch 4 removes the old core function that was replaced by the new one, as there is no more user of it. Patch 5 updates DAMON_STAT to use the new one instead of its in-house nearly-duplicate self implementation of the functionality. Finally patches 6 and 7 update the DAMON_RECLAIM and DAMON_LRU_SORT user documentation for the new behaviors, respectively.

Changes from RFC
- rfc: https://lore.kernel.org/[email protected]
- Fix typos: s/phiscal/physical/

SeongJae Park (7):
mm/damon: introduce damon_set_region_system_rams_default() mm/damon/reclaim: cover all system rams
mm/damon/lru_sort: cover all system rams
mm/damon/core: remove damon_set_region_biggest_system_ram_default() mm/damon/stat: use damon_set_region_system_rams_default() Docs/admin-guide/mm/damon/reclaim: update for entire memory monitoring Docs/admin-guide/mm/damon/lru_sort: update for entire memory
monitoring

 .../admin-guide/mm/damon/lru_sort.rst         |  6 ++-
 .../admin-guide/mm/damon/reclaim.rst          |  6 ++-
 include/linux/damon.h                         |  2 +-
 mm/damon/core.c                               | 49 +++++++++--------
 mm/damon/lru_sort.c                           |  8 +--
 mm/damon/reclaim.c                            | 14 ++---
 mm/damon/stat.c                               | 53 ++-----------------
 7 files changed, 50 insertions(+), 88 deletions(-)

base-commit: 01b1d4a72970ced030ffe246ba99c961c746527d

Signature · 1 line
2.47.3
author maintainer
#1 lore raw

PATCH 1/7 mm/damon: introduce damon_set_region_system_rams_default()

damon_set_region_biggest_system_ram_default() sets the monitoring target region as the caller requested. If the caller didn't specify the region, it finds the biggest System RAM of the system and sets it as the target region. When there are more than one considerable size of System RAM resources in the system, the default target setup makes no sense. Introduce a variant, namely damon_set_region_system_rams_default(). It sets a physical address range that covers all System RAM resources as the default target region.

---
 include/linux/damon.h |  5 +++
 mm/damon/core.c       | 77 ++++++++++++++++++++++++++++++++++++++++---
 2 files changed, 77 insertions(+), 5 deletions(-)
include/linux/damon.h +5 -0
index f2370a3a4a9a3..f656908b2d389 100644
@@ -1010,6 +1010,11 @@ int damon_kdamond_pid(struct damon_ctx *ctx);
 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_system_rams_default(struct damon_target *t,
+				unsigned long *start, unsigned long *end,
+				unsigned long addr_unit,
+				unsigned long min_region_sz);
+
 int damon_set_region_biggest_system_ram_default(struct damon_target *t,
 				unsigned long *start, unsigned long *end,
 				unsigned long addr_unit,
mm/damon/core.c +72 -5

92 lines not on this page · raw message

Signature · 1 line
2.47.3
#2 lore raw

Re: [PATCH 1/7] mm/damon: introduce damon_set_region_system_rams_default()

Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider: - [High] The default region setup creates a single contiguous bounding box encompassing all System RAM…

Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
- [High] The default region setup creates a single contiguous bounding box encompassing all System RAM resources, incorrectly including unpopulated memory holes.
- [High] Integer overflow during physical address boundary calculation (arg.res.end + 1) can cause DAMON initialization to fail.
--

commit cd855b0d7d334ccf9a13e1331105a3281e5b0aeb
Author: SeongJae Park <[email protected]>

mm/damon: introduce damon_set_region_system_rams_default()

Introduces a default target setup for DAMON that sets a physical address range covering all System RAM resources when the caller doesn't specify a region.

Quoted 4 lines
mm/damon/core.c +0 -0
index 05e4bef367db..980a31cd3498 100644

[ ... ]

mm/damon/core.c static unsigned long damon_res_to_core_addr(resource_size_t ra, · line 3370

Quoted 10 lines
mm/damon/core.c +10 -0
+static bool damon_find_system_rams_range(unsigned long *start,
+		unsigned long *end, unsigned long addr_unit)
+{
+	struct damon_system_ram_range_walk_arg arg = {};
+
+	walk_system_ram_res(0, -1, &arg, damon_system_ram_walk_fn);
+	if (!arg.walked)
+		return false;
+	*start = damon_res_to_core_addr(arg.res.start, addr_unit);
+	*end = damon_res_to_core_addr(arg.res.end + 1, addr_unit);

Can arg.res.end + 1 overflow here?

If a 32-bit system has physical memory extending to the end of the address space, arg.res.end will be the maximum representable value. Adding 1 would overflow to 0, making *end 0. The subsequent check if (*end <= *start) would then evaluate to true, causing the function to silently return false and abort initialization with -EINVAL.

Quoted 4 lines
mm/damon/core.c +4 -0
+	if (*end <= *start)
+		return false;
+	return true;
+}

[ ... ]

Quoted 6 lines
mm/damon/core.c +6 -0
+int damon_set_region_system_rams_default(struct damon_target *t,
+			unsigned long *start, unsigned long *end,
+			unsigned long addr_unit, unsigned long min_region_sz)
+{
+	struct damon_addr_range addr_range;
+

mm/damon/core.c static unsigned long damon_res_to_core_addr(resource_size_t ra, · line 3408

Quoted 10 lines
mm/damon/core.c +10 -0
+	if (*start > *end)
+		return -EINVAL;
+
+	if (!*start && !*end &&
+		!damon_find_system_rams_range(start, end, addr_unit))
+		return -EINVAL;
+
+	addr_range.start = *start;
+	addr_range.end = *end;
+	return damon_set_regions(t, &addr_range, 1, min_region_sz);

Does this create a single bounding box encompassing all System RAM resources, including unpopulated memory holes?

On systems with sparse physical memory layouts, this combined range will encompass massive memory holes. Because DAMON uses uniform random sampling within a region to estimate access frequencies, samples landing in the gaps will inherently register as unaccessed, diluting the perceived access rates and preventing effective adaptive region splitting and merging.

Could the implementation instead construct an array of multiple ranges, one for each distinct System RAM resource, and pass them to damon_set_regions()?

Quoted 1 line

+}

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
author maintainer
#3 lore raw

Re: [PATCH 1/7] mm/damon: introduce damon_set_region_system_rams_default()

Quoted 3 lines · On Wed, 29 Apr 2026 04:39:02 +0000 [email protected] wrote:

Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
- [High] The default region setup creates a single contiguous bounding box encompassing all System RAM resources, incorrectly including unpopulated memory holes.
- [High] Integer overflow during physical address boundary calculation (arg.res.end + 1) can cause DAMON initialization to fail.

Both are not a blocker of this patch in my opinion. Please read below for details.

Quoted 29 lines

--

commit cd855b0d7d334ccf9a13e1331105a3281e5b0aeb
Author: SeongJae Park <[email protected]>

mm/damon: introduce damon_set_region_system_rams_default()

Introduces a default target setup for DAMON that sets a physical address range covering all System RAM resources when the caller doesn't specify a region.

Quoted 4 lines
mm/damon/core.c +0 -0
index 05e4bef367db..980a31cd3498 100644

[ ... ]

mm/damon/core.c static unsigned long damon_res_to_core_addr(resource_size_t ra, · line 3370

Quoted 10 lines
mm/damon/core.c +10 -0
+static bool damon_find_system_rams_range(unsigned long *start,
+		unsigned long *end, unsigned long addr_unit)
+{
+	struct damon_system_ram_range_walk_arg arg = {};
+
+	walk_system_ram_res(0, -1, &arg, damon_system_ram_walk_fn);
+	if (!arg.walked)
+		return false;
+	*start = damon_res_to_core_addr(arg.res.start, addr_unit);
+	*end = damon_res_to_core_addr(arg.res.end + 1, addr_unit);

Can arg.res.end + 1 overflow here?

Quoted 5 lines

If a 32-bit system has physical memory extending to the end of the address space, arg.res.end will be the maximum representable value. Adding 1 would overflow to 0, making *end 0. The subsequent check if (*end <= *start) would then evaluate to true, causing the function to silently return false and abort initialization with -EINVAL.

Yes, such corner case could exist. But, similar overflow-caused initialization could happen even before this patch, if the biggest System RAM's end address is same to the U32T_MAX. And even in the corner case, failing initialization shouldn't cause a real problem. The user could manually set the monitoring regions and work.

So, not a blocker of this patch.

Quoted 26 lines
Quoted 5 lines
mm/damon/core.c +4 -0
+	if (*end <= *start)
+		return false;
+	return true;
+}

[ ... ]

Quoted 6 lines
mm/damon/core.c +6 -0
+int damon_set_region_system_rams_default(struct damon_target *t,
+			unsigned long *start, unsigned long *end,
+			unsigned long addr_unit, unsigned long min_region_sz)
+{
+	struct damon_addr_range addr_range;
+

mm/damon/core.c static unsigned long damon_res_to_core_addr(resource_size_t ra, · line 3408

Quoted 10 lines
mm/damon/core.c +10 -0
+	if (*start > *end)
+		return -EINVAL;
+
+	if (!*start && !*end &&
+		!damon_find_system_rams_range(start, end, addr_unit))
+		return -EINVAL;
+
+	addr_range.start = *start;
+	addr_range.end = *end;
+	return damon_set_regions(t, &addr_range, 1, min_region_sz);

Does this create a single bounding box encompassing all System RAM resources, including unpopulated memory holes?

Quoted 5 lines

On systems with sparse physical memory layouts, this combined range will encompass massive memory holes. Because DAMON uses uniform random sampling within a region to estimate access frequencies, samples landing in the gaps will inherently register as unaccessed, diluting the perceived access rates and preventing effective adaptive region splitting and merging.

As also answered to the same previous questions, DAMON's adaptive regions adjustment mechanism should solve this accuracy issue.

So, not a blocker for this patch.

Quoted 4 lines

Could the implementation instead construct an array of multiple ranges, one for each distinct System RAM resource, and pass them to damon_set_regions()?

When the number of such distinct areas is high, because distict regions cannot be merged, it will degrade the accuracy. So, no. Like vaddr, adding a finite number of biggest gaps might make sense. But, it wouldn't be late to revist after such problematic real use case is found.

Thanks,
SJ

[...]

author maintainer
#4 lore raw

PATCH 2/7 mm/damon/reclaim: cover all system rams

In reply to SeongJae Park

DAMON_RECLAIM allows users to set the physical address range to monitor and do the work on. When users don't explicitly set the range, the biggest System RAM resource of the system is selected as the monitoring target address range. The intention was to reduce the overhead from monitoring non-System RAM areas because monitoring of non-System RAM may be meaningless. However, because of the sampling based access check and adaptive regions adjustment, the overhead should be negligible. It makes more sense to just cover all system rams of the system. Do so.

---
 mm/damon/reclaim.c | 14 +++++++-------
 1 file changed, 7 insertions(+), 7 deletions(-)
mm/damon/reclaim.c +7 -7
index b330ff1695907..a60ee800d63e9 100644
@@ -113,7 +113,8 @@ DEFINE_DAMON_MODULES_MON_ATTRS_PARAMS(damon_reclaim_mon_attrs);
  * Start of the target memory region in physical address.
  *
  * The start physical address of memory region that DAMON_RECLAIM will do work
- * against.  By default, biggest System RAM is used as the region.
+ * against.  By default, the system's entire physical memory is used as the
+ * region.
  */
 static unsigned long monitor_region_start __read_mostly;
 module_param(monitor_region_start, ulong, 0600);
@@ -122,7 +123,8 @@ module_param(monitor_region_start, ulong, 0600);
  * End of the target memory region in physical address.
  *
  * The end physical address of memory region that DAMON_RECLAIM will do work
- * against.  By default, biggest System RAM is used as the region.
+ * against.  By default, the system's entire physical memory is used as the
+ * region.
  */
 static unsigned long monitor_region_end __read_mostly;
 module_param(monitor_region_end, ulong, 0600);
@@ -232,11 +234,9 @@ static int damon_reclaim_apply_parameters(void)
 		damos_add_filter(scheme, filter);
 	}
 
-	err = damon_set_region_biggest_system_ram_default(param_target,
-					&monitor_region_start,
-					&monitor_region_end,
-					param_ctx->addr_unit,
-					param_ctx->min_region_sz);
+	err = damon_set_region_system_rams_default(param_target,
+			&monitor_region_start, &monitor_region_end,
+			param_ctx->addr_unit, param_ctx->min_region_sz);
 	if (err)
 		goto out;
 	err = damon_commit_ctx(ctx, param_ctx);
Signature · 1 line
2.47.3
#5 lore raw

Re: [PATCH 2/7] mm/damon/reclaim: cover all system rams

Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider: - [High] Massive single DAMON region spanning physical address holes causes CPU soft lockups and quota…

Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
- [High] Massive single DAMON region spanning physical address holes causes CPU soft lockups and quota starvation.
- [High] Time-of-Check to Time-of-Use (TOCTOU) vulnerability in damon_set_region_system_rams_default() leads to infinite loop and OOM panic. --

commit 179df0c96a01c49e5644b5cc1a9154fb63368993
Author: SeongJae Park <[email protected]>

mm/damon/reclaim: cover all system rams

This commit changes DAMON_RECLAIM to monitor the entire system RAM by default, rather than just the biggest System RAM region, to cover all available memory.

Quoted 4 lines
mm/damon/reclaim.c +0 -0
index b330ff169590..a60ee800d63e 100644

[ ... ]

mm/damon/reclaim.c static int damon_reclaim_apply_parameters(void) · line 239

Quoted 12 lines
mm/damon/reclaim.c +3 -5
@@ -232,11 +234,9 @@ static int damon_reclaim_apply_parameters(void)
 		damos_add_filter(scheme, filter);
 	}
 
-	err = damon_set_region_biggest_system_ram_default(param_target,
-					&monitor_region_start,
-					&monitor_region_end,
-					param_ctx->addr_unit,
-					param_ctx->min_region_sz);
+	err = damon_set_region_system_rams_default(param_target,
+			&monitor_region_start, &monitor_region_end,
+			param_ctx->addr_unit, param_ctx->min_region_sz);

Can monitor_region_start and monitor_region_end be modified concurrently via sysfs module parameters while this code is executing?

Looking at damon_set_region_system_rams_default(), the pointers are dereferenced multiple times:

mm/damon/core.c:damon_set_region_system_rams_default() {
	if (*start > *end)
		return -EINVAL;

	if (!*start && !*end &&
		!damon_find_system_rams_range(start, end, addr_unit))
		return -EINVAL;

	addr_range.start = *start;
	addr_range.end = *end;
	return damon_set_regions(t, &addr_range, 1, min_region_sz);
}

If a concurrent sysfs write alters the values between the initial check and the subsequent assignment, could this result in an inverted range where start is greater than end?

If an inverted range is passed to damon_set_regions(), the size calculation (end - start) could underflow to a massive value. When the thread later executes damon_apply_min_nr_regions(), it might enter an infinite loop trying to split the underflowed region, endlessly allocating damon_region objects.

Additionally, could damon_find_system_rams_range() create a single bounding box that spans massive unpopulated physical address holes on sparse memory systems?

Since DAMON applies schemes by linearly looping over the region page-by-page, would spinning over terabytes of holes without calling cond_resched() cause CPU soft lockups?

Furthermore, because these holes are never accessed, they might perfectly match PAGEOUT schemes. Could the massive region size (including holes) be incorrectly charged against the reclaim quota, instantly depleting it and preventing actual RAM from being reclaimed?

Would it be better to dynamically populate multiple regions (one for each RAM block) instead of using a single bounding box?

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=2
author maintainer
#6 lore raw

Re: [PATCH 2/7] mm/damon/reclaim: cover all system rams

Quoted 3 lines · On Wed, 29 Apr 2026 05:23:16 +0000 [email protected] wrote:

Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
- [High] Massive single DAMON region spanning physical address holes causes CPU soft lockups and quota starvation.
- [High] Time-of-Check to Time-of-Use (TOCTOU) vulnerability in damon_set_region_system_rams_default() leads to infinite loop and OOM panic.

No blocker of this patch in my opinion. Pleae read below for more details.

Quoted 22 lines

--

commit 179df0c96a01c49e5644b5cc1a9154fb63368993
Author: SeongJae Park <[email protected]>

mm/damon/reclaim: cover all system rams

This commit changes DAMON_RECLAIM to monitor the entire system RAM by default, rather than just the biggest System RAM region, to cover all available memory.

Quoted 4 lines
mm/damon/reclaim.c +0 -0
index b330ff169590..a60ee800d63e 100644

[ ... ]

Quoted 4 lines
mm/damon/reclaim.c +0 -0
@@ -232,11 +234,9 @@ static int damon_reclaim_apply_parameters(void)
 		damos_add_filter(scheme, filter);
 	}
 
Quoted 11 lines

mm/damon/reclaim.c static int damon_reclaim_apply_parameters(void) · line 239

Quoted 8 lines
mm/damon/reclaim.c +3 -5
-	err = damon_set_region_biggest_system_ram_default(param_target,
-					&monitor_region_start,
-					&monitor_region_end,
-					param_ctx->addr_unit,
-					param_ctx->min_region_sz);
+	err = damon_set_region_system_rams_default(param_target,
+			&monitor_region_start, &monitor_region_end,
+			param_ctx->addr_unit, param_ctx->min_region_sz);

Can monitor_region_start and monitor_region_end be modified concurrently via sysfs module parameters while this code is executing?

No.

The function can be invoked in three places.

1. damon_reclaim_init()
2. enabled parameter write callback
3. commit_inputs parameter write callback

Because init function is called before users can write to sysfs, path 1 cannot race with paths 2 and 3. Because parameter write callbacks are protected by kernel_param_lock, paths 2 and 3 cannot race each other.

Quoted 17 lines

Looking at damon_set_region_system_rams_default(), the pointers are dereferenced multiple times:

mm/damon/core.c:damon_set_region_system_rams_default() {
	if (*start > *end)
		return -EINVAL;

	if (!*start && !*end &&
		!damon_find_system_rams_range(start, end, addr_unit))
		return -EINVAL;

	addr_range.start = *start;
	addr_range.end = *end;
	return damon_set_regions(t, &addr_range, 1, min_region_sz);
}
Quoted 8 lines

If a concurrent sysfs write alters the values between the initial check and the subsequent assignment, could this result in an inverted range where start is greater than end?

If an inverted range is passed to damon_set_regions(), the size calculation (end - start) could underflow to a massive value. When the thread later executes damon_apply_min_nr_regions(), it might enter an infinite loop trying to split the underflowed region, endlessly allocating damon_region objects.

So, such an issue cannot happen.

Quoted 8 lines

Additionally, could damon_find_system_rams_range() create a single bounding box that spans massive unpopulated physical address holes on sparse memory systems?

Since DAMON applies schemes by linearly looping over the region page-by-page, would spinning over terabytes of holes without calling cond_resched() cause CPU soft lockups?

Answered on RFC. To repeat, operations for the holes should be lightweight enough, since we will just see it is hole and move to next page. Users can manually set the monitoring regions.

Quoted 5 lines

Furthermore, because these holes are never accessed, they might perfectly match PAGEOUT schemes. Could the massive region size (including holes) be incorrectly charged against the reclaim quota, instantly depleting it and preventing actual RAM from being reclaimed?

Also answered on RFC. Users can manually set the regions for this kind of extremem corner case.

Quoted 3 lines

Would it be better to dynamically populate multiple regions (one for each RAM block) instead of using a single bounding box?

I answered this on the review to the first patch of this series.

Thanks,
SJ

[...]

author maintainer
#7 lore raw

PATCH 3/7 mm/damon/lru_sort: cover all system rams

In reply to SeongJae Park

DAMON_LRU_SORT allows users to set the physical address range to monitor and do the work on. When users don't explicitly set the range, the biggest system ram resource of the system is selected as the monitoring target address range. The intention was to reduce the overhead from monitoring non-System RAM areas because monitoring non-System RAM may be meaningless. However, because of the sampling based access check and adaptive regions adjustment, the overhead should be negligible. It makes more sense to just cover all system rams of the system. Do so.

---
 mm/damon/lru_sort.c | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)
mm/damon/lru_sort.c +5 -3
index 7569e471160a0..2eb559d913b62 100644
@@ -139,7 +139,8 @@ DEFINE_DAMON_MODULES_MON_ATTRS_PARAMS(damon_lru_sort_mon_attrs);
  * Start of the target memory region in physical address.
  *
  * The start physical address of memory region that DAMON_LRU_SORT will do work
- * against.  By default, biggest System RAM is used as the region.
+ * against.  By default, the system's entire physical memory is used as the
+ * region.
  */
 static unsigned long monitor_region_start __read_mostly;
 module_param(monitor_region_start, ulong, 0600);
@@ -148,7 +149,8 @@ module_param(monitor_region_start, ulong, 0600);
  * End of the target memory region in physical address.
  *
  * The end physical address of memory region that DAMON_LRU_SORT will do work
- * against.  By default, biggest System RAM is used as the region.
+ * against.  By default, the system's entire physical memory is used as the
+ * region.
  */
 static unsigned long monitor_region_end __read_mostly;
 module_param(monitor_region_end, ulong, 0600);
@@ -326,7 +328,7 @@ static int damon_lru_sort_apply_parameters(void)
 	if (err)
 		goto out;
 
-	err = damon_set_region_biggest_system_ram_default(param_target,
+	err = damon_set_region_system_rams_default(param_target,
 					&monitor_region_start,
 					&monitor_region_end,
 					param_ctx->addr_unit,
Signature · 1 line
2.47.3
#8 lore raw

Re: [PATCH 3/7] mm/damon/lru_sort: cover all system rams

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider: - [High] Single bounding box for sparse memory layouts causes soft lockups and algorithmic failure --

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [High] Single bounding box for sparse memory layouts causes soft lockups and algorithmic failure --

commit 692650636f4214ec9c2fa1c5d7fd43fe3bf049fe
Author: SeongJae Park <[email protected]>

mm/damon/lru_sort: cover all system rams

This commit changes the default monitoring region from the biggest System RAM resource to a single region that spans all system RAMs. This is intended to cover the entire physical memory instead of just the largest block.

Quoted 4 lines
mm/damon/lru_sort.c +0 -0
index 7569e471160a..2eb559d913b6 100644

[ ... ]

mm/damon/lru_sort.c static int damon_lru_sort_apply_parameters(void) · line 334

Quoted 9 lines
mm/damon/lru_sort.c +1 -1
@@ -326,7 +328,7 @@ static int damon_lru_sort_apply_parameters(void)
 	if (err)
 		goto out;
 
-	err = damon_set_region_biggest_system_ram_default(param_target,
+	err = damon_set_region_system_rams_default(param_target,
 					&monitor_region_start,
 					&monitor_region_end,
 					param_ctx->addr_unit,

Could this lead to a regression on systems with sparse memory layouts?

When creating a single bounding box from the first to the last physical address, systems with sparse memory like CXL or distant NUMA nodes could end up with a region containing terabytes of unpopulated physical address space.

Will this cause soft lockups during DAMOS operations?

If a scheme like PAGEOUT iterates linearly over this massive region in PAGE_SIZE increments, iterating over these large memory holes might stall the CPU and trigger the watchdog, since cond_resched() is typically placed after the loop.

Does this also cause an algorithmic regression with the sampling probability?

DAMON's adaptive logic merges adjacent regions with identical access frequencies. Since memory holes report 0 accesses, they might be aggressively merged with interspersed RAM into maximum-sized regions. Because sampling selects a single random address per region, the probability of actually sampling the populated RAM might drop to near zero.

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=3
author maintainer
#9 lore raw

Re: [PATCH 3/7] mm/damon/lru_sort: cover all system rams

Quoted 2 lines · On Wed, 29 Apr 2026 06:03:13 +0000 [email protected] wrote:

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [High] Single bounding box for sparse memory layouts causes soft lockups and algorithmic failure

Not a real issue in my opinion. Please read below for more details.

Quoted 41 lines

--

commit 692650636f4214ec9c2fa1c5d7fd43fe3bf049fe
Author: SeongJae Park <[email protected]>

mm/damon/lru_sort: cover all system rams

This commit changes the default monitoring region from the biggest System RAM resource to a single region that spans all system RAMs. This is intended to cover the entire physical memory instead of just the largest block.

Quoted 4 lines
mm/damon/lru_sort.c +0 -0
index 7569e471160a..2eb559d913b6 100644

[ ... ]

mm/damon/lru_sort.c static int damon_lru_sort_apply_parameters(void) · line 334

Quoted 9 lines
mm/damon/lru_sort.c +1 -1
@@ -326,7 +328,7 @@ static int damon_lru_sort_apply_parameters(void)
 	if (err)
 		goto out;
 
-	err = damon_set_region_biggest_system_ram_default(param_target,
+	err = damon_set_region_system_rams_default(param_target,
 					&monitor_region_start,
 					&monitor_region_end,
 					param_ctx->addr_unit,

Could this lead to a regression on systems with sparse memory layouts?

When creating a single bounding box from the first to the last physical address, systems with sparse memory like CXL or distant NUMA nodes could end up with a region containing terabytes of unpopulated physical address space.

Will this cause soft lockups during DAMOS operations?

If a scheme like PAGEOUT iterates linearly over this massive region in PAGE_SIZE increments, iterating over these large memory holes might stall the CPU and trigger the watchdog, since cond_resched() is typically placed after the loop.

Quoted 7 lines

Does this also cause an algorithmic regression with the sampling probability?

DAMON's adaptive logic merges adjacent regions with identical access frequencies. Since memory holes report 0 accesses, they might be aggressively merged with interspersed RAM into maximum-sized regions. Because sampling selects a single random address per region, the probability of actually sampling the populated RAM might drop to near zero.

Exactly same question to the one for the second patch of this series. My answer to it is also samely applied here. Not a real issue.

Thanks,
SJ

[...]

author maintainer
#10 lore raw

PATCH 4/7 mm/damon/core: remove damon_set_region_biggest_system_ram_default()

In reply to SeongJae Park

Now nobody is using damon_set_region_biggest_system_ram_default(). Remove it.

---
 include/linux/damon.h |  5 ----
 mm/damon/core.c       | 64 -------------------------------------------
 2 files changed, 69 deletions(-)
include/linux/damon.h +0 -5
index f656908b2d389..c7a31572689be 100644
@@ -1015,11 +1015,6 @@ int damon_set_region_system_rams_default(struct damon_target *t,
 				unsigned long addr_unit,
 				unsigned long min_region_sz);
 
-int damon_set_region_biggest_system_ram_default(struct damon_target *t,
-				unsigned long *start, unsigned long *end,
-				unsigned long addr_unit,
-				unsigned long min_region_sz);
-
 #endif	/* CONFIG_DAMON */
 
 #endif	/* _DAMON_H */
mm/damon/core.c +0 -64

70 lines not on this page · raw message

Signature · 1 line
2.47.3
author maintainer
#11 lore raw

PATCH 5/7 mm/damon/stat: use damon_set_region_system_rams_default()

In reply to SeongJae Park

damon_stat_set_moniotirng_region() is nearly a duplicate of the core function, damon_set_region_system_rams_default(). Use the core implementation.

---
 mm/damon/stat.c | 53 +++----------------------------------------------
 1 file changed, 3 insertions(+), 50 deletions(-)
mm/damon/stat.c +3 -50
index 3951b762cbddf..f4d3203e92639 100644
@@ -148,59 +148,12 @@ static int damon_stat_damon_call_fn(void *data)
 	return 0;
 }
 
-struct damon_stat_system_ram_range_walk_arg {
-	bool walked;
-	struct resource res;
-};
-
-static int damon_stat_system_ram_walk_fn(struct resource *res, void *arg)
-{
-	struct damon_stat_system_ram_range_walk_arg *a = arg;
-
-	if (!a->walked) {
-		a->walked = true;
-		a->res.start = res->start;
-	}
-	a->res.end = res->end;
-	return 0;
-}
-
-static unsigned long damon_stat_res_to_core_addr(resource_size_t ra,
-		unsigned long addr_unit)
-{
-	/*
-	 * Use div_u64() for avoiding linking errors related with __udivdi3,
-	 * __aeabi_uldivmod, or similar problems.  This should also improve the
-	 * performance optimization (read div_u64() comment for the detail).
-	 */
-	if (sizeof(ra) == 8 && sizeof(addr_unit) == 4)
-		return div_u64(ra, addr_unit);
-	return ra / addr_unit;
-}
-
-static int damon_stat_set_monitoring_region(struct damon_target *t,
-		unsigned long addr_unit, unsigned long min_region_sz)
-{
-	struct damon_addr_range addr_range;
-	struct damon_stat_system_ram_range_walk_arg arg = {};
-
-	walk_system_ram_res(0, -1, &arg, damon_stat_system_ram_walk_fn);
-	if (!arg.walked)
-		return -EINVAL;
-	addr_range.start = damon_stat_res_to_core_addr(
-			arg.res.start, addr_unit);
-	addr_range.end = damon_stat_res_to_core_addr(
-			arg.res.end + 1, addr_unit);
-	if (addr_range.end <= addr_range.start)
-		return -EINVAL;
-	return damon_set_regions(t, &addr_range, 1, min_region_sz);
-}
-
 static struct damon_ctx *damon_stat_build_ctx(void)
 {
 	struct damon_ctx *ctx;
 	struct damon_attrs attrs;
 	struct damon_target *target;
+	unsigned long start = 0, end = 0;
 
 	ctx = damon_new_ctx();
 	if (!ctx)
@@ -230,8 +183,8 @@ static struct damon_ctx *damon_stat_build_ctx(void)
 	if (!target)
 		goto free_out;
 	damon_add_target(ctx, target);
-	if (damon_stat_set_monitoring_region(target, ctx->addr_unit,
-				ctx->min_region_sz))
+	if (damon_set_region_system_rams_default(target, &start, &end,
+				ctx->addr_unit, ctx->min_region_sz))
 		goto free_out;
 	return ctx;
 free_out:
Signature · 1 line
2.47.3
author maintainer
#12 lore raw

PATCH 6/7 Docs/admin-guide/mm/damon/reclaim: update for entire memory monitoring

In reply to SeongJae Park

Update DAMON_RECLAIM usage document for the changed default monitoring target region selection.

---
 Documentation/admin-guide/mm/damon/reclaim.rst | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
Documentation/admin-guide/mm/damon/reclaim.rst +4 -2
index 01a34c215b66f..57ab8b1876506 100644
@@ -229,7 +229,8 @@ Start of target memory region in physical address.
 
 The start physical address of memory region that DAMON_RECLAIM will do work
 against.  That is, DAMON_RECLAIM will find cold memory regions in this region
-and reclaims.  By default, biggest System RAM is used as the region.
+and reclaims.  By default, the system's entire physical memory is used as the
+region.
 
 monitor_region_end
 ------------------
@@ -238,7 +239,8 @@ End of target memory region in physical address.
 
 The end physical address of memory region that DAMON_RECLAIM will do work
 against.  That is, DAMON_RECLAIM will find cold memory regions in this region
-and reclaims.  By default, biggest System RAM is used as the region.
+and reclaims.  By default, the system's entire physical memory is used as the
+region.
 
 addr_unit
 ---------
Signature · 1 line
2.47.3
#13 lore raw

Re: [PATCH 6/7] Docs/admin-guide/mm/damon/reclaim: update for entire memory monitoring

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider: - [Low] The commit updates the English documentation for DAMON_RECLAIM but fails to update the…

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Low] The commit updates the English documentation for DAMON_RECLAIM but fails to update the corresponding translated documents. --

commit 0775463e5909bcac92ff21d728b9a1b112304371
Author: SeongJae Park <[email protected]>

Docs/admin-guide/mm/damon/reclaim: update for entire memory monitoring

This commit updates the DAMON_RECLAIM usage document to reflect the new default monitoring target region selection, which now spans the system's entire physical memory instead of just the biggest System RAM region.

Documentation/admin-guide/mm/damon/reclaim.rst Start of target memory region in physical address. · line 233

Quoted 11 lines
Documentation/admin-guide/mm/damon/reclaim.rst +2 -1
index 01a34c215b66..57ab8b187650 100644
@@ -229,7 +229,8 @@ Start of target memory region in physical address.
 
 The start physical address of memory region that DAMON_RECLAIM will do work
 against.  That is, DAMON_RECLAIM will find cold memory regions in this region
-and reclaims.  By default, biggest System RAM is used as the region.
+and reclaims.  By default, the system's entire physical memory is used as the
+region.

Should the corresponding zh_CN and zh_TW translations be updated alongside this to keep them in sync? The translated documents currently still state that the biggest System RAM is used by default.

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=6
author maintainer
#14 lore raw

Re: [PATCH 6/7] Docs/admin-guide/mm/damon/reclaim: update for entire memory monitoring

Quoted 19 lines · On Wed, 29 Apr 2026 07:02:01 +0000 [email protected] wrote:

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Low] The commit updates the English documentation for DAMON_RECLAIM but fails to update the corresponding translated documents. --

commit 0775463e5909bcac92ff21d728b9a1b112304371
Author: SeongJae Park <[email protected]>

Docs/admin-guide/mm/damon/reclaim: update for entire memory monitoring

This commit updates the DAMON_RECLAIM usage document to reflect the new default monitoring target region selection, which now spans the system's entire physical memory instead of just the biggest System RAM region.

Quoted 6 lines
Documentation/admin-guide/mm/damon/reclaim.rst +0 -0
index 01a34c215b66..57ab8b187650 100644
@@ -229,7 +229,8 @@ Start of target memory region in physical address.
 
Quoted 9 lines

Documentation/admin-guide/mm/damon/reclaim.rst Start of target memory region in physical address. · line 233

Quoted 5 lines
Documentation/admin-guide/mm/damon/reclaim.rst +2 -1
 The start physical address of memory region that DAMON_RECLAIM will do work
 against.  That is, DAMON_RECLAIM will find cold memory regions in this region
-and reclaims.  By default, biggest System RAM is used as the region.
+and reclaims.  By default, the system's entire physical memory is used as the
+region.

Should the corresponding zh_CN and zh_TW translations be updated alongside this to keep them in sync? The translated documents currently still state that the biggest System RAM is used by default.

Updates of the translations are usually done by the contributors. Hopefully they will do, and I will help if needed.

Thanks,
SJ

[...]

author maintainer
#15 lore raw

PATCH 7/7 Docs/admin-guide/mm/damon/lru_sort: update for entire memory monitoring

In reply to SeongJae Park

Update DAMON_LRU_SORT usage document for the changed default monitoring target region selection.

---
 Documentation/admin-guide/mm/damon/lru_sort.rst | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
Documentation/admin-guide/mm/damon/lru_sort.rst +4 -2
index 25e2f042a383f..b93ca9b0853d2 100644
@@ -246,7 +246,8 @@ monitor_region_start
 Start of target memory region in physical address.
 
 The start physical address of memory region that DAMON_LRU_SORT will do work
-against.  By default, biggest System RAM is used as the region.
+against.  By default, the system's entire physical memory is used as the
+region.
 
 monitor_region_end
 ------------------
@@ -254,7 +255,8 @@ monitor_region_end
 End of target memory region in physical address.
 
 The end physical address of memory region that DAMON_LRU_SORT will do work
-against.  By default, biggest System RAM is used as the region.
+against.  By default, the system's entire physical memory is used as the
+region.
 
 addr_unit
 ---------
Signature · 1 line
2.47.3
author maintainer
#16 lore raw
In reply to SeongJae Park
Quoted 21 lines · On Tue, 28 Apr 2026 21:12:22 -0700 SeongJae Park <[email protected]> wrote:

DAMON_RECLAIM and DAMON_LRU_SORT set the biggest 'System RAM' resource of the system as the default monitoring target address range. The main intention behind the design is to minimize the overhead coming from monitoring of non-System RAM areas.

This could result in an odd setup when there are multiple discrete System RAMs of considerable sizes. For example, there are System RAMs each having 500 GiB size. In this case, only the first 500 GiB will be set as the monitoring region by default. This is particularly common on NUMA systems. Hence the modules allow users to set the monitoring target address range using the module parameters if the default setup doesn't work for them. In other words, the current design trades ease of setup for lower overhead.

However, because DAMON utilizes the sampling based access check and the adaptive regions adjustment mechanisms, the overhead from the monitoring of non-System RAM areas should be negligible in most setups. Meanwhile, the setup complexity is causing real headaches for users who need to run those modules on various types of systems. That is, the current tradeoff is not a good deal.

Quoted 3 lines

Set the physical address range that can cover all System RAM areas of the system as the default monitoring regions for DAMON_RECLAIM and DAMON_LRU_SORT.

FYI, Sashiko reviews and my review of the reviews are available on replies to this thread that Cc-ing only me and [email protected]
(https://lore.kernel.org/[email protected]). In short, no real issue that blocks this series is found by Sashiko.

Thanks,
SJ

[...]