From: SeongJae Park <sj@kernel.org>
To: Bijan Tabatabai <bijan311@gmail.com>
Cc: SeongJae Park <sj@kernel.org>,
damon@lists.linux.dev, linux-mm@kvack.org,
linux-kernel@vger.kernel.org,
Andrew Morton <akpm@linux-foundation.org>,
Bijan Tabatabai <bijantabatab@micron.com>
Subject: Re: [PATCH] mm/damon/core: skip needless update of next_{aggregation,ops_update}_sis
Date: Wed, 6 Aug 2025 12:09:10 -0700 [thread overview]
Message-ID: <20250806190911.49728-1-sj@kernel.org> (raw)
In-Reply-To: <20250806164316.5728-1-bijan311@gmail.com>
Hi Bijan,
On Wed, 6 Aug 2025 11:43:16 -0500 Bijan Tabatabai <bijan311@gmail.com> wrote:
> From: Bijan Tabatabai <bijantabatab@micron.com>
>
> In damon_set_attrs(), ctx->next_{aggregation,ops_update}_sis would be
> reset, even if the sample interval, aggregation interval, or ops update
> interval were not changed. If damon_set_attrs() is called relatively
> frequently, such as by frequent "commit" operations, aggregation and ops
> update operations could be needlessly delayed.
>
> This patch avoids this by only updating next_{aggregation,ops_update}_sis
> if the relevant intervals were changed.
>
> Cc: Bijan Tabatabai <bijan311@gmail.com>
> Signed-off-by: Bijan Tabatabai <bijantabatab@micron.com>
> ---
> This patch came from discussions in [1].
>
> [1] https://lore.kernel.org/all/20250805162022.4920-1-bijan311@gmail.com/
Thank you for sending this patch as we discussed on the thread!
> ---
> mm/damon/core.c | 16 ++++++++++++----
> 1 file changed, 12 insertions(+), 4 deletions(-)
>
> diff --git a/mm/damon/core.c b/mm/damon/core.c
> index 6a2fe1f2c952..1c3d8b92257c 100644
> --- a/mm/damon/core.c
> +++ b/mm/damon/core.c
> @@ -693,6 +693,12 @@ int damon_set_attrs(struct damon_ctx *ctx, struct damon_attrs *attrs)
> unsigned long sample_interval = attrs->sample_interval ?
> attrs->sample_interval : 1;
> struct damos *s;
> + bool sample_interval_changed = ctx->attrs.sample_interval !=
> + attrs->sample_interval;
> + bool aggr_interval_changed = ctx->attrs.aggr_interval !=
> + attrs->aggr_interval;
> + bool ops_update_interval_changed = ctx->attrs.ops_update_interval !=
> + attrs->ops_update_interval;
> bool aggregating = ctx->passed_sample_intervals <
> ctx->next_aggregation_sis;
>
> @@ -710,10 +716,12 @@ int damon_set_attrs(struct damon_ctx *ctx, struct damon_attrs *attrs)
> if (!attrs->aggr_samples)
> attrs->aggr_samples = attrs->aggr_interval / sample_interval;
>
> - ctx->next_aggregation_sis = ctx->passed_sample_intervals +
> - attrs->aggr_interval / sample_interval;
> - ctx->next_ops_update_sis = ctx->passed_sample_intervals +
> - attrs->ops_update_interval / sample_interval;
> + if (sample_interval_changed || aggr_interval_changed)
> + ctx->next_aggregation_sis = ctx->passed_sample_intervals +
> + attrs->aggr_interval / sample_interval;
> + if (sample_interval_changed || ops_update_interval_changed)
> + ctx->next_ops_update_sis = ctx->passed_sample_intervals +
> + attrs->ops_update_interval / sample_interval;
>
> damon_update_monitoring_results(ctx, attrs, aggregating);
> ctx->attrs = *attrs;
Long story short, this (original) code is bit complicated and hence I suggest
to make this change less optimum but simpler.
damon_update_monitoring_results() assumes it is called only just after
next_{aggr,ops_update}_sis are updated. And the assumption is important for
the pseudo-moving-sum access frequency maintenance. As a result, this can make
the monitoring results temporarily corrupted, and splat warning once. Please
refer to commit 591c4c78be063 ("mm/damon/core: warn and fix nr_accesses[_bp]
corruption") or the patch thread[1] if you want more details.
Also damon_set_attrs() is called not only from commit situation. So I think
this maybe not an ideal part to modify.
What about modifying damon_commit_ctx() to check if new and old
damon_ctx->attrs are entirely same, and skip calling damon_set_attrs() in the
case? Doing the entire damon_attrs comparison might be suboptimum, but would
make the change simpler. I assume the suboptimum comparison is not a real
problem for your use case, so I think that could be a good tradeoff?
Also, I realize the moving sum access frequencies maintenance and
damon_set_attrs() are not well documented and organized. I will try to make
those better cleaned up and documented.
[1] https://lkml.kernel.org/r/20250513002715.40126-2-sj@kernel.org
Thanks,
SJ
> --
> 2.43.0
next prev parent reply other threads:[~2025-08-06 19:09 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-08-06 16:43 Bijan Tabatabai
2025-08-06 19:09 ` SeongJae Park [this message]
2025-08-06 19:49 ` Bijan Tabatabai
2025-08-06 21:42 ` 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=20250806190911.49728-1-sj@kernel.org \
--to=sj@kernel.org \
--cc=akpm@linux-foundation.org \
--cc=bijan311@gmail.com \
--cc=bijantabatab@micron.com \
--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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox