From: SeongJae Park <sj@kernel.org>
To: JaeJoon Jung <rgbi3307@gmail.com>
Cc: SeongJae Park <sj@kernel.org>,
Asier Gutierrez <gutierrez.asier@huawei-partners.com>,
akpm@linux-foundation.org, damon@lists.linux.dev,
linux-mm@kvack.org, linux-kernel@vger.kernel.org,
wangkefeng.wang@huawei.com, artem.kuzin@huawei.com,
stepanov.anatoly@huawei.com
Subject: Re: [RFC PATCH v1] mm: improve call_controls_lock
Date: Wed, 31 Dec 2025 18:00:27 -0800 [thread overview]
Message-ID: <20260101020028.88096-1-sj@kernel.org> (raw)
In-Reply-To: <CAHOvCC6or4a5YM-byNFkB4q8v8YO=ZrT0VymYQfSXEx84wgeZw@mail.gmail.com>
On Thu, 1 Jan 2026 10:11:58 +0900 JaeJoon Jung <rgbi3307@gmail.com> wrote:
> On Thu, 1 Jan 2026 at 00:32, SeongJae Park <sj@kernel.org> wrote:
> >
> > On Wed, 31 Dec 2025 15:10:12 +0900 JaeJoon Jung <rgbi3307@gmail.com> wrote:
> >
> > > On Wed, 31 Dec 2025 at 13:59, SeongJae Park <sj@kernel.org> wrote:
> > > >
> > > > On Wed, 31 Dec 2025 11:15:00 +0900 JaeJoon Jung <rgbi3307@gmail.com> wrote:
> > > >
> > > > > On Tue, 30 Dec 2025 at 00:23, SeongJae Park <sj@kernel.org> wrote:
> > > > > >
> > > > > > Hello Asier,
> > > > > >
> > > > > >
> > > > > > Thank you for sending this patch!
> > > > > >
> > > > > > On Mon, 29 Dec 2025 14:55:32 +0000 Asier Gutierrez <gutierrez.asier@huawei-partners.com> wrote:
> > > > > >
> > > > > > > This is a minor patch set for a call_controls_lock synchronization improvement.
> > > > > >
> > > > > > Please break description lines to not exceed 75 characters per line.
> > > > > >
> > > > > > >
> > > > > > > Spinlocks are faster than mutexes, even when the mutex takes the fast
> > > > > > > path. Hence, this patch replaces the mutex call_controls_lock with a spinlock.
> > > > > >
> > > > > > But call_controls_lock is not being used on performance critical part.
> > > > > > Actually, most of DAMON code is not performance critical. I really appreciate
> > > > > > your patch, but I have to say I don't think this change is really needed now.
> > > > > > Please let me know if I'm missing something.
> > > > >
> > > > > Paradoxically, when it comes to locking, spin_lock is better than
> > > > > mutex_lock
> > > > > because "most of DAMON code is not performance critical."
> > > > >
> > > > > DAMON code only accesses the ctx belonging to kdamond itself. For
> > > > > example:
> > > > > kdamond.0 --> ctx.0
> > > > > kdamond.1 --> ctx.1
> > > > > kdamond.2 --> ctx.2
> > > > > kdamond.# --> ctx.#
> > > > >
> > > > > There is no cross-approach as shown below:
> > > > > kdamond.0 --> ctx.1
> > > > > kdamond.1 --> ctx.2
> > > > > kdamond.2 --> ctx.0
> > > > >
> > > > > Only the data belonging to kdamond needs to be resolved for concurrent access.
> > > > > most DAMON code needs to lock/unlock briefly when add/del linked
> > > > > lists,
> > > > > so spin_lock is effective.
> > > >
> > > > I don't disagree this. Both spinlock and mutex effectively work for DAMON's
> > > > locking usages.
> > > >
> > > > > If you handle it with a mutex, it becomes
> > > > > more
> > > > > complicated because the rescheduling occurs as a context switch occurs
> > > > > inside the kernel.
> > > >
> > > > Can you please elaborate what kind of complexities you are saying about?
> > > > Adding some examples would be nice.
> > > >
> > > > > Moreover, since the call_controls_lock that is
> > > > > currently
> > > > > being raised as a problem only occurs in two places, the kdamon_call()
> > > > > loop
> > > > > and the damon_call() function, it is effective to handle it with a
> > > > > spin_lock
> > > > > as shown below.
> > > > >
> > > > > @@ -1502,14 +1501,15 @@ int damon_call(struct damon_ctx *ctx, struct
> > > > > damon_call_control *control)
> > > > > control->canceled = false;
> > > > > INIT_LIST_HEAD(&control->list);
> > > > >
> > > > > - mutex_lock(&ctx->call_controls_lock);
> > > > > + spin_lock(&ctx->call_controls_lock);
> > > > > + /* damon_is_running */
> > > > > if (ctx->kdamond) {
> > > > > list_add_tail(&control->list, &ctx->call_controls);
> > > > > } else {
> > > > > - mutex_unlock(&ctx->call_controls_lock);
> > > > > + spin_unlock(&ctx->call_controls_lock);
> > > > > return -EINVAL;
> > > > > }
> > > > > - mutex_unlock(&ctx->call_controls_lock);
> > > > > + spin_unlock(&ctx->call_controls_lock);
> > > > >
> > > > > if (control->repeat)
> > > > > return 0;
> > > >
> > > > Are you saying the above diff can fix the damon_call() use-after-free bug [1]?
> > > > Can you please elaborate why you think so?
> > > >
> > > > [1] https://lore.kernel.org/20251231012315.75835-1-sj@kernel.org
> > > >
> > >
> > > The above code works fine with spin_lock. However, when booting the kernel,
> > > the spin_lock call trace from damon_call() is output as follows:
> > > If you have any experience with the following, please share it.
> >
> > Can you please reply to my questions above, first?
>
> I have answered your above question.
Are you saying your reply [1] that posted today? Unfortunately I was unable to
get all answers to my questions from it, so I asked your more explanation as a
reply to that.
> And, since call_controls_lock has a
> short waiting time, I think it would be a good idea to consider spin_lock.
This sounds like you are only repeating what you told so far, without
additional explanation. Hopefully the additional explanation can be made on
the thread [1]. Please keep replying there.
[1] https://lore.kernel.org/CAHOvCC65azs4BU2fyP-kxvFWB3ZPCfyZ7KCO8N1sc0jtTENmNw@mail.gmail.com
Thanks,
SJ
[...]
next prev parent reply other threads:[~2026-01-01 2:00 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-12-29 14:55 [RFC PATCH v1] mm: improve call_controls_lock Asier Gutierrez
2025-12-29 15:22 ` SeongJae Park
2025-12-30 9:02 ` Gutierrez Asier
2025-12-31 5:01 ` SeongJae Park
2025-12-31 2:15 ` JaeJoon Jung
2025-12-31 4:59 ` SeongJae Park
2025-12-31 6:10 ` JaeJoon Jung
2025-12-31 7:51 ` JaeJoon Jung
2026-01-12 10:32 ` Gutierrez Asier
2026-01-12 15:36 ` SeongJae Park
2025-12-31 15:32 ` SeongJae Park
2026-01-01 1:11 ` JaeJoon Jung
2026-01-01 2:00 ` SeongJae Park [this message]
2026-01-01 2:34 ` JaeJoon Jung
2026-01-01 22:44 ` SeongJae Park
2026-01-01 1:07 ` JaeJoon Jung
2026-01-01 1:51 ` SeongJae Park
2026-01-01 2:29 ` JaeJoon Jung
2026-01-06 6:41 ` kernel test robot
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=20260101020028.88096-1-sj@kernel.org \
--to=sj@kernel.org \
--cc=akpm@linux-foundation.org \
--cc=artem.kuzin@huawei.com \
--cc=damon@lists.linux.dev \
--cc=gutierrez.asier@huawei-partners.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=rgbi3307@gmail.com \
--cc=stepanov.anatoly@huawei.com \
--cc=wangkefeng.wang@huawei.com \
/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.