[PATCH 08/12] mm/damon/sysfs-schemes: implement max_nr_snapshots file

SeongJae Park
2025-12-16T08:01:56Z

Add a new DAMON sysfs file for setting and getting the newly introduced
per-DAMON-snapshot level DAMOS deactivation control parameter,
max_nr_snapshots. The file has a name same to the parameter and placed
under the damos stat directory.

Signed-off-by: SeongJae Park <sj@kernel.org>
---
mm/damon/sysfs-schemes.c | 28 ++++++++++++++++++++++++++++
1 file changed, 28 insertions(+)

diff --git a/mm/damon/sysfs-schemes.c b/mm/damon/sysfs-schemes.c
index a1f555e1125a..e198234f0763 100644
--- a/mm/damon/sysfs-schemes.c
+++ b/mm/damon/sysfs-schemes.c
@@ -205,6 +205,7 @@ struct damon_sysfs_stats {
unsigned long sz_ops_filter_passed;
unsigned long qt_exceeds;
unsigned long nr_snapshots;
+ unsigned long max_nr_snapshots;
};

static struct damon_sysfs_stats *damon_sysfs_stats_alloc(void)
@@ -275,6 +276,28 @@ static ssize_t nr_snapshots_show(struct kobject *kobj,
return sysfs_emit(buf, "%lu\n", stats->nr_snapshots);
}

+static ssize_t max_nr_snapshots_show(struct kobject *kobj,
+ struct kobj_attribute *attr, char *buf)
+{
+ struct damon_sysfs_stats *stats = container_of(kobj,
+ struct damon_sysfs_stats, kobj);
+
+ return sysfs_emit(buf, "%lu\n", stats->max_nr_snapshots);
+}
+
+static ssize_t max_nr_snapshots_store(struct kobject *kobj,
+ struct kobj_attribute *attr, const char *buf, size_t count)
+{
+ struct damon_sysfs_stats *stats = container_of(kobj,
+ struct damon_sysfs_stats, kobj);
+ unsigned long max_nr_snapshots, err = kstrtoul(buf, 0, &max_nr_snapshots);
+
+ if (err)
+ return err;
+ stats->max_nr_snapshots = max_nr_snapshots;
+ return count;
+}
+
static void damon_sysfs_stats_release(struct kobject *kobj)
{
kfree(container_of(kobj, struct damon_sysfs_stats, kobj));
@@ -301,6 +324,9 @@ static struct kobj_attribute damon_sysfs_stats_qt_exceeds_attr =
static struct kobj_attribute damon_sysfs_stats_nr_snapshots_attr =
__ATTR_RO_MODE(nr_snapshots, 0400);

+static struct kobj_attribute damon_sysfs_stats_max_nr_snapshots_attr =
+ __ATTR_RW_MODE(max_nr_snapshots, 0600);
+
static struct attribute *damon_sysfs_stats_attrs[] = {
&damon_sysfs_stats_nr_tried_attr.attr,
&damon_sysfs_stats_sz_tried_attr.attr,
@@ -309,6 +335,7 @@ static struct attribute *damon_sysfs_stats_attrs[] = {
&damon_sysfs_stats_sz_ops_filter_passed_attr.attr,
&damon_sysfs_stats_qt_exceeds_attr.attr,
&damon_sysfs_stats_nr_snapshots_attr.attr,
+ &damon_sysfs_stats_max_nr_snapshots_attr.attr,
NULL,
};
ATTRIBUTE_GROUPS(damon_sysfs_stats);
@@ -2730,6 +2757,7 @@ static struct damos *damon_sysfs_mk_scheme(
damon_destroy_scheme(scheme);
return NULL;
}
+ scheme->max_nr_snapshots = sysfs_scheme->stats->max_nr_snapshots;
return scheme;
}

--
2.47.3