From: Yuho Choi <dbgh9129@gmail.com>
To: SeongJae Park <sj@kernel.org>, Andrew Morton <akpm@linux-foundation.org>
Cc: damon@lists.linux.dev, linux-mm@kvack.org,
linux-kernel@vger.kernel.org, Yuho Choi <dbgh9129@gmail.com>
Subject: [PATCH v1] mm/damon/stat: roll back context on damon_call() failure
Date: Thu, 28 May 2026 23:15:19 -0400 [thread overview]
Message-ID: <20260529031519.1617000-1-dbgh9129@gmail.com> (raw)
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
next reply other threads:[~2026-05-29 3:15 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-05-29 3:15 Yuho Choi [this message]
2026-05-29 14:44 ` [PATCH v1] mm/damon/stat: roll back context on damon_call() failure 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
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260529031519.1617000-1-dbgh9129@gmail.com \
--to=dbgh9129@gmail.com \
--cc=akpm@linux-foundation.org \
--cc=damon@lists.linux.dev \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=sj@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox