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)
{
r->age <= s->pattern.max_age_region;
}
+/*
+ * damos_quota_is_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_is_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_is_set(&s->quota) || !c->ops.get_scheme_score)
return ret;
return c->ops.get_scheme_score(c, r, s) >= s->quota.min_score;
}
if (c->ops.apply_scheme) {
- if (quota->esz && quota->charged_sz + sz > quota->esz) {
+ if (damos_quota_is_set(quota) &&
+ quota->charged_sz + sz > quota->esz) {
sz = ALIGN_DOWN(quota->esz - quota->charged_sz,
c->min_region_sz);
if (!sz)
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_is_set(quota) &&
+ quota->charged_sz >= quota->esz) {
quota->charge_target_from = t;
quota->charge_addr_from = r->ar.end + 1;
}
continue;
/* Check the quota */
- if (quota->esz && quota->charged_sz >= quota->esz)
+ if (damos_quota_is_set(quota) &&
+ quota->charged_sz >= quota->esz)
continue;
if (damos_skip_charged_region(t, r, s, c->min_region_sz))
/* 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_is_set(quota) &&
+ quota->charged_sz >= quota->esz)
s->stat.qt_exceeds++;
quota->total_charged_sz += quota->charged_sz;
quota->charged_from = jiffies;