Re: [PATCH v2 2/2] selftests/damon/sysfs.py: validate memcg_path staging readback

From: SeongJae Park

Date: Fri May 29 2026 - 11:25:07 EST


On Fri, 29 May 2026 17:21:31 +0800 Cheng Nie <niecheng1@xxxxxxxxxxxxx> wrote:

> Add a dedicated test at the end of main() that writes memcg_path to
> sysfs and checks the readback path. Validate the readback rather than
> a derived memcg_id so the test stays focused on DAMON sysfs behavior
> and avoids depending on the local userspace cgroup mount layout.

Nice addition of a test, thank you!

>
> Signed-off-by: Cheng Nie <niecheng1@xxxxxxxxxxxxx>
> ---
> tools/testing/selftests/damon/sysfs.py | 39 ++++++++++++++++++++++++++
> 1 file changed, 39 insertions(+)
>
> diff --git a/tools/testing/selftests/damon/sysfs.py b/tools/testing/selftests/damon/sysfs.py
> index aa03a1187489..0f20bc9c46b7 100755
> --- a/tools/testing/selftests/damon/sysfs.py
> +++ b/tools/testing/selftests/damon/sysfs.py
> @@ -250,6 +250,43 @@ 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()],
> + )])])
> + err = kdamonds.start()
> + if err is not None:
> + fail('memcg_path staging: kdamond start', {'error': err})

I'd prefer the error message to be in form of something like "'memcg_path
staging: kdamond start (%s)' % err" for consistency.

> +
> + context = _damon_sysfs.DamonCtx(
> + targets=[_damon_sysfs.DamonTarget(pid=-1)],
> + schemes=[_damon_sysfs.Damos(ops_filters=[memcg_filter])])
> + context.idx = 0
> + context.kdamond = kdamonds.kdamonds[0]
> + kdamonds.kdamonds[0].contexts = [context]
> +
> + err = kdamonds.kdamonds[0].commit()
> + if err is not None:
> + fail('memcg_path staging: kdamond commit', {'error': err})

It seems we don't really need to do commit(). As Sashiko mentioned [1], it
also depends on CONFIG_MEMCG and active cgroup configuration. It would be
suffice to simply 'stage'. We don't have stage() method on Kdamonds, though.
What about setting all parameters including the memcg filter at the beginning,
do 'kdamonds.start()', but ignore the failure, and check the content of the
memcg_path file?

[1] https://lore.kernel.org/20260529094327.6D5031F00893@xxxxxxxxxxxxxxx


Thanks,
SJ

[...]