DAMOS access pattern is the primary target region selection method. It uses DAMOS core filters as only secondary filters. Hence DAMOS core filters are applied in damos_apply_scheme() and damos_adjust_quota(). There is no real reason to keep filters as secondary class. The multiple places for core filters application only make it duplicated and easy to make mistakes. Also, users can distinguish target regions based on probe_hits using only core filters. In the attributes only monitoring mode, core filters become the primary target region selection method for this reason. Treat DAMOS core filter as the primary method. Handle it in a single place, __damos_valid_target(), which is handling the DAMOS access pattern. Update __damos_valid_target() to receive damon_ctx, to allow it access to core filters. One consequence of this change is that DAMOS_QUOTA_NODE_ELIGIBLE_MEM_BP will be aware of the core filters. It is a sort of behavioral change. But it is hard to imagine users who really depend on the old behavior. The new behavior is rather more intuitive in my opinion. Signed-off-by: SJ Park --- mm/damon/core.c | 26 +++++++++++++++----------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/mm/damon/core.c b/mm/damon/core.c index 2766ebec0150..6345cbc60bfb 100644 --- a/mm/damon/core.c +++ b/mm/damon/core.c @@ -2535,12 +2535,20 @@ static noinline_for_stack void kdamond_tune_intervals(struct damon_ctx *c) damon_set_attrs(c, &new_attrs); } +static bool damos_core_filter_out(struct damon_ctx *ctx, + struct damon_target *t, struct damon_region *r, + struct damos *s); + static bool __damos_valid_target(struct damon_region *r, struct damos *s, - struct damon_ctx *c) + struct damon_ctx *c, struct damon_target *t) { unsigned long sz; - unsigned int nr_accesses = damon_nr_accesses_mvsum(r, c); + unsigned int nr_accesses; + + if (damos_core_filter_out(c, t, r, s)) + return false; + nr_accesses = damon_nr_accesses_mvsum(r, c); sz = damon_sz_region(r); return s->pattern.min_sz_region <= sz && sz <= s->pattern.max_sz_region && @@ -2563,9 +2571,9 @@ static bool damos_quota_is_set(struct damos_quota *quota) } static bool damos_valid_target(struct damon_ctx *c, struct damon_region *r, - struct damos *s) + struct damos *s, struct damon_target *t) { - bool ret = __damos_valid_target(r, s, c); + bool ret = __damos_valid_target(r, s, c, t); if (!ret || !damos_quota_is_set(&s->quota) || !c->ops.get_scheme_score) return ret; @@ -2896,8 +2904,6 @@ static void damos_apply_scheme(struct damon_ctx *c, struct damon_target *t, } if (c->ops.apply_scheme) { - if (damos_core_filter_out(c, t, r, s)) - return; sz = damon_sz_region(r); if (damos_quota_is_set(quota) && quota->charged_sz + sz > quota->esz) { @@ -2957,7 +2963,7 @@ static void damon_do_apply_schemes(struct damon_ctx *c, s->max_nr_snapshots <= s->stat.nr_snapshots) continue; - if (damos_valid_target(c, r, s)) + if (damos_valid_target(c, r, s, t)) damos_apply_scheme(c, t, r, s); if (damon_is_last_region(r, t)) @@ -3218,7 +3224,7 @@ static phys_addr_t damos_calc_eligible_bytes(struct damon_ctx *c, damon_for_each_region(r, t) { phys_addr_t addr, end_addr; - if (!__damos_valid_target(r, s, c)) + if (!__damos_valid_target(r, s, c, t)) continue; /* Convert from core address units to physical bytes */ @@ -3565,9 +3571,7 @@ static void damos_adjust_quota(struct damon_ctx *c, struct damos *s) (DAMOS_MAX_SCORE + 1)); damon_for_each_target(t, c) { damon_for_each_region(r, t) { - if (!__damos_valid_target(r, s, c)) - continue; - if (damos_core_filter_out(c, t, r, s)) + if (!__damos_valid_target(r, s, c, t)) continue; score = c->ops.get_scheme_score(c, r, s); c->regions_score_histogram[score] += -- 2.47.3