[RFC PATCH v4 4/9] mm/damon/ops-common: use probe-weighted score when probe weights are set
From: Ravi Jonnalagadda
Date: Mon Oct 05 2026 - 04:50:55 EST
When probe weights are configured (damon_has_probe_weights()), use
damon_probe_hits_wsum() for the frequency subscore in damon_hot_score()
instead of damon_nr_accesses_mvsum(). This routes the probe hits of a
perf-event probe into the DAMOS priority score.
Make damon_has_probe_weights() non-static and declare it in damon.h so
ops-common.c can call it.
Scale the weighted-hit sum in 64 bits and clamp the result to
DAMON_MAX_SUBSCORE, so a large sum cannot overflow the subscore range.
Signed-off-by: Ravi Jonnalagadda <ravis.opensrc@xxxxxxxxx>
---
include/linux/damon.h | 1 +
mm/damon/core.c | 2 +-
mm/damon/ops-common.c | 19 ++++++++++++++++---
3 files changed, 18 insertions(+), 4 deletions(-)
diff --git a/include/linux/damon.h b/include/linux/damon.h
index 7c5a416e1eff..b0895ef477ed 100644
--- a/include/linux/damon.h
+++ b/include/linux/damon.h
@@ -1306,6 +1306,7 @@ 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, bool mv,
struct damon_ctx *ctx);
+bool damon_has_probe_weights(struct damon_ctx *c);
int damon_set_regions(struct damon_target *t, struct damon_addr_range *ranges,
unsigned int nr_ranges, unsigned long min_region_sz);
diff --git a/mm/damon/core.c b/mm/damon/core.c
index a15dc7e9125a..9fc536238c2f 100644
--- a/mm/damon/core.c
+++ b/mm/damon/core.c
@@ -331,7 +331,7 @@ static struct damon_probe *damon_nth_probe(int n, struct damon_ctx *ctx)
return NULL;
}
-static bool damon_has_probe_weights(struct damon_ctx *c)
+bool damon_has_probe_weights(struct damon_ctx *c)
{
struct damon_probe *p;
diff --git a/mm/damon/ops-common.c b/mm/damon/ops-common.c
index 2f3bf86a221b..3c5cd745f4ba 100644
--- a/mm/damon/ops-common.c
+++ b/mm/damon/ops-common.c
@@ -172,9 +172,22 @@ int damon_hot_score(struct damon_ctx *c, struct damon_region *r,
unsigned int age_weight = s->quota.weight_age;
int hotness;
- freq_subscore = mult_frac(damon_nr_accesses_mvsum(r, c),
- DAMON_MAX_SUBSCORE,
- damon_nr_samples_per_aggr(&c->attrs));
+ if (damon_has_probe_weights(c)) {
+ unsigned int wsum = damon_probe_hits_wsum(r, false, true, c);
+ u64 subscore = div_u64((u64)wsum * DAMON_MAX_SUBSCORE,
+ damon_nr_samples_per_aggr(&c->attrs));
+
+ /*
+ * Score by the weighted probe hits. Clamp to
+ * DAMON_MAX_SUBSCORE so a large weighted-hit sum cannot
+ * overflow the subscore range.
+ */
+ freq_subscore = min_t(u64, subscore, DAMON_MAX_SUBSCORE);
+ } else {
+ freq_subscore = mult_frac(damon_nr_accesses_mvsum(r, c),
+ DAMON_MAX_SUBSCORE,
+ damon_nr_samples_per_aggr(&c->attrs));
+ }
age_in_sec = div_u64((u64)r->age * c->attrs.aggr_interval,
USEC_PER_SEC);
--
Git-157)