* [PATCH] mm/damon/core: recalculate intervals tuning deadline on attrs update
@ 2026-05-14 7:48 niecheng
2026-05-14 14:41 ` SeongJae Park
0 siblings, 1 reply; 4+ messages in thread
From: niecheng @ 2026-05-14 7:48 UTC (permalink / raw)
To: sj; +Cc: akpm, damon, linux-mm, linux-kernel, kernel, niecheng
damon_set_attrs() refreshes next_aggregation_sis and
next_ops_update_sis for online monitoring attribute updates, but it
does not refresh next_intervals_tune_sis.
Because of that, enabling intervals auto-tuning via an online attrs
commit can leave next_intervals_tune_sis stale. If a context starts
with intervals_goal.aggrs == 0 and later updates attrs online to set it
non-zero, kdamond_fn() can treat the tuning deadline as already expired
and tune the intervals earlier than intended.
This has been possible since the intervals auto-tuning feature was
introduced, because that commit initialized the deadline at kdamond
start but did not refresh it on later attrs updates.
Fix it by recalculating next_intervals_tune_sis in damon_set_attrs(),
using the same passed_sample_intervals-based schedule as the other
runtime deadlines.
Fixes: f04b0fedbe71 ("mm/damon/core: implement intervals auto-tuning")
Signed-off-by: niecheng <niecheng1@uniontech.com>
---
mm/damon/core.c | 2 ++
1 file changed, 2 insertions(+)
diff --git a/mm/damon/core.c b/mm/damon/core.c
index 3dbbbfdeff71..501694d4a590 100644
--- a/mm/damon/core.c
+++ b/mm/damon/core.c
@@ -797,6 +797,8 @@ int damon_set_attrs(struct damon_ctx *ctx, struct damon_attrs *attrs)
attrs->aggr_interval / sample_interval;
ctx->next_ops_update_sis = ctx->passed_sample_intervals +
attrs->ops_update_interval / sample_interval;
+ ctx->next_intervals_tune_sis = ctx->passed_sample_intervals +
+ attrs->aggr_samples * attrs->intervals_goal.aggrs;
damon_update_monitoring_results(ctx, attrs, aggregating);
ctx->attrs = *attrs;
--
2.51.0
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH] mm/damon/core: recalculate intervals tuning deadline on attrs update
2026-05-14 7:48 [PATCH] mm/damon/core: recalculate intervals tuning deadline on attrs update niecheng
@ 2026-05-14 14:41 ` SeongJae Park
2026-05-14 16:15 ` niecheng
2026-05-14 16:37 ` [PATCH] mm/damon/core: clarify next_intervals_tune_sis update path niecheng
0 siblings, 2 replies; 4+ messages in thread
From: SeongJae Park @ 2026-05-14 14:41 UTC (permalink / raw)
To: niecheng; +Cc: SeongJae Park, akpm, damon, linux-mm, linux-kernel, kernel
Hello Nicheng,
On Thu, 14 May 2026 15:48:46 +0800 niecheng <niecheng1@uniontech.com> wrote:
> damon_set_attrs() refreshes next_aggregation_sis and
> next_ops_update_sis for online monitoring attribute updates, but it
> does not refresh next_intervals_tune_sis.
>
> Because of that, enabling intervals auto-tuning via an online attrs
> commit can leave next_intervals_tune_sis stale. If a context starts
> with intervals_goal.aggrs == 0 and later updates attrs online to set it
> non-zero, kdamond_fn() can treat the tuning deadline as already expired
> and tune the intervals earlier than intended.
>
> This has been possible since the intervals auto-tuning feature was
> introduced, because that commit initialized the deadline at kdamond
> start but did not refresh it on later attrs updates.
Good finding, thank you for sharing this!
But, the next_interval_tune_sis will be updated based on the updated
aggregation and sampling intervals, just before the next intervals tuning is
made.
In detail, the code flow of the kdamond_fn() main loop is like below:
- call kdamond_call()
- call damon_set_attrs()
- update aggregation and sampling intervals
- if passed_ample_intervals >= next_intervals_tune_sis:
- update next_intervals_tune_sis with updated aggregation and sampling
intervals
- call kdamond_tune_intervals()
So, the old next_intervals_tune_sis will be used only once. I agree not
everyone will think it is the best behavior. But seems ok to me. I'd like to
keep the current code in favor of less complexity. What do you think?
Nevertheless, apparently the code can better be documented. Maybe it is worthy
to add a comment about this. For example, maybe it is better to add a comment
saying "next_intervals_tune_sis will be updated inside kdamond_fn()" on the
damon_set_attrs(). If you'd like to, please feel free to post such a patch.
Thanks,
SJ
[...]
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] mm/damon/core: recalculate intervals tuning deadline on attrs update
2026-05-14 14:41 ` SeongJae Park
@ 2026-05-14 16:15 ` niecheng
2026-05-14 16:37 ` [PATCH] mm/damon/core: clarify next_intervals_tune_sis update path niecheng
1 sibling, 0 replies; 4+ messages in thread
From: niecheng @ 2026-05-14 16:15 UTC (permalink / raw)
To: sj; +Cc: akpm, damon, linux-mm, linux-kernel, niecheng1, kernel
Hi SJ,
You are right.
I rechecked kdamond_fn(), and what I observed is a one-shot earlier
intervals tuning after the online update, rather than a persistent
stale-deadline bug.
So I will drop my previous patch and send a small follow-up comment
patch for this subtle behavior.
Thanks,
Niecheng
^ permalink raw reply [flat|nested] 4+ messages in thread
* [PATCH] mm/damon/core: clarify next_intervals_tune_sis update path
2026-05-14 14:41 ` SeongJae Park
2026-05-14 16:15 ` niecheng
@ 2026-05-14 16:37 ` niecheng
1 sibling, 0 replies; 4+ messages in thread
From: niecheng @ 2026-05-14 16:37 UTC (permalink / raw)
To: sj; +Cc: akpm, damon, linux-mm, linux-kernel, niecheng1, kernel
damon_set_attrs() updates next_aggregation_sis and
next_ops_update_sis for online attrs updates, but it does not update
next_intervals_tune_sis there.
This can look like a missing update when reading damon_set_attrs()
alone, while next_intervals_tune_sis is actually updated in
kdamond_fn().
Add a short comment to make this explicit.
Suggested-by: SeongJae Park <sj@kernel.org>
Link: https://lore.kernel.org/linux-mm/20260514144102.120203-1-sj@kernel.org/
Signed-off-by: niecheng <niecheng1@uniontech.com>
---
mm/damon/core.c | 3 +++
1 file changed, 3 insertions(+)
diff --git a/mm/damon/core.c b/mm/damon/core.c
index 3dbbbfdeff71..a21ae41ca695 100644
--- a/mm/damon/core.c
+++ b/mm/damon/core.c
@@ -797,6 +797,9 @@ int damon_set_attrs(struct damon_ctx *ctx, struct damon_attrs *attrs)
attrs->aggr_interval / sample_interval;
ctx->next_ops_update_sis = ctx->passed_sample_intervals +
attrs->ops_update_interval / sample_interval;
+ /*
+ * next_intervals_tune_sis will be updated inside kdamond_fn().
+ */
damon_update_monitoring_results(ctx, attrs, aggregating);
ctx->attrs = *attrs;
--
2.51.0
^ permalink raw reply related [flat|nested] 4+ messages in thread
end of thread, other threads:[~2026-05-14 16:39 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-05-14 7:48 [PATCH] mm/damon/core: recalculate intervals tuning deadline on attrs update niecheng
2026-05-14 14:41 ` SeongJae Park
2026-05-14 16:15 ` niecheng
2026-05-14 16:37 ` [PATCH] mm/damon/core: clarify next_intervals_tune_sis update path niecheng
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox