* [RFC PATCH v4 1/7] mm/damon/vaddr: advance migration attempt in folio level for filter out
2026-11-28 19:00 [RFC PATCH v4 0/7] mm/damon: various improvements/cleanups for code, tests and comments SJ Park
@ 2026-11-28 19:00 ` SJ Park
2026-11-28 19:00 ` [RFC PATCH v4 2/7] mm/damon/vaddr: use damos->last_applied for migrate action SJ Park
` (5 subsequent siblings)
6 siblings, 0 replies; 8+ messages in thread
From: SJ Park @ 2026-11-28 19:00 UTC (permalink / raw)
Cc: SJ Park, Andrew Morton, damon, linux-mm
damos_va_migrate_pmd_entry() finds folios to migrate under the given
pmd, using a loop for the pmd address range. The loop advances in page
size if a given folio is excluded by DAMOS ops filters. DAMOS ops
filters work in folio granularity. Hence it is more efficient and makes
sense to advance in the folio size.
Advance the loop in folio size for the ops filter out decision. For
that, do the folio size based loop advancement offset update before
applying DAMOS ops filters.
Closes: https://sashiko.dev/#/bug/linux-67c34df7-6dfb-4e18-9ce0-0d26915e5785
Signed-off-by: SJ Park <sj@kernel.org>
---
mm/damon/vaddr.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/mm/damon/vaddr.c b/mm/damon/vaddr.c
index 750e643e020f..ca7ce9bd96e7 100644
--- a/mm/damon/vaddr.c
+++ b/mm/damon/vaddr.c
@@ -883,12 +883,12 @@ static int damos_va_migrate_pmd_entry(pmd_t *pmd, unsigned long addr,
folio = vm_normal_folio(walk->vma, addr, ptent);
if (!folio)
continue;
+ page_idx = folio_page_idx(folio, pte_page(ptent));
+ nr = folio_nr_pages(folio) - page_idx;
if (damos_va_filter_out(s, folio, walk->vma, addr, pte, NULL))
continue;
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;
}
pte_unmap_unlock(start_pte, ptl);
return 0;
--
2.47.3
^ permalink raw reply related [flat|nested] 8+ messages in thread* [RFC PATCH v4 2/7] mm/damon/vaddr: use damos->last_applied for migrate action
2026-11-28 19:00 [RFC PATCH v4 0/7] mm/damon: various improvements/cleanups for code, tests and comments SJ Park
2026-11-28 19:00 ` [RFC PATCH v4 1/7] mm/damon/vaddr: advance migration attempt in folio level for filter out SJ Park
@ 2026-11-28 19:00 ` SJ Park
2026-11-28 19:00 ` [RFC PATCH v4 3/7] mm/damon/vaddr: implement sz_filter_passed for migrate_{hot,cold} action SJ Park
` (4 subsequent siblings)
6 siblings, 0 replies; 8+ messages in thread
From: SJ Park @ 2026-11-28 19:00 UTC (permalink / raw)
Cc: SJ Park, Andrew Morton, damon, linux-mm
To avoid applying the same DAMOS action multiple times to folios that
are located across adjacent regions, damos->last_applied was introduced.
DAMOS_MIGRATE_{HOT,COLD} action support in vaddr is not utilizing it.
Use it to avoid unnecessarily applying the same action to the same folio
multiple times.
Signed-off-by: SJ Park <sj@kernel.org>
---
mm/damon/vaddr.c | 18 +++++++++++-------
1 file changed, 11 insertions(+), 7 deletions(-)
diff --git a/mm/damon/vaddr.c b/mm/damon/vaddr.c
index ca7ce9bd96e7..fd649cd335c9 100644
--- a/mm/damon/vaddr.c
+++ b/mm/damon/vaddr.c
@@ -837,6 +837,12 @@ static void damos_va_migrate_dests_add(struct folio *folio,
list_add(&folio->lru, &migration_lists[i]);
}
+static inline bool damos_va_invalid_folio(struct folio *folio,
+ struct damos *s)
+{
+ return !folio || folio == s->last_applied;
+}
+
static int damos_va_migrate_pmd_entry(pmd_t *pmd, unsigned long addr,
unsigned long next, struct mm_walk *walk)
{
@@ -856,8 +862,9 @@ static int damos_va_migrate_pmd_entry(pmd_t *pmd, unsigned long addr,
if (!pmd_present(pmde))
goto huge_out;
folio = vm_normal_folio_pmd(walk->vma, addr, pmde);
- if (!folio)
+ if (damos_va_invalid_folio(folio, s))
goto huge_out;
+ s->last_applied = folio;
if (damos_va_filter_out(s, folio, walk->vma, addr, NULL, pmd))
goto huge_out;
damos_va_migrate_dests_add(folio, walk->vma, addr, s,
@@ -885,6 +892,9 @@ static int damos_va_migrate_pmd_entry(pmd_t *pmd, unsigned long addr,
continue;
page_idx = folio_page_idx(folio, pte_page(ptent));
nr = folio_nr_pages(folio) - page_idx;
+ if (damos_va_invalid_folio(folio, s))
+ continue;
+ s->last_applied = folio;
if (damos_va_filter_out(s, folio, walk->vma, addr, pte, NULL))
continue;
damos_va_migrate_dests_add(folio, walk->vma, addr, s,
@@ -993,12 +1003,6 @@ struct damos_va_stat_private {
unsigned long *sz_filter_passed;
};
-static inline bool damos_va_invalid_folio(struct folio *folio,
- struct damos *s)
-{
- return !folio || folio == s->last_applied;
-}
-
static int damos_va_stat_pmd_entry(pmd_t *pmd, unsigned long addr,
unsigned long next, struct mm_walk *walk)
{
--
2.47.3
^ permalink raw reply related [flat|nested] 8+ messages in thread* [RFC PATCH v4 3/7] mm/damon/vaddr: implement sz_filter_passed for migrate_{hot,cold} action
2026-11-28 19:00 [RFC PATCH v4 0/7] mm/damon: various improvements/cleanups for code, tests and comments SJ Park
2026-11-28 19:00 ` [RFC PATCH v4 1/7] mm/damon/vaddr: advance migration attempt in folio level for filter out SJ Park
2026-11-28 19:00 ` [RFC PATCH v4 2/7] mm/damon/vaddr: use damos->last_applied for migrate action SJ Park
@ 2026-11-28 19:00 ` SJ Park
2026-11-28 19:00 ` [RFC PATCH v4 4/7] mm/damon/sysfs-schemes: drop redundant and racy zero target_value check SJ Park
` (3 subsequent siblings)
6 siblings, 0 replies; 8+ messages in thread
From: SJ Park @ 2026-11-28 19:00 UTC (permalink / raw)
Cc: SJ Park, Andrew Morton, damon, linux-mm
Support of DAMOS ops filter and sz_filter_passed support is up to each
operation set. DAMON_VADDR supports both for only damos_stat action.
It intentionally does not support those for madvise-based actions
because applying filters could make it unnecessarily complicated and
expensive. The vaddr implementation of migrate_{hot,cold} action does
support DAMOS ops filters but sz_filter_passed. There is no real reason
to not support sz_filter_passed. Add the support.
Pass the sz_filter_passed pointer to the filter applying logic and
accumulate the number.
Closes: https://sashiko.dev/#/bug/linux-986e8b64-8e65-4e32-970f-4d3ebdf8206e
Signed-off-by: SJ Park <sj@kernel.org>
---
mm/damon/vaddr.c | 5 +++++
1 file changed, 5 insertions(+)
diff --git a/mm/damon/vaddr.c b/mm/damon/vaddr.c
index fd649cd335c9..170f77f74e84 100644
--- a/mm/damon/vaddr.c
+++ b/mm/damon/vaddr.c
@@ -776,6 +776,7 @@ static bool damos_va_filter_out(struct damos *scheme, struct folio *folio,
struct damos_va_migrate_private {
struct list_head *migration_lists;
struct damos *scheme;
+ unsigned long *sz_filter_passed;
};
/*
@@ -849,6 +850,7 @@ 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;
+ unsigned long *sz_filter_passed = priv->sz_filter_passed;
struct folio *folio;
spinlock_t *ptl;
pte_t *start_pte, *pte, ptent;
@@ -867,6 +869,7 @@ static int damos_va_migrate_pmd_entry(pmd_t *pmd, unsigned long addr,
s->last_applied = folio;
if (damos_va_filter_out(s, folio, walk->vma, addr, NULL, pmd))
goto huge_out;
+ *sz_filter_passed += folio_size(folio);
damos_va_migrate_dests_add(folio, walk->vma, addr, s,
migration_lists);
huge_out:
@@ -897,6 +900,7 @@ static int damos_va_migrate_pmd_entry(pmd_t *pmd, unsigned long addr,
s->last_applied = folio;
if (damos_va_filter_out(s, folio, walk->vma, addr, pte, NULL))
continue;
+ *sz_filter_passed += folio_size(folio);
damos_va_migrate_dests_add(folio, walk->vma, addr, s,
migration_lists);
}
@@ -975,6 +979,7 @@ static unsigned long damos_va_migrate(struct damon_target *target,
priv.migration_lists = kmalloc_objs(*priv.migration_lists, nr_dests);
if (!priv.migration_lists)
return 0;
+ priv.sz_filter_passed = sz_filter_passed;
for (int i = 0; i < nr_dests; i++)
INIT_LIST_HEAD(&priv.migration_lists[i]);
--
2.47.3
^ permalink raw reply related [flat|nested] 8+ messages in thread* [RFC PATCH v4 4/7] mm/damon/sysfs-schemes: drop redundant and racy zero target_value check
2026-11-28 19:00 [RFC PATCH v4 0/7] mm/damon: various improvements/cleanups for code, tests and comments SJ Park
` (2 preceding siblings ...)
2026-11-28 19:00 ` [RFC PATCH v4 3/7] mm/damon/vaddr: implement sz_filter_passed for migrate_{hot,cold} action SJ Park
@ 2026-11-28 19:00 ` SJ Park
2026-11-28 19:00 ` [RFC PATCH v4 5/7] selftests/damon/damos_apply_interval: remove unused variables SJ Park
` (2 subsequent siblings)
6 siblings, 0 replies; 8+ messages in thread
From: SJ Park @ 2026-11-28 19:00 UTC (permalink / raw)
Cc: SJ Park, Andrew Morton, damon, linux-mm
DAMON sysfs interface disallowed zero target_value because it could
result in divide-by-zero in damos_quota_store(). Because similar checks
were duplicated to other DAMON API callers, a patch series that starts
with commit 610c4438fb66 ("mm/damon/core: error
damos_commit_quota_goal() for zero target_value") added a same check in
the core layer central parameters, and dropped redundant checks in
DAMON_LRU_SORT and DAMON_SAMPLIE_MTIER. It forgot to drop that in the
DAMON sysfs interface.
Now the zero target_value check in DAMON sysfs interface is only
redundant. Further, it has a time-of-check to time-of-use (toctou) race
with target_value_store(). It can confuse readers to believe [1] the
division-by-zero can still happen. Drop the redundant and racy check.
[1] https://lore.kernel.org/20261021005234.94107-1-sj@kernel.org
Signed-off-by: SJ Park <sj@kernel.org>
---
mm/damon/sysfs-schemes.c | 3 ---
1 file changed, 3 deletions(-)
diff --git a/mm/damon/sysfs-schemes.c b/mm/damon/sysfs-schemes.c
index 750f70f0c31b..b0d07994f6c0 100644
--- a/mm/damon/sysfs-schemes.c
+++ b/mm/damon/sysfs-schemes.c
@@ -2917,9 +2917,6 @@ static int damos_sysfs_add_quota_score(
struct damos_sysfs_quota_goal *sysfs_goal =
sysfs_goals->goals_arr[i];
- if (!sysfs_goal->target_value)
- continue;
-
goal = damos_new_quota_goal(sysfs_goal->metric,
sysfs_goal->complement,
sysfs_goal->target_value);
--
2.47.3
^ permalink raw reply related [flat|nested] 8+ messages in thread* [RFC PATCH v4 5/7] selftests/damon/damos_apply_interval: remove unused variables
2026-11-28 19:00 [RFC PATCH v4 0/7] mm/damon: various improvements/cleanups for code, tests and comments SJ Park
` (3 preceding siblings ...)
2026-11-28 19:00 ` [RFC PATCH v4 4/7] mm/damon/sysfs-schemes: drop redundant and racy zero target_value check SJ Park
@ 2026-11-28 19:00 ` SJ Park
2026-11-28 19:00 ` [RFC PATCH v4 6/7] selftests/damon: remove unused imports of sys and time modules SJ Park
2026-11-28 19:00 ` [RFC PATCH v4 7/7] mm/damon: update file intro comments to call DAMON just DAMON SJ Park
6 siblings, 0 replies; 8+ messages in thread
From: SJ Park @ 2026-11-28 19:00 UTC (permalink / raw)
Cc: SJ Park, Shuah Khan, damon, linux-kselftest, linux-mm
wss_collected and nr_quota_exceeds in damos_apply_interval.py are
assigned to but never used. Remove.
The issue is found using flake8.
Signed-off-by: SJ Park <sj@kernel.org>
---
tools/testing/selftests/damon/damos_apply_interval.py | 2 --
1 file changed, 2 deletions(-)
diff --git a/tools/testing/selftests/damon/damos_apply_interval.py b/tools/testing/selftests/damon/damos_apply_interval.py
index 0bf7768b2006..0ad110be0fb9 100755
--- a/tools/testing/selftests/damon/damos_apply_interval.py
+++ b/tools/testing/selftests/damon/damos_apply_interval.py
@@ -42,8 +42,6 @@ def main():
print('kdamond start failed: %s' % err)
exit(1)
- wss_collected = []
- nr_quota_exceeds = 0
while proc.poll() == None:
time.sleep(0.1)
err = kdamonds.kdamonds[0].update_schemes_stats()
--
2.47.3
^ permalink raw reply related [flat|nested] 8+ messages in thread* [RFC PATCH v4 6/7] selftests/damon: remove unused imports of sys and time modules
2026-11-28 19:00 [RFC PATCH v4 0/7] mm/damon: various improvements/cleanups for code, tests and comments SJ Park
` (4 preceding siblings ...)
2026-11-28 19:00 ` [RFC PATCH v4 5/7] selftests/damon/damos_apply_interval: remove unused variables SJ Park
@ 2026-11-28 19:00 ` SJ Park
2026-11-28 19:00 ` [RFC PATCH v4 7/7] mm/damon: update file intro comments to call DAMON just DAMON SJ Park
6 siblings, 0 replies; 8+ messages in thread
From: SJ Park @ 2026-11-28 19:00 UTC (permalink / raw)
Cc: SJ Park, Shuah Khan, damon, linux-kselftest, linux-mm
sysfs_no_op_commit_break.py imports 'sys' module but never uses it.
sysfs_update_schemes_tried_regions_hang imports 'time' module but never
uses it. Remove the unnecessary imports.
The issue is found using flake8.
Signed-off-by: SJ Park <sj@kernel.org>
---
tools/testing/selftests/damon/sysfs_no_op_commit_break.py | 1 -
.../selftests/damon/sysfs_update_schemes_tried_regions_hang.py | 1 -
2 files changed, 2 deletions(-)
diff --git a/tools/testing/selftests/damon/sysfs_no_op_commit_break.py b/tools/testing/selftests/damon/sysfs_no_op_commit_break.py
index 81774ddc55ac..5664f75186ba 100755
--- a/tools/testing/selftests/damon/sysfs_no_op_commit_break.py
+++ b/tools/testing/selftests/damon/sysfs_no_op_commit_break.py
@@ -4,7 +4,6 @@
import json
import os
import subprocess
-import sys
import _damon_sysfs
diff --git a/tools/testing/selftests/damon/sysfs_update_schemes_tried_regions_hang.py b/tools/testing/selftests/damon/sysfs_update_schemes_tried_regions_hang.py
index 625761c243b5..326a14f04053 100755
--- a/tools/testing/selftests/damon/sysfs_update_schemes_tried_regions_hang.py
+++ b/tools/testing/selftests/damon/sysfs_update_schemes_tried_regions_hang.py
@@ -4,7 +4,6 @@
import os
import subprocess
import sys
-import time
sys.path.append(os.path.dirname(os.path.abspath(__file__)))
import _damon_sysfs
--
2.47.3
^ permalink raw reply related [flat|nested] 8+ messages in thread* [RFC PATCH v4 7/7] mm/damon: update file intro comments to call DAMON just DAMON
2026-11-28 19:00 [RFC PATCH v4 0/7] mm/damon: various improvements/cleanups for code, tests and comments SJ Park
` (5 preceding siblings ...)
2026-11-28 19:00 ` [RFC PATCH v4 6/7] selftests/damon: remove unused imports of sys and time modules SJ Park
@ 2026-11-28 19:00 ` SJ Park
6 siblings, 0 replies; 8+ messages in thread
From: SJ Park @ 2026-11-28 19:00 UTC (permalink / raw)
Cc: SJ Park, Andrew Morton, damon, linux-mm
DAMON source file intro comments call DAMON as Data Access Monitor.
Since the introduction of DAMOS, DAMON has been somewhat more than a
Data Access Monitor. Update the comments to call it just DAMON. Also
some of the comments are not appropriate. Update those together.
Signed-off-by: SJ Park <sj@kernel.org>
---
mm/damon/core.c | 2 +-
mm/damon/ops-common.c | 2 +-
mm/damon/ops-common.h | 2 +-
mm/damon/tests/core-kunit.h | 2 +-
mm/damon/tests/paddr-kunit.h | 2 +-
mm/damon/tests/sysfs-kunit.h | 2 +-
mm/damon/tests/vaddr-kunit.h | 2 +-
7 files changed, 7 insertions(+), 7 deletions(-)
diff --git a/mm/damon/core.c b/mm/damon/core.c
index b791a2621bd6..fa32ebf7ad09 100644
--- a/mm/damon/core.c
+++ b/mm/damon/core.c
@@ -1,6 +1,6 @@
// SPDX-License-Identifier: GPL-2.0
/*
- * Data Access Monitor
+ * DAMON Core
*/
#define pr_fmt(fmt) "damon: " fmt
diff --git a/mm/damon/ops-common.c b/mm/damon/ops-common.c
index 2216a0023154..38720794c9fc 100644
--- a/mm/damon/ops-common.c
+++ b/mm/damon/ops-common.c
@@ -1,6 +1,6 @@
// SPDX-License-Identifier: GPL-2.0
/*
- * Common Code for Data Access Monitoring
+ * Common Code for DAMON Operation Set
*/
#include <linux/hugetlb.h>
diff --git a/mm/damon/ops-common.h b/mm/damon/ops-common.h
index ee2705825100..aabcf09ff501 100644
--- a/mm/damon/ops-common.h
+++ b/mm/damon/ops-common.h
@@ -1,6 +1,6 @@
/* SPDX-License-Identifier: GPL-2.0 */
/*
- * Common Code for Data Access Monitoring
+ * Common Code for DAMON Operation Set
*/
#include <linux/damon.h>
diff --git a/mm/damon/tests/core-kunit.h b/mm/damon/tests/core-kunit.h
index 4446574a3565..73c3bd6a9612 100644
--- a/mm/damon/tests/core-kunit.h
+++ b/mm/damon/tests/core-kunit.h
@@ -1,6 +1,6 @@
/* SPDX-License-Identifier: GPL-2.0 */
/*
- * Data Access Monitor Unit Tests
+ * DAMON Core Unit Tests
*/
#ifdef CONFIG_DAMON_KUNIT_TEST
diff --git a/mm/damon/tests/paddr-kunit.h b/mm/damon/tests/paddr-kunit.h
index 2b11f0e67a12..547e1b3c989f 100644
--- a/mm/damon/tests/paddr-kunit.h
+++ b/mm/damon/tests/paddr-kunit.h
@@ -1,6 +1,6 @@
/* SPDX-License-Identifier: GPL-2.0 */
/*
- * Data Access Monitor Unit Tests
+ * DAMON Physical Address Space Operation Set Unit Tests
*/
#ifdef CONFIG_DAMON_PADDR_KUNIT_TEST
diff --git a/mm/damon/tests/sysfs-kunit.h b/mm/damon/tests/sysfs-kunit.h
index 16373ba751db..c2bba2e01301 100644
--- a/mm/damon/tests/sysfs-kunit.h
+++ b/mm/damon/tests/sysfs-kunit.h
@@ -1,6 +1,6 @@
/* SPDX-License-Identifier: GPL-2.0 */
/*
- * Data Access Monitor Unit Tests
+ * DAMON sysfs Interface Unit Tests
*/
#ifdef CONFIG_DAMON_SYSFS_KUNIT_TEST
diff --git a/mm/damon/tests/vaddr-kunit.h b/mm/damon/tests/vaddr-kunit.h
index d61b503e319a..979e459327bf 100644
--- a/mm/damon/tests/vaddr-kunit.h
+++ b/mm/damon/tests/vaddr-kunit.h
@@ -1,6 +1,6 @@
/* SPDX-License-Identifier: GPL-2.0 */
/*
- * Data Access Monitor Unit Tests
+ * DAMON Virtual Address Space Operation Set Unit Tests
*/
#ifdef CONFIG_DAMON_VADDR_KUNIT_TEST
--
2.47.3
^ permalink raw reply related [flat|nested] 8+ messages in thread