Commit 898810e5 authored by SeongJae Park's avatar SeongJae Park Committed by Andrew Morton

mm/damon/core: split out scheme quota adjustment logic into a new function

DAMOS quota adjustment logic in 'kdamond_apply_schemes()', has some amount
of code, and the logic is not so straightforward.  Split it out to a new
function for better readability.

Link: https://lkml.kernel.org/r/20221026225943.100429-5-sj@kernel.orgSigned-off-by: default avatarSeongJae Park <sj@kernel.org>
Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
parent d1cbbf62
...@@ -848,59 +848,64 @@ static void damos_set_effective_quota(struct damos_quota *quota) ...@@ -848,59 +848,64 @@ static void damos_set_effective_quota(struct damos_quota *quota)
quota->esz = esz; quota->esz = esz;
} }
static void kdamond_apply_schemes(struct damon_ctx *c) static void damos_adjust_quota(struct damon_ctx *c, struct damos *s)
{ {
struct damos_quota *quota = &s->quota;
struct damon_target *t; struct damon_target *t;
struct damon_region *r, *next_r; struct damon_region *r;
struct damos *s; unsigned long cumulated_sz;
unsigned int score, max_score = 0;
damon_for_each_scheme(s, c) { if (!quota->ms && !quota->sz)
struct damos_quota *quota = &s->quota; return;
unsigned long cumulated_sz;
unsigned int score, max_score = 0;
if (!s->wmarks.activated) /* New charge window starts */
continue; if (time_after_eq(jiffies, quota->charged_from +
msecs_to_jiffies(quota->reset_interval))) {
if (quota->esz && quota->charged_sz >= quota->esz)
s->stat.qt_exceeds++;
quota->total_charged_sz += quota->charged_sz;
quota->charged_from = jiffies;
quota->charged_sz = 0;
damos_set_effective_quota(quota);
}
if (!quota->ms && !quota->sz) if (!c->ops.get_scheme_score)
continue; return;
/* New charge window starts */ /* Fill up the score histogram */
if (time_after_eq(jiffies, quota->charged_from + memset(quota->histogram, 0, sizeof(quota->histogram));
msecs_to_jiffies( damon_for_each_target(t, c) {
quota->reset_interval))) { damon_for_each_region(r, t) {
if (quota->esz && quota->charged_sz >= quota->esz) if (!__damos_valid_target(r, s))
s->stat.qt_exceeds++; continue;
quota->total_charged_sz += quota->charged_sz; score = c->ops.get_scheme_score(c, t, r, s);
quota->charged_from = jiffies; quota->histogram[score] += damon_sz_region(r);
quota->charged_sz = 0; if (score > max_score)
damos_set_effective_quota(quota); max_score = score;
} }
}
if (!c->ops.get_scheme_score) /* Set the min score limit */
continue; for (cumulated_sz = 0, score = max_score; ; score--) {
cumulated_sz += quota->histogram[score];
if (cumulated_sz >= quota->esz || !score)
break;
}
quota->min_score = score;
}
/* Fill up the score histogram */ static void kdamond_apply_schemes(struct damon_ctx *c)
memset(quota->histogram, 0, sizeof(quota->histogram)); {
damon_for_each_target(t, c) { struct damon_target *t;
damon_for_each_region(r, t) { struct damon_region *r, *next_r;
if (!__damos_valid_target(r, s)) struct damos *s;
continue;
score = c->ops.get_scheme_score(
c, t, r, s);
quota->histogram[score] += damon_sz_region(r);
if (score > max_score)
max_score = score;
}
}
/* Set the min score limit */ damon_for_each_scheme(s, c) {
for (cumulated_sz = 0, score = max_score; ; score--) { if (!s->wmarks.activated)
cumulated_sz += quota->histogram[score]; continue;
if (cumulated_sz >= quota->esz || !score)
break; damos_adjust_quota(c, s);
}
quota->min_score = score;
} }
damon_for_each_target(t, c) { damon_for_each_target(t, c) {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment