From: Mattathias Pinchover DAMOS stat sz_ops_filter_passed shows the total bytes that passed operations layer-handled DAMOS filters, accumulated from the beginning of the scheme's execution. Users who want the amount for only the latest apply interval, e.g., the size of a workload's anonymous memory that is cold as of now, need to keep the previous values in user space and compute the difference with the help of nr_snapshots. Because nr_snapshots is increased once per target per apply interval, the computation is complicated and error-prone, especially for contexts having multiple targets. Introduce a new DAMOS stat, sz_ops_filter_passed_last. It is updated at the end of each apply interval of the scheme with the amount of sz_ops_filter_passed increase in the interval. Assisted-by: Claude:claude-opus-5-5 Signed-off-by: Mattathias Pinchover Reviewed-by: SJ Park Signed-off-by: SJ Park --- include/linux/damon.h | 6 ++++++ mm/damon/core.c | 5 +++++ 2 files changed, 11 insertions(+) diff --git a/include/linux/damon.h b/include/linux/damon.h index 06bd92981af21..3aff5c525132b 100644 --- a/include/linux/damon.h +++ b/include/linux/damon.h @@ -351,6 +351,9 @@ struct damos_watermarks { * @sz_applied: Total size of regions that the scheme is applied. * @sz_ops_filter_passed: * Total bytes that passed ops layer-handled DAMOS filters. + * @sz_ops_filter_passed_last: + * Bytes that passed ops layer-handled DAMOS filters in the last + * apply interval. * @qt_exceeds: Total number of times the quota of the scheme has exceeded. * @nr_snapshots: * Total number of DAMON snapshots that the scheme is completely @@ -379,6 +382,7 @@ struct damos_stat { unsigned long nr_applied; unsigned long sz_applied; unsigned long sz_ops_filter_passed; + unsigned long sz_ops_filter_passed_last; unsigned long qt_exceeds; unsigned long nr_snapshots; }; @@ -578,6 +582,8 @@ struct damos { * @action */ unsigned long next_apply_sis; + /* @stat.sz_ops_filter_passed at the start of the current apply interval */ + unsigned long sz_ops_filter_passed_at_start; /* informs if ongoing DAMOS walk for this scheme is finished */ bool walk_completed; /* diff --git a/mm/damon/core.c b/mm/damon/core.c index 986404b547ebd..a99663f1f7ef0 100644 --- a/mm/damon/core.c +++ b/mm/damon/core.c @@ -769,6 +769,7 @@ struct damos *damon_new_scheme(struct damos_access_pattern *pattern, * or damon_attrs are updated. */ scheme->next_apply_sis = 0; + scheme->sz_ops_filter_passed_at_start = 0; scheme->walk_completed = false; INIT_LIST_HEAD(&scheme->core_filters); INIT_LIST_HEAD(&scheme->ops_filters); @@ -3532,6 +3533,10 @@ static noinline_for_stack void kdamond_apply_schemes(struct damon_ctx *c) if (time_before(c->passed_sample_intervals, s->next_apply_sis)) continue; damos_walk_complete(c, s); + s->stat.sz_ops_filter_passed_last = + s->stat.sz_ops_filter_passed - + s->sz_ops_filter_passed_at_start; + s->sz_ops_filter_passed_at_start = s->stat.sz_ops_filter_passed; damos_set_next_apply_sis(s, c); s->last_applied = NULL; damos_trace_stat(c, s); -- 2.47.3