Linux Kernel Selftest development
 help / color / mirror / Atom feed
* [PATCH 0/7] mm/damon: misc cleanups
@ 2026-08-31 14:26 SJ Park
  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 ` [PATCH 6/7] selftests/damon: prevent remaining cross-object state pollution SJ Park
  0 siblings, 2 replies; 3+ messages in thread
From: SJ Park @ 2026-08-31 14:26 UTC (permalink / raw)
  To: Andrew Morton
  Cc: SJ Park, Zenghui Yu (Huawei), Greg Kroah-Hartman, Shuah Khan,
	damon, linux-kernel, linux-kselftest, linux-mm

Cleanup the code, tests and samples for clarifications and readability.

The patches are individually sent by the authors.  I'm reposting those
as one series for convenience of handling.  For this reason, changelog
is on each patch's commentary section.

Enze Li (1):
  samples/damon/mtier: add comment for struct region_range

Hari Mishal (1):
  selftests/damon/sysfs.py: clean up sh processes used for
    obsolete_target test

Jaeyeon Lee (1):
  mm/damon/tests: use scoped_guard() for damon_test_ops_registration

Li Youhong (1):
  mm/damon/ops-common: factor out damon_putback_folio_list()

SJ Park (1):
  mm/damon/core: introduce damon_set_target_pid()

Zenghui Yu (Huawei) (1):
  mm/damon/core: remove declaration of __damon_commit_ctx()

zhaozhengzhuo (1):
  selftests/damon: prevent remaining cross-object state pollution

 include/linux/damon.h                         |  1 +
 mm/damon/core.c                               | 14 ++++++-
 mm/damon/ops-common.c                         | 30 +++++++--------
 mm/damon/sysfs.c                              |  6 +--
 mm/damon/tests/core-kunit.h                   | 21 +++++-----
 samples/damon/mtier.c                         |  5 +++
 samples/damon/prcl.c                          |  5 +--
 samples/damon/wsse.c                          |  5 +--
 tools/testing/selftests/damon/_damon_sysfs.py | 38 ++++++++++++++-----
 tools/testing/selftests/damon/sysfs.py        |  4 ++
 10 files changed, 79 insertions(+), 50 deletions(-)


base-commit: 58132fed7967e3401e3f293a0a2cc983161e229e
-- 
2.47.3

^ permalink raw reply	[flat|nested] 3+ 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
@ 2026-08-31 14:26 ` SJ Park
  2026-08-31 14:26 ` [PATCH 6/7] selftests/damon: prevent remaining cross-object state pollution SJ Park
  1 sibling, 0 replies; 3+ 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] 3+ 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
  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
  1 sibling, 0 replies; 3+ 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] 3+ messages in thread

end of thread, other threads:[~2026-08-31 14:26 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-08-31 14:26 [PATCH 0/7] mm/damon: misc cleanups SJ Park
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 ` [PATCH 6/7] selftests/damon: prevent remaining cross-object state pollution SJ Park

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox