From: SeongJae Park <sj@kernel.org>
To: SeongJae Park <sj@kernel.org>
Cc: damon@lists.linux.dev, linux-kernel@vger.kernel.org, linux-mm@kvack.org
Subject: Re: (sashiko review) [RFC PATCH 1/2] mm/damon/stat: add a parameter for reading kdamond pid
Date: Mon, 13 Apr 2026 22:37:41 -0700 [thread overview]
Message-ID: <20260414053742.90296-1-sj@kernel.org> (raw)
In-Reply-To: <20260414045002.88110-2-sj@kernel.org>
TL; DR: Sashiko found a bug of this patch; I will fix it in the next revision.
Sashiko also found one issue in the existing code; I will work on it
separately.
Forwarding full sashiko review in a reply format with my inline comments below,
for sharing details of my view and doing followup discussions via mails if
needed.
> # review url: https://sashiko.dev/#/patchset/20260414045002.88110-2-sj@kernel.org
> # start of sashiko.dev inline review
> commit fc6c9ec12df0df57fcce5c90c7a0604cddb1cc78
> Author: SeongJae Park <sj@kernel.org>
>
> mm/damon/stat: add a parameter for reading kdamond pid
>
> This commit exposes the PID of the DAMON_STAT kdamond via a new read-only
> module parameter, kdamond_pid. It intends to set this to -1 when DAMON_STAT
> is disabled.
>
> > diff --git a/mm/damon/stat.c b/mm/damon/stat.c
> > index 99ba346f9e325..21fa04d95eeac 100644
> > --- a/mm/damon/stat.c
> > +++ b/mm/damon/stat.c
> [ ... ]
> > @@ -260,6 +269,9 @@ static int damon_stat_start(void)
> > damon_stat_context = NULL;
> > return err;
> > }
> > + kdamond_pid = damon_kdamond_pid(damon_stat_context);
> > + if (kdamond_pid < 0)
> > + return kdamond_pid;
>
> If damon_kdamond_pid() returns an error code, doesn't this leave the global
> kdamond_pid set to that negative error code instead of -1?
>
> Also, if we take this early return path, does this code leak the
> damon_stat_context allocation? The error path just above it correctly
> calls damon_destroy_ctx(damon_stat_context) and sets it to NULL.
Nice catch. I will fix this like below in the next revision.
'''
--- a/mm/damon/stat.c
+++ b/mm/damon/stat.c
@@ -223,8 +223,12 @@ static int damon_stat_start(void)
return err;
}
kdamond_pid = damon_kdamond_pid(damon_stat_context);
- if (kdamond_pid < 0)
- return kdamond_pid;
+ if (kdamond_pid < 0) {
+ err = kdamond_pid;
+ kdamond_pid = -1;
+ damon_destroy_ctx(damon_stat_context);
+ damon_stat_context = NULL;
+ return err;
damon_stat_last_refresh_jiffies = jiffies;
call_control.data = damon_stat_context;
'''
>
> >
> > damon_stat_last_refresh_jiffies = jiffies;
> > call_control.data = damon_stat_context;
> > return damon_call(damon_stat_context, &call_control);
> > }
>
> If damon_call() fails here and returns an error, the caller will handle it
> by setting enabled to false. Does this leave kdamond_pid holding a stale
> positive PID instead of being reset to -1?
Nice catch, but not this patch's fault. I will separately work on it.
>
> > @@ -269,6 +281,7 @@ static int damon_stat_start(void)
> > static void damon_stat_stop(void)
> > {
> > damon_stop(&damon_stat_context, 1);
> > + kdamond_pid = -1;
> > damon_destroy_ctx(damon_stat_context);
> > damon_stat_context = NULL;
> > }
>
>
> # end of sashiko.dev inline review
> # review url: https://sashiko.dev/#/patchset/20260414045002.88110-2-sj@kernel.org
Thanks,
SJ
# hkml [1] generated a draft of this mail. You can regenerate
# this using below command:
#
# hkml patch sashiko_dev --for_forwarding \
# 20260414045002.88110-2-sj@kernel.org
#
# [1] https://github.com/sjp38/hackermail
next prev parent reply other threads:[~2026-04-14 5:37 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-04-14 4:49 [RFC PATCH 0/2] mm/damon/stat: add kdamond_pid parameter SeongJae Park
2026-04-14 4:49 ` [RFC PATCH 1/2] mm/damon/stat: add a parameter for reading kdamond pid SeongJae Park
2026-04-14 5:37 ` SeongJae Park [this message]
2026-04-16 4:13 ` (sashiko review) " SeongJae Park
2026-04-14 4:50 ` [RFC PATCH 2/2] Docs/admin-guide/mm/damon/stat: document kdamond_pid parameter 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=20260414053742.90296-1-sj@kernel.org \
--to=sj@kernel.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 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.