From: SJ Park <sj@kernel.org>
Cc: SJ Park <sj@kernel.org>,
Andrew Morton <akpm@linux-foundation.org>,
damon@lists.linux.dev, linux-kernel@vger.kernel.org,
linux-mm@kvack.org
Subject: [RFC PATCH v2.1 2/7] mm/damon/core: extend probe_hits_wsum() for moving sum based calculation
Date: Wed, 9 Sep 2026 21:03:13 -0700 [thread overview]
Message-ID: <20260910040319.147037-3-sj@kernel.org> (raw)
In-Reply-To: <20260910040319.147037-1-sj@kernel.org>
damon_probe_hits_wsum() is being called only in aggregation time. In
future, it could also be used by DAMOS. In this case, since DAMOS uses
its own apply_interval, it could be called in sampling time. Then using
the not yet fully aggregated probe_hits could result in suboptimum
outcomes. Extend damon_probe_hits_wsum() to get the weighted sum based
on moving sum to prepare the DAMOS usage.
Signed-off-by: SJ Park <sj@kernel.org>
---
include/linux/damon.h | 2 +-
mm/damon/core.c | 8 ++++++--
mm/damon/paddr.c | 2 +-
mm/damon/vaddr.c | 2 +-
4 files changed, 9 insertions(+), 5 deletions(-)
diff --git a/include/linux/damon.h b/include/linux/damon.h
index 1deda16bb70b5..9fa99f92a2e94 100644
--- a/include/linux/damon.h
+++ b/include/linux/damon.h
@@ -1073,7 +1073,7 @@ unsigned int damon_nr_accesses_mvsum(struct damon_region *r,
struct damon_ctx *ctx);
unsigned char damon_probe_hits_mvsum(int probe_idx, struct damon_region *r,
struct damon_ctx *ctx);
-unsigned int damon_probe_hits_wsum(struct damon_region *r, bool last,
+unsigned int damon_probe_hits_wsum(struct damon_region *r, bool last, bool mv,
struct damon_ctx *ctx);
int damon_set_regions(struct damon_target *t, struct damon_addr_range *ranges,
diff --git a/mm/damon/core.c b/mm/damon/core.c
index 06cf2ab7e97d7..50e0f9407db2b 100644
--- a/mm/damon/core.c
+++ b/mm/damon/core.c
@@ -469,11 +469,12 @@ static bool damon_is_last_region(struct damon_region *r,
* damon_probe_hits_wsum() - Returns probe hits weighted sum of a region.
* @r: region to get the weighted sum of.
* @last: if the request is for last-window aggregated probe hits.
+ * @mv: use moving sum.
* @ctx: context of &r.
*
* Return: the weighted sum of probe hits of the region.
*/
-unsigned int damon_probe_hits_wsum(struct damon_region *r, bool last,
+unsigned int damon_probe_hits_wsum(struct damon_region *r, bool last, bool mv,
struct damon_ctx *ctx)
{
struct damon_probe *probe;
@@ -483,6 +484,9 @@ unsigned int damon_probe_hits_wsum(struct damon_region *r, bool last,
damon_for_each_probe(probe, ctx) {
if (last)
sum += r->last_probe_hits[i++] * probe->weight;
+ else if (mv)
+ sum += damon_probe_hits_mvsum(i++, r, ctx) *
+ probe->weight;
else
sum += r->probe_hits[i++] * probe->weight;
}
@@ -3456,7 +3460,7 @@ static unsigned int damon_merge_score(struct damon_region *r, bool last,
struct damon_ctx *ctx, bool use_probe_hits)
{
if (use_probe_hits)
- return damon_probe_hits_wsum(r, last, ctx);
+ return damon_probe_hits_wsum(r, last, false, ctx);
if (last)
return r->last_nr_accesses;
return r->nr_accesses;
diff --git a/mm/damon/paddr.c b/mm/damon/paddr.c
index d7c81829445ba..b8f4d28165dd7 100644
--- a/mm/damon/paddr.c
+++ b/mm/damon/paddr.c
@@ -202,7 +202,7 @@ static unsigned int damon_pa_apply_probes(struct damon_ctx *ctx,
folio_put(folio);
if (return_max_wsum)
max_wsum = max(damon_probe_hits_wsum(r, false,
- ctx), max_wsum);
+ false, ctx), max_wsum);
}
}
return max_wsum;
diff --git a/mm/damon/vaddr.c b/mm/damon/vaddr.c
index 9a38dc89a156e..4aecf34e39be2 100644
--- a/mm/damon/vaddr.c
+++ b/mm/damon/vaddr.c
@@ -704,7 +704,7 @@ static unsigned int damon_va_apply_probes(struct damon_ctx *ctx,
__damon_va_apply_probes(ctx, mm, r);
if (return_max_wsum)
max_wsum = max(damon_probe_hits_wsum(r, false,
- ctx), max_wsum);
+ false, ctx), max_wsum);
}
if (mm)
mmput(mm);
--
2.47.3
next prev parent reply other threads:[~2026-09-10 4:03 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-10 4:03 [RFC PATCH v2.1 0/7] mm/damon: introduce probe_hits_wsum DAMOS core filter SJ Park
2026-09-10 4:03 ` [RFC PATCH v2.1 1/7] mm/damon/api: introduce DAMOS_FILTER_TYPE_PROBE_HITS_WSUM SJ Park
2026-09-10 4:13 ` sashiko-bot
2026-09-10 4:17 ` SJ Park
2026-09-10 4:03 ` SJ Park [this message]
2026-09-10 4:08 ` [RFC PATCH v2.1 2/7] mm/damon/core: extend probe_hits_wsum() for moving sum based calculation sashiko-bot
2026-09-10 4:03 ` [RFC PATCH v2.1 3/7] mm/damon/core: support probe_hits_wsum damos core filter SJ Park
2026-09-10 4:16 ` sashiko-bot
2026-09-10 4:20 ` SJ Park
2026-09-10 4:03 ` [RFC PATCH v2.1 4/7] mm/damon/sysfs-schemes: rename sysfs_filter->sz_range to range_{min,max} SJ Park
2026-09-10 4:14 ` sashiko-bot
2026-09-10 4:03 ` [RFC PATCH v2.1 5/7] mm/damon/sysfs-schemes: support probe_hits_wsum damos core filter SJ Park
2026-09-10 4:18 ` sashiko-bot
2026-09-10 4:23 ` SJ Park
2026-09-10 4:03 ` [RFC PATCH v2.1 6/7] Docs/mm/damon/design: update for probe_hits_wsum DAMOS " SJ Park
2026-09-10 4:05 ` sashiko-bot
2026-09-10 4:03 ` [RFC PATCH v2.1 7/7] Docs/admin-guide/mm/damon/usage: update for probe_hits_wsum DAMOS filter SJ Park
2026-09-10 4:05 ` sashiko-bot
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=20260910040319.147037-3-sj@kernel.org \
--to=sj@kernel.org \
--cc=akpm@linux-foundation.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.