mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
synced 2026-05-08 00:29:36 -04:00
mm/damon/sysfs-schemes: decouple from damos_filter_type
Decouple DAMOS sysfs interface from damos_filter_type. For this, define and use new sysfs-schemes internal data structure that maps the user-space keywords and damos_filter_type, instead of having the implicit and unflexible array index rule. Link: https://lkml.kernel.org/r/20250622213759.50930-5-sj@kernel.org Signed-off-by: SeongJae Park <sj@kernel.org> Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
This commit is contained in:
committed by
Andrew Morton
parent
041f54604f
commit
a39346daec
@@ -341,16 +341,45 @@ static struct damon_sysfs_scheme_filter *damon_sysfs_scheme_filter_alloc(
|
||||
return filter;
|
||||
}
|
||||
|
||||
/* Should match with enum damos_filter_type */
|
||||
static const char * const damon_sysfs_scheme_filter_type_strs[] = {
|
||||
"anon",
|
||||
"active",
|
||||
"memcg",
|
||||
"young",
|
||||
"hugepage_size",
|
||||
"unmapped",
|
||||
"addr",
|
||||
"target",
|
||||
struct damos_sysfs_filter_type_name {
|
||||
enum damos_filter_type type;
|
||||
char *name;
|
||||
};
|
||||
|
||||
static const struct damos_sysfs_filter_type_name
|
||||
damos_sysfs_filter_type_names[] = {
|
||||
{
|
||||
.type = DAMOS_FILTER_TYPE_ANON,
|
||||
.name = "anon",
|
||||
},
|
||||
{
|
||||
.type = DAMOS_FILTER_TYPE_ACTIVE,
|
||||
.name = "active",
|
||||
},
|
||||
{
|
||||
.type = DAMOS_FILTER_TYPE_MEMCG,
|
||||
.name = "memcg",
|
||||
},
|
||||
{
|
||||
.type = DAMOS_FILTER_TYPE_YOUNG,
|
||||
.name = "young",
|
||||
},
|
||||
{
|
||||
.type = DAMOS_FILTER_TYPE_HUGEPAGE_SIZE,
|
||||
.name = "hugepage_size",
|
||||
},
|
||||
{
|
||||
.type = DAMOS_FILTER_TYPE_UNMAPPED,
|
||||
.name = "unmapped",
|
||||
},
|
||||
{
|
||||
.type = DAMOS_FILTER_TYPE_ADDR,
|
||||
.name = "addr",
|
||||
},
|
||||
{
|
||||
.type = DAMOS_FILTER_TYPE_TARGET,
|
||||
.name = "target",
|
||||
},
|
||||
};
|
||||
|
||||
static ssize_t type_show(struct kobject *kobj,
|
||||
@@ -358,9 +387,16 @@ static ssize_t type_show(struct kobject *kobj,
|
||||
{
|
||||
struct damon_sysfs_scheme_filter *filter = container_of(kobj,
|
||||
struct damon_sysfs_scheme_filter, kobj);
|
||||
int i;
|
||||
|
||||
return sysfs_emit(buf, "%s\n",
|
||||
damon_sysfs_scheme_filter_type_strs[filter->type]);
|
||||
for (i = 0; i < ARRAY_SIZE(damos_sysfs_filter_type_names); i++) {
|
||||
const struct damos_sysfs_filter_type_name *type_name;
|
||||
|
||||
type_name = &damos_sysfs_filter_type_names[i];
|
||||
if (type_name->type == filter->type)
|
||||
return sysfs_emit(buf, "%s\n", type_name->name);
|
||||
}
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
static bool damos_sysfs_scheme_filter_valid_type(
|
||||
@@ -385,16 +421,19 @@ static ssize_t type_store(struct kobject *kobj,
|
||||
{
|
||||
struct damon_sysfs_scheme_filter *filter = container_of(kobj,
|
||||
struct damon_sysfs_scheme_filter, kobj);
|
||||
enum damos_filter_type type;
|
||||
ssize_t ret = -EINVAL;
|
||||
int i;
|
||||
|
||||
for (type = 0; type < NR_DAMOS_FILTER_TYPES; type++) {
|
||||
if (sysfs_streq(buf, damon_sysfs_scheme_filter_type_strs[
|
||||
type])) {
|
||||
for (i = 0; i < ARRAY_SIZE(damos_sysfs_filter_type_names); i++) {
|
||||
const struct damos_sysfs_filter_type_name *type_name;
|
||||
|
||||
type_name = &damos_sysfs_filter_type_names[i];
|
||||
if (sysfs_streq(buf, type_name->name)) {
|
||||
if (!damos_sysfs_scheme_filter_valid_type(
|
||||
filter->handle_layer, type))
|
||||
filter->handle_layer,
|
||||
type_name->type))
|
||||
break;
|
||||
filter->type = type;
|
||||
filter->type = type_name->type;
|
||||
ret = count;
|
||||
break;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user