This patch extends the DAMON sysfs interface to support the configuration of target priorities, enabling users to assign and adjust the relative importance of monitored processes at runtime. Signed-off-by: Enze Li --- mm/damon/sysfs.c | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/mm/damon/sysfs.c b/mm/damon/sysfs.c index e2bd2d7becdd..224d9e89d967 100644 --- a/mm/damon/sysfs.c +++ b/mm/damon/sysfs.c @@ -213,6 +213,9 @@ struct damon_sysfs_target { struct damon_sysfs_regions *regions; int pid; bool obsolete; +#ifdef CONFIG_DAMON_AUTO_TUNING + int priority; +#endif }; static struct damon_sysfs_target *damon_sysfs_target_alloc(void) @@ -298,9 +301,44 @@ static struct kobj_attribute damon_sysfs_target_pid_attr = static struct kobj_attribute damon_sysfs_target_obsolete_attr = __ATTR_RW_MODE(obsolete_target, 0600); +#ifdef CONFIG_DAMON_AUTO_TUNING +static ssize_t target_priority_show(struct kobject *kobj, + struct kobj_attribute *attr, char *buf) +{ + struct damon_sysfs_target *target = container_of(kobj, + struct damon_sysfs_target, kobj); + + return sysfs_emit(buf, "%d\n", target->priority); +} + +static ssize_t target_priority_store(struct kobject *kobj, + struct kobj_attribute *attr, const char *buf, size_t count) +{ + int err, value; + struct damon_sysfs_target *target = container_of(kobj, + struct damon_sysfs_target, kobj); + err = kstrtoint(buf, 0, &value); + if (err) + return -EINVAL; + + if (value > 0 && value <= 100) + target->priority = value; + else + return -EINVAL; + + return count; +} + +static struct kobj_attribute damon_sysfs_target_priority = + __ATTR_RW_MODE(target_priority, 0600); +#endif + static struct attribute *damon_sysfs_target_attrs[] = { &damon_sysfs_target_pid_attr.attr, &damon_sysfs_target_obsolete_attr.attr, +#ifdef CONFIG_DAMON_AUTO_TUNING + &damon_sysfs_target_priority.attr, +#endif NULL, }; ATTRIBUTE_GROUPS(damon_sysfs_target); @@ -1406,6 +1444,9 @@ static int damon_sysfs_add_target(struct damon_sysfs_target *sys_target, return -EINVAL; } t->obsolete = sys_target->obsolete; +#ifdef CONFIG_DAMON_AUTO_TUNING + t->priority = sys_target->priority; +#endif return damon_sysfs_set_regions(t, sys_target->regions, ctx->min_sz_region); } -- 2.43.0