* [PATCH 1/7] mm/damon/core: remove declaration of __damon_commit_ctx()
2026-08-31 14:26 [PATCH 0/7] mm/damon: misc cleanups SJ Park
@ 2026-08-31 14:26 ` SJ Park
2026-08-31 17:44 ` sashiko-bot
2026-08-31 14:26 ` [PATCH 2/7] mm/damon/core: introduce damon_set_target_pid() SJ Park
` (5 subsequent siblings)
6 siblings, 1 reply; 17+ messages in thread
From: SJ Park @ 2026-08-31 14:26 UTC (permalink / raw)
To: Andrew Morton; +Cc: Zenghui Yu (Huawei), SJ Park, damon, linux-kernel, linux-mm
From: "Zenghui Yu (Huawei)" <zenghui.yu@linux.dev>
It was added by commit b1471afe4d10 ("mm/damon/core: do parameter testing
commit on damon_start()") but is actually not needed. Remove it.
Changes from v1
- v1: https://lore.kernel.org/20260806170701.79266-1-zenghui.yu@linux.dev
- Collect R-b: from SJ.
- Rebase to latest mm-new.
Cc: "Zenghui Yu (Huawei)" <zenghui.yu@linux.dev>
Signed-off-by: Zenghui Yu (Huawei) <zenghui.yu@linux.dev>
Reviewed-by: SJ Park <sj@kernel.org>
Signed-off-by: SJ Park <sj@kernel.org>
---
mm/damon/core.c | 2 --
1 file changed, 2 deletions(-)
diff --git a/mm/damon/core.c b/mm/damon/core.c
index b3f8bea774c2d..79515ef03fc2a 100644
--- a/mm/damon/core.c
+++ b/mm/damon/core.c
@@ -1961,8 +1961,6 @@ static int __damon_start(struct damon_ctx *ctx)
return err;
}
-static int __damon_commit_ctx(struct damon_ctx *dst, struct damon_ctx *src);
-
/**
* damon_start() - Starts the monitorings for a given group of contexts.
* @ctxs: an array of the pointers for contexts to start monitoring
--
2.47.3
^ permalink raw reply related [flat|nested] 17+ messages in thread* [PATCH 2/7] mm/damon/core: introduce damon_set_target_pid()
2026-08-31 14:26 [PATCH 0/7] mm/damon: misc cleanups SJ Park
2026-08-31 14:26 ` [PATCH 1/7] mm/damon/core: remove declaration of __damon_commit_ctx() SJ Park
@ 2026-08-31 14:26 ` SJ Park
2026-08-31 17:58 ` sashiko-bot
2026-08-31 23:31 ` Andrew Morton
2026-08-31 14:26 ` [PATCH 3/7] mm/damon/ops-common: factor out damon_putback_folio_list() SJ Park
` (4 subsequent siblings)
6 siblings, 2 replies; 17+ messages in thread
From: SJ Park @ 2026-08-31 14:26 UTC (permalink / raw)
To: Andrew Morton; +Cc: SJ Park, damon, linux-kernel, linux-mm, Enze Li
The logic that finds the struct pid for a given pid number and assigns
it to a damon_target is duplicated in multiple places. Including
damon_sysfs_add_target() of mm/damon/sysfs.c and the start functions
of the two sample modules, samples/damon/wsse.c and
samples/damon/prcl.c. Add a function that does the work, and replace
the duplicated code in the places with calls to the function.
Signed-off-by: Enze Li <lienze@kylinos.cn>
Reviewed-by: SJ Park <sj@kernel.org>
Signed-off-by: SJ Park <sj@kernel.org>
---
Changes from v1
- v1: https://lore.kernel.org/20260817125319.888994-1-lienze@kylinos.cn
- Collect R-b: from SJ.
- Rebase to latest mm-new.
include/linux/damon.h | 1 +
mm/damon/core.c | 12 ++++++++++++
mm/damon/sysfs.c | 6 ++----
samples/damon/prcl.c | 5 +----
samples/damon/wsse.c | 5 +----
5 files changed, 17 insertions(+), 12 deletions(-)
diff --git a/include/linux/damon.h b/include/linux/damon.h
index 0c8b7ddef9abb..5607f98ec6306 100644
--- a/include/linux/damon.h
+++ b/include/linux/damon.h
@@ -1055,6 +1055,7 @@ int damos_commit_quota_goals(struct damos_quota *dst, struct damos_quota *src);
struct damon_target *damon_new_target(void);
void damon_add_target(struct damon_ctx *ctx, struct damon_target *t);
bool damon_targets_empty(struct damon_ctx *ctx);
+int damon_set_target_pid(struct damon_target *t, int pid);
void damon_free_target(struct damon_target *t);
void damon_destroy_target(struct damon_target *t, struct damon_ctx *ctx);
unsigned int damon_nr_regions(struct damon_target *t);
diff --git a/mm/damon/core.c b/mm/damon/core.c
index 79515ef03fc2a..a5ea3e61e7f41 100644
--- a/mm/damon/core.c
+++ b/mm/damon/core.c
@@ -10,6 +10,7 @@
#include <linux/kthread.h>
#include <linux/memcontrol.h>
#include <linux/mm.h>
+#include <linux/pid.h>
#include <linux/psi.h>
#include <linux/sched.h>
#include <linux/slab.h>
@@ -802,6 +803,17 @@ bool damon_targets_empty(struct damon_ctx *ctx)
return list_empty(&ctx->adaptive_targets);
}
+/*
+ * Assign the struct pid of the given pid number to the given target.
+ */
+int damon_set_target_pid(struct damon_target *t, int pid)
+{
+ t->pid = find_get_pid(pid);
+ if (!t->pid)
+ return -EINVAL;
+ return 0;
+}
+
static void damon_del_target(struct damon_target *t)
{
list_del(&t->list);
diff --git a/mm/damon/sysfs.c b/mm/damon/sysfs.c
index f05b256c90ee7..dcb739ce0a729 100644
--- a/mm/damon/sysfs.c
+++ b/mm/damon/sysfs.c
@@ -3,7 +3,6 @@
* DAMON sysfs Interface
*/
-#include <linux/pid.h>
#include <linux/sched.h>
#include <linux/slab.h>
@@ -2036,9 +2035,8 @@ static int damon_sysfs_add_target(struct damon_sysfs_target *sys_target,
return -ENOMEM;
damon_add_target(ctx, t);
if (damon_target_has_pid(ctx)) {
- t->pid = find_get_pid(sys_target->pid);
- if (!t->pid)
- /* caller will destroy targets */
+ /* caller will destroy targets */
+ if (damon_set_target_pid(t, sys_target->pid))
return -EINVAL;
}
t->obsolete = sys_target->obsolete;
diff --git a/samples/damon/prcl.c b/samples/damon/prcl.c
index 842099bd62286..83ddf12811d57 100644
--- a/samples/damon/prcl.c
+++ b/samples/damon/prcl.c
@@ -32,7 +32,6 @@ module_param_cb(enabled, &enabled_param_ops, &enabled, 0600);
MODULE_PARM_DESC(enabled, "Enable or disable DAMON_SAMPLE_PRCL");
static struct damon_ctx *ctx;
-static struct pid *target_pidp;
static int damon_sample_prcl_repeat_call_fn(void *data)
{
@@ -79,12 +78,10 @@ static int damon_sample_prcl_start(void)
return -ENOMEM;
}
damon_add_target(ctx, target);
- target_pidp = find_get_pid(target_pid);
- if (!target_pidp) {
+ if (damon_set_target_pid(target, target_pid)) {
damon_destroy_ctx(ctx);
return -EINVAL;
}
- target->pid = target_pidp;
scheme = damon_new_scheme(
&(struct damos_access_pattern) {
diff --git a/samples/damon/wsse.c b/samples/damon/wsse.c
index 37fd5da201588..53944aea8428e 100644
--- a/samples/damon/wsse.c
+++ b/samples/damon/wsse.c
@@ -33,7 +33,6 @@ module_param_cb(enabled, &enabled_param_ops, &enabled, 0600);
MODULE_PARM_DESC(enabled, "Enable or disable DAMON_SAMPLE_WSSE");
static struct damon_ctx *ctx;
-static struct pid *target_pidp;
static int damon_sample_wsse_repeat_call_fn(void *data)
{
@@ -79,12 +78,10 @@ static int damon_sample_wsse_start(void)
return -ENOMEM;
}
damon_add_target(ctx, target);
- target_pidp = find_get_pid(target_pid);
- if (!target_pidp) {
+ if (damon_set_target_pid(target, target_pid)) {
damon_destroy_ctx(ctx);
return -EINVAL;
}
- target->pid = target_pidp;
err = damon_start(&ctx, 1, true);
if (err) {
--
2.47.3
^ permalink raw reply related [flat|nested] 17+ messages in thread* Re: [PATCH 2/7] mm/damon/core: introduce damon_set_target_pid()
2026-08-31 14:26 ` [PATCH 2/7] mm/damon/core: introduce damon_set_target_pid() SJ Park
@ 2026-08-31 17:58 ` sashiko-bot
2026-08-31 23:31 ` Andrew Morton
1 sibling, 0 replies; 17+ messages in thread
From: sashiko-bot @ 2026-08-31 17:58 UTC (permalink / raw)
To: SJ Park; +Cc: damon
> The logic that finds the struct pid for a given pid number and assigns
> it to a damon_target is duplicated in multiple places. Including
> damon_sysfs_add_target() of mm/damon/sysfs.c and the start functions
> of the two sample modules, samples/damon/wsse.c and
> samples/damon/prcl.c. Add a function that does the work, and replace
> the duplicated code in the places with calls to the function.
>
> Signed-off-by: Enze Li <lienze@kylinos.cn>
> Reviewed-by: SJ Park <sj@kernel.org>
> Signed-off-by: SJ Park <sj@kernel.org>
Sashiko has reviewed this patch and found no issues. It looks great!
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260831142611.77572-1-sj@kernel.org?part=2
^ permalink raw reply [flat|nested] 17+ messages in thread
* Re: [PATCH 2/7] mm/damon/core: introduce damon_set_target_pid()
2026-08-31 14:26 ` [PATCH 2/7] mm/damon/core: introduce damon_set_target_pid() SJ Park
2026-08-31 17:58 ` sashiko-bot
@ 2026-08-31 23:31 ` Andrew Morton
2026-09-01 0:40 ` SJ Park
1 sibling, 1 reply; 17+ messages in thread
From: Andrew Morton @ 2026-08-31 23:31 UTC (permalink / raw)
To: SJ Park; +Cc: damon, linux-kernel, linux-mm, Enze Li
On Mon, 31 Aug 2026 07:26:04 -0700 SJ Park <sj@kernel.org> wrote:
> The logic that finds the struct pid for a given pid number and assigns
> it to a damon_target is duplicated in multiple places. Including
> damon_sysfs_add_target() of mm/damon/sysfs.c and the start functions
> of the two sample modules, samples/damon/wsse.c and
> samples/damon/prcl.c. Add a function that does the work, and replace
> the duplicated code in the places with calls to the function.
>
> Signed-off-by: Enze Li <lienze@kylinos.cn>
> Reviewed-by: SJ Park <sj@kernel.org>
> Signed-off-by: SJ Park <sj@kernel.org>
I assumed that From:Enze was intended here.
^ permalink raw reply [flat|nested] 17+ messages in thread
* Re: [PATCH 2/7] mm/damon/core: introduce damon_set_target_pid()
2026-08-31 23:31 ` Andrew Morton
@ 2026-09-01 0:40 ` SJ Park
0 siblings, 0 replies; 17+ messages in thread
From: SJ Park @ 2026-09-01 0:40 UTC (permalink / raw)
To: Andrew Morton; +Cc: SJ Park, damon, linux-kernel, linux-mm, Enze Li
On Mon, 31 Aug 2026 16:31:19 -0700 Andrew Morton <akpm@linux-foundation.org> wrote:
> On Mon, 31 Aug 2026 07:26:04 -0700 SJ Park <sj@kernel.org> wrote:
>
> > The logic that finds the struct pid for a given pid number and assigns
> > it to a damon_target is duplicated in multiple places. Including
> > damon_sysfs_add_target() of mm/damon/sysfs.c and the start functions
> > of the two sample modules, samples/damon/wsse.c and
> > samples/damon/prcl.c. Add a function that does the work, and replace
> > the duplicated code in the places with calls to the function.
> >
> > Signed-off-by: Enze Li <lienze@kylinos.cn>
> > Reviewed-by: SJ Park <sj@kernel.org>
> > Signed-off-by: SJ Park <sj@kernel.org>
>
> I assumed that From:Enze was intended here.
You're correct Andrew. I found you already fixed this when applying this to
mm-new. Appreciate!
Thanks,
SJ
^ permalink raw reply [flat|nested] 17+ messages in thread
* [PATCH 3/7] mm/damon/ops-common: factor out damon_putback_folio_list()
2026-08-31 14:26 [PATCH 0/7] mm/damon: misc cleanups SJ Park
2026-08-31 14:26 ` [PATCH 1/7] mm/damon/core: remove declaration of __damon_commit_ctx() SJ Park
2026-08-31 14:26 ` [PATCH 2/7] mm/damon/core: introduce damon_set_target_pid() SJ Park
@ 2026-08-31 14:26 ` SJ Park
2026-08-31 18:00 ` sashiko-bot
2026-08-31 14:26 ` [PATCH 4/7] selftests/damon/sysfs.py: clean up sh processes used for obsolete_target test SJ Park
` (3 subsequent siblings)
6 siblings, 1 reply; 17+ messages in thread
From: SJ Park @ 2026-08-31 14:26 UTC (permalink / raw)
To: Andrew Morton; +Cc: Li Youhong, SJ Park, damon, linux-kernel, linux-mm
From: Li Youhong <liyouhong@kylinos.cn>
The putback loop is duplicated in damon_migrate_folio_list() and on the
invalid-nid path of damon_migrate_pages(). Factor it into a small helper
for readability. No functional change.
Signed-off-by: Li Youhong <liyouhong@kylinos.cn>
Reviewed-by: SJ Park <sj@kernel.org>
Signed-off-by: SJ Park <sj@kernel.org>
---
Changes from v1
- v1: https://lore.kernel.org/20260818020650.2844354-1-dayou5941@163.com
- Collect R-b: from SJ.
- Rebase to latest mm-new.
mm/damon/ops-common.c | 30 +++++++++++++++---------------
1 file changed, 15 insertions(+), 15 deletions(-)
diff --git a/mm/damon/ops-common.c b/mm/damon/ops-common.c
index fbda70d8ea4d0..7a2e40bc7baed 100644
--- a/mm/damon/ops-common.c
+++ b/mm/damon/ops-common.c
@@ -330,6 +330,19 @@ static unsigned int __damon_migrate_folio_list(
return nr_succeeded;
}
+static void damon_putback_folio_list(struct list_head *folio_list)
+{
+ struct folio *folio;
+
+ while (!list_empty(folio_list)) {
+ folio = lru_to_folio(folio_list);
+ list_del(&folio->lru);
+ node_stat_sub_folio(folio, NR_ISOLATED_ANON +
+ folio_is_file_lru(folio));
+ folio_putback_lru(folio);
+ }
+}
+
static unsigned int damon_migrate_folio_list(struct list_head *folio_list,
struct pglist_data *pgdat,
int target_nid)
@@ -371,13 +384,7 @@ static unsigned int damon_migrate_folio_list(struct list_head *folio_list,
list_splice(&ret_folios, folio_list);
- while (!list_empty(folio_list)) {
- folio = lru_to_folio(folio_list);
- list_del(&folio->lru);
- node_stat_sub_folio(folio, NR_ISOLATED_ANON +
- folio_is_file_lru(folio));
- folio_putback_lru(folio);
- }
+ damon_putback_folio_list(folio_list);
return nr_migrated;
}
@@ -394,14 +401,7 @@ unsigned long damon_migrate_pages(struct list_head *folio_list, int target_nid)
if (target_nid < 0 || target_nid >= MAX_NUMNODES ||
!node_state(target_nid, N_MEMORY)) {
- while (!list_empty(folio_list)) {
- struct folio *folio = lru_to_folio(folio_list);
-
- list_del(&folio->lru);
- node_stat_sub_folio(folio, NR_ISOLATED_ANON +
- folio_is_file_lru(folio));
- folio_putback_lru(folio);
- }
+ damon_putback_folio_list(folio_list);
return nr_migrated;
}
--
2.47.3
^ permalink raw reply related [flat|nested] 17+ messages in thread* [PATCH 4/7] selftests/damon/sysfs.py: clean up sh processes used for obsolete_target test
2026-08-31 14:26 [PATCH 0/7] mm/damon: misc cleanups SJ Park
` (2 preceding siblings ...)
2026-08-31 14:26 ` [PATCH 3/7] mm/damon/ops-common: factor out damon_putback_folio_list() SJ Park
@ 2026-08-31 14:26 ` SJ Park
2026-08-31 18:06 ` sashiko-bot
2026-08-31 14:26 ` [PATCH 5/7] mm/damon/tests: use scoped_guard() for damon_test_ops_registration SJ Park
` (2 subsequent siblings)
6 siblings, 1 reply; 17+ messages in thread
From: SJ Park @ 2026-08-31 14:26 UTC (permalink / raw)
To: Andrew Morton
Cc: Hari Mishal, Greg Kroah-Hartman, SJ Park, Shuah Khan, damon,
linux-kernel, linux-kselftest, linux-mm
From: Hari Mishal <harimishal1@gmail.com>
The obsolete_target test spawns three sh processes and uses their pids
as DAMON monitoring targets. These processes are never terminated or
waited on, so they are left running (or become zombies) as orphaned
children after the test program exits.
Terminate each process and communicate() with it after the targets are
no longer needed, so it exits and gets reaped instead of being leaked.
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Signed-off-by: Hari Mishal <harimishal1@gmail.com>
Reviewed-by: SJ Park <sj@kernel.org>
Signed-off-by: SJ Park <sj@kernel.org>
---
Changes from v2
- v2: https://lore.kernel.org/20260722012349.9738-1-harimishal1@gmail.com
- Collect R-b: from SJ.
- Rebase to latest mm-new.
Changes from v1
- v1: https://lore.kernel.org/20260721190404.135937-1-harimishal1@gmail.com
- Terminate each sh process directly instead of giving it its own stdin
pipe to close, dropping the stdin=PIPE changes and shrinking the diff.
tools/testing/selftests/damon/sysfs.py | 4 ++++
1 file changed, 4 insertions(+)
diff --git a/tools/testing/selftests/damon/sysfs.py b/tools/testing/selftests/damon/sysfs.py
index 3ffa054b63867..88a26422ff44c 100755
--- a/tools/testing/selftests/damon/sysfs.py
+++ b/tools/testing/selftests/damon/sysfs.py
@@ -385,6 +385,10 @@ def main():
assert_ctxs_committed(kdamonds)
kdamonds.stop()
+ for proc in (proc1, proc2, proc3):
+ proc.terminate()
+ proc.communicate()
+
test_memcg_filter_memcg_path_staging()
if __name__ == '__main__':
--
2.47.3
^ permalink raw reply related [flat|nested] 17+ messages in thread* [PATCH 5/7] mm/damon/tests: use scoped_guard() for damon_test_ops_registration
2026-08-31 14:26 [PATCH 0/7] mm/damon: misc cleanups SJ Park
` (3 preceding siblings ...)
2026-08-31 14:26 ` [PATCH 4/7] selftests/damon/sysfs.py: clean up sh processes used for obsolete_target test SJ Park
@ 2026-08-31 14:26 ` SJ Park
2026-08-31 18:12 ` sashiko-bot
2026-08-31 14:26 ` [PATCH 6/7] selftests/damon: prevent remaining cross-object state pollution SJ Park
2026-08-31 14:26 ` [PATCH 7/7] samples/damon/mtier: add comment for struct region_range SJ Park
6 siblings, 1 reply; 17+ messages in thread
From: SJ Park @ 2026-08-31 14:26 UTC (permalink / raw)
To: Andrew Morton; +Cc: Jaeyeon Lee, SJ Park, damon, linux-kernel, linux-mm
From: Jaeyeon Lee <jaeyeon.lee.dev@gmail.com>
Replace manual mutex_lock() and mutex_unlock() calls with the
scoped_guard() macro. This simplifies the code, improves readability,
and ensures that the lock is automatically released when the scope
ends, preventing potential lock leaks in the future.
Signed-off-by: Jaeyeon Lee <jaeyeon.lee.dev@gmail.com>
Reviewed-by: SJ Park <sj@kernel.org>
Signed-off-by: SJ Park <sj@kernel.org>
---
Changes from v1
- v1: https://lore.kernel.org/20260815143039.17291-1-jaeyeon.lee.dev@gmail.com
- Collec R-b: from SJ.
- Rebase to latest mm-new.
mm/damon/tests/core-kunit.h | 21 ++++++++++-----------
1 file changed, 10 insertions(+), 11 deletions(-)
diff --git a/mm/damon/tests/core-kunit.h b/mm/damon/tests/core-kunit.h
index 65443aba03300..ec7260a3bfea8 100644
--- a/mm/damon/tests/core-kunit.h
+++ b/mm/damon/tests/core-kunit.h
@@ -434,17 +434,17 @@ static void damon_test_ops_registration(struct kunit *test)
KUNIT_EXPECT_EQ(test, damon_select_ops(c, NR_DAMON_OPS), -EINVAL);
/* Registration should success after unregistration */
- mutex_lock(&damon_ops_lock);
- bak = damon_registered_ops[DAMON_OPS_VADDR];
- damon_registered_ops[DAMON_OPS_VADDR] = (struct damon_operations){};
- mutex_unlock(&damon_ops_lock);
+ scoped_guard(mutex, &damon_ops_lock) {
+ bak = damon_registered_ops[DAMON_OPS_VADDR];
+ damon_registered_ops[DAMON_OPS_VADDR] =
+ (struct damon_operations){};
+ }
ops.id = DAMON_OPS_VADDR;
KUNIT_EXPECT_EQ(test, damon_register_ops(&ops), 0);
- mutex_lock(&damon_ops_lock);
- damon_registered_ops[DAMON_OPS_VADDR] = bak;
- mutex_unlock(&damon_ops_lock);
+ scoped_guard(mutex, &damon_ops_lock)
+ damon_registered_ops[DAMON_OPS_VADDR] = bak;
/* Check double-registration failure again */
KUNIT_EXPECT_EQ(test, damon_register_ops(&ops), -EINVAL);
@@ -452,10 +452,9 @@ static void damon_test_ops_registration(struct kunit *test)
damon_destroy_ctx(c);
if (need_cleanup) {
- mutex_lock(&damon_ops_lock);
- damon_registered_ops[DAMON_OPS_VADDR] =
- (struct damon_operations){};
- mutex_unlock(&damon_ops_lock);
+ scoped_guard(mutex, &damon_ops_lock)
+ damon_registered_ops[DAMON_OPS_VADDR] =
+ (struct damon_operations){};
}
}
--
2.47.3
^ permalink raw reply related [flat|nested] 17+ messages in thread* [PATCH 6/7] selftests/damon: prevent remaining cross-object state pollution
2026-08-31 14:26 [PATCH 0/7] mm/damon: misc cleanups SJ Park
` (4 preceding siblings ...)
2026-08-31 14:26 ` [PATCH 5/7] mm/damon/tests: use scoped_guard() for damon_test_ops_registration SJ Park
@ 2026-08-31 14:26 ` SJ Park
2026-08-31 18:17 ` sashiko-bot
2026-08-31 14:26 ` [PATCH 7/7] samples/damon/mtier: add comment for struct region_range SJ Park
6 siblings, 1 reply; 17+ messages in thread
From: SJ Park @ 2026-08-31 14:26 UTC (permalink / raw)
To: Andrew Morton
Cc: zhaozhengzhuo, SJ Park, Shuah Khan, damon, linux-kernel,
linux-kselftest, linux-mm
From: zhaozhengzhuo <zhaozhengzhuo@uniontech.com>
_damon_sysfs.py defines constructors with mutable default arguments,
including DamosAccessPattern(), DamosQuota(), DamosWatermarks(),
DamosDests(), IntervalsGoal(), and empty lists.
Default arguments are evaluated once at function definition time.
Damos() instances created without explicit arguments therefore share
the same DamosQuota(), and the other default-constructed sub-objects
and lists are shared in the same way. The sub-objects keep
back-pointers to their owner scheme, so constructing the second Damos()
rebinds the shared quota's scheme pointer to the second object. An
item appended to one object's default contexts or filters list is also
visible from other default-constructed objects.
The shared state can corrupt test configurations. DamosQuota.sysfs_dir()
derives the sysfs directory from its scheme pointer, so operating on
the first scheme's default quota may write to the second scheme's
directory. The wrong values often match the defaults, so tests still
pass, but the behavior depends on object creation order.
Commit 8319dadcbd81 ("selftests/damon: prevent cross-context state
pollution in DamonCtx") fixed the same pattern in DamonCtx only. Fix
the remaining constructors by defaulting to None and creating fresh
objects or lists inside each constructor. Explicit arguments keep
their previous behavior.
Signed-off-by: zhaozhengzhuo <zhaozhengzhuo@uniontech.com>
Reviewed-by: SJ Park <sj@kernel.org>
Signed-off-by: SJ Park <sj@kernel.org>
---
Changes from v1
- v1: https://lore.kernel.org/38E4AAAAEDFCC283+20260827021515.1316838-1-zhaozhengzhuo@uniontech.com
- Collec R-b: from SJ.
- Rebase to latest mm-new.
tools/testing/selftests/damon/_damon_sysfs.py | 38 ++++++++++++++-----
1 file changed, 28 insertions(+), 10 deletions(-)
diff --git a/tools/testing/selftests/damon/_damon_sysfs.py b/tools/testing/selftests/damon/_damon_sysfs.py
index e6a2265d721e8..f604b7d6530b3 100644
--- a/tools/testing/selftests/damon/_damon_sysfs.py
+++ b/tools/testing/selftests/damon/_damon_sysfs.py
@@ -321,8 +321,10 @@ class DamosFilters:
filters = None
scheme = None # owner scheme
- def __init__(self, name, filters=[]):
+ def __init__(self, name, filters=None):
self.name = name
+ if filters is None:
+ filters = []
self.filters = filters
for idx, filter_ in enumerate(self.filters):
filter_.idx = idx
@@ -368,7 +370,9 @@ class DamosDests:
dests = None
scheme = None # owner scheme
- def __init__(self, dests=[]):
+ def __init__(self, dests=None):
+ if dests is None:
+ dests = []
self.dests = dests
for idx, dest in enumerate(self.dests):
dest.idx = idx
@@ -426,15 +430,21 @@ class Damos:
stats = None
tried_regions = None
- def __init__(self, action='stat', access_pattern=DamosAccessPattern(),
- quota=DamosQuota(), watermarks=DamosWatermarks(),
- core_filters=[], ops_filters=[], filters=[], target_nid=0,
- dests=DamosDests(), apply_interval_us=0):
+ def __init__(self, action='stat', access_pattern=None, quota=None,
+ watermarks=None, core_filters=None, ops_filters=None,
+ filters=None, target_nid=0, dests=None,
+ apply_interval_us=0):
self.action = action
+ if access_pattern is None:
+ access_pattern = DamosAccessPattern()
self.access_pattern = access_pattern
self.access_pattern.scheme = self
+ if quota is None:
+ quota = DamosQuota()
self.quota = quota
self.quota.scheme = self
+ if watermarks is None:
+ watermarks = DamosWatermarks()
self.watermarks = watermarks
self.watermarks.scheme = self
@@ -448,6 +458,8 @@ class Damos:
self.filters.scheme = self
self.target_nid = target_nid
+ if dests is None:
+ dests = DamosDests()
self.dests = dests
self.dests.scheme = self
@@ -568,10 +580,12 @@ class DamonAttrs:
context = None
def __init__(self, sample_us=5000, aggr_us=100000,
- intervals_goal=IntervalsGoal(), update_us=1000000,
- min_nr_regions=10, max_nr_regions=1000):
+ intervals_goal=None, update_us=1000000, min_nr_regions=10,
+ max_nr_regions=1000):
self.sample_us = sample_us
self.aggr_us = aggr_us
+ if intervals_goal is None:
+ intervals_goal = IntervalsGoal()
self.intervals_goal = intervals_goal
self.intervals_goal.attrs = self
self.update_us = update_us
@@ -703,7 +717,9 @@ class Kdamond:
idx = None # index of this kdamond between siblings
kdamonds = None # parent
- def __init__(self, contexts=[], refresh_ms=None):
+ def __init__(self, contexts=None, refresh_ms=None):
+ if contexts is None:
+ contexts = []
self.contexts = contexts
self.refresh_ms = refresh_ms
for idx, context in enumerate(self.contexts):
@@ -853,7 +869,9 @@ class Kdamond:
class Kdamonds:
kdamonds = []
- def __init__(self, kdamonds=[]):
+ def __init__(self, kdamonds=None):
+ if kdamonds is None:
+ kdamonds = []
self.kdamonds = kdamonds
for idx, kdamond in enumerate(self.kdamonds):
kdamond.idx = idx
--
2.47.3
^ permalink raw reply related [flat|nested] 17+ messages in thread* Re: [PATCH 6/7] selftests/damon: prevent remaining cross-object state pollution
2026-08-31 14:26 ` [PATCH 6/7] selftests/damon: prevent remaining cross-object state pollution SJ Park
@ 2026-08-31 18:17 ` sashiko-bot
0 siblings, 0 replies; 17+ messages in thread
From: sashiko-bot @ 2026-08-31 18:17 UTC (permalink / raw)
To: SJ Park; +Cc: damon
> From: zhaozhengzhuo <zhaozhengzhuo@uniontech.com>
>
> _damon_sysfs.py defines constructors with mutable default arguments,
> including DamosAccessPattern(), DamosQuota(), DamosWatermarks(),
> DamosDests(), IntervalsGoal(), and empty lists.
>
> Default arguments are evaluated once at function definition time.
> Damos() instances created without explicit arguments therefore share
> the same DamosQuota(), and the other default-constructed sub-objects
> and lists are shared in the same way. The sub-objects keep
> back-pointers to their owner scheme, so constructing the second Damos()
> rebinds the shared quota's scheme pointer to the second object. An
> item appended to one object's default contexts or filters list is also
> visible from other default-constructed objects.
>
> The shared state can corrupt test configurations. DamosQuota.sysfs_dir()
> derives the sysfs directory from its scheme pointer, so operating on
> the first scheme's default quota may write to the second scheme's
> directory. The wrong values often match the defaults, so tests still
> pass, but the behavior depends on object creation order.
>
> Commit 8319dadcbd81 ("selftests/damon: prevent cross-context state
> pollution in DamonCtx") fixed the same pattern in DamonCtx only. Fix
> the remaining constructors by defaulting to None and creating fresh
> objects or lists inside each constructor. Explicit arguments keep
> their previous behavior.
>
> Signed-off-by: zhaozhengzhuo <zhaozhengzhuo@uniontech.com>
> Reviewed-by: SJ Park <sj@kernel.org>
> Signed-off-by: SJ Park <sj@kernel.org>
Sashiko has reviewed this patch and found no issues. It looks great!
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260831142611.77572-1-sj@kernel.org?part=6
^ permalink raw reply [flat|nested] 17+ messages in thread
* [PATCH 7/7] samples/damon/mtier: add comment for struct region_range
2026-08-31 14:26 [PATCH 0/7] mm/damon: misc cleanups SJ Park
` (5 preceding siblings ...)
2026-08-31 14:26 ` [PATCH 6/7] selftests/damon: prevent remaining cross-object state pollution SJ Park
@ 2026-08-31 14:26 ` SJ Park
2026-08-31 18:18 ` sashiko-bot
6 siblings, 1 reply; 17+ messages in thread
From: SJ Park @ 2026-08-31 14:26 UTC (permalink / raw)
To: Andrew Morton; +Cc: Enze Li, SJ Park, damon, linux-kernel, linux-mm
From: Enze Li <lienze@kylinos.cn>
The mtier sample defines a local struct region_range using phys_addr_t
instead of damon_addr_range which uses unsigned long. Add a comment
explaining the rationale: on 32-bit systems with more than 4GiB memory,
phys_addr_t will be 64-bit while unsigned long is 32-bit.
Signed-off-by: Enze Li <lienze@kylinos.cn>
Reviewed-by: SJ Park <sj@kernel.org>
Signed-off-by: SJ Park <sj@kernel.org>
---
Changes from v1
- v1: https://lore.kernel.org/20260721070756.54435-1-lienze@kylinos.cn
- Collect R-b: from SJ.
- Rebase to latest mm-new.
samples/damon/mtier.c | 5 +++++
1 file changed, 5 insertions(+)
diff --git a/samples/damon/mtier.c b/samples/damon/mtier.c
index d1123ebbfab90..bea45c87cc9be 100644
--- a/samples/damon/mtier.c
+++ b/samples/damon/mtier.c
@@ -52,6 +52,11 @@ module_param(detect_node_addresses, bool, 0600);
static struct damon_ctx *ctxs[2];
+/*
+ * Use phys_addr_t instead of damon_addr_range (unsigned long) for physical
+ * addresses. On 32-bit systems with more than 4GB memory, phys_addr_t will
+ * be 64-bit while unsigned long is 32-bit.
+ */
struct region_range {
phys_addr_t start;
phys_addr_t end;
--
2.47.3
^ permalink raw reply related [flat|nested] 17+ messages in thread