From: Liew Rui Yan <aethernet65535@gmail.com>
To: aethernet65535@gmail.com, sj@kernel.org
Cc: damon@lists.linux.dev, linux-mm@kvack.org
Subject: Re: (sashiko review) [RFC PATCH] mm/damon: reset thread status parameters upon kdamond termination
Date: Tue, 31 Mar 2026 06:42:32 +0800 [thread overview]
Message-ID: <20260330224232.14212-1-aethernet65535@gmail.com> (raw)
In-Reply-To: <20260330195107.71609-1-aethernet65535@gmail.com>
On Tue, 31 Mar 2026 03:51:07 +0800 Liew Rui Yan <aethernet65535@gmail.com> wrote:
> [...]
> > > +static void damon_update_thread_status(struct damon_ctx *ctx)
> > > +{
> > > + if (ctx->thread_status.kdamond_pid)
> > > + *ctx->thread_status.kdamond_pid = -1;
> > > + if (ctx->thread_status.enabled)
> > > + *ctx->thread_status.enabled = false;
> >
> > Can this write race with the user enabling the module? If a user writes 'Y'
> > to 'enabled', the store function spawns kdamond and prepares to set 'enabled'
> > to true. If kdamond exits immediately (e.g., due to invalid targets), could
> > this line asynchronously set 'enabled' to false before the store function
> > overwrites it with true?
> >
> > If so, the system would be left in a state where the thread is dead but
> > 'enabled' is true. Subsequent attempts to write 'N' to 'enabled' would fail
> > on damon_stop(), leaving the module permanently locked.
>
> You are right. I now see the potential race between kdamond exiting and
> the enabled_store(). While it seems unlikely, the window exists and
> could lead to an inconsistent state. I'm sitll thinking about the way to
> synchronize this without introducing new issues. I will try to address
> this is next-version once I have a solid plan.
I think I've found a solution for the race.
In damon_lru_sort_enabled_store(), the current code sets 'enabled =
enable' only after damon_lru_sort_turn(enable) returns successfully.
This creates the window you mentioned.
I plan to update 'enabled' before calling damon_lru_sort_turn(), and
rollback the value only if the turn operation fails.
Best regards,
Rui Yan
next prev parent reply other threads:[~2026-03-30 22:42 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-03-30 16:43 [RFC PATCH] mm/damon: reset thread status parameters upon kdamond termination Liew Rui Yan
2026-03-30 18:53 ` (sashiko review) " Liew Rui Yan
2026-03-30 19:51 ` Liew Rui Yan
2026-03-30 22:42 ` Liew Rui Yan [this message]
2026-03-31 5:02 ` SeongJae Park
2026-03-31 6:58 ` Liew Rui Yan
2026-03-31 16:09 ` Liew Rui Yan
2026-04-01 0:44 ` SeongJae Park
2026-04-01 8:24 ` Liew Rui Yan
2026-04-01 15:41 ` SeongJae Park
2026-04-02 5:34 ` Liew Rui Yan
2026-04-02 13:54 ` SeongJae Park
2026-04-03 4:34 ` Liew Rui Yan
2026-04-03 14:06 ` SeongJae Park
2026-04-01 0:29 ` SeongJae Park
2026-04-01 8:23 ` Liew Rui Yan
2026-04-02 0: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=20260330224232.14212-1-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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.