DAMON development mailing list
 help / color / mirror / Atom feed
* [PATCH v3 0/2] selftests/damon: fix memcg_path staging handling
@ 2026-06-01  7:36 Cheng Nie
  2026-06-01  7:48 ` [PATCH v3 1/2] selftests/damon/_damon_sysfs.py: fix memcg_path assignment Cheng Nie
  2026-06-01  7:49 ` [PATCH v3 2/2] selftests/damon/sysfs.py: validate memcg_path staging readback Cheng Nie
  0 siblings, 2 replies; 9+ messages in thread
From: Cheng Nie @ 2026-06-01  7:36 UTC (permalink / raw)
  To: sj; +Cc: shuah, damon, linux-mm, linux-kselftest, linux-kernel, niecheng1

Changes from v2:
- updated memcg_path staging test to configure the memcg filter before
  start()
- removed commit() from the staging test
- ignored start() failure and checked memcg_path readback only
- adjusted the failure messages to follow the requested style

Cheng Nie (2):
  selftests/damon/_damon_sysfs.py: fix memcg_path assignment
  selftests/damon/sysfs.py: validate memcg_path staging readback

 tools/testing/selftests/damon/_damon_sysfs.py |  2 +-
 tools/testing/selftests/damon/sysfs.py        | 34 +++++++++++++++++++
 2 files changed, 35 insertions(+), 1 deletion(-)

-- 
2.51.0

^ permalink raw reply	[flat|nested] 9+ messages in thread

* [PATCH v3 2/2] selftests/damon/sysfs.py: validate memcg_path staging readback
       [not found] <20260601073635.200015-1-niecheng1@uniontech.com>
@ 2026-06-01  7:45 ` Cheng Nie
  2026-06-01  8:03   ` sashiko-bot
  0 siblings, 1 reply; 9+ messages in thread
From: Cheng Nie @ 2026-06-01  7:45 UTC (permalink / raw)
  To: sj; +Cc: shuah, damon, linux-mm, linux-kselftest, linux-kernel, kernel,
	niecheng1

Add a dedicated test at the end of main() that writes memcg_path to
sysfs and checks the readback path.  Configure the memcg filter before
start(), verify staging readback without commit(), and ignore start()
failures so the test does not depend on CONFIG_MEMCG or cgroup layout.

Signed-off-by: Cheng Nie <niecheng1@uniontech.com>
---
 tools/testing/selftests/damon/sysfs.py | 34 ++++++++++++++++++++++++++
 1 file changed, 34 insertions(+)

diff --git a/tools/testing/selftests/damon/sysfs.py b/tools/testing/selftests/damon/sysfs.py
index aa03a1187489..7a17ab88361b 100755
--- a/tools/testing/selftests/damon/sysfs.py
+++ b/tools/testing/selftests/damon/sysfs.py
@@ -250,6 +250,38 @@ def assert_ctxs_committed(kdamonds):
             if ctx in ctxs_paused_for_dump:
                 ctx.pause = False
 
