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. A new sysfs file, priority, is added under each target’s directory (e.g., /sys/kernel/mm/damon/admin/kdamonds/0/contexts//targets//priority). Users can write an integer value to this file to set the priority level for the corresponding target. Reading the file returns the currently assigned priority. The interface integrates seamlessly with the existing priority-based scheduling mechanism introduced in the core DAMON logic. When a priority value is set via sysfs, it directly influences the frequency of scheme applications for the target. This enhancement provides user-space administrators and adaptive system controllers with the ability to dynamically adjust monitoring and memory management priorities based on real-time workload requirements. The change maintains full backward compatibility -- targets without a configured priority use the default behavior, ensuring no disruption to existing deployments. Signed-off-by: Enze Li --- mm/damon/sysfs.c | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/mm/damon/sysfs.c b/mm/damon/sysfs.c index 6d2b0dab50cb..cd08732f3b6d 100644 --- a/mm/damon/sysfs.c +++ b/mm/damon/sysfs.c @@ -212,6 +212,7 @@ struct damon_sysfs_target { struct kobject kobj; struct damon_sysfs_regions *regions; int pid; + int priority; }; static struct damon_sysfs_target *damon_sysfs_target_alloc(void) @@ -271,8 +272,33 @@ static void damon_sysfs_target_release(struct kobject *kobj) static struct kobj_attribute damon_sysfs_target_pid_attr = __ATTR_RW_MODE(pid_target, 0600); +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) +{ + struct damon_sysfs_target *target = container_of(kobj, + struct damon_sysfs_target, kobj); + int err = kstrtoint(buf, 0, &target->priority); + + if (err) + return -EINVAL; + return count; +} + +static struct kobj_attribute damon_sysfs_target_priority = + __ATTR_RW_MODE(target_priority, 0600); + static struct attribute *damon_sysfs_target_attrs[] = { &damon_sysfs_target_pid_attr.attr, + &damon_sysfs_target_priority.attr, NULL, }; ATTRIBUTE_GROUPS(damon_sysfs_target); @@ -1340,6 +1366,8 @@ static int damon_sysfs_add_target(struct damon_sysfs_target *sys_target, /* caller will destroy targets */ return -EINVAL; } + t->priority = sys_target->priority; + return damon_sysfs_set_regions(t, sys_target->regions); } -- 2.51.0