From 2430a8d5172c257158091368b81e27fdce535475 Mon Sep 17 00:00:00 2001 From: SJ Park Date: Fri, 10 Jul 2026 06:46:45 -0700 Subject: [PATCH] mm/damon/sysfs: implement probe/weight file Implement a new sysfs file, 'weight', under probe directory. Users will be able to set the probe weight and enable the attributes only monitoring using it. Link: https://lore.kernel.org/20260710134651.18084-17-sj@kernel.org Signed-off-by: SJ Park Cc: David Hildenbrand Cc: Jonathan Corbet Cc: Liam R. Howlett Cc: Lorenzo Stoakes Cc: Michal Hocko Cc: Mike Rapoport Cc: Suren Baghdasaryan Cc: Vlastimil Babka Signed-off-by: Andrew Morton --- mm/damon/sysfs.c | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/mm/damon/sysfs.c b/mm/damon/sysfs.c index 6d7e36c9e509..b5fe036f7801 100644 --- a/mm/damon/sysfs.c +++ b/mm/damon/sysfs.c @@ -1065,6 +1065,7 @@ static const struct kobj_type damon_sysfs_filters_ktype = { struct damon_sysfs_probe { struct kobject kobj; + unsigned int weight; struct damon_sysfs_filters *filters; }; @@ -1100,12 +1101,35 @@ static void damon_sysfs_probe_rm_dirs(struct damon_sysfs_probe *probe) } } +static ssize_t weight_show(struct kobject *kobj, struct kobj_attribute *attr, + char *buf) +{ + struct damon_sysfs_probe *probe = container_of(kobj, + struct damon_sysfs_probe, kobj); + + return sysfs_emit(buf, "%u\n", probe->weight); +} + +static ssize_t weight_store(struct kobject *kobj, + struct kobj_attribute *attr, const char *buf, size_t count) +{ + struct damon_sysfs_probe *probe = container_of(kobj, + struct damon_sysfs_probe, kobj); + int err = kstrtouint(buf, 0, &probe->weight); + + return err ? err : count; +} + static void damon_sysfs_probe_release(struct kobject *kobj) { kfree(container_of(kobj, struct damon_sysfs_probe, kobj)); } +static struct kobj_attribute damon_sysfs_probe_weight_attr = + __ATTR_RW_MODE(weight, 0600); + static struct attribute *damon_sysfs_probe_attrs[] = { + &damon_sysfs_probe_weight_attr.attr, NULL, }; ATTRIBUTE_GROUPS(damon_sysfs_probe); @@ -1965,6 +1989,7 @@ static int damon_sysfs_set_probes(struct damon_ctx *ctx, return -ENOMEM; damon_add_probe(ctx, p); sys_probe = sys_probes->probes_arr[i]; + p->weight = sys_probe->weight; err = damon_sysfs_set_probe(p, sys_probe); if (err) return err;