+def test_memcg_filter_memcg_path_staging():
+    global kdamonds
+    memcg_filter = _damon_sysfs.DamosFilter(
+            type_='memcg', matching=True, allow=True, memcg_path='/')
+    kdamonds = _damon_sysfs.Kdamonds(
+            [_damon_sysfs.Kdamond(
+                contexts=[_damon_sysfs.DamonCtx(
+                    targets=[_damon_sysfs.DamonTarget(pid=-1)],
+                    schemes=[_damon_sysfs.Damos(
+                        ops_filters=[memcg_filter])],
+                    )])])
+    kdamonds.start()
+
+    shown, rd_err = _damon_sysfs.read_file(
+            os.path.join(memcg_filter.sysfs_dir(), 'memcg_path'))
+    if rd_err is not None:
+        print('memcg_path staging: sysfs read (%s)' % rd_err)
+        kdamonds.stop()
+        exit(1)
+    if shown.rstrip('\n') != memcg_filter.memcg_path:
+        print('memcg_path staging: memcg_path readback '
+              '(shown=%s, expected=%s)' %
+              (shown.rstrip('\n'), memcg_filter.memcg_path))
+        kdamonds.stop()
+        exit(1)
+
+    err = kdamonds.stop()
+    if err is not None:
+        print('memcg_path staging: kdamond stop (%s)' % err)
+        exit(1)
+    kdamonds = None
+
 def main():
     global kdamonds
     kdamonds = _damon_sysfs.Kdamonds(
@@ -356,5 +388,7 @@ def main():
     assert_ctxs_committed(kdamonds)
     kdamonds.stop()
 
+    test_memcg_filter_memcg_path_staging()
+
 if __name__ == '__main__':
     main()
-- 
2.51.0


^ permalink raw reply related	[flat|nested] 9+ messages in thread

* [PATCH v3 1/2] selftests/damon/_damon_sysfs.py: fix memcg_path assignment
  2026-06-01  7:36 [PATCH v3 0/2] selftests/damon: fix memcg_path staging handling Cheng Nie
@ 2026-06-01  7:48 ` Cheng Nie
  2026-06-01  7:49 ` [PATCH v3 2/2] selftests/damon/sysfs.py: validate memcg_path staging readback Cheng Nie
  1 sibling, 0 replies; 9+ messages in thread
From: Cheng Nie @ 2026-06-01  7:48 UTC (permalink / raw)
  To: niecheng1; +Cc: damon, linux-kernel, linux-kselftest, linux-mm, shuah, sj

DamosFilter stores memcg_path for sysfs staging, but the constructor
assigns it with a trailing comma and therefore turns it into a tuple.

Fix the assignment so memcg_path is stored as the intended string.
This makes memcg filter staging and follow-up validation use the
written path correctly.

Signed-off-by: Cheng Nie <niecheng1@uniontech.com>
Reviewed-by: SeongJae Park <sj@kernel.org>
---
 tools/testing/selftests/damon/_damon_sysfs.py | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/tools/testing/selftests/damon/_damon_sysfs.py b/tools/testing/selftests/damon/_damon_sysfs.py
index 8b12cc048440..43075892215e 100644
--- a/tools/testing/selftests/damon/_damon_sysfs.py
+++ b/tools/testing/selftests/damon/_damon_sysfs.py
@@ -271,7 +271,7 @@ class DamosFilter:
         self.type_ = type_
         self.matching = matching
         self.allow = allow
-        self.memcg_path = memcg_path,
+        self.memcg_path = memcg_path
         self.addr_start = addr_start
         self.addr_end = addr_end
         self.target_idx = target_idx
-- 
2.51.0


^ permalink raw reply related	[flat|nested] 9+ messages in thread

* [PATCH v3 2/2] selftests/damon/sysfs.py: validate memcg_path staging readback
  2026-06-01  7:36 [PATCH v3 0/2] selftests/damon: fix memcg_path staging handling Cheng Nie
  2026-06-01  7:48 ` [PATCH v3 1/2] selftests/damon/_damon_sysfs.py: fix memcg_path assignment Cheng Nie
@ 2026-06-01  7:49 ` Cheng Nie
  2026-06-01  8:03   ` sashiko-bot
  1 sibling, 1 reply; 9+ messages in thread
From: Cheng Nie @ 2026-06-01  7:49 UTC (permalink / raw)
  To: niecheng1; +Cc: damon, linux-kernel, linux-kselftest, linux-mm, shuah, sj

Add a dedicated test at the end of main() that writes memcg_path to
sysfs and checks the readback path.  Configure the memcg filter before
start(), verify staging readback without commit(), and ignore start()
failures so the test does not depend on CONFIG_MEMCG or cgroup layout.

Signed-off-by: Cheng Nie <niecheng1@uniontech.com>
---
 tools/testing/selftests/damon/sysfs.py | 34 ++++++++++++++++++++++++++
 1 file changed, 34 insertions(+)

diff --git a/tools/testing/selftests/damon/sysfs.py b/tools/testing/selftests/damon/sysfs.py
index aa03a1187489..7a17ab88361b 100755
--- a/tools/testing/selftests/damon/sysfs.py
+++ b/tools/testing/selftests/damon/sysfs.py
@@ -250,6 +250,38 @@ def assert_ctxs_committed(kdamonds):
             if ctx in ctxs_paused_for_dump:
                 ctx.pause = False
 
+def test_memcg_filter_memcg_path_staging():
+    global kdamonds
+    memcg_filter = _damon_sysfs.DamosFilter(
+            type_='memcg', matching=True, allow=True, memcg_path='/')
+    kdamonds = _damon_sysfs.Kdamonds(
+            [_damon_sysfs.Kdamond(
+                contexts=[_damon_sysfs.DamonCtx(
+                    targets=[_damon_sysfs.DamonTarget(pid=-1)],
+                    schemes=[_damon_sysfs.Damos(
+                        ops_filters=[memcg_filter])],
+                    )])])
+    kdamonds.start()
+
+    shown, rd_err = _damon_sysfs.read_file(
+            os.path.join(memcg_filter.sysfs_dir(), 'memcg_path'))
+    if rd_err is not None:
+        print('memcg_path staging: sysfs read (%s)' % rd_err)
+        kdamonds.stop()
+        exit(1)
+    if shown.rstrip('\n') != memcg_filter.memcg_path:
+        print('memcg_path staging: memcg_path readback '
+              '(shown=%s, expected=%s)' %
+              (shown.rstrip('\n'), memcg_filter.memcg_path))
+        kdamonds.stop()
+        exit(1)
+
+    err = kdamonds.stop()
+    if err is not None:
+        print('memcg_path staging: kdamond stop (%s)' % err)
+        exit(1)
+    kdamonds = None
+
 def main():
     global kdamonds
     kdamonds = _damon_sysfs.Kdamonds(
@@ -356,5 +388,7 @@ def main():
     assert_ctxs_committed(kdamonds)
     kdamonds.stop()
 
+    test_memcg_filter_memcg_path_staging()
+
 if __name__ == '__main__':
     main()
-- 
2.51.0


^ permalink raw reply related	[flat|nested] 9+ messages in thread

* Re: [PATCH v3 2/2] selftests/damon/sysfs.py: validate memcg_path staging readback
  2026-06-01  7:49 ` [PATCH v3 2/2] selftests/damon/sysfs.py: validate memcg_path staging readback Cheng Nie
@ 2026-06-01  8:03   ` sashiko-bot
  2026-06-01  8:46     ` Cheng Nie
  0 siblings, 1 reply; 9+ messages in thread
From: sashiko-bot @ 2026-06-01  8:03 UTC (permalink / raw)
  To: Cheng Nie; +Cc: damon

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Medium] The test fails if CONFIG_MEMCG is disabled because stopping an unstarted kdamond returns an error, defeating the intent of ignoring start failures.
--

