Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

mm/damon/sysfs: implement addr_unit file under context dir

Only DAMON kernel API callers can use addr_unit parameter. Implement a
sysfs file to let DAMON sysfs ABI users use it.

Additionally, addr_unit must be set to a non-zero value.

Link: https://lkml.kernel.org/r/20250828171242.59810-8-sj@kernel.org
Signed-off-by: SeongJae Park <sj@kernel.org>
Signed-off-by: Quanmin Yan <yanquanmin1@huawei.com>
Reviewed-by: SeongJae Park <sj@kernel.org>
Cc: David Hildenbrand <david@redhat.com>
Cc: Jonathan Corbet <corbet@lwn.net>
Cc: Kefeng Wang <wangkefeng.wang@huawei.com>
Cc: Liam Howlett <liam.howlett@oracle.com>
Cc: Lorenzo Stoakes <lorenzo.stoakes@oracle.com>
Cc: Michal Hocko <mhocko@suse.com>
Cc: Mike Rapoport <rppt@kernel.org>
Cc: Suren Baghdasaryan <surenb@google.com>
Cc: Vlastimil Babka <vbabka@suse.cz>
Cc: ze zuo <zuoze1@huawei.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>

authored by

SeongJae Park and committed by
Andrew Morton
540a2aeb 01e7ee33

+33
+33
mm/damon/sysfs.c
··· 834 834 struct damon_sysfs_context { 835 835 struct kobject kobj; 836 836 enum damon_ops_id ops_id; 837 + unsigned long addr_unit; 837 838 struct damon_sysfs_attrs *attrs; 838 839 struct damon_sysfs_targets *targets; 839 840 struct damon_sysfs_schemes *schemes; ··· 850 849 return NULL; 851 850 context->kobj = (struct kobject){}; 852 851 context->ops_id = ops_id; 852 + context->addr_unit = 1; 853 853 return context; 854 854 } 855 855 ··· 999 997 return -EINVAL; 1000 998 } 1001 999 1000 + static ssize_t addr_unit_show(struct kobject *kobj, 1001 + struct kobj_attribute *attr, char *buf) 1002 + { 1003 + struct damon_sysfs_context *context = container_of(kobj, 1004 + struct damon_sysfs_context, kobj); 1005 + 1006 + return sysfs_emit(buf, "%lu\n", context->addr_unit); 1007 + } 1008 + 1009 + static ssize_t addr_unit_store(struct kobject *kobj, 1010 + struct kobj_attribute *attr, const char *buf, size_t count) 1011 + { 1012 + struct damon_sysfs_context *context = container_of(kobj, 1013 + struct damon_sysfs_context, kobj); 1014 + unsigned long input_addr_unit; 1015 + int err = kstrtoul(buf, 0, &input_addr_unit); 1016 + 1017 + if (err) 1018 + return err; 1019 + if (!input_addr_unit) 1020 + return -EINVAL; 1021 + 1022 + context->addr_unit = input_addr_unit; 1023 + return count; 1024 + } 1025 + 1002 1026 static void damon_sysfs_context_release(struct kobject *kobj) 1003 1027 { 1004 1028 kfree(container_of(kobj, struct damon_sysfs_context, kobj)); ··· 1036 1008 static struct kobj_attribute damon_sysfs_context_operations_attr = 1037 1009 __ATTR_RW_MODE(operations, 0600); 1038 1010 1011 + static struct kobj_attribute damon_sysfs_context_addr_unit_attr = 1012 + __ATTR_RW_MODE(addr_unit, 0600); 1013 + 1039 1014 static struct attribute *damon_sysfs_context_attrs[] = { 1040 1015 &damon_sysfs_context_avail_operations_attr.attr, 1041 1016 &damon_sysfs_context_operations_attr.attr, 1017 + &damon_sysfs_context_addr_unit_attr.attr, 1042 1018 NULL, 1043 1019 }; 1044 1020 ATTRIBUTE_GROUPS(damon_sysfs_context); ··· 1429 1397 err = damon_select_ops(ctx, sys_ctx->ops_id); 1430 1398 if (err) 1431 1399 return err; 1400 + ctx->addr_unit = sys_ctx->addr_unit; 1432 1401 err = damon_sysfs_set_attrs(ctx, sys_ctx->attrs); 1433 1402 if (err) 1434 1403 return err;