From: SJ Park <sj@kernel.org>
Cc: SJ Park <sj@kernel.org>,
Andrew Morton <akpm@linux-foundation.org>,
damon@lists.linux.dev, linux-kernel@vger.kernel.org,
linux-mm@kvack.org
Subject: [RFC PATCH 09/11] mm/damon/core: stop ctx in damon_call() before reruning an error
Date: Sat, 4 Jul 2026 11:11:32 -0700 [thread overview]
Message-ID: <20260704181135.132956-10-sj@kernel.org> (raw)
In-Reply-To: <20260704181135.132956-1-sj@kernel.org>
damon_call() failure makes the DAMON context to stop if it was running.
The stop is asynchronously done in kdamond thread, though. The caller's
error handling should handle the race, too. It is complicated and easy
to make mistakes.
Update damon_call() to ensure the context is stopped in the case.
Signed-off-by: SJ Park <sj@kernel.org>
---
mm/damon/core.c | 11 +++++++++--
1 file changed, 9 insertions(+), 2 deletions(-)
diff --git a/mm/damon/core.c b/mm/damon/core.c
index 1a6c30ae91711..5f16d2e13ebf7 100644
--- a/mm/damon/core.c
+++ b/mm/damon/core.c
@@ -2009,6 +2009,8 @@ int damon_kdamond_pid(struct damon_ctx *ctx)
* @ctx has succeeded. Otherwise, this function could fall into an indefinite
* wait.
*
+ * When this function is failed, the @ctx is guaranteed to be stopped.
+ *
* Return: 0 on success, negative error code otherwise.
*/
int damon_call(struct damon_ctx *ctx, struct damon_call_control *control)
@@ -2021,7 +2023,7 @@ int damon_call(struct damon_ctx *ctx, struct damon_call_control *control)
mutex_lock(&ctx->call_controls_lock);
if (ctx->call_controls_obsolete) {
mutex_unlock(&ctx->call_controls_lock);
- return -ECANCELED;
+ goto canceled;
}
list_add_tail(&control->list, &ctx->call_controls);
mutex_unlock(&ctx->call_controls_lock);
@@ -2029,8 +2031,13 @@ int damon_call(struct damon_ctx *ctx, struct damon_call_control *control)
return 0;
wait_for_completion(&control->completion);
if (control->canceled)
- return -ECANCELED;
+ goto canceled;
return 0;
+
+canceled:
+ __damon_stop(ctx);
+ return -ECANCELED;
+
}
/**
--
2.47.3
next prev parent reply other threads:[~2026-07-04 18:11 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-07-04 18:11 [RFC PATCH 00/11] mm/damon: refactor damon_{start,stop,commit}() for simple error handling SJ Park
2026-07-04 18:11 ` [RFC PATCH 01/11] mm/damon/core: stop ctxs in damon_start() before returning an error SJ Park
2026-07-04 18:11 ` [RFC PATCH 02/11] samples/damon/mtier: do not stop first context for damon_start() failure SJ Park
2026-07-04 18:11 ` [RFC PATCH 03/11] mm/damon/core: make damon_stop() never fails SJ Park
2026-07-04 18:11 ` [RFC PATCH 04/11] mm/damon/sysfs: ignore damon_stop() return value SJ Park
2026-07-04 18:11 ` [RFC PATCH 05/11] mm/damon/reclaaim: " SJ Park
2026-07-04 18:11 ` [RFC PATCH 06/11] mm/damon/lru_sort: " SJ Park
2026-07-04 18:11 ` [RFC PATCH 07/11] mm/damon/core: change damon_stop() return type to void SJ Park
2026-07-04 18:11 ` [RFC PATCH 08/11] samples/damon/mtier: stop all contexts with single damon_stop() call SJ Park
2026-07-04 18:11 ` SJ Park [this message]
2026-07-04 18:11 ` [RFC PATCH 10/11] samples/damon/wsse: do not stop ctx for damon_call() failure SJ Park
2026-07-04 18:11 ` [RFC PATCH 11/11] samples/damon/prcl: do not stop DAMON " SJ 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=20260704181135.132956-10-sj@kernel.org \
--to=sj@kernel.org \
--cc=akpm@linux-foundation.org \
--cc=damon@lists.linux.dev \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.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