commit 82e2d2dc23cd1bb3cb389943f0bf754e63c68c96
Author: Cheng Nie <niecheng1@uniontech.com>

selftests/damon/sysfs.py: validate memcg_path staging readback

This commit adds a test to validate the staging readback of memcg_path in
DAMON sysfs without committing it. It configures the memcg filter, verifies
the readback, and attempts to ignore start() failures to avoid depending on
CONFIG_MEMCG or cgroup layout.

> diff --git a/tools/testing/selftests/damon/sysfs.py b/tools/testing/selftests/damon/sysfs.py
> index aa03a1187489f..7a17ab88361bc 100755
> --- a/tools/testing/selftests/damon/sysfs.py
> +++ b/tools/testing/selftests/damon/sysfs.py
> @@ -250,6 +250,38 @@ def assert_ctxs_committed(kdamonds):
[ ... ]
> +def test_memcg_filter_memcg_path_staging():
> +    global kdamonds
> +    memcg_filter = _damon_sysfs.DamosFilter(
> +            type_='memcg', matching=True, allow=True, memcg_path='/')
> +    kdamonds = _damon_sysfs.Kdamonds(
> +            [_damon_sysfs.Kdamond(
> +                contexts=[_damon_sysfs.DamonCtx(
> +                    targets=[_damon_sysfs.DamonTarget(pid=-1)],
> +                    schemes=[_damon_sysfs.Damos(
> +                        ops_filters=[memcg_filter])],
> +                    )])])
> +    kdamonds.start()
[ ... ]
> +    err = kdamonds.stop()
> +    if err is not None:
> +        print('memcg_path staging: kdamond stop (%s)' % err)
> +        exit(1)

[Severity: Medium]
The commit message mentions ignoring start() failures so the test does not
depend on CONFIG_MEMCG or cgroup layout. However, if start() fails,
kdamonds.stop() will return an error because the kernel's
damon_sysfs_turn_damon_off() returns -EINVAL when kdamond->damon_ctx is
NULL.

Does this cause the test to exit(1) and fail anyway on environments without
CONFIG_MEMCG when checking the return value of stop() here?

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/D4787203018006D6+20260601073635.200015-1-niecheng1@uniontech.com?part=2

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH v3 2/2] selftests/damon/sysfs.py: validate memcg_path staging readback
  2026-06-01  7:45 ` Cheng Nie
@ 2026-06-01  8:03   ` sashiko-bot
  0 siblings, 0 replies; 9+ messages in thread
From: sashiko-bot @ 2026-06-01  8:03 UTC (permalink / raw)
  To: Cheng Nie; +Cc: damon

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Medium] Test fails on teardown when `start()` fails, defeating the stated intent of decoupling the test from `CONFIG_MEMCG`.
--

commit 995afe8f607b12ca4f4469ac19ac53b1340cae11
Author: Cheng Nie <niecheng1@uniontech.com>

selftests/damon/sysfs.py: validate memcg_path staging readback

This commit adds a dedicated test to write memcg_path to sysfs and verify
the readback path. It intentionally ignores kdamonds.start() failures so
the test operates independently of CONFIG_MEMCG or cgroup layout.

> diff --git a/tools/testing/selftests/damon/sysfs.py b/tools/testing/selftests/damon/sysfs.py
> index aa03a1187489f..7a17ab88361bc 100755
> --- a/tools/testing/selftests/damon/sysfs.py
> +++ b/tools/testing/selftests/damon/sysfs.py
> @@ -250,6 +250,38 @@ def assert_ctxs_committed(kdamonds):
[ ... ]
> +def test_memcg_filter_memcg_path_staging():
[ ... ]
> +    kdamonds.start()
> +
> +    shown, rd_err = _damon_sysfs.read_file(
> +            os.path.join(memcg_filter.sysfs_dir(), 'memcg_path'))
> +    if rd_err is not None:
> +        print('memcg_path staging: sysfs read (%s)' % rd_err)
> +        kdamonds.stop()
> +        exit(1)
> +    if shown.rstrip('\n') != memcg_filter.memcg_path:
> +        print('memcg_path staging: memcg_path readback '
> +              '(shown=%s, expected=%s)' %
> +              (shown.rstrip('\n'), memcg_filter.memcg_path))
> +        kdamonds.stop()
> +        exit(1)
> +
> +    err = kdamonds.stop()
> +    if err is not None:
> +        print('memcg_path staging: kdamond stop (%s)' % err)
> +        exit(1)

[Severity: Medium]
If start() fails as expected when CONFIG_MEMCG is disabled, won't this
subsequent call to kdamonds.stop() return an error?

Writing 'off' to the 'state' sysfs file of an unstarted kdamond causes
damon_sysfs_turn_damon_off() to unconditionally return -EINVAL. This error
propagates back to the Python script via write_file(), causing the script
to exit with status 1.

Does checking this error and exiting with a failure defeat the stated intent
of ignoring the start() failure in the first place?

> +    kdamonds = None
> +

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260601073635.200015-1-niecheng1@uniontech.com?part=2

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH v3 2/2] selftests/damon/sysfs.py: validate memcg_path staging readback
  2026-06-01  8:03   ` sashiko-bot
@ 2026-06-01  8:46     ` Cheng Nie
  2026-06-01 14:33       ` SeongJae Park
  0 siblings, 1 reply; 9+ messages in thread
From: Cheng Nie @ 2026-06-01  8:46 UTC (permalink / raw)
  To: sashiko-bot; +Cc: sj, damon, niecheng1, sashiko-reviews

Hi SJ,

Thanks to Sashiko for the feedback on patch 2/2.  I will send a v4 soon
that fixes the stop() cleanup issue in the memcg_path staging test.

Thanks,
Cheng Nie

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH v3 2/2] selftests/damon/sysfs.py: validate memcg_path staging readback
  2026-06-01  8:46     ` Cheng Nie
@ 2026-06-01 14:33       ` SeongJae Park
  2026-06-02  1:28         ` Cheng Nie
  0 siblings, 1 reply; 9+ messages in thread
From: SeongJae Park @ 2026-06-01 14:33 UTC (permalink / raw)
  To: Cheng Nie; +Cc: SeongJae Park, sashiko-bot, damon, sashiko-reviews

Hi Cheng,

On Mon,  1 Jun 2026 16:46:35 +0800 Cheng Nie <niecheng1@uniontech.com> wrote:

> Hi SJ,
> 
> Thanks to Sashiko for the feedback on patch 2/2.  I will send a v4 soon
> that fixes the stop() cleanup issue in the memcg_path staging test.

Thank you.  From next time, however, unless the new version is for very trivial
things like mail setup, please give time for other reviewers to comment (say,
one day?) before sending a new version.


Thanks,
SJ

[...]

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH v3 2/2] selftests/damon/sysfs.py: validate memcg_path staging readback
  2026-06-01 14:33       ` SeongJae Park
@ 2026-06-02  1:28         ` Cheng Nie
  0 siblings, 0 replies; 9+ messages in thread
From: Cheng Nie @ 2026-06-02  1:28 UTC (permalink / raw)
  To: sj; +Cc: damon, niecheng1, sashiko-bot, sashiko-reviews

Hi SJ,

Thank you for the reminder.  Sorry for sending v4 too quickly; I will
wait for reviewers before posting a new version next time.

Thanks,
Cheng Nie

^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2026-06-02  1:29 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-06-01  7:36 [PATCH v3 0/2] selftests/damon: fix memcg_path staging handling Cheng Nie
2026-06-01  7:48 ` [PATCH v3 1/2] selftests/damon/_damon_sysfs.py: fix memcg_path assignment Cheng Nie
2026-06-01  7:49 ` [PATCH v3 2/2] selftests/damon/sysfs.py: validate memcg_path staging readback Cheng Nie
2026-06-01  8:03   ` sashiko-bot
2026-06-01  8:46     ` Cheng Nie
2026-06-01 14:33       ` SeongJae Park
2026-06-02  1:28         ` Cheng Nie
     [not found] <20260601073635.200015-1-niecheng1@uniontech.com>
2026-06-01  7:45 ` Cheng Nie
2026-06-01  8:03   ` sashiko-bot

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