[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20250706214518.56529-1-sj@kernel.org>
Date: Sun, 6 Jul 2025 14:45:18 -0700
From: SeongJae Park <sj@...nel.org>
To: SeongJae Park <sj@...nel.org>
Cc: Andrew Morton <akpm@...ux-foundation.org>,
damon@...ts.linux.dev,
kernel-team@...a.com,
linux-kernel@...r.kernel.org,
linux-mm@...ck.org
Subject: Re: [RFC PATCH 02/14] mm/damon/core: introduce repeat mode damon_call()
On Sun, 6 Jul 2025 13:00:06 -0700 SeongJae Park <sj@...nel.org> wrote:
> damon_call() can be useful for reading or writing DAMON internal data
> for one time. A common pattern of DAMON core usage from DAMON modules
> is doing such reads and writes repeatedly, for example, to periodically
> update the DAMOS stats. To do that with damon_call(), callers should
> call damon_call() repeatedly, with their own delay loop. Each caller
> doing that is repetitive. Introduce a repeat mode damon_call().
> Callers can use the mode by setting a new field in damon_call_control.
> If the mode is turned on, damon_call() returns success immediately, and
> DAMON repeats invoking the callback function inside the kdamond main
> loop.
>
> Signed-off-by: SeongJae Park <sj@...nel.org>
> ---
[...]
> @@ -2389,6 +2393,7 @@ static void kdamond_usleep(unsigned long usecs)
> static void kdamond_call(struct damon_ctx *ctx, bool cancel)
> {
> struct damon_call_control *control;
> + LIST_HEAD(repeat_controls);
> int ret = 0;
>
> while (true) {
> @@ -2407,8 +2412,18 @@ static void kdamond_call(struct damon_ctx *ctx, bool cancel)
> mutex_lock(&ctx->call_controls_lock);
> list_del(&control->list);
> mutex_unlock(&ctx->call_controls_lock);
> - complete(&control->completion);
> + if (!control->repeat)
> + complete(&control->completion);
> + else
> + list_add(&control->list, &repeat_controls);
> }
> + control = list_first_entry_or_null(&repeat_controls,
> + struct damon_call_control, list);
> + if (!control || cancel)
> + return;
> + mutex_lock(&ctx->call_controls_lock);
> + list_add_tail(&control->list, &ctx->call_controls);
> + mutex_unlock(&ctx->call_controls_lock);
> }
Below fixup should be added on this. Without it, the repeat_controls handling
is never executed, so callback will be invoked only once.
diff --git a/mm/damon/core.c b/mm/damon/core.c
index 7a4dc76dd023..3c0c3cef43e7 100644
--- a/mm/damon/core.c
+++ b/mm/damon/core.c
@@ -2402,7 +2402,7 @@ static void kdamond_call(struct damon_ctx *ctx, bool cancel)
struct damon_call_control, list);
mutex_unlock(&ctx->call_controls_lock);
if (!control)
- return;
+ break;
if (cancel) {
control->canceled = true;
} else {
I'll add this on next version of this series.
Thanks,
SJ
[...]
Powered by blists - more mailing lists