DAMON development mailing list
 help / color / mirror / Atom feed
* [PATCH v1] mm/damon/stat: roll back context on damon_call() failure
@ 2026-05-29  3:15 Yuho Choi
  2026-05-29 14:44 ` SeongJae Park
  0 siblings, 1 reply; 6+ messages in thread
From: Yuho Choi @ 2026-05-29  3:15 UTC (permalink / raw)
  To: SeongJae Park, Andrew Morton; +Cc: damon, linux-mm, linux-kernel, Yuho Choi

damon_stat_start() allocates and starts damon_stat_context before
registering the repeated damon_call() callback.  If damon_call() fails,
the function currently returns the error while leaving the context
allocated and stored in the global pointer.

The retry-time cleanup added for this path only runs if users try to
enable DAMON_STAT again.  If no retry happens, the failed start leaves
the context allocated indefinitely.

Roll back the failed start by stopping the kdamond before destroying
the context and clearing the global pointer.  damon_stop() waits for a
live kdamond via kthread_stop_put(); if the worker has already completed
teardown, there is no kdamond left to wait on and the context can be
destroyed.

Fixes: 405f61996d9d ("mm/damon/stat: use damon_call() repeat mode instead of damon_callback")
Signed-off-by: Yuho Choi <dbgh9129@gmail.com>
---
 mm/damon/stat.c | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)

diff --git a/mm/damon/stat.c b/mm/damon/stat.c
index 3951b762cbdd..7f222b5b7193 100644
--- a/mm/damon/stat.c
+++ b/mm/damon/stat.c
@@ -266,7 +266,14 @@ static int damon_stat_start(void)
 
 	damon_stat_last_refresh_jiffies = jiffies;
 	call_control.data = damon_stat_context;
-	return damon_call(damon_stat_context, &call_control);
+	err = damon_call(damon_stat_context, &call_control);
+	if (err) {
+		damon_stop(&damon_stat_context, 1);
+		damon_destroy_ctx(damon_stat_context);
+		damon_stat_context = NULL;
+		return err;
+	}
+	return 0;
 }
 
 static void damon_stat_stop(void)
-- 
2.43.0


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

end of thread, other threads:[~2026-05-29 23:40 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-05-29  3:15 [PATCH v1] mm/damon/stat: roll back context on damon_call() failure Yuho Choi
2026-05-29 14:44 ` SeongJae Park
2026-05-29 15:17   ` 최유호
2026-05-29 16:00     ` SeongJae Park
2026-05-29 20:29       ` 최유호
2026-05-29 23:40         ` SeongJae Park

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