[RFC PATCH v2 02/10] mm/damon/core: allow quota goals set zero effective size quota
From: SeongJae Park
Date: Tue Mar 03 2026 - 23:42:05 EST
User-explicit quotas (size and time quotas) having zero value means the
quotas are unset. And, effective size quota is set as the minimum value
of the explicit quotas. When quota goals are set, the goal-based quota
tuner can make it lower. But the existing only single tuner never sets
the effective size quota zero. Because of the fact, DAMON core assumes
zero effective quota means the user has set no quota.
Multiple tuners are now allowed, though. In the future, some tuners
might want to set a zero effective size quota. There is no reason to
restrict that. Meanwhile, because of the current implementation, it
will only deactivate all quotas and make the scheme work at its full
speed.
Introduce a dedicated function for checking if no quota is set. The
function checks the fact by showing if the user-set explicit quotas are
zero and no goal is installed. It is decoupled from zero effective
quota, and hence allows future tuners set zero effective quota for
intentionally deactivating the scheme by a purpose.
Signed-off-by: SeongJae Park <sj@xxxxxxxxxx>
---
mm/damon/core.c | 29 ++++++++++++++++++++++++-----
1 file changed, 24 insertions(+), 5 deletions(-)
diff --git a/mm/damon/core.c b/mm/damon/core.c
index c5503fdb10bb7..d657b87dd99e8 100644
--- a/mm/damon/core.c
+++ b/mm/damon/core.c
@@ -387,6 +387,11 @@ void damos_destroy_quota_goal(struct damos_quota_goal *g)
damos_free_quota_goal(g);
}
+static bool damos_quota_goals_empty(struct damos_quota *q)
+{
+ return list_empty(&q->goals);
+}
+
/* initialize fields of @quota that normally API users wouldn't set */
static struct damos_quota *damos_quota_init(struct damos_quota *quota)
{
@@ -1782,12 +1787,24 @@ static bool __damos_valid_target(struct damon_region *r, struct damos *s)
r->age <= s->pattern.max_age_region;
}
+/*
+ * damos_quota_set() - Return if the given quota is actually set.
+ * @quota: The quota to check.
+ *
+ * Returns true if the quota is set, false otherwise.
+ */
+static bool damos_quota_set(struct damos_quota *quota)
+{
+ return quota->esz || quota->sz || quota->ms ||
+ !damos_quota_goals_empty(quota);
+}
+
static bool damos_valid_target(struct damon_ctx *c, struct damon_region *r,
struct damos *s)
{
bool ret = __damos_valid_target(r, s);
- if (!ret || !s->quota.esz || !c->ops.get_scheme_score)
+ if (!ret || !damos_quota_set(&s->quota) || !c->ops.get_scheme_score)
return ret;
return c->ops.get_scheme_score(c, r, s) >= s->quota.min_score;
@@ -2057,7 +2074,8 @@ static void damos_apply_scheme(struct damon_ctx *c, struct damon_target *t,
}
if (c->ops.apply_scheme) {
- if (quota->esz && quota->charged_sz + sz > quota->esz) {
+ if (damos_quota_set(quota) &&
+ quota->charged_sz + sz > quota->esz) {
sz = ALIGN_DOWN(quota->esz - quota->charged_sz,
c->min_region_sz);
if (!sz)
@@ -2076,7 +2094,8 @@ static void damos_apply_scheme(struct damon_ctx *c, struct damon_target *t,
quota->total_charged_ns += timespec64_to_ns(&end) -
timespec64_to_ns(&begin);
quota->charged_sz += sz;
- if (quota->esz && quota->charged_sz >= quota->esz) {
+ if (damos_quota_set(quota) &&
+ quota->charged_sz >= quota->esz) {
quota->charge_target_from = t;
quota->charge_addr_from = r->ar.end + 1;
}
@@ -2104,7 +2123,7 @@ static void damon_do_apply_schemes(struct damon_ctx *c,
continue;
/* Check the quota */
- if (quota->esz && quota->charged_sz >= quota->esz)
+ if (damos_quota_set(quota) && quota->charged_sz >= quota->esz)
continue;
if (damos_skip_charged_region(t, r, s, c->min_region_sz))
@@ -2389,7 +2408,7 @@ static void damos_adjust_quota(struct damon_ctx *c, struct damos *s)
/* New charge window starts */
if (time_after_eq(jiffies, quota->charged_from +
msecs_to_jiffies(quota->reset_interval))) {
- if (quota->esz && quota->charged_sz >= quota->esz)
+ if (damos_quota_set(quota) && quota->charged_sz >= quota->esz)
s->stat.qt_exceeds++;
quota->total_charged_sz += quota->charged_sz;
quota->charged_from = jiffies;
--
2.47.3