There is no way to specify DAMOS target regions with a deterministic time based age range. Extend DAMOS core filter to specify target regions with age in milliseconds. Introduce new damos_filter_type, DAMOS_FILTER_TYPE_AGE_MS in DAMON API, and implement support of the type in the core layer. Convert the age in aggregation intervals to milliseconds and use it when the filter is evaluated. Reuse damos_filter->range_{min,max} to save the age range. Signed-off-by: SJ Park --- include/linux/damon.h | 16 ++++++++++------ mm/damon/core.c | 9 ++++++++- 2 files changed, 18 insertions(+), 7 deletions(-) diff --git a/include/linux/damon.h b/include/linux/damon.h index 380f9cf6ddd82..1302ffb6f0bcb 100644 --- a/include/linux/damon.h +++ b/include/linux/damon.h @@ -394,13 +394,16 @@ struct damos_stat { * @DAMOS_FILTER_TYPE_ADDR: Address range. * @DAMOS_FILTER_TYPE_TARGET: Data Access Monitoring target. * @DAMOS_FILTER_TYPE_PROBE_HITS_WSUM: probe_hits weighted sum range. + * @DAMOS_FILTER_TYPE_AGE_MS: Region age range in milliseconds. * - * All types except &DAMOS_FILTER_TYPE_ADDR, &DAMOS_FILTER_TYPE_TARGET and - * &DAMOS_FILTER_TYPE_PROBE_HITS_WSUM are handled by the underlying &struct - * damon_operations as a part of scheme action trying, and therefore accounted - * as 'tried'. In contrast, &DAMOS_FILTER_TYPE_ADDR, &DAMOS_FILTER_TYPE_TARGET - * and &DAMOS_FILTER_TYPE_PROBE_HITS_WSUM filters are handled by the core layer - * before trying of the action, and therefore not accounted as 'tried'. + * All types except &DAMOS_FILTER_TYPE_ADDR, &DAMOS_FILTER_TYPE_TARGET, + * &DAMOS_FILTER_TYPE_PROBE_HITS_WSUM and &DAMOS_FILTER_TYPE_AGE_MS are handled + * by the underlying &struct damon_operations as a part of scheme action + * trying, and therefore accounted as 'tried'. In contrast, + * &DAMOS_FILTER_TYPE_ADDR, &DAMOS_FILTER_TYPE_TARGET, + * &DAMOS_FILTER_TYPE_PROBE_HITS_WSUM and &DAMOS_FILTER_TYPE_AGE_MS filters are + * handled by the core layer before trying of the action, and therefore not + * accounted as 'tried'. * * Support for the operations-handled filters depends on the running * &struct damon_operations. @@ -415,6 +418,7 @@ enum damos_filter_type { DAMOS_FILTER_TYPE_ADDR, DAMOS_FILTER_TYPE_TARGET, DAMOS_FILTER_TYPE_PROBE_HITS_WSUM, + DAMOS_FILTER_TYPE_AGE_MS, }; /** diff --git a/mm/damon/core.c b/mm/damon/core.c index d36823f4d0928..d631863b034db 100644 --- a/mm/damon/core.c +++ b/mm/damon/core.c @@ -659,6 +659,7 @@ bool damos_filter_for_ops(enum damos_filter_type type) case DAMOS_FILTER_TYPE_ADDR: case DAMOS_FILTER_TYPE_TARGET: case DAMOS_FILTER_TYPE_PROBE_HITS_WSUM: + case DAMOS_FILTER_TYPE_AGE_MS: return false; default: break; @@ -1336,6 +1337,7 @@ static int damos_commit_filter_arg( dst->sz_range = src->sz_range; break; case DAMOS_FILTER_TYPE_PROBE_HITS_WSUM: + case DAMOS_FILTER_TYPE_AGE_MS: if (src->range_max < src->range_min) return -EINVAL; dst->range_min = src->range_min; @@ -2552,7 +2554,7 @@ static bool damos_filter_match(struct damon_ctx *ctx, struct damon_target *t, bool matched = false; struct damon_target *ti; int target_idx = 0; - unsigned long start, end, wsum; + unsigned long start, end, wsum, age_ms; *err = 0; switch (filter->type) { @@ -2594,6 +2596,11 @@ static bool damos_filter_match(struct damon_ctx *ctx, struct damon_target *t, matched = filter->range_min <= wsum && wsum <= filter->range_max; break; + case DAMOS_FILTER_TYPE_AGE_MS: + age_ms = r->age * ctx->attrs.aggr_interval / USEC_PER_MSEC; + matched = filter->range_min <= age_ms && + age_ms <= filter->range_max; + break; default: return false; } -- 2.47.3