From: Liew Rui Yan <aethernet65535@gmail.com>
To: SeongJae Park <sj@kernel.org>
Cc: damon@lists.linux.dev, linux-mm@kvack.org,
Liew Rui Yan <aethernet65535@gmail.com>
Subject: [PATCH v2 1/2] mm/damon/lru_sort: reset thread status parameters upon kdamond termination
Date: Tue, 14 Apr 2026 02:52:48 +0800 [thread overview]
Message-ID: <20260413185249.5921-2-aethernet65535@gmail.com> (raw)
In-Reply-To: <20260413185249.5921-1-aethernet65535@gmail.com>
Problem
========
When kdamond terminates unexpectedly, 'enabled' remains 'Y' and
'kdamond_pid' remains stale. This prevents user from restarting DAMON
because both writing 'Y' and 'N' to 'enabled' will fail.
"Unexpected termination" here means the kdamond exits without any user
request (e.g., not by writing 'N' to 'enabled').
User Impact
===========
Once kdamond terminates this way, it cannot be restarted via sysfs
because:
1. DAMON_LRU_SORT is built into the kernel, so it cannot be unloaded and
reloaded at runtime.
2. Writing 'N' to 'enabled' fails because kdamond no longer exists;
Writing 'Y' does nothing, as 'enabled' is already Y.
As a result, the only way to restore DAMON functionality is a full
system reboot.
Solution
========
damon_commit_ctx() sets 'maybe_corrupted=true' at the beginning and only
sets it to false upon successful completion. When 'maybe_corrupted'
remains true, kdamond will terminate eventually.
Therefore:
1. In damon_lru_sort_turn(): Add fallback logic to reset
parameters when damon_stop() fails but kdamond is not running.
2. In damon_lru_sort_apply_parameters(): Reset parameters
when damon_commit_ctx() fails, as kdamond will terminate due to
maybe_corrupted mechanism.
Signed-off-by: Liew Rui Yan <aethernet65535@gmail.com>
---
mm/damon/lru_sort.c | 13 +++++++++++--
1 file changed, 11 insertions(+), 2 deletions(-)
diff --git a/mm/damon/lru_sort.c b/mm/damon/lru_sort.c
index 554559d72976..96c8d0dfcafd 100644
--- a/mm/damon/lru_sort.c
+++ b/mm/damon/lru_sort.c
@@ -344,6 +344,10 @@ static int damon_lru_sort_apply_parameters(void)
if (err)
goto out;
err = damon_commit_ctx(ctx, param_ctx);
+ if (err) {
+ enabled = false;
+ kdamond_pid = -1;
+ }
out:
damon_destroy_ctx(param_ctx);
return err;
@@ -388,8 +392,13 @@ static int damon_lru_sort_turn(bool on)
if (!on) {
err = damon_stop(&ctx, 1);
- if (!err)
- kdamond_pid = -1;
+ if (err) {
+ if (!damon_is_running(ctx))
+ err = 0;
+ else
+ return err;
+ }
+ kdamond_pid = -1;
return err;
}
--
2.53.0
next prev parent reply other threads:[~2026-04-13 18:52 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-04-13 18:52 [PATCH v2 0/2] mm/damon: " Liew Rui Yan
2026-04-13 18:52 ` Liew Rui Yan [this message]
2026-04-13 19:54 ` (sashiko review) [PATCH v2 1/2] mm/damon/lru_sort: " Liew Rui Yan
2026-04-13 18:52 ` [PATCH v2 2/2] mm/damon/reclaim: " Liew Rui Yan
2026-04-13 19:57 ` (sashiko review) " Liew Rui Yan
2026-04-13 22:05 ` [PATCH v2 0/2] mm/damon: " Liew Rui Yan
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=20260413185249.5921-2-aethernet65535@gmail.com \
--to=aethernet65535@gmail.com \
--cc=damon@lists.linux.dev \
--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