selftests/damon/sysfs: add obsolete_target test

A new DAMON sysfs file for pin-point target removal, namely
obsolete_target, has been added.  Add a test for the functionality.  It
starts DAMON with three monitoring target processes, mark one in the
middle as obsolete, commit it, and confirm the internal DAMON status is
updated to remove the target in the middle.

Link: https://lkml.kernel.org/r/20251023012535.69625-10-sj@kernel.org
Signed-off-by: SeongJae Park <sj@kernel.org>
Cc: Bijan Tabatabai <bijan311@gmail.com>
Cc: David Hildenbrand <david@redhat.com>
Cc: Jonathan Corbet <corbet@lwn.net>
Cc: Liam Howlett <liam.howlett@oracle.com>
Cc: Lorenzo Stoakes <lorenzo.stoakes@oracle.com>
Cc: Michal Hocko <mhocko@suse.com>
Cc: Mike Rapoport <rppt@kernel.org>
Cc: Shuah Khan <shuah@kernel.org>
Cc: Suren Baghdasaryan <surenb@google.com>
Cc: Vlastimil Babka <vbabka@suse.cz>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
This commit is contained in:
SeongJae Park
2025-10-22 18:25:33 -07:00
committed by Andrew Morton
parent 65a9033db7
commit 809ba69f9f

View File

@@ -279,5 +279,42 @@ def main():
kdamonds.stop()
# test obsolete_target.
proc1 = subprocess.Popen(['sh'], stdout=subprocess.PIPE,
stderr=subprocess.PIPE)
proc2 = subprocess.Popen(['sh'], stdout=subprocess.PIPE,
stderr=subprocess.PIPE)
proc3 = subprocess.Popen(['sh'], stdout=subprocess.PIPE,
stderr=subprocess.PIPE)
kdamonds = _damon_sysfs.Kdamonds(
[_damon_sysfs.Kdamond(
contexts=[_damon_sysfs.DamonCtx(
ops='vaddr',
targets=[
_damon_sysfs.DamonTarget(pid=proc1.pid),
_damon_sysfs.DamonTarget(pid=proc2.pid),
_damon_sysfs.DamonTarget(pid=proc3.pid),
],
schemes=[_damon_sysfs.Damos()],
)])])
err = kdamonds.start()
if err is not None:
print('kdamond start failed: %s' % err)
exit(1)
kdamonds.kdamonds[0].contexts[0].targets[1].obsolete = True
kdamonds.kdamonds[0].commit()
status, err = dump_damon_status_dict(kdamonds.kdamonds[0].pid)
if err is not None:
print(err)
kdamonds.stop()
exit(1)
del kdamonds.kdamonds[0].contexts[0].targets[1]
assert_ctxs_committed(kdamonds.kdamonds[0].contexts, status['contexts'])
kdamonds.stop()
if __name__ == '__main__':
main()