Skip to contentSkip to conversation

mm/damon: various fixes and cleanup of code, test, and docs

PATCH In review SJ Park 5 participants 25 messages Nov 2 – Nov 17

Subsystems (5)
lore
Share & tools
lore

SJ Park

author maintainer
#0 lore raw

cover mm/damon: various fixes and cleanup of code, test, and docs

Fix and cleanup various parts of DAMON including its code, test, and documentation.

Optimize the efficiency and monitoring accuracy of DAMON code with the first five patches. Remove unnecessary initializations in damon_new_ctx() with patch 1 from Adrian Huang (Lenovo). Align MMU notifier ranges when clearing PTE/PMD young bits with patches 2 and 3 from Shubhang Kaushik (Ampere) and Aveline Noir. Avoid DAMON_STAT idle time percentile overflow on 32-bit architectures, and optimize out unnecessary folio LRU isolation from DAMOS_MIGRATE action, with patches 4 and 5 from Aveline Noir, respectively.

Fix and cleanup tests and documents with remaining four patches. Let sysfs.py test does not hang when it is executed under interactive terminal with patch 6 from Jaeyeong Lee. Fix typos, grammatical errors and styles in DAMON_RECLAIM comments and DAMON_LRU_SORT user documents with patches 7 and 8 from Manuel. Finally, document how to disable watermarks of DAMON_RECLAIM with patch 9 from Jinjie Ruan.

Reviewer notes. This is a collection of DAMON patches that are posted by individual contributors and resposted as an mm.git merge request. Each patch has its own changelog.

Adrian Huang (Lenovo) (1):
mm/damon/core: remove unnecessary zero-initialization in

    damon_new_ctx()

Aveline Noir (3):
mm/damon/ops-common: align MMU notifier range when clearing PMD young
bit
mm/damon/stat: avoid 32-bit overflow in idle percentiles mm/damon/{p,v}addr: skip folios already on the migration target node

Jaeyeon Lee (1):
selftests/damon/sysfs.py: stop obsolete_target shells hanging the test

Jinjie Ruan (1):
Docs/admin-guide/mm/damon/reclaim: document how to disable watermarks

Manuel Ebner (2):
mm/damon/reclaim: fix typo and grammar Docs/admin-guide/mm/damon/lru_sort: fix grammar and stlye

Shubhang Kaushik (Ampere) (1):
mm/damon/ops-common: align MMU notifier range when clearing PTE young
bit

 .../admin-guide/mm/damon/lru_sort.rst         | 61 +++++++++----------
 .../admin-guide/mm/damon/reclaim.rst          |  4 ++
 mm/damon/core.c                               |  5 --
 mm/damon/ops-common.c                         |  7 ++-
 mm/damon/paddr.c                              |  2 +
 mm/damon/reclaim.c                            | 14 ++---
 mm/damon/stat.c                               |  5 +-
 mm/damon/vaddr.c                              | 18 +++---
 tools/testing/selftests/damon/sysfs.py        | 12 ++--
 9 files changed, 67 insertions(+), 61 deletions(-)

base-commit: 18e5bc25101d458c94de6ccb0f7df5d8ec000fb7

Signature · 1 line
2.47.3
author maintainer
#1 lore raw

PATCH 1/9 mm/damon/core: remove unnecessary zero-initialization in damon_new_ctx()

From: "Adrian Huang (Lenovo)" <[email protected]>

damon_new_ctx() allocates the context structure using kzalloc(), which already initializes all fields to zero.

The explicit initialization of passed_sample_intervals, next_aggregation_sis, and next_ops_update_sis is therefore redundant. In addition, they are later initialized by kdamond_init_ctx() before use.

Remove the unnecessary assignments to simplify the code.

---
Changes from v1
- v1: https://lore.kernel.org/[email protected]
- Collect R-b: from SJ.
- Rebase to latest mm-new.

 mm/damon/core.c | 5 -----
 1 file changed, 5 deletions(-)
mm/damon/core.c +0 -5
index 7441cdea57dc5..9d54899004026 100644
@@ -918,11 +918,6 @@ struct damon_ctx *damon_new_ctx(void)
 	ctx->attrs.aggr_interval = 100 * 1000;
 	ctx->attrs.ops_update_interval = 60 * 1000 * 1000;
 
-	ctx->passed_sample_intervals = 0;
-	/* These will be set from kdamond_init_ctx() */
-	ctx->next_aggregation_sis = 0;
-	ctx->next_ops_update_sis = 0;
-
 	mutex_init(&ctx->kdamond_lock);
 	INIT_LIST_HEAD(&ctx->call_controls);
 	mutex_init(&ctx->call_controls_lock);
Signature · 1 line
2.47.3
author maintainer
#3 lore raw

PATCH 2/9 mm/damon/ops-common: align MMU notifier range when clearing PTE young bit

In reply to SJ Park

From: "Shubhang Kaushik (Ampere)" <[email protected]>

DAMON selects a byte-granular sampling address. damon_ptep_mkold() clears the young bit of the PTE covering that address, but passes the unaligned range [addr, addr + PAGE_SIZE) to MMU notifiers.

For an unaligned address, that range extends into the following page. KVM ages every guest page intersecting the notifier range, so it can age a secondary mapping for the following page although DAMON cleared only the sampled page's primary PTE.

Align the address before both the primary PTE operation and the MMU notifier call so that they cover the same page.

Fixes 3f49584b262c ("mm/damon: implement primitives for the virtual memory address spaces")

---
Changes from v1
- v1: https://lore.kernel.org/20261021-damon-align-pte-young-notifier-v1-1-d0365ac45b66@gentwo.org
- Collect R-b: from SJ.
- Collect R-b: and T-b: from Aveline.
- Update subject prefix.
- Rebase to latest mm-new.

 mm/damon/ops-common.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
mm/damon/ops-common.c +3 -2
index 2f3bf86a221be..f88c6fd189fca 100644
@@ -64,6 +64,8 @@ void damon_ptep_mkold(pte_t *pte, struct vm_area_struct *vma, unsigned long addr
 	bool young = false;
 	unsigned long pfn;
 
+	addr = PAGE_ALIGN_DOWN(addr);
+
 	if (likely(pte_present(pteval)))
 		pfn = pte_pfn(pteval);
 	else
@@ -83,8 +85,7 @@ void damon_ptep_mkold(pte_t *pte, struct vm_area_struct *vma, unsigned long addr
 		 * Arch implementation of ptep_test_and_clear_young() may
 		 * require aligned @addr
 		 */
-		young |= ptep_test_and_clear_young(vma, PAGE_ALIGN_DOWN(addr),
-				pte);
+		young |= ptep_test_and_clear_young(vma, addr, pte);
 	young |= mmu_notifier_clear_young(vma->vm_mm, addr, addr + PAGE_SIZE);
 	if (young)
 		folio_set_young(folio);
Signature · 1 line
2.47.3
author maintainer
#5 lore raw

PATCH 3/9 mm/damon/ops-common: align MMU notifier range when clearing PMD young bit

In reply to SJ Park

From: Aveline Noir <[email protected]>

damon_pmdp_mkold() clears the young bit of a PMD but notifies [addr, addr + HPAGE_PMD_SIZE), where addr can be an unaligned sampling address. This can miss part of the sampled huge page and age secondary mappings in the next one.

Align addr to HPAGE_PMD_MASK so both operations cover the same huge page.

Fixes 3f49584b262c ("mm/damon: implement primitives for the virtual memory address spaces")
Cc Shubhang Kaushik (Ampere) <[email protected]>

---
Changes from v1
- v1: https://lore.kernel.org/r/20261021-damon-align-pte-young-notifier-v1-1-d0365ac45b66@gentwo.org/
- Drop Link: tag.
- Collect R-b: from SJ.
- Update subject prefix.
- Rebase to latest mm-new.

 mm/damon/ops-common.c | 2 ++
 1 file changed, 2 insertions(+)
mm/damon/ops-common.c +2 -0
index f88c6fd189fca..b9571f53e538c 100644
@@ -102,6 +102,8 @@ void damon_pmdp_mkold(pmd_t *pmd, struct vm_area_struct *vma, unsigned long addr
 	bool young = false;
 	unsigned long pfn;
 
+	addr &= HPAGE_PMD_MASK;
+
 	if (likely(pmd_present(pmdval)))
 		pfn = pmd_pfn(pmdval);
 	else
Signature · 1 line
2.47.3
author maintainer
#7 lore raw

PATCH 4/9 mm/damon/stat: avoid 32-bit overflow in idle percentiles

In reply to SJ Park

From: Aveline Noir <[email protected]>

On 32-bit, accounted_bytes * 100 can wrap before division by total_sz. Some entries in memory_idle_ms_percentiles then keep their old values instead of being updated.

For example, a 256 MiB i386 QEMU guest reported p0=19200 ms, but p50 and p100 were both zero. The issue was also shared with another mail [1].

Cast accounted_bytes to u64 before multiplying and use div64_ul() for the division. Compute the percentage once per region.

---
Changes from v1
- v1: https://lore.kernel.org/[email protected]
- Collect R-b: from SJ.
- Rebase to latest mm-new.

 mm/damon/stat.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
mm/damon/stat.c +3 -2
index b05b68f73e10d..eccd372810d04 100644
@@ -114,7 +114,7 @@ static void damon_stat_set_idletime_percentiles(struct damon_ctx *c)
 {
 	struct damon_region **sorted_regions, *region;
 	int nr_regions;
-	unsigned long total_sz, accounted_bytes = 0;
+	unsigned long total_sz, accounted_bytes = 0, percentile;
 	int err, i, next_percentile = 0;
 
 	err = damon_stat_sort_regions(c, &sorted_regions, &nr_regions,
@@ -124,7 +124,8 @@ static void damon_stat_set_idletime_percentiles(struct damon_ctx *c)
 	for (i = 0; i < nr_regions; i++) {
 		region = sorted_regions[i];
 		accounted_bytes += region->ar.end - region->ar.start;
-		while (next_percentile <= accounted_bytes * 100 / total_sz)
+		percentile = div64_ul((u64)accounted_bytes * 100, total_sz);
+		while (next_percentile <= percentile)
 			memory_idle_ms_percentiles[next_percentile++] =
 				damon_stat_idletime(region) *
 				(long)c->attrs.aggr_interval / USEC_PER_MSEC;
Signature · 1 line
2.47.3
author maintainer
#12 lore raw

PATCH 5/9 mm/damon/{p,v}addr: skip folios already on the migration target node

In reply to SJ Park

From: Aveline Noir <[email protected]>

While measuring DAMOS migration overhead, I found that the target_nid path isolates folios already on the target node, then puts them back on the LRU without migrating them.

Skip them before isolation in vaddr and paddr, as the vaddr explicit destinations path already does.

In a synthetic same-node fvaddr test on a two-node x86-64 KVM guest (8 interleaved runs per kernel), guest-kernel cycles fell by about 29% with 4 KiB regions and 90% with 16 MiB regions. Median kdamond CPU time fell by about 76% with 16 MiB regions, with no clear change with 4 KiB regions.

---
Changes from v1
- v1: https://lore.kernel.org/179320218513.2.7432933245840036676.damon-same-node-skip@gmail.com
- Put performance results in commit message.
- Use two tabs indentation for second parameter lines.
- Collect R-b: from SJ.
- Rebase to latest mm-new.

 mm/damon/paddr.c |  2 ++
 mm/damon/vaddr.c | 18 ++++++++++--------
 2 files changed, 12 insertions(+), 8 deletions(-)
mm/damon/paddr.c +2 -0
index 2cfdc356b4157..5b773012a8764 100644
@@ -368,6 +368,8 @@ static unsigned long damon_pa_migrate(struct damon_region *r,
 		else
 			*sz_filter_passed += folio_size(folio) / addr_unit;
 
+		if (folio_nid(folio) == s->target_nid)
+			goto put_folio;
 		if (!folio_isolate_lru(folio))
 			goto put_folio;
 		node_stat_add_folio(folio, NR_ISOLATED_ANON +
mm/damon/vaddr.c +10 -8
index b549496ea8e2c..1e65e7651cd98 100644
@@ -786,14 +786,15 @@ struct damos_va_migrate_private {
  */
 static void damos_va_migrate_dests_add(struct folio *folio,
 		struct vm_area_struct *vma, unsigned long addr,
-		struct damos_migrate_dests *dests,
+		struct damos *s,
 		struct list_head *migration_lists)
 {
+	struct damos_migrate_dests *dests = &s->migrate_dests;
 	pgoff_t ilx;
 	int order;
 	unsigned int target;
 	unsigned int weight_total = 0;
-	int i;
+	int i, nid;
 
 	/*
 	 * If dests is empty, there is only one migration list corresponding
@@ -801,7 +802,8 @@ static void damos_va_migrate_dests_add(struct folio *folio,
 	 */
 	if (!dests->nr_dests) {
 		i = 0;
-		goto isolate;
+		nid = s->target_nid;
+		goto check_nid;
 	}
 
 	order = folio_order(folio);
@@ -821,12 +823,13 @@ static void damos_va_migrate_dests_add(struct folio *folio,
 			break;
 		target -= dests->weight_arr[i];
 	}
+	nid = dests->node_id_arr[i];
 
+check_nid:
 	/* If the folio is already in the right node, don't do anything */
-	if (folio_nid(folio) == dests->node_id_arr[i])
+	if (folio_nid(folio) == nid)
 		return;
 
-isolate:
 	if (!folio_isolate_lru(folio))
 		return;
 	node_stat_add_folio(folio, NR_ISOLATED_ANON +
@@ -840,7 +843,6 @@ static int damos_va_migrate_pmd_entry(pmd_t *pmd, unsigned long addr,
 	struct damos_va_migrate_private *priv = walk->private;
 	struct list_head *migration_lists = priv->migration_lists;
 	struct damos *s = priv->scheme;
-	struct damos_migrate_dests *dests = &s->migrate_dests;
 	struct folio *folio;
 	spinlock_t *ptl;
 	pte_t *start_pte, *pte, ptent;
@@ -858,7 +860,7 @@ static int damos_va_migrate_pmd_entry(pmd_t *pmd, unsigned long addr,
 			goto huge_out;
 		if (damos_va_filter_out(s, folio, walk->vma, addr, NULL, pmd))
 			goto huge_out;
-		damos_va_migrate_dests_add(folio, walk->vma, addr, dests,
+		damos_va_migrate_dests_add(folio, walk->vma, addr, s,
 				migration_lists);
 huge_out:
 		spin_unlock(ptl);
@@ -883,7 +885,7 @@ static int damos_va_migrate_pmd_entry(pmd_t *pmd, unsigned long addr,
 			continue;
 		if (damos_va_filter_out(s, folio, walk->vma, addr, pte, NULL))
 			continue;
-		damos_va_migrate_dests_add(folio, walk->vma, addr, dests,
+		damos_va_migrate_dests_add(folio, walk->vma, addr, s,
 				migration_lists);
 		page_idx = folio_page_idx(folio, pte_page(ptent));
 		nr = folio_nr_pages(folio) - page_idx;
Signature · 1 line
2.47.3
author maintainer
#15 lore raw

PATCH 6/9 selftests/damon/sysfs.py: stop obsolete_target shells hanging the test

In reply to SJ Park

From: Jaeyeon Lee <[email protected]>

The obsolete_target test spawns three 'sh' processes as monitoring targets. The processes inherit stdin from the test. When the test is run via 'make run_tests' from an interactive terminal, the kselftest runner executes it under 'timeout', which puts it in a background process group. The 'sh' processes then try to read the terminal, so the kernel sends SIGTTIN to the whole process group. This stops the 'sh' processes, and also the child the test has just forked to spawn the next 'sh', before it can run 'sh'. The test then waits on that child forever, until the kselftest runner kills it after 45 seconds. The test passes when run directly.

Fix this by passing stdin=subprocess.PIPE when spawning the processes. The processes then read from a pipe that never receives input, so they stay alive and idle as the test expects.

---
Changes from v1
- v1: https://lore.kernel.org/[email protected]
- Collect R-b: from SJ.
- Rebase to latest mm-new.

 tools/testing/selftests/damon/sysfs.py | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)
tools/testing/selftests/damon/sysfs.py +6 -6
index 66c826189320d..ce54fa21c09fe 100755
@@ -390,12 +390,12 @@ def main():
     kdamonds.stop()
 
     # test obsolete_target.
-    proc1 = subprocess.Popen(['sh'], stdout=subprocess.PIPE,
-                             stderr=subprocess.PIPE)
-    proc2 = subprocess.Popen(['sh'], stdout=subprocess.PIPE,
-                             stderr=subprocess.PIPE)
-    proc3 = subprocess.Popen(['sh'], stdout=subprocess.PIPE,
-                             stderr=subprocess.PIPE)
+    proc1 = subprocess.Popen(['sh'], stdin=subprocess.PIPE,
+                             stdout=subprocess.PIPE, stderr=subprocess.PIPE)
+    proc2 = subprocess.Popen(['sh'], stdin=subprocess.PIPE,
+                             stdout=subprocess.PIPE, stderr=subprocess.PIPE)
+    proc3 = subprocess.Popen(['sh'], stdin=subprocess.PIPE,
+                             stdout=subprocess.PIPE, stderr=subprocess.PIPE)
     kdamonds = _damon_sysfs.Kdamonds(
             [_damon_sysfs.Kdamond(
                 contexts=[_damon_sysfs.DamonCtx(
Signature · 1 line
2.47.3
author maintainer
#17 lore raw

PATCH 7/9 mm/damon/reclaim: fix typo and grammar

In reply to SJ Park

From: Manuel Ebner <[email protected]>

DAMON_RCLAIM -> DAMON_RECLAIM
set as -> set to

Cc "Adrian Huang (Lenovo)" <[email protected]>
CC Adrian Huang (Lenovo) <[email protected]>

---
Changes from v1
- v1: https://lore.kernel.org/[email protected]
- Collect R-b: from Enze.
- Update subject prefix.
- Collect R-b: from SJ.
- Rebase to latest mm-new.

 mm/damon/reclaim.c | 14 +++++++-------
 1 file changed, 7 insertions(+), 7 deletions(-)
mm/damon/reclaim.c +7 -7
index 014b0779ea6dd..a84cea070ec76 100644
@@ -19,8 +19,8 @@
 /*
  * Enable or disable DAMON_RECLAIM.
  *
- * You can enable DAMON_RCLAIM by setting the value of this parameter as ``Y``.
- * Setting it as ``N`` disables DAMON_RECLAIM.  Note that DAMON_RECLAIM could
+ * You can enable DAMON_RECLAIM by setting the value of this parameter to ``Y``.
+ * Setting it to ``N`` disables DAMON_RECLAIM.  Note that DAMON_RECLAIM could
  * do no real monitoring and reclamation due to the watermarks-based activation
  * condition.  Refer to below descriptions for the watermarks parameter for
  * this.
@@ -31,9 +31,9 @@ static bool enabled __read_mostly;
  * Make DAMON_RECLAIM reads the input parameters again, except ``enabled``.
  *
  * Input parameters that updated while DAMON_RECLAIM is running are not applied
- * by default.  Once this parameter is set as ``Y``, DAMON_RECLAIM reads values
+ * by default.  Once this parameter is set to ``Y``, DAMON_RECLAIM reads values
  * of parameters except ``enabled`` again.  Once the re-reading is done, this
- * parameter is set as ``N``.  If invalid parameters are found while the
+ * parameter is set to ``N``.  If invalid parameters are found while the
  * re-reading, DAMON_RECLAIM will be disabled.
  */
 static bool commit_inputs __read_mostly;
@@ -92,11 +92,11 @@ module_param(quota_autotune_feedback, ulong, 0600);
 /*
  * Auto-tune monitoring intervals.
  *
- * If this parameter is set as ``Y``, DAMON_RECLAIM automatically tunes DAMON's
+ * If this parameter is set to ``Y``, DAMON_RECLAIM automatically tunes DAMON's
  * sampling and aggregation intervals.  The auto-tuning aims to capture
  * meaningful amount of access events in each DAMON-snapshot, while keeping the
  * sampling intervals 5 milliseconds in minimum, and 10 seconds in maximum.
- * Setting this as ``N`` disables the auto-tuning.
+ * Setting this to ``N`` disables the auto-tuning.
  *
  * Disabled by default.
  */
@@ -151,7 +151,7 @@ static unsigned long addr_unit __read_mostly = 1;
 /*
  * Skip anonymous pages reclamation.
  *
- * If this parameter is set as ``Y``, DAMON_RECLAIM does not reclaim anonymous
+ * If this parameter is set to ``Y``, DAMON_RECLAIM does not reclaim anonymous
  * pages.  By default, ``N``.
  */
 static bool skip_anon __read_mostly;
Signature · 1 line
2.47.3
author maintainer
#19 lore raw

PATCH 8/9 Docs/admin-guide/mm/damon/lru_sort: fix grammar and stlye

In reply to SJ Park

From: Manuel Ebner <[email protected]>

Fix tenses. Split long sentences thereby imporove readability. Replace 'set as' with 'set to'. Replace [] with () to make the file uniform.

---
Changes from v3
- v3: https://lore.kernel.org/[email protected]
- Rebase to latest mm-new.

[v3]
Split long line
Fix path in subject / One-line summary

[v2]
https://lore.kernel.org/[email protected]
Collect R-b: from SJ.

[v1]
https://lore.kernel.org/[email protected]
Wordsmith commit message.
Fixup a few trivial wording.

 .../admin-guide/mm/damon/lru_sort.rst         | 61 +++++++++----------
 1 file changed, 30 insertions(+), 31 deletions(-)
Documentation/admin-guide/mm/damon/lru_sort.rst +30 -31
index b93ca9b0853d2..f1eeb6389c377 100644
@@ -5,20 +5,19 @@ DAMON-based LRU-lists Sorting
 =============================
 
 DAMON-based LRU-lists Sorting (DAMON_LRU_SORT) is a static kernel module that
-aimed to be used for proactive and lightweight data access pattern based
+aims to be used for proactive and lightweight data access pattern based
 (de)prioritization of pages on their LRU-lists for making LRU-lists a more
 trusworthy data access pattern source.
 
 Where Proactive LRU-lists Sorting is Required?
 ==============================================
 
-As page-granularity access checking overhead could be significant on huge
-systems, LRU lists are normally not proactively sorted but partially and
-reactively sorted for special events including specific user requests, system
-calls and memory pressure.  As a result, LRU lists are sometimes not so
-perfectly prepared to be used as a trustworthy access pattern source for some
-situations including reclamation target pages selection under sudden memory
-pressure.
+As page-granularity access checking overhead could be significant on huge systems,
+LRU lists are normally not fully nor proactively sorted but rather partially
+and reactively sorted for special events.  These events include specific user requests,
+system calls and memory pressure.  As a result, LRU lists are sometimes not
+suitable to be used as a trustworthy access pattern source.  These situations
+including reclamation target page selection under sudden memory pressure.
 
 Because DAMON can identify access patterns of best-effort accuracy while
 inducing only user-specified range of overhead, proactively running
@@ -28,9 +27,9 @@ pattern source with low and controlled overhead.
 How It Works?
 =============
 
-DAMON_LRU_SORT finds hot pages (pages of memory regions that showing access
-rates that higher than a user-specified threshold) and cold pages (pages of
-memory regions that showing no access for a time that longer than a
+DAMON_LRU_SORT finds hot pages (pages of memory regions that show access
+rates that are higher than a user-specified threshold) and cold pages (pages of
+memory regions that show no access for a duration that is longer than a
 user-specified threshold) using DAMON, and prioritizes hot pages while
 deprioritizing cold pages on their LRU-lists.  To avoid it consuming too much
 CPU for the prioritizations, a CPU time usage limit can be configured.  Under
@@ -63,10 +62,10 @@ enabled
 
 Enable or disable DAMON_LRU_SORT.
 
-You can enable DAMON_LRU_SORT by setting the value of this parameter as ``Y``.
-Setting it as ``N`` disables DAMON_LRU_SORT.  Note that DAMON_LRU_SORT could do
+You can enable DAMON_LRU_SORT by setting the value of this parameter to ``Y``.
+Setting it to ``N`` disables DAMON_LRU_SORT.  Note that DAMON_LRU_SORT could do
 no real monitoring and LRU-lists sorting due to the watermarks-based activation
-condition.  Refer to below descriptions for the watermarks parameter for this.
+condition.  Refer to below descriptions of the watermarks parameter for this.
 
 commit_inputs
 -------------
@@ -74,9 +73,9 @@ commit_inputs
 Make DAMON_LRU_SORT reads the input parameters again, except ``enabled``.
 
 Input parameters that updated while DAMON_LRU_SORT is running are not applied
-by default.  Once this parameter is set as ``Y``, DAMON_LRU_SORT reads values
+by default.  Once this parameter is set to ``Y``, DAMON_LRU_SORT reads values
 of parameters except ``enabled`` again.  Once the re-reading is done, this
-parameter is set as ``N``.  If invalid parameters are found while the
+parameter is set to ``N``.  If invalid parameters are found while the
 re-reading, DAMON_LRU_SORT will be disabled.
 
 Once ``Y`` is written to this parameter, the user must not write to any
@@ -86,37 +85,37 @@ violate this rule, the kernel may exhibit undefined behavior.
 active_mem_bp
 -------------
 
-Desired active to [in]active memory ratio in bp (1/10,000).
+Desired active to (in)active memory ratio in bp (1/10,000).
 
 While keeping the caps that set by other quotas, DAMON_LRU_SORT automatically
 increases and decreases the effective level of the quota aiming the LRU
-[de]prioritizations of the hot and cold memory resulting in this active to
-[in]active memory ratio.  Value zero means disabling this auto-tuning feature.
+(de)prioritizations of the hot and cold memory resulting in this active to
+(in)active memory ratio.  Value zero means disabling this auto-tuning feature.
 
 Disabled by default.
 
 autotune_monitoring_intervals
 -----------------------------
 
-If this parameter is set as ``Y``, DAMON_LRU_SORT automatically tunes DAMON's
+If this parameter is set to ``Y``, DAMON_LRU_SORT automatically tunes DAMON's
 sampling and aggregation intervals.  The auto-tuning aims to capture meaningful
 amount of access events in each DAMON-snapshot, while keeping the sampling
-interval 5 milliseconds in minimum, and 10 seconds in maximum.  Setting this as
-``N`` disables the auto-tuning.
+interval to 5 milliseconds in minimum, and to 10 seconds in maximum.  Setting this
+to ``N`` disables the auto-tuning.
 
 Disabled by default.
 
 filter_young_pages
 ------------------
 
-Filter [non-]young pages accordingly for LRU [de]prioritizations.
+Filter (non-)young pages accordingly for LRU (de)prioritizations.
 
 If this is set, check page level access (youngness) once again before each
-LRU [de]prioritization operation.  LRU prioritization operation is skipped
+LRU (de)prioritization operation.  LRU prioritization operation is skipped
 if the page has not accessed since the last check (not young).  LRU
 deprioritization operation is skipped if the page has accessed since the
 last check (young).  The feature is enabled or disabled if this parameter is
-set as ``Y`` or ``N``, respectively.
+set to ``Y`` or ``N``, respectively.
 
 Disabled by default.
 
@@ -235,7 +234,7 @@ max_nr_regions
 Maximum number of monitoring regions.
 
 The maximum number of monitoring regions of DAMON for the cold memory
-monitoring.  This can be used to set upper-bound of the monitoring overhead.
+monitoring.  This can be used to set the upper-bound of the monitoring overhead.
 However, setting this too low could result in bad monitoring quality.  Please
 refer to the DAMON documentation (:doc:`usage`) for more detail.  1000 by
 defaults.
@@ -268,7 +267,7 @@ This parameter is for setting and getting the :ref:`address unit
 
 ``monitor_region_start`` and ``monitor_region_end`` should be provided in this
 unit.  For example, let's suppose ``addr_unit``, ``monitor_region_start`` and
-``monitor_region_end`` are set as ``1024``, ``0`` and ``10``, respectively.
+``monitor_region_end`` are set to ``1024``, ``0`` and ``10``, respectively.
 Then DAMON_LRU_SORT will work for 10 KiB length of physical address range that
 starts from address zero (``[0 * 1024, 10 * 1024)`` in bytes).
 
@@ -291,22 +290,22 @@ If DAMON_LRU_SORT is enabled, this becomes the PID of the worker thread.  Else,
 nr_lru_sort_tried_hot_regions
 -----------------------------
 
-Number of hot memory regions that tried to be LRU-sorted.
+Number of hot memory regions that were tried to be LRU-sorted.
 
 bytes_lru_sort_tried_hot_regions
 --------------------------------
 
-Total bytes of hot memory regions that tried to be LRU-sorted.
+Total bytes of hot memory regions that were tried to be LRU-sorted.
 
 nr_lru_sorted_hot_regions
 -------------------------
 
-Number of hot memory regions that successfully be LRU-sorted.
+Number of hot memory regions that were successfully LRU-sorted.
 
 bytes_lru_sorted_hot_regions
 ----------------------------
 
-Total bytes of hot memory regions that successfully be LRU-sorted.
+Total bytes of hot memory regions that were successfully LRU-sorted.
 
 nr_hot_quota_exceeds
 --------------------
Signature · 1 line
2.47.3
author maintainer
#23 lore raw

PATCH 9/9 Docs/admin-guide/mm/damon/reclaim: document how to disable watermarks

In reply to SJ Park

From: Jinjie Ruan <[email protected]>

DAMON_RECLAIM runs its scheme only while the free memory rate is between wmarks_low and wmarks_mid.

But some users want to reclaim cold pages even while the system has plenty of free memory, and it is not obvious that the existing watermarks parameters can already do that. So Document the setup.

---
Changes from v1
- v1: https://lore.kernel.org/[email protected]
- Collect R-b: from SJ.
- Rebase to latest mm-new.

 Documentation/admin-guide/mm/damon/reclaim.rst | 4 ++++
 1 file changed, 4 insertions(+)
Documentation/admin-guide/mm/damon/reclaim.rst +4 -0
index ec7e3e32b4ac6..14f9b82b38ed9 100644
@@ -193,6 +193,10 @@ DAMON_RECLAIM becomes inactive, so it does nothing but periodically checks the
 watermarks.  In the case, the system falls back to the LRU-list based page
 granularity reclamation logic.
 
+To keep DAMON_RECLAIM always active regardless of the free memory rate, set
+``wmarks_high``, ``wmarks_mid`` and ``wmarks_low`` to ``1000``, ``1000`` and
+``0``, respectively.
+
 sample_interval
 ---------------
 
Signature · 1 line
2.47.3
#2 lore raw

Re: [PATCH 1/9] mm/damon/core: remove unnecessary zero-initialization in damon_new_ctx()

In reply to SJ Park
Sashiko has reviewed this patch and found no issues.
Quoted 9 lines

From: "Adrian Huang (Lenovo)" <[email protected]>

damon_new_ctx() allocates the context structure using kzalloc(), which already initializes all fields to zero.

The explicit initialization of passed_sample_intervals, next_aggregation_sis, and next_ops_update_sis is therefore redundant. In addition, they are later initialized by kdamond_init_ctx() before use.

Quoted 6 lines

Remove the unnecessary assignments to simplify the code.

Sashiko has reviewed this patch and found no issues.

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

Re: [PATCH 2/9] mm/damon/ops-common: align MMU notifier range when clearing PTE young bit

In reply to SJ Park
Sashiko has reviewed this patch and found no issues.
Quoted 14 lines

From: "Shubhang Kaushik (Ampere)" <[email protected]>

DAMON selects a byte-granular sampling address. damon_ptep_mkold() clears the young bit of the PTE covering that address, but passes the unaligned range [addr, addr + PAGE_SIZE) to MMU notifiers.

For an unaligned address, that range extends into the following page. KVM ages every guest page intersecting the notifier range, so it can age a secondary mapping for the following page although DAMON cleared only the sampled page's primary PTE.

Align the address before both the primary PTE operation and the MMU notifier call so that they cover the same page.

Quoted 6 lines
Fixes 3f49584b262c ("mm/damon: implement primitives for the virtual memory address spaces")

Sashiko has reviewed this patch and found no issues.

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

Re: [PATCH 3/9] mm/damon/ops-common: align MMU notifier range when clearing PMD young bit

In reply to SJ Park
Sashiko has reviewed this patch and found no issues.
Quoted 7 lines

From: Aveline Noir <[email protected]>

damon_pmdp_mkold() clears the young bit of a PMD but notifies [addr, addr + HPAGE_PMD_SIZE), where addr can be an unaligned sampling address. This can miss part of the sampled huge page and age secondary mappings in the next one.

Quoted 7 lines

Align addr to HPAGE_PMD_MASK so both operations cover the same huge page.

Fixes 3f49584b262c ("mm/damon: implement primitives for the virtual memory address spaces")
Cc Shubhang Kaushik (Ampere) <[email protected]>

Sashiko has reviewed this patch and found no issues.

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

Re: [PATCH 4/9] mm/damon/stat: avoid 32-bit overflow in idle percentiles

In reply to SJ Park
Sashiko has reviewed this patch and found no issues.
Quoted 12 lines

From: Aveline Noir <[email protected]>

On 32-bit, accounted_bytes * 100 can wrap before division by total_sz. Some entries in memory_idle_ms_percentiles then keep their old values instead of being updated.

For example, a 256 MiB i386 QEMU guest reported p0=19200 ms, but p50 and p100 were both zero. The issue was also shared with another mail [1].

Cast accounted_bytes to u64 before multiplying and use div64_ul() for the division. Compute the percentage once per region.

Quoted 6 lines

Sashiko has reviewed this patch and found no issues.

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

Re: [PATCH 5/9] mm/damon/{p,v}addr: skip folios already on the migration target node

In reply to SJ Park
Sashiko has reviewed this patch and found no issues.
Quoted 15 lines

From: Aveline Noir <[email protected]>

While measuring DAMOS migration overhead, I found that the target_nid path isolates folios already on the target node, then puts them back on the LRU without migrating them.

Skip them before isolation in vaddr and paddr, as the vaddr explicit destinations path already does.

In a synthetic same-node fvaddr test on a two-node x86-64 KVM guest (8 interleaved runs per kernel), guest-kernel cycles fell by about 29% with 4 KiB regions and 90% with 16 MiB regions. Median kdamond CPU time fell by about 76% with 16 MiB regions, with no clear change with 4 KiB regions.

Quoted 3 lines

Sashiko has reviewed this patch and found no issues.

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

Re: [PATCH 6/9] selftests/damon/sysfs.py: stop obsolete_target shells hanging the test

In reply to SJ Park
Sashiko has reviewed this patch and found no issues.
Quoted 17 lines

From: Jaeyeon Lee <[email protected]>

The obsolete_target test spawns three 'sh' processes as monitoring targets. The processes inherit stdin from the test. When the test is run via 'make run_tests' from an interactive terminal, the kselftest runner executes it under 'timeout', which puts it in a background process group. The 'sh' processes then try to read the terminal, so the kernel sends SIGTTIN to the whole process group. This stops the 'sh' processes, and also the child the test has just forked to spawn the next 'sh', before it can run 'sh'. The test then waits on that child forever, until the kselftest runner kills it after 45 seconds. The test passes when run directly.

Fix this by passing stdin=subprocess.PIPE when spawning the processes. The processes then read from a pipe that never receives input, so they stay alive and idle as the test expects.

Quoted 5 lines

Sashiko has reviewed this patch and found no issues.

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

Re: [PATCH 7/9] mm/damon/reclaim: fix typo and grammar

In reply to SJ Park
Sashiko has reviewed this patch and found no issues.
Quoted 11 lines

From: Manuel Ebner <[email protected]>

DAMON_RCLAIM -> DAMON_RECLAIM
set as -> set to

Cc "Adrian Huang (Lenovo)" <[email protected]>
CC Adrian Huang (Lenovo) <[email protected]>

Sashiko has reviewed this patch and found no issues.

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

Re: [PATCH 8/9] Docs/admin-guide/mm/damon/lru_sort: fix grammar and stlye

In reply to SJ Park
Sashiko has reviewed this patch and found no issues.
Quoted 8 lines

From: Manuel Ebner <[email protected]>

Fix tenses. Split long sentences thereby imporove readability. Replace 'set as' with 'set to'. Replace [] with () to make the file uniform.

Sashiko has reviewed this patch and found no issues.

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

Re: [PATCH 9/9] Docs/admin-guide/mm/damon/reclaim: document how to disable watermarks

In reply to SJ Park
Sashiko has reviewed this patch and found no issues.
Quoted 5 lines

From: Jinjie Ruan <[email protected]>

DAMON_RECLAIM runs its scheme only while the free memory rate is between wmarks_low and wmarks_mid.

Quoted 7 lines

But some users want to reclaim cold pages even while the system has plenty of free memory, and it is not obvious that the existing watermarks parameters can already do that. So Document the setup.

Sashiko has reviewed this patch and found no issues.

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

Re: [PATCH 8/9] Docs/admin-guide/mm/damon/lru_sort: fix grammar and stlye

In reply to SJ Park

Hi Manuel,

Quoted 1 line

Docs/admin-guide/mm/damon/lru_sort: fix grammar and stlye

"stlye" -> "style"?

Quoted 1 line

Fix tenses. Split long sentences thereby imporove readability.

"imporove" -> "improve"

Documentation/admin-guide/mm/damon/lru_sort.rst DAMON-based LRU-lists Sorting · line 20

Quoted 2 lines
Documentation/admin-guide/mm/damon/lru_sort.rst +2 -0
+suitable to be used as a trustworthy access pattern source. These situations
+including reclamation target page selection under sudden memory pressure.

Shouldn't this be "These situations include"? As written it is a sentence fragment.

Thanks,
Daniel

author maintainer Reviewed-by on v1 5/9
#14 lore raw

Re: [PATCH 5/9] mm/damon/{p,v}addr: skip folios already on the migration target node

In reply to SJ Park
Quoted 15 lines · On Mon, 2 Nov 2026 07:07:52 -0800 SJ Park <[email protected]> wrote:

From: Aveline Noir <[email protected]>

While measuring DAMOS migration overhead, I found that the target_nid path isolates folios already on the target node, then puts them back on the LRU without migrating them.

Skip them before isolation in vaddr and paddr, as the vaddr explicit destinations path already does.

In a synthetic same-node fvaddr test on a two-node x86-64 KVM guest (8 interleaved runs per kernel), guest-kernel cycles fell by about 29% with 4 KiB regions and 90% with 16 MiB regions. Median kdamond CPU time fell by about 76% with 16 MiB regions, with no clear change with 4 KiB regions.

Quoted 3 lines

Somehow I dropped my R-b, sorry. Andrew, could you please add below?

Thanks,
SJ

[...]

#21 lore raw

Re: [PATCH 8/9] Docs/admin-guide/mm/damon/lru_sort: fix grammar and stlye

In reply to [email protected]

Hi,

I think sashiko review really help the improve patch-quality, however I have some constructive feedback. In this review a couple typos got missed.

On Mon, 2026-11-02 at 15:36 +0000, [email protected] wrote

Quoted 1 line
Quoted 1 line

Re: [PATCH 8/9] Docs/admin-guide/mm/damon/lru_sort: fix grammar and stlye

The missed typo here is 'stlye'.

Quoted 3 lines
Quoted 3 lines

From: Manuel Ebner <[email protected]>

Fix tenses. Split long sentences thereby imporove readability.  Replace

The typo here is 'imporove'.

Quoted 7 lines
Quoted 5 lines

'set as' with 'set to'. Replace [] with () to make the file uniform.

Sashiko has reviewed this patch and found no issues.

In the diff

Quoted 2 lines

Documentation/admin-guide/mm/damon/lru_sort.rst DAMON-based LRU-lists Sorting · line 20

Quoted 2 lines
Documentation/admin-guide/mm/damon/lru_sort.rst +2 -0
+suitable to be used as a trustworthy access pattern source.  These situations
+including reclamation target page selection under sudden memory pressure.

'including' should be 'include'

Maybe you can improve the automatic review process.

Thanks
Manuel

#9 lore raw

Re: [PATCH 4/9] mm/damon/stat: avoid 32-bit overflow in idle percentiles

In reply to SJ Park

Hi SJ, Aveline,

The value stored a few lines below has the same problem on 32-bit:

	damon_stat_idletime(region) *
	(long)c->attrs.aggr_interval / USEC_PER_MSEC;

The product is the region's idle time in microseconds, held in a 32-bit long, so it wraps once a region has been idle for more than about 36 minutes, whatever the intervals are. The cold-end percentiles then come out negative or wrong. Doing the multiply in s64 with div_s64() would keep the sign and avoid it.

Hope it helps !

author maintainer
#10 lore raw

Re: [PATCH 4/9] mm/damon/stat: avoid 32-bit overflow in idle percentiles

Hello David,

Quoted 7 lines · On Sat, 14 Nov 2026 18:10:34 +0000 David Carlier <[email protected]> wrote:

Hi SJ, Aveline,

The value stored a few lines below has the same problem on 32-bit:

	damon_stat_idletime(region) *
	(long)c->attrs.aggr_interval / USEC_PER_MSEC;
Quoted 7 lines

The product is the region's idle time in microseconds, held in a 32-bit long, so it wraps once a region has been idle for more than about 36 minutes, whatever the intervals are. The cold-end percentiles then come out negative or wrong. Doing the multiply in s64 with div_s64() would keep the sign and avoid it.

Hope it helps !

Yes, this is helpful. Thank you for sharing. Would you like to send a patch for this issue?

Thanks,
SJ

[...]

#11 lore raw

Re: [PATCH 4/9] mm/damon/stat: avoid 32-bit overflow in idle percentiles

Hi SJ

Quoted 18 lines · SJ Park

Hello David,

Quoted 13 lines · On Sat, 14 Nov 2026 18:10:34 +0000 David Carlier <[email protected]> wrote:

Hi SJ, Aveline,

The value stored a few lines below has the same problem on 32-bit:

      damon_stat_idletime(region) *
      (long)c->attrs.aggr_interval / USEC_PER_MSEC;

The product is the region's idle time in microseconds, held in a 32-bit long, so it wraps once a region has been idle for more than about 36 minutes, whatever the intervals are. The cold-end percentiles then come out negative or wrong. Doing the multiply in s64 with div_s64() would keep the sign and avoid it.

Quoted 6 lines
Quoted 1 line

Hope it helps !

Yes, this is helpful. Thank you for sharing. Would you like to send a patch
for this issue?

Yes I sent it, thanks.

Cheers

Quoted 7 lines

Thanks,
SJ

[...]