Commit e63a30c5 authored by SeongJae Park's avatar SeongJae Park Committed by Andrew Morton

mm/damon/core: split damos application logic into a new function

The DAMOS action applying function, 'damon_do_apply_schemes()', is still
long and not easy to read.  Split out the code for applying a single
action to a single region into a new function for better readability.

Link: https://lkml.kernel.org/r/20221026225943.100429-3-sj@kernel.orgSigned-off-by: default avatarSeongJae Park <sj@kernel.org>
Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
parent 2ea34989
...@@ -755,6 +755,44 @@ static bool damos_skip_charged_region(struct damon_target *t, ...@@ -755,6 +755,44 @@ static bool damos_skip_charged_region(struct damon_target *t,
return false; return false;
} }
static void damos_apply_scheme(struct damon_ctx *c, struct damon_target *t,
struct damon_region *r, struct damos *s)
{
struct damos_quota *quota = &s->quota;
unsigned long sz = damon_sz_region(r);
struct timespec64 begin, end;
unsigned long sz_applied = 0;
if (c->ops.apply_scheme) {
if (quota->esz && quota->charged_sz + sz > quota->esz) {
sz = ALIGN_DOWN(quota->esz - quota->charged_sz,
DAMON_MIN_REGION);
if (!sz)
goto update_stat;
damon_split_region_at(t, r, sz);
}
ktime_get_coarse_ts64(&begin);
sz_applied = c->ops.apply_scheme(c, t, r, s);
ktime_get_coarse_ts64(&end);
quota->total_charged_ns += timespec64_to_ns(&end) -
timespec64_to_ns(&begin);
quota->charged_sz += sz;
if (quota->esz && quota->charged_sz >= quota->esz) {
quota->charge_target_from = t;
quota->charge_addr_from = r->ar.end + 1;
}
}
if (s->action != DAMOS_STAT)
r->age = 0;
update_stat:
s->stat.nr_tried++;
s->stat.sz_tried += sz;
if (sz_applied)
s->stat.nr_applied++;
s->stat.sz_applied += sz_applied;
}
static void damon_do_apply_schemes(struct damon_ctx *c, static void damon_do_apply_schemes(struct damon_ctx *c,
struct damon_target *t, struct damon_target *t,
struct damon_region *r) struct damon_region *r)
...@@ -763,9 +801,6 @@ static void damon_do_apply_schemes(struct damon_ctx *c, ...@@ -763,9 +801,6 @@ static void damon_do_apply_schemes(struct damon_ctx *c,
damon_for_each_scheme(s, c) { damon_for_each_scheme(s, c) {
struct damos_quota *quota = &s->quota; struct damos_quota *quota = &s->quota;
unsigned long sz;
struct timespec64 begin, end;
unsigned long sz_applied = 0;
if (!s->wmarks.activated) if (!s->wmarks.activated)
continue; continue;
...@@ -780,37 +815,7 @@ static void damon_do_apply_schemes(struct damon_ctx *c, ...@@ -780,37 +815,7 @@ static void damon_do_apply_schemes(struct damon_ctx *c,
if (!damos_valid_target(c, t, r, s)) if (!damos_valid_target(c, t, r, s))
continue; continue;
/* Apply the scheme */ damos_apply_scheme(c, t, r, s);
sz = damon_sz_region(r);
if (c->ops.apply_scheme) {
if (quota->esz &&
quota->charged_sz + sz > quota->esz) {
sz = ALIGN_DOWN(quota->esz - quota->charged_sz,
DAMON_MIN_REGION);
if (!sz)
goto update_stat;
damon_split_region_at(t, r, sz);
}
ktime_get_coarse_ts64(&begin);
sz_applied = c->ops.apply_scheme(c, t, r, s);
ktime_get_coarse_ts64(&end);
quota->total_charged_ns += timespec64_to_ns(&end) -
timespec64_to_ns(&begin);
quota->charged_sz += sz;
if (quota->esz && quota->charged_sz >= quota->esz) {
quota->charge_target_from = t;
quota->charge_addr_from = r->ar.end + 1;
}
}
if (s->action != DAMOS_STAT)
r->age = 0;
update_stat:
s->stat.nr_tried++;
s->stat.sz_tried += sz;
if (sz_applied)
s->stat.nr_applied++;
s->stat.sz_applied += sz_applied;
} }
} }
......
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