From: Liew Rui Yan <aethernet65535@gmail.com>
To: SJ Park <sj@kernel.org>
Cc: damon@lists.linux.dev, linux-mm@kvack.org,
Liew Rui Yan <aethernet65535@gmail.com>
Subject: [PATCH 2/2] mm/damon: skip deactivated schemes in watermark checks and add fallback sleep
Date: Fri, 7 Aug 2026 17:35:26 +0800 [thread overview]
Message-ID: <20260807093526.183009-3-aethernet65535@gmail.com> (raw)
In-Reply-To: <20260807093526.183009-1-aethernet65535@gmail.com>
According to DAMOS design documentation, a scheme is deactivated when
nr_snapshots reaches max_nr_snapshots. However, the previous
kdamond_wait_activation() still checked the schemes which nr_snapshots
reached max_nr_snapshots.
This caused an issue - when all schemes were deactivated due to
max_nr_snapshots, but their watermarks were still satisfied,
damos_wmark_wait_us() would return 0, causing kdamond_wait_activation()
to return 0 (activated). The main loop would then continue without
sleeping, leading to unnecessary overhead since all schemes would be
skipped in damon_do_apply_schemes().
To fix this:
- Add a damos_is_deactivated() helper that checks both wmarks.activated
and max_nr_snapshots conditions.
- Replace the wmarks.activated-only checks with damos_is_deactivated()
in both damon_do_apply_schemes() and kdamond_apply_schemes().
- In kdamond_wait_activation(), skip deactivated schemes when calculating
the minimum wait time.
- When no active schemes remain, sleep for sample_interval as a fallback
(consistent with pause behavior) instead of returning 0.
Signed-off-by: Liew Rui Yan <aethernet65535@gmail.com>
---
mm/damon/core.c | 30 ++++++++++++++++++++++--------
1 file changed, 22 insertions(+), 8 deletions(-)
diff --git a/mm/damon/core.c b/mm/damon/core.c
index 7230483e771f..57d1a21a8a0a 100644
--- a/mm/damon/core.c
+++ b/mm/damon/core.c
@@ -2633,6 +2633,17 @@ static void damos_apply_scheme(struct damon_ctx *c, struct damon_target *t,
damos_update_stat(s, sz, sz_applied, sz_ops_filter_passed);
}
+static bool damos_is_deactivated(struct damos *s)
+{
+ if (!s->wmarks.activated)
+ return true;
+ if (s->max_nr_snapshots &&
+ s->max_nr_snapshots <= s->stat.nr_snapshots)
+ return true;
+
+ return false;
+}
+
static void damon_do_apply_schemes(struct damon_ctx *c,
struct damon_target *t,
struct damon_region *r)
@@ -2645,7 +2656,7 @@ static void damon_do_apply_schemes(struct damon_ctx *c,
if (time_before(c->passed_sample_intervals, s->next_apply_sis))
continue;
- if (!s->wmarks.activated)
+ if (damos_is_deactivated(s))
continue;
/* Check the quota */
@@ -2655,10 +2666,6 @@ static void damon_do_apply_schemes(struct damon_ctx *c,
if (damos_skip_charged_region(t, r, s, c->min_region_sz))
continue;
- if (s->max_nr_snapshots &&
- s->max_nr_snapshots <= s->stat.nr_snapshots)
- continue;
-
if (damos_valid_target(c, r, s))
damos_apply_scheme(c, t, r, s);
@@ -3220,7 +3227,7 @@ static void kdamond_apply_schemes(struct damon_ctx *c)
if (time_before(c->passed_sample_intervals, s->next_apply_sis))
continue;
- if (!s->wmarks.activated)
+ if (damos_is_deactivated(s))
continue;
has_schemes_to_apply = true;
@@ -3704,16 +3711,23 @@ static int kdamond_wait_activation(struct damon_ctx *ctx)
while (!kdamond_need_stop(ctx)) {
damon_for_each_scheme(s, ctx) {
+ if (s->max_nr_snapshots &&
+ s->max_nr_snapshots <= s->stat.nr_snapshots)
+ continue;
+
wait_time = damos_wmark_wait_us(s);
if (!init_wait_time || wait_time < min_wait_time) {
init_wait_time = true;
min_wait_time = wait_time;
}
}
- if (!min_wait_time)
+ if (!min_wait_time && init_wait_time)
return 0;
- kdamond_usleep(min_wait_time);
+ if (min_wait_time)
+ kdamond_usleep(min_wait_time);
+ else
+ kdamond_usleep(ctx->attrs.sample_interval);
kdamond_call(ctx, false);
if (ctx->maybe_corrupted)
--
2.55.0
next prev parent reply other threads:[~2026-08-07 9:35 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-08-07 9:35 [RFC PATCH 0/2] mm/damon: fix nr_snapshots semantics and max_nr_snapshots check coverage Liew Rui Yan
2026-08-07 9:35 ` [PATCH 1/2] mm/damon: fix nr_snapshots counting using tried_applied flag Liew Rui Yan
2026-08-07 9:48 ` sashiko-bot
2026-08-07 13:52 ` SJ Park
2026-08-07 9:35 ` Liew Rui Yan [this message]
2026-08-07 9:47 ` [PATCH 2/2] mm/damon: skip deactivated schemes in watermark checks and add fallback sleep sashiko-bot
2026-08-07 14:07 ` SJ Park
2026-08-07 16:18 ` Liew Rui Yan
2026-08-08 0:07 ` SJ Park
2026-08-08 21:55 ` Liew Rui Yan
2026-08-08 22:50 ` SJ Park
2026-08-07 14:12 ` [RFC PATCH 0/2] mm/damon: fix nr_snapshots semantics and max_nr_snapshots check coverage SJ Park
2026-08-07 16:19 ` Liew Rui Yan
2026-08-07 23:59 ` SJ 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=20260807093526.183009-3-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.