Commit 9f6e47ab authored by SeongJae Park's avatar SeongJae Park Committed by Andrew Morton

mm/damon/sysfs-schemes: support target damos filter

Extend DAMON sysfs interface to support the DAMON monitoring target based
DAMOS filter.  Users can use it via writing 'target' to the filter's
'type' file and specifying the index of the target from the corresponding
DAMON context's monitoring targets list to 'target_idx' sysfs file.

Link: https://lkml.kernel.org/r/20230802214312.110532-10-sj@kernel.orgSigned-off-by: default avatarSeongJae Park <sj@kernel.org>
Cc: Brendan Higgins <brendanhiggins@google.com>
Cc: Jonathan Corbet <corbet@lwn.net>
Cc: Shuah Khan <shuah@kernel.org>
Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
parent 17e7c724
...@@ -283,6 +283,7 @@ struct damon_sysfs_scheme_filter { ...@@ -283,6 +283,7 @@ struct damon_sysfs_scheme_filter {
bool matching; bool matching;
char *memcg_path; char *memcg_path;
struct damon_addr_range addr_range; struct damon_addr_range addr_range;
int target_idx;
}; };
static struct damon_sysfs_scheme_filter *damon_sysfs_scheme_filter_alloc(void) static struct damon_sysfs_scheme_filter *damon_sysfs_scheme_filter_alloc(void)
...@@ -295,6 +296,7 @@ static const char * const damon_sysfs_scheme_filter_type_strs[] = { ...@@ -295,6 +296,7 @@ static const char * const damon_sysfs_scheme_filter_type_strs[] = {
"anon", "anon",
"memcg", "memcg",
"addr", "addr",
"target",
}; };
static ssize_t type_show(struct kobject *kobj, static ssize_t type_show(struct kobject *kobj,
...@@ -413,6 +415,25 @@ static ssize_t addr_end_store(struct kobject *kobj, ...@@ -413,6 +415,25 @@ static ssize_t addr_end_store(struct kobject *kobj,
return err ? err : count; return err ? err : count;
} }
static ssize_t damon_target_idx_show(struct kobject *kobj,
struct kobj_attribute *attr, char *buf)
{
struct damon_sysfs_scheme_filter *filter = container_of(kobj,
struct damon_sysfs_scheme_filter, kobj);
return sysfs_emit(buf, "%d\n", filter->target_idx);
}
static ssize_t damon_target_idx_store(struct kobject *kobj,
struct kobj_attribute *attr, const char *buf, size_t count)
{
struct damon_sysfs_scheme_filter *filter = container_of(kobj,
struct damon_sysfs_scheme_filter, kobj);
int err = kstrtoint(buf, 0, &filter->target_idx);
return err ? err : count;
}
static void damon_sysfs_scheme_filter_release(struct kobject *kobj) static void damon_sysfs_scheme_filter_release(struct kobject *kobj)
{ {
struct damon_sysfs_scheme_filter *filter = container_of(kobj, struct damon_sysfs_scheme_filter *filter = container_of(kobj,
...@@ -437,12 +458,16 @@ static struct kobj_attribute damon_sysfs_scheme_filter_addr_start_attr = ...@@ -437,12 +458,16 @@ static struct kobj_attribute damon_sysfs_scheme_filter_addr_start_attr =
static struct kobj_attribute damon_sysfs_scheme_filter_addr_end_attr = static struct kobj_attribute damon_sysfs_scheme_filter_addr_end_attr =
__ATTR_RW_MODE(addr_end, 0600); __ATTR_RW_MODE(addr_end, 0600);
static struct kobj_attribute damon_sysfs_scheme_filter_damon_target_idx_attr =
__ATTR_RW_MODE(damon_target_idx, 0600);
static struct attribute *damon_sysfs_scheme_filter_attrs[] = { static struct attribute *damon_sysfs_scheme_filter_attrs[] = {
&damon_sysfs_scheme_filter_type_attr.attr, &damon_sysfs_scheme_filter_type_attr.attr,
&damon_sysfs_scheme_filter_matching_attr.attr, &damon_sysfs_scheme_filter_matching_attr.attr,
&damon_sysfs_scheme_filter_memcg_path_attr.attr, &damon_sysfs_scheme_filter_memcg_path_attr.attr,
&damon_sysfs_scheme_filter_addr_start_attr.attr, &damon_sysfs_scheme_filter_addr_start_attr.attr,
&damon_sysfs_scheme_filter_addr_end_attr.attr, &damon_sysfs_scheme_filter_addr_end_attr.attr,
&damon_sysfs_scheme_filter_damon_target_idx_attr.attr,
NULL, NULL,
}; };
ATTRIBUTE_GROUPS(damon_sysfs_scheme_filter); ATTRIBUTE_GROUPS(damon_sysfs_scheme_filter);
...@@ -1539,6 +1564,8 @@ static int damon_sysfs_set_scheme_filters(struct damos *scheme, ...@@ -1539,6 +1564,8 @@ static int damon_sysfs_set_scheme_filters(struct damos *scheme,
return -EINVAL; return -EINVAL;
} }
filter->addr_range = sysfs_filter->addr_range; filter->addr_range = sysfs_filter->addr_range;
} else if (filter->type == DAMOS_FILTER_TYPE_TARGET) {
filter->target_idx = sysfs_filter->target_idx;
} }
damos_add_filter(scheme, filter); damos_add_filter(scheme, filter);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment