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 <sj@kernel.org>
Cc: David Hildenbrand <david@kernel.org>
Cc: Jonathan Corbet <corbet@lwn.net>
Cc: Liam R. Howlett <liam@infradead.org>
Cc: Lorenzo Stoakes <ljs@kernel.org>
Cc: Michal Hocko <mhocko@suse.com>
Cc: Mike Rapoport <rppt@kernel.org>
Cc: Suren Baghdasaryan <surenb@google.com>
Cc: Vlastimil Babka <vbabka@kernel.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
This commit is contained in:
SJ Park 2026-07-10 06:46:45 -07:00 committed by Andrew Morton
parent 8d5e0ebac9
commit 2430a8d517

View File

@ -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;