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,27 +848,20 @@ static void damos_set_effective_quota(struct damos_quota *quota) ...@@ -848,27 +848,20 @@ 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 damon_target *t;
struct damon_region *r, *next_r;
struct damos *s;
damon_for_each_scheme(s, c) {
struct damos_quota *quota = &s->quota; struct damos_quota *quota = &s->quota;
struct damon_target *t;
struct damon_region *r;
unsigned long cumulated_sz; unsigned long cumulated_sz;
unsigned int score, max_score = 0; unsigned int score, max_score = 0;
if (!s->wmarks.activated)
continue;
if (!quota->ms && !quota->sz) if (!quota->ms && !quota->sz)
continue; return;
/* New charge window starts */ /* New charge window starts */
if (time_after_eq(jiffies, quota->charged_from + if (time_after_eq(jiffies, quota->charged_from +
msecs_to_jiffies( msecs_to_jiffies(quota->reset_interval))) {
quota->reset_interval))) {
if (quota->esz && quota->charged_sz >= quota->esz) if (quota->esz && quota->charged_sz >= quota->esz)
s->stat.qt_exceeds++; s->stat.qt_exceeds++;
quota->total_charged_sz += quota->charged_sz; quota->total_charged_sz += quota->charged_sz;
...@@ -878,7 +871,7 @@ static void kdamond_apply_schemes(struct damon_ctx *c) ...@@ -878,7 +871,7 @@ static void kdamond_apply_schemes(struct damon_ctx *c)
} }
if (!c->ops.get_scheme_score) if (!c->ops.get_scheme_score)
continue; return;
/* Fill up the score histogram */ /* Fill up the score histogram */
memset(quota->histogram, 0, sizeof(quota->histogram)); memset(quota->histogram, 0, sizeof(quota->histogram));
...@@ -886,8 +879,7 @@ static void kdamond_apply_schemes(struct damon_ctx *c) ...@@ -886,8 +879,7 @@ static void kdamond_apply_schemes(struct damon_ctx *c)
damon_for_each_region(r, t) { damon_for_each_region(r, t) {
if (!__damos_valid_target(r, s)) if (!__damos_valid_target(r, s))
continue; continue;
score = c->ops.get_scheme_score( score = c->ops.get_scheme_score(c, t, r, s);
c, t, r, s);
quota->histogram[score] += damon_sz_region(r); quota->histogram[score] += damon_sz_region(r);
if (score > max_score) if (score > max_score)
max_score = score; max_score = score;
...@@ -901,6 +893,19 @@ static void kdamond_apply_schemes(struct damon_ctx *c) ...@@ -901,6 +893,19 @@ static void kdamond_apply_schemes(struct damon_ctx *c)
break; break;
} }
quota->min_score = score; quota->min_score = score;
}
static void kdamond_apply_schemes(struct damon_ctx *c)
{
struct damon_target *t;
struct damon_region *r, *next_r;
struct damos *s;
damon_for_each_scheme(s, c) {
if (!s->wmarks.activated)
continue;
damos_adjust_quota(c, s);
} }
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