summaryrefslogtreecommitdiff
path: root/samples
diff options
context:
space:
mode:
authorSJ Park <sj@kernel.org>2026-06-28 14:54:41 -0700
committerAndrew Morton <akpm@linux-foundation.org>2026-07-05 16:23:13 -0700
commitcf9fe9a8ccbeaefdff3e76ce88ee254ba00d8b07 (patch)
treef9bb28ba267170edcfd5bc79484e7b1b24b55d72 /samples
parent3a419625c0a778119b8cf36aad415e9b9301ca76 (diff)
downloadlinux-next-cf9fe9a8ccbeaefdff3e76ce88ee254ba00d8b07.tar.gz
linux-next-cf9fe9a8ccbeaefdff3e76ce88ee254ba00d8b07.zip
samples/damon/prcl: handle damon_start() failure
damon_sample_prcl_start() callers assume it will clean up resources when it fails. And the function does the cleanup for context buildup failures. However, it is not doing the cleanup for damon_start() failure. As a result, when damon_start() fails, it leaks the memory for DAMON context. Free the context in case of the failure to fix the issues. Note that the issue can reliably be reproduced because the module calls damon_start() in the exclusive mode. For example, $ sudo damo start $ echo $$ | sudo tee /sys/module/damon_sample_prcl/parameters/target_pid $ echo Y | sudo tee /sys/module/damon_sample_prcl/parameters/enabled $ sudo cat /proc/allocinfo | grep damon_new_ctx Because the first command is running another DAMON instance, the third command fails the damon_start() call because the new DAMON instance cannot exclusively run. And without this fix, by repeating the third and the fourth commands above, we can show the memory consumption is only increasing due to the leaks. It requires the sudo permission though. The issue was discovered [1] by Sashiko. Link: https://lore.kernel.org/20260628215447.96166-3-sj@kernel.org Link: https://lore.kernel.org/20260609145814.70163-1-sj@kernel.org [1] Fixes: 2aca254620a8 ("samples/damon: introduce a skeleton of a smaple DAMON module for proactive reclamation") Signed-off-by: SJ Park <sj@kernel.org> Reviewed-by: Zenghui Yu <zenghui.yu@linux.dev> Cc: <stable@vger.kernel.org> # 6.14.x Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Diffstat (limited to 'samples')
-rw-r--r--samples/damon/prcl.c4
1 files changed, 3 insertions, 1 deletions
diff --git a/samples/damon/prcl.c b/samples/damon/prcl.c
index b7c50f2656ce..0db259894691 100644
--- a/samples/damon/prcl.c
+++ b/samples/damon/prcl.c
@@ -106,8 +106,10 @@ static int damon_sample_prcl_start(void)
damon_set_schemes(ctx, &scheme, 1);
err = damon_start(&ctx, 1, true);
- if (err)
+ if (err) {
+ damon_destroy_ctx(ctx);
return err;
+ }
repeat_call_control.data = ctx;
return damon_call(ctx, &repeat_call_control);