selftests/damon/sysfs.py: clean up sh processes used for obsolete_target test
Subsystems (3)
PATCH 1/1 selftests/damon/sysfs.py: clean up sh processes used for obsolete_target test
The obsolete_target test spawns three sh processes and uses their pids as DAMON monitoring targets. These processes are created without their own stdin, so they inherit the test program's stdin, and they are never waited on or told to exit. As a result, they are left running (or become zombies) as orphaned children after the test program exits.
Give each sh process its own dedicated stdin pipe instead of inheriting the test program's, and after the targets are no longer needed, communicate() with each process to close its stdin. This sends EOF to the shell, which makes it exit, and communicate() then reaps the process.
--- tools/testing/selftests/damon/sysfs.py | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-)
tools/testing/selftests/damon/sysfs.py +9 -3
@@ -328,11 +328,14 @@ def main(): kdamonds.stop() # test obsolete_target. - proc1 = subprocess.Popen(['sh'], stdout=subprocess.PIPE, + proc1 = subprocess.Popen(['sh'], stdin=subprocess.PIPE, + stdout=subprocess.PIPE, stderr=subprocess.PIPE) - proc2 = subprocess.Popen(['sh'], stdout=subprocess.PIPE, + proc2 = subprocess.Popen(['sh'], stdin=subprocess.PIPE, + stdout=subprocess.PIPE, stderr=subprocess.PIPE) - proc3 = subprocess.Popen(['sh'], stdout=subprocess.PIPE, + proc3 = subprocess.Popen(['sh'], stdin=subprocess.PIPE, + stdout=subprocess.PIPE, stderr=subprocess.PIPE) kdamonds = _damon_sysfs.Kdamonds( [_damon_sysfs.Kdamond(
@@ -356,5 +359,8 @@ def main(): assert_ctxs_committed(kdamonds) kdamonds.stop() + for proc in (proc1, proc2, proc3): + proc.communicate() + if __name__ == '__main__': main()
Signature · 1 line
2.43.0
SJ Park
maintainerHello Hari,
Quoted 5 lines · On Tue, 21 Jul 2026 21:04:04 +0200 Hari Mishal <[email protected]> wrote:
The
obsolete_targettest spawns three sh processes and uses their pids as DAMON monitoring targets. These processes are created without their own stdin, so they inherit the test program's stdin, and they are never waited on or told to exit. As a result, they are left running (or become zombies) as orphaned children after the test program exits.
Thank you for finding this problem and sharing this great patch!
Quoted 6 lines
Give each sh process its own dedicated stdin pipe instead of inheriting the test program's, and after the targets are no longer needed,
communicate()with each process to close its stdin. This sends EOF to the shell, which makes it exit, andcommunicate()then reaps the process.
Can't we use terminate() or kill() instead of communicate()?
Thanks,
SJ
[...]
PATCH v2 1/1 selftests/damon/sysfs.py: clean up sh processes used for obsolete_target test
In reply to Hari MishalThe 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.
---
v2: 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(+)
tools/testing/selftests/damon/sysfs.py +4 -0
@@ -356,5 +356,9 @@ def main(): assert_ctxs_committed(kdamonds) kdamonds.stop() + for proc in (proc1, proc2, proc3): + proc.terminate() + proc.communicate() + if __name__ == '__main__': main()
Signature · 1 line
2.43.0
Hello Hari,
From the next time, please don't post a new version of a patch as a reply to the previous version. Post a new version as a new thread, with changelogs [1] including links to previous revisions.
Also, give others sufficient time, say, one day, to add comments before posting a new version. If someone publicly asked questions to your patch, please answer the questions and keep the discussion in public until the discussion is clearly completed, before posting a new version.
Quoted 7 lines · On Wed, 22 Jul 2026 03:23:49 +0200 Hari Mishal <[email protected]> wrote:
The
obsolete_targettest 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.
Makes sense to me. Thank you for this patch.
Quoted 2 lines
Signed-off-by Hari Mishal <[email protected]>
Quoted 4 lines
---
v2: Terminate each sh process directly instead of giving it its own
stdin pipe to close, dropping the stdin=PIPE changes and shrinking the diff.
When you add changelog, please add links to the previous revisions.
Finally, please use mm-new [2] as the baseline of DAMON patches from the next time.
This patch is applied to damon/next [2] tree. If this patch is not added to mm.git in short term (~1 week?), I will ask mm.git maintainer (Andrew Morton) to pick this. So, no action from your side is needed for now. If it seems I also forgot doing that or you cannot wait for my action, please feel free to directly ask that to Andrew.
[1] https://docs.kernel.org/process/submitting-patches.html#commentary
[2] https://origin.kernel.org/doc/html/latest/mm/damon/maintainer-profile.html#scm-trees
Thanks,
SJ
[...]
SJ Park
maintainerOn Tue, 21 Jul 2026 20:38:43 -0700 SJ Park <[email protected]> wrote:
[...]
Quoted 5 lines
This patch is applied to damon/next [2] tree. If this patch is not added to mm.git in short term (~1 week?), I will ask mm.git maintainer (Andrew Morton) to pick this. So, no action from your side is needed for now. If it seems I also forgot doing that or you cannot wait for my action, please feel free to directly ask that to Andrew.
We (mm community) now want to focus on making mm.git more stabilized and therefore ready for the next merge window, rather than adding more changes that are not really urgent. I agree and want to help [1] that. For the reason, unless Andre pick this first, I will request adding this to mm.git only after next -rc1 release. Let me know if you think this is really urgent.
[1] https://lore.kernel.org/[email protected]
Thanks,
SJ
Quoted 8 lines
From the next time, please don't post a new version of a patch as a reply to the previous version. Post a new version as a new thread, with changelogs [1] including links to previous revisions.
Also, give others sufficient time, say, one day, to add comments before posting a new version. If someone publicly asked questions to your patch, please answer the questions and keep the discussion in public until the discussion is clearly completed, before posting a new version.
Got it! Will keep it in mind for next time. Sorry about all the confusion! :)
Quoted 9 lines
Quoted 7 lines
The
obsolete_targettest 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.Makes sense to me. Thank you for this patch.
Ofc, happy to contribute!
Quoted 12 lines
Quoted 2 lines
Signed-off-by Hari Mishal <[email protected]>Reviewed-by SJ Park <[email protected]>Quoted 4 lines
---
v2: Terminate each sh process directly instead of giving it its own
stdin pipe to close, dropping the stdin=PIPE changes and shrinking the diff.When you add changelog, please add links to the previous revisions.
Quoted 9 lines
Finally, please use mm-new [2] as the baseline of DAMON patches from the next time.
This patch is applied to damon/next [2] tree. If this patch is not added to mm.git in short term (~1 week?), I will ask mm.git maintainer (Andrew Morton) to pick this. So, no action from your side is needed for now. If it seems I also forgot doing that or you cannot wait for my action, please feel free to directly ask that to Andrew.
I'm quite happy to wait! Thanks for your clarity.
Quoted 7 lines
We (mm community) now want to focus on making mm.git more stabilized and therefore ready for the next merge window, rather than adding more changes that are not really urgent. I agree and want to help [1] that. For the reason, unless Andre pick this first, I will request adding this to mm.git only after next -rc1 release. Let me know if you think this is really urgent.
Definitely don't think it's an urgent change. Anyone who is using a tool like damon would be able to debug this quite easily. Thanks for clarity, again.
Accidentally dropped reply all AGAIN, sorry about this. Resending to make sure everything is public again.
Cheers,
Hari
SJ Park
maintainerOn Wed, 22 Jul 2026 21:15:56 +0200 Hari Mishal <[email protected]> wrote:
[...]
Quoted 11 lines
Quoted 7 lines
We (mm community) now want to focus on making mm.git more stabilized and therefore ready for the next merge window, rather than adding more changes that are not really urgent. I agree and want to help [1] that. For the reason, unless Andre pick this first, I will request adding this to mm.git only after next -rc1 release. Let me know if you think this is really urgent.
Definitely don't think it's an urgent change. Anyone who is using a tool like damon would be able to debug this quite easily. Thanks for clarity, again.
Thank you for confirming, Hari!
Quoted 3 lines
Accidentally dropped reply all AGAIN, sorry about this. Resending to make sure everything is public again.
No worry, we all make mistakes and learn from those :)
Thanks,
SJ