* [RFC PATCH 0/6] mm/damon: misc cleanup/improvements for core, vaddr, sysfs and tests
@ 2026-10-31 20:26 SJ Park
2026-10-31 20:26 ` [RFC PATCH 1/6] mm/damon/core: handle invalid target in damos_fix_stale_charge_pointers() SJ Park
` (5 more replies)
0 siblings, 6 replies; 7+ messages in thread
From: SJ Park @ 2026-10-31 20:26 UTC (permalink / raw)
Cc: SJ Park, Andrew Morton, Shuah Khan, damon, linux-kernel,
linux-kselftest, linux-mm
Refactor code, optimize code speed, and add a missing feature support on
various areas of DAMON.
Consolidate invalid DAMOS quota charge pointers fixes into single place
in core with patch 1. Optimize the efficiency of vaddr damos_migrate
action under filter failures with patch 2. Implement sz_filter_passed
feature for damos_migrate action in vaddr, with patch 3. Drop a
redundant and racy quota goal target value validation in sysfs, in favor
of that in the core layer, with patch 4. Drop unused variables and
imports from selftests with patch 5 and 6.
SJ Park (6):
mm/damon/core: handle invalid target in
damos_fix_stale_charge_pointers()
mm/damon/vaddr: advance migration attempt in folio level for filter
out
mm/damon/vaddr: implement sz_filter_passed for migrate_{hot,cold}
action
mm/damon/sysfs-schemes: drop redundant and racy zero target_value
check
selftests/damon/damos_apply_interval: remove unused variables
selftests/damon: remove unused imports of os and sys modules
mm/damon/core.c | 15 ++++++---------
mm/damon/sysfs-schemes.c | 3 ---
mm/damon/vaddr.c | 8 ++++++--
.../selftests/damon/damos_apply_interval.py | 2 --
.../selftests/damon/sysfs_no_op_commit_break.py | 1 -
.../sysfs_update_schemes_tried_regions_hang.py | 1 -
6 files changed, 12 insertions(+), 18 deletions(-)
base-commit: de796f0221d9cfc6a468e83934b9514c43b0a4b3
--
2.47.3
^ permalink raw reply [flat|nested] 7+ messages in thread
* [RFC PATCH 1/6] mm/damon/core: handle invalid target in damos_fix_stale_charge_pointers()
2026-10-31 20:26 [RFC PATCH 0/6] mm/damon: misc cleanup/improvements for core, vaddr, sysfs and tests SJ Park
@ 2026-10-31 20:26 ` SJ Park
2026-10-31 20:26 ` [RFC PATCH 2/6] mm/damon/vaddr: advance migration attempt in folio level for filter out SJ Park
` (4 subsequent siblings)
5 siblings, 0 replies; 7+ messages in thread
From: SJ Park @ 2026-10-31 20:26 UTC (permalink / raw)
Cc: SJ Park, Andrew Morton, damon, linux-kernel, linux-mm
The fixup of DAMOS quota charge pointers
(damos->charge_{target,addr}_from) for removed targets and regions is
done in damos_fix_stale_charge_pointers(). A similar fixup for invalid
(terminated pid) targets is done in kdamond_apply_schemes(). Having
similar fixups in different places only make it confusing to read the
code. Consolidate the fixups into damos_fix_stale_charge_pointers().
Signed-off-by: SJ Park <sj@kernel.org>
---
mm/damon/core.c | 15 ++++++---------
1 file changed, 6 insertions(+), 9 deletions(-)
diff --git a/mm/damon/core.c b/mm/damon/core.c
index 73b571b429cb3..ce75db510a9d3 100644
--- a/mm/damon/core.c
+++ b/mm/damon/core.c
@@ -3394,7 +3394,11 @@ static void damos_fix_stale_charge_pointers(struct damon_ctx *c,
return;
damon_for_each_target(t, c) {
if (t == quota->charge_target_from) {
- if (damon_nr_regions(t) > 0)
+ bool valid_target = true;
+
+ if (c->ops.target_valid && !c->ops.target_valid(t))
+ valid_target = false;
+ if (valid_target && damon_nr_regions(t) > 0)
return;
break;
}
@@ -3513,15 +3517,8 @@ static noinline_for_stack void kdamond_apply_schemes(struct damon_ctx *c)
max_region_sz = damon_region_sz_limit(c);
mutex_lock(&c->walk_control_lock);
damon_for_each_target(t, c) {
- if (c->ops.target_valid && c->ops.target_valid(t) == false) {
- damon_for_each_scheme(s, c) {
- if (s->quota.charge_target_from != t)
- continue;
- s->quota.charge_target_from = NULL;
- s->quota.charge_addr_from = 0;
- }
+ if (c->ops.target_valid && c->ops.target_valid(t) == false)
continue;
- }
damos_apply_target(c, t, max_region_sz);
}
--
2.47.3
^ permalink raw reply [flat|nested] 7+ messages in thread
* [RFC PATCH 2/6] mm/damon/vaddr: advance migration attempt in folio level for filter out
2026-10-31 20:26 [RFC PATCH 0/6] mm/damon: misc cleanup/improvements for core, vaddr, sysfs and tests SJ Park
2026-10-31 20:26 ` [RFC PATCH 1/6] mm/damon/core: handle invalid target in damos_fix_stale_charge_pointers() SJ Park
@ 2026-10-31 20:26 ` SJ Park
2026-10-31 20:26 ` [RFC PATCH 3/6] mm/damon/vaddr: implement sz_filter_passed for migrate_{hot,cold} action SJ Park
` (3 subsequent siblings)
5 siblings, 0 replies; 7+ messages in thread
From: SJ Park @ 2026-10-31 20:26 UTC (permalink / raw)
Cc: SJ Park, Andrew Morton, damon, linux-kernel, 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 b549496ea8e2c..c271b6d63c027 100644
--- a/mm/damon/vaddr.c
+++ b/mm/damon/vaddr.c
@@ -881,12 +881,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, dests,
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 [flat|nested] 7+ messages in thread
* [RFC PATCH 3/6] mm/damon/vaddr: implement sz_filter_passed for migrate_{hot,cold} action
2026-10-31 20:26 [RFC PATCH 0/6] mm/damon: misc cleanup/improvements for core, vaddr, sysfs and tests SJ Park
2026-10-31 20:26 ` [RFC PATCH 1/6] mm/damon/core: handle invalid target in damos_fix_stale_charge_pointers() SJ Park
2026-10-31 20:26 ` [RFC PATCH 2/6] mm/damon/vaddr: advance migration attempt in folio level for filter out SJ Park
@ 2026-10-31 20:26 ` SJ Park
2026-10-31 20:26 ` [RFC PATCH 4/6] mm/damon/sysfs-schemes: drop redundant and racy zero target_value check SJ Park
` (2 subsequent siblings)
5 siblings, 0 replies; 7+ messages in thread
From: SJ Park @ 2026-10-31 20:26 UTC (permalink / raw)
Cc: SJ Park, Andrew Morton, damon, linux-kernel, 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 | 4 ++++
1 file changed, 4 insertions(+)
diff --git a/mm/damon/vaddr.c b/mm/damon/vaddr.c
index c271b6d63c027..112095c2d53fd 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;
};
/*
@@ -840,6 +841,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 damos_migrate_dests *dests = &s->migrate_dests;
struct folio *folio;
spinlock_t *ptl;
@@ -858,6 +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;
+ *sz_filter_passed += folio_size(folio);
damos_va_migrate_dests_add(folio, walk->vma, addr, dests,
migration_lists);
huge_out:
@@ -885,6 +888,7 @@ static int damos_va_migrate_pmd_entry(pmd_t *pmd, unsigned long addr,
nr = folio_nr_pages(folio) - page_idx;
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, dests,
migration_lists);
}
--
2.47.3
^ permalink raw reply [flat|nested] 7+ messages in thread
* [RFC PATCH 4/6] mm/damon/sysfs-schemes: drop redundant and racy zero target_value check
2026-10-31 20:26 [RFC PATCH 0/6] mm/damon: misc cleanup/improvements for core, vaddr, sysfs and tests SJ Park
` (2 preceding siblings ...)
2026-10-31 20:26 ` [RFC PATCH 3/6] mm/damon/vaddr: implement sz_filter_passed for migrate_{hot,cold} action SJ Park
@ 2026-10-31 20:26 ` SJ Park
2026-10-31 20:26 ` [RFC PATCH 5/6] selftests/damon/damos_apply_interval: remove unused variables SJ Park
2026-10-31 20:26 ` [RFC PATCH 6/6] selftests/damon: remove unused imports of os and sys modules SJ Park
5 siblings, 0 replies; 7+ messages in thread
From: SJ Park @ 2026-10-31 20:26 UTC (permalink / raw)
Cc: SJ Park, Andrew Morton, damon, linux-kernel, 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 637f1bd0c950b..38efdc258ef3f 100644
--- a/mm/damon/sysfs-schemes.c
+++ b/mm/damon/sysfs-schemes.c
@@ -2898,9 +2898,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 [flat|nested] 7+ messages in thread
* [RFC PATCH 5/6] selftests/damon/damos_apply_interval: remove unused variables
2026-10-31 20:26 [RFC PATCH 0/6] mm/damon: misc cleanup/improvements for core, vaddr, sysfs and tests SJ Park
` (3 preceding siblings ...)
2026-10-31 20:26 ` [RFC PATCH 4/6] mm/damon/sysfs-schemes: drop redundant and racy zero target_value check SJ Park
@ 2026-10-31 20:26 ` SJ Park
2026-10-31 20:26 ` [RFC PATCH 6/6] selftests/damon: remove unused imports of os and sys modules SJ Park
5 siblings, 0 replies; 7+ messages in thread
From: SJ Park @ 2026-10-31 20:26 UTC (permalink / raw)
Cc: SJ Park, Shuah Khan, damon, linux-kernel, 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 0bf7768b2006a..0ad110be0fb94 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 [flat|nested] 7+ messages in thread
* [RFC PATCH 6/6] selftests/damon: remove unused imports of os and sys modules
2026-10-31 20:26 [RFC PATCH 0/6] mm/damon: misc cleanup/improvements for core, vaddr, sysfs and tests SJ Park
` (4 preceding siblings ...)
2026-10-31 20:26 ` [RFC PATCH 5/6] selftests/damon/damos_apply_interval: remove unused variables SJ Park
@ 2026-10-31 20:26 ` SJ Park
5 siblings, 0 replies; 7+ messages in thread
From: SJ Park @ 2026-10-31 20:26 UTC (permalink / raw)
Cc: SJ Park, Shuah Khan, damon, linux-kernel, linux-kselftest, linux-mm
sysfs_no_op_commit_break.py imports os module but never uses it.
sysfs_update_schemes_tried_regions_hang imports the sys 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 81774ddc55ac4..5664f75186bac 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 625761c243b58..326a14f040534 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 [flat|nested] 7+ messages in thread
end of thread, other threads:[~2026-10-31 20:26 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-10-31 20:26 [RFC PATCH 0/6] mm/damon: misc cleanup/improvements for core, vaddr, sysfs and tests SJ Park
2026-10-31 20:26 ` [RFC PATCH 1/6] mm/damon/core: handle invalid target in damos_fix_stale_charge_pointers() SJ Park
2026-10-31 20:26 ` [RFC PATCH 2/6] mm/damon/vaddr: advance migration attempt in folio level for filter out SJ Park
2026-10-31 20:26 ` [RFC PATCH 3/6] mm/damon/vaddr: implement sz_filter_passed for migrate_{hot,cold} action SJ Park
2026-10-31 20:26 ` [RFC PATCH 4/6] mm/damon/sysfs-schemes: drop redundant and racy zero target_value check SJ Park
2026-10-31 20:26 ` [RFC PATCH 5/6] selftests/damon/damos_apply_interval: remove unused variables SJ Park
2026-10-31 20:26 ` [RFC PATCH 6/6] selftests/damon: remove unused imports of os and sys modules SJ Park
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®