Commit ac35264b authored by SeongJae Park's avatar SeongJae Park Committed by Andrew Morton

mm/damon/sysfs-schemes: implement filters directory

DAMOS filters are currently supported by only DAMON kernel API.  To expose
the feature to user space, implement a DAMON sysfs directory named
'filters' under each scheme directory.  Please note that this is
implementing only the directory.  Following commits will implement more
files and directories, and finally connect the DAMOS filters feature.

Link: https://lkml.kernel.org/r/20221205230830.144349-6-sj@kernel.orgSigned-off-by: default avatarSeongJae Park <sj@kernel.org>
Cc: Jonathan Corbet <corbet@lwn.net>
Cc: Shuah Khan <shuah@kernel.org>
Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
parent d56fe242
...@@ -258,6 +258,63 @@ static struct kobj_type damon_sysfs_stats_ktype = { ...@@ -258,6 +258,63 @@ static struct kobj_type damon_sysfs_stats_ktype = {
.default_groups = damon_sysfs_stats_groups, .default_groups = damon_sysfs_stats_groups,
}; };
/*
* filters directory
*/
struct damon_sysfs_scheme_filters {
struct kobject kobj;
int nr;
};
static struct damon_sysfs_scheme_filters *
damon_sysfs_scheme_filters_alloc(void)
{
return kzalloc(sizeof(struct damon_sysfs_scheme_filters), GFP_KERNEL);
}
static ssize_t nr_filters_show(struct kobject *kobj,
struct kobj_attribute *attr, char *buf)
{
struct damon_sysfs_scheme_filters *filters = container_of(kobj,
struct damon_sysfs_scheme_filters, kobj);
return sysfs_emit(buf, "%d\n", filters->nr);
}
static ssize_t nr_filters_store(struct kobject *kobj,
struct kobj_attribute *attr, const char *buf, size_t count)
{
int nr, err = kstrtoint(buf, 0, &nr);
if (err)
return err;
if (nr < 0)
return -EINVAL;
return count;
}
static void damon_sysfs_scheme_filters_release(struct kobject *kobj)
{
kfree(container_of(kobj, struct damon_sysfs_scheme_filters, kobj));
}
static struct kobj_attribute damon_sysfs_scheme_filters_nr_attr =
__ATTR_RW_MODE(nr_filters, 0600);
static struct attribute *damon_sysfs_scheme_filters_attrs[] = {
&damon_sysfs_scheme_filters_nr_attr.attr,
NULL,
};
ATTRIBUTE_GROUPS(damon_sysfs_scheme_filters);
static struct kobj_type damon_sysfs_scheme_filters_ktype = {
.release = damon_sysfs_scheme_filters_release,
.sysfs_ops = &kobj_sysfs_ops,
.default_groups = damon_sysfs_scheme_filters_groups,
};
/* /*
* watermarks directory * watermarks directory
*/ */
...@@ -784,6 +841,7 @@ struct damon_sysfs_scheme { ...@@ -784,6 +841,7 @@ struct damon_sysfs_scheme {
struct damon_sysfs_access_pattern *access_pattern; struct damon_sysfs_access_pattern *access_pattern;
struct damon_sysfs_quotas *quotas; struct damon_sysfs_quotas *quotas;
struct damon_sysfs_watermarks *watermarks; struct damon_sysfs_watermarks *watermarks;
struct damon_sysfs_scheme_filters *filters;
struct damon_sysfs_stats *stats; struct damon_sysfs_stats *stats;
struct damon_sysfs_scheme_regions *tried_regions; struct damon_sysfs_scheme_regions *tried_regions;
}; };
...@@ -878,6 +936,24 @@ static int damon_sysfs_scheme_set_watermarks(struct damon_sysfs_scheme *scheme) ...@@ -878,6 +936,24 @@ static int damon_sysfs_scheme_set_watermarks(struct damon_sysfs_scheme *scheme)
return err; return err;
} }
static int damon_sysfs_scheme_set_filters(struct damon_sysfs_scheme *scheme)
{
struct damon_sysfs_scheme_filters *filters =
damon_sysfs_scheme_filters_alloc();
int err;
if (!filters)
return -ENOMEM;
err = kobject_init_and_add(&filters->kobj,
&damon_sysfs_scheme_filters_ktype, &scheme->kobj,
"filters");
if (err)
kobject_put(&filters->kobj);
else
scheme->filters = filters;
return err;
}
static int damon_sysfs_scheme_set_stats(struct damon_sysfs_scheme *scheme) static int damon_sysfs_scheme_set_stats(struct damon_sysfs_scheme *scheme)
{ {
struct damon_sysfs_stats *stats = damon_sysfs_stats_alloc(); struct damon_sysfs_stats *stats = damon_sysfs_stats_alloc();
...@@ -926,9 +1002,12 @@ static int damon_sysfs_scheme_add_dirs(struct damon_sysfs_scheme *scheme) ...@@ -926,9 +1002,12 @@ static int damon_sysfs_scheme_add_dirs(struct damon_sysfs_scheme *scheme)
err = damon_sysfs_scheme_set_watermarks(scheme); err = damon_sysfs_scheme_set_watermarks(scheme);
if (err) if (err)
goto put_quotas_access_pattern_out; goto put_quotas_access_pattern_out;
err = damon_sysfs_scheme_set_stats(scheme); err = damon_sysfs_scheme_set_filters(scheme);
if (err) if (err)
goto put_watermarks_quotas_access_pattern_out; goto put_watermarks_quotas_access_pattern_out;
err = damon_sysfs_scheme_set_stats(scheme);
if (err)
goto put_filters_watermarks_quotas_access_pattern_out;
err = damon_sysfs_scheme_set_tried_regions(scheme); err = damon_sysfs_scheme_set_tried_regions(scheme);
if (err) if (err)
goto put_tried_regions_out; goto put_tried_regions_out;
...@@ -937,6 +1016,9 @@ static int damon_sysfs_scheme_add_dirs(struct damon_sysfs_scheme *scheme) ...@@ -937,6 +1016,9 @@ static int damon_sysfs_scheme_add_dirs(struct damon_sysfs_scheme *scheme)
put_tried_regions_out: put_tried_regions_out:
kobject_put(&scheme->tried_regions->kobj); kobject_put(&scheme->tried_regions->kobj);
scheme->tried_regions = NULL; scheme->tried_regions = NULL;
put_filters_watermarks_quotas_access_pattern_out:
kobject_put(&scheme->filters->kobj);
scheme->filters = NULL;
put_watermarks_quotas_access_pattern_out: put_watermarks_quotas_access_pattern_out:
kobject_put(&scheme->watermarks->kobj); kobject_put(&scheme->watermarks->kobj);
scheme->watermarks = NULL; scheme->watermarks = NULL;
...@@ -956,6 +1038,7 @@ static void damon_sysfs_scheme_rm_dirs(struct damon_sysfs_scheme *scheme) ...@@ -956,6 +1038,7 @@ static void damon_sysfs_scheme_rm_dirs(struct damon_sysfs_scheme *scheme)
damon_sysfs_quotas_rm_dirs(scheme->quotas); damon_sysfs_quotas_rm_dirs(scheme->quotas);
kobject_put(&scheme->quotas->kobj); kobject_put(&scheme->quotas->kobj);
kobject_put(&scheme->watermarks->kobj); kobject_put(&scheme->watermarks->kobj);
kobject_put(&scheme->filters->kobj);
kobject_put(&scheme->stats->kobj); kobject_put(&scheme->stats->kobj);
damon_sysfs_scheme_regions_rm_dirs(scheme->tried_regions); damon_sysfs_scheme_regions_rm_dirs(scheme->tried_regions);
kobject_put(&scheme->tried_regions->kobj); kobject_put(&scheme->tried_regions->kobj);
......
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