Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

mm/damon/core: implement max_nr_snapshots

There are DAMOS use cases that require user-space centric control of its
activation and deactivation. Having the control plane on the user-space,
or using DAMOS as a way for monitoring results collection are such
examples.

DAMON parameters online commit, DAMOS quotas and watermarks can be useful
for this purpose. However, those features work only at the
sub-DAMON-snapshot level. In some use cases, the DAMON-snapshot level
control is required. For example, in DAMOS-based monitoring results
collection use case, the user online-installs a DAMOS scheme with
DAMOS_STAT action, wait it be applied to whole regions of a single
DAMON-snapshot, retrieves the stats and tried regions information, and
online-uninstall the scheme. It is efficient to ensure the lifetime of
the scheme as no more no less one snapshot consumption.

To support such use cases, introduce a new DAMOS core API per-scheme
parameter, namely max_nr_snapshots. As the name implies, it is the upper
limit of nr_snapshots, which is a DAMOS stat that represents the number of
DAMON-snapshots that the scheme has fully applied. If the limit is set
with a non-zero value and nr_snapshots reaches or exceeds the limit, the
scheme is deactivated.

Link: https://lkml.kernel.org/r/20251216080128.42991-8-sj@kernel.org
Signed-off-by: SeongJae Park <sj@kernel.org>
Cc: Jonathan Corbet <corbet@lwn.net>
Cc: Liam Howlett <liam.howlett@oracle.com>
Cc: Lorenzo Stoakes <lorenzo.stoakes@oracle.com>
Cc: "Masami Hiramatsu (Google)" <mhiramat@kernel.org>
Cc: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
Cc: Michal Hocko <mhocko@suse.com>
Cc: Mike Rapoport <rppt@kernel.org>
Cc: Steven Rostedt <rostedt@goodmis.org>
Cc: Suren Baghdasaryan <surenb@google.com>
Cc: Vlastimil Babka <vbabka@suse.cz>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>

authored by

SeongJae Park and committed by
Andrew Morton
84e425c6 ccaa2d06

+15 -1
+5
include/linux/damon.h
··· 499 499 * @ops_filters: ops layer handling &struct damos_filter objects list. 500 500 * @last_applied: Last @action applied ops-managing entity. 501 501 * @stat: Statistics of this scheme. 502 + * @max_nr_snapshots: Upper limit of nr_snapshots stat. 502 503 * @list: List head for siblings. 503 504 * 504 505 * For each @apply_interval_us, DAMON finds regions which fit in the ··· 534 533 * finished. 535 534 * 536 535 * After applying the &action to each region, &stat is updated. 536 + * 537 + * If &max_nr_snapshots is set as non-zero and &stat.nr_snapshots be same to or 538 + * greater than it, the scheme is deactivated. 537 539 */ 538 540 struct damos { 539 541 struct damos_access_pattern pattern; ··· 571 567 struct list_head ops_filters; 572 568 void *last_applied; 573 569 struct damos_stat stat; 570 + unsigned long max_nr_snapshots; 574 571 struct list_head list; 575 572 }; 576 573
+10 -1
mm/damon/core.c
··· 401 401 INIT_LIST_HEAD(&scheme->core_filters); 402 402 INIT_LIST_HEAD(&scheme->ops_filters); 403 403 scheme->stat = (struct damos_stat){}; 404 + scheme->max_nr_snapshots = 0; 404 405 INIT_LIST_HEAD(&scheme->list); 405 406 406 407 scheme->quota = *(damos_quota_init(quota)); ··· 1079 1078 return err; 1080 1079 1081 1080 err = damos_commit_filters(dst, src); 1082 - return err; 1081 + if (err) 1082 + return err; 1083 + 1084 + dst->max_nr_snapshots = src->max_nr_snapshots; 1085 + return 0; 1083 1086 } 1084 1087 1085 1088 static int damon_commit_schemes(struct damon_ctx *dst, struct damon_ctx *src) ··· 1987 1982 continue; 1988 1983 1989 1984 if (damos_skip_charged_region(t, &r, s, c->min_sz_region)) 1985 + continue; 1986 + 1987 + if (s->max_nr_snapshots && 1988 + s->max_nr_snapshots <= s->stat.nr_snapshots) 1990 1989 continue; 1991 1990 1992 1991 if (damos_valid_target(c, t, r, s))