From: SeongJae Park <sj@kernel.org>
Cc: SeongJae Park <sj@kernel.org>,
Andrew Morton <akpm@linux-foundation.org>,
damon@lists.linux.dev, linux-kernel@vger.kernel.org,
linux-mm@kvack.org
Subject: [RFC PATCH 07/12] mm/damon/core: implement max_nr_snapshots
Date: Sun, 23 Nov 2025 10:43:21 -0800 [thread overview]
Message-ID: <20251123184329.85287-8-sj@kernel.org> (raw)
In-Reply-To: <20251123184329.85287-1-sj@kernel.org>
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.
Signed-off-by: SeongJae Park <sj@kernel.org>
---
include/linux/damon.h | 5 +++++
mm/damon/core.c | 11 ++++++++++-
2 files changed, 15 insertions(+), 1 deletion(-)
diff --git a/include/linux/damon.h b/include/linux/damon.h
index 43dfbfe2292f..a67292a2f09d 100644
--- a/include/linux/damon.h
+++ b/include/linux/damon.h
@@ -499,6 +499,7 @@ struct damos_migrate_dests {
* @ops_filters: ops layer handling &struct damos_filter objects list.
* @last_applied: Last @action applied ops-managing entity.
* @stat: Statistics of this scheme.
+ * @max_nr_snapshots: Upper limit of nr_snapshots stat.
* @list: List head for siblings.
*
* For each @apply_interval_us, DAMON finds regions which fit in the
@@ -533,6 +534,9 @@ struct damos_migrate_dests {
* finished.
*
* After applying the &action to each region, &stat is updated.
+ *
+ * If &max_nr_snapshots is set as non-zero and &stat.nr_snapshots be same to or
+ * greater than it, the scheme is deactivated.
*/
struct damos {
struct damos_access_pattern pattern;
@@ -567,6 +571,7 @@ struct damos {
struct list_head ops_filters;
void *last_applied;
struct damos_stat stat;
+ unsigned long max_nr_snapshots;
struct list_head list;
};
diff --git a/mm/damon/core.c b/mm/damon/core.c
index af922d5e500c..36313cd1ff1c 100644
--- a/mm/damon/core.c
+++ b/mm/damon/core.c
@@ -401,6 +401,7 @@ struct damos *damon_new_scheme(struct damos_access_pattern *pattern,
INIT_LIST_HEAD(&scheme->core_filters);
INIT_LIST_HEAD(&scheme->ops_filters);
scheme->stat = (struct damos_stat){};
+ scheme->max_nr_snapshots = 0;
INIT_LIST_HEAD(&scheme->list);
scheme->quota = *(damos_quota_init(quota));
@@ -1078,7 +1079,11 @@ static int damos_commit(struct damos *dst, struct damos *src)
return err;
err = damos_commit_filters(dst, src);
- return err;
+ if (err)
+ return err;
+
+ dst->max_nr_snapshots = src->max_nr_snapshots;
+ return 0;
}
static int damon_commit_schemes(struct damon_ctx *dst, struct damon_ctx *src)
@@ -1955,6 +1960,10 @@ static void damon_do_apply_schemes(struct damon_ctx *c,
if (damos_skip_charged_region(t, &r, s, c->min_sz_region))
continue;
+ if (s->max_nr_snapshots &&
+ s->max_nr_snapshots <= s->stat.nr_snapshots)
+ continue;
+
if (damos_valid_target(c, t, r, s))
damos_apply_scheme(c, t, r, s);
--
2.47.3
next prev parent reply other threads:[~2025-11-23 18:44 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-11-23 18:43 [RFC PATCH 00/12] mm/damos/stat: introduce nr_snapshots, max_nr_snapshots and tracepoint SeongJae Park
2025-11-23 18:43 ` [RFC PATCH 01/12] mm/damon/core: introduce nr_snapshots damos stat SeongJae Park
2025-11-23 18:43 ` [RFC PATCH 02/12] mm/damon/sysfs-schemes: introduce nr_snapshots damos stat file SeongJae Park
2025-11-23 18:43 ` [RFC PATCH 03/12] Docs/mm/damon/design: update for nr_snapshots damos stat SeongJae Park
2025-11-23 18:43 ` [RFC PATCH 04/12] Docs/admin-guide/mm/damon/usage: " SeongJae Park
2025-11-23 18:43 ` [RFC PATCH 05/12] Docs/ABI/damon: " SeongJae Park
2025-11-23 18:43 ` [RFC PATCH 06/12] mm/damon: update damos kerneldoc for stat field SeongJae Park
2025-11-23 18:43 ` SeongJae Park [this message]
2025-11-23 18:43 ` [RFC PATCH 08/12] mm/damon/sysfs-schemes: implement max_nr_snapshots file SeongJae Park
2025-11-23 18:43 ` [RFC PATCH 09/12] Docs/mm/damon/design: update for max_nr_snapshots SeongJae Park
2025-11-23 18:43 ` [RFC PATCH 10/12] Docs/admin-guide/mm/damon/usage: " SeongJae Park
2025-11-23 18:43 ` [RFC PATCH 11/12] Docs/ABI/damon: " SeongJae Park
2025-11-23 18:43 ` [RFC PATCH 12/12] mm/damon/core: add trace point for damos stat per apply interval SeongJae Park
2025-11-24 15:15 ` Steven Rostedt
2025-11-24 15:37 ` SeongJae Park
2025-11-23 19:54 ` [RFC PATCH 00/12] mm/damos/stat: introduce nr_snapshots, max_nr_snapshots and tracepoint SeongJae Park
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20251123184329.85287-8-sj@kernel.org \
--to=sj@kernel.org \
--cc=akpm@linux-foundation.org \
--cc=damon@lists.linux.dev \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox