mm/damon/sysfs: implement intervals tuning goal directory
Implement DAMON sysfs interface directory and its files for setting DAMON sampling and aggregation intervals auto-tuning goal. Link: https://lkml.kernel.org/r/20250303221726.484227-4-sj@kernel.org Signed-off-by: SeongJae Park <sj@kernel.org> Cc: Jonathan Corbet <corbet@lwn.net> Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
This commit is contained in:
committed by
Andrew Morton
parent
f04b0fedbe
commit
8fbbcbeaaf
189
mm/damon/sysfs.c
189
mm/damon/sysfs.c
@@ -408,6 +408,164 @@ static const struct kobj_type damon_sysfs_targets_ktype = {
|
||||
.default_groups = damon_sysfs_targets_groups,
|
||||
};
|
||||
|
||||
/*
|
||||
* intervals goal directory
|
||||
*/
|
||||
|
||||
struct damon_sysfs_intervals_goal {
|
||||
struct kobject kobj;
|
||||
unsigned long access_bp;
|
||||
unsigned long aggrs;
|
||||
unsigned long min_sample_us;
|
||||
unsigned long max_sample_us;
|
||||
};
|
||||
|
||||
static struct damon_sysfs_intervals_goal *damon_sysfs_intervals_goal_alloc(
|
||||
unsigned long access_bp, unsigned long aggrs,
|
||||
unsigned long min_sample_us, unsigned long max_sample_us)
|
||||
{
|
||||
struct damon_sysfs_intervals_goal *goal = kmalloc(sizeof(*goal),
|
||||
GFP_KERNEL);
|
||||
|
||||
if (!goal)
|
||||
return NULL;
|
||||
|
||||
goal->kobj = (struct kobject){};
|
||||
goal->access_bp = access_bp;
|
||||
goal->aggrs = aggrs;
|
||||
goal->min_sample_us = min_sample_us;
|
||||
goal->max_sample_us = max_sample_us;
|
||||
return goal;
|
||||
}
|
||||
|
||||
static ssize_t access_bp_show(struct kobject *kobj,
|
||||
struct kobj_attribute *attr, char *buf)
|
||||
{
|
||||
struct damon_sysfs_intervals_goal *goal = container_of(kobj,
|
||||
struct damon_sysfs_intervals_goal, kobj);
|
||||
|
||||
return sysfs_emit(buf, "%lu\n", goal->access_bp);
|
||||
}
|
||||
|
||||
static ssize_t access_bp_store(struct kobject *kobj,
|
||||
struct kobj_attribute *attr, const char *buf, size_t count)
|
||||
{
|
||||
struct damon_sysfs_intervals_goal *goal = container_of(kobj,
|
||||
struct damon_sysfs_intervals_goal, kobj);
|
||||
unsigned long nr;
|
||||
int err = kstrtoul(buf, 0, &nr);
|
||||
|
||||
if (err)
|
||||
return err;
|
||||
|
||||
goal->access_bp = nr;
|
||||
return count;
|
||||
}
|
||||
|
||||
static ssize_t aggrs_show(struct kobject *kobj,
|
||||
struct kobj_attribute *attr, char *buf)
|
||||
{
|
||||
struct damon_sysfs_intervals_goal *goal = container_of(kobj,
|
||||
struct damon_sysfs_intervals_goal, kobj);
|
||||
|
||||
return sysfs_emit(buf, "%lu\n", goal->aggrs);
|
||||
}
|
||||
|
||||
static ssize_t aggrs_store(struct kobject *kobj,
|
||||
struct kobj_attribute *attr, const char *buf, size_t count)
|
||||
{
|
||||
struct damon_sysfs_intervals_goal *goal = container_of(kobj,
|
||||
struct damon_sysfs_intervals_goal, kobj);
|
||||
unsigned long nr;
|
||||
int err = kstrtoul(buf, 0, &nr);
|
||||
|
||||
if (err)
|
||||
return err;
|
||||
|
||||
goal->aggrs = nr;
|
||||
return count;
|
||||
}
|
||||
|
||||
static ssize_t min_sample_us_show(struct kobject *kobj,
|
||||
struct kobj_attribute *attr, char *buf)
|
||||
{
|
||||
struct damon_sysfs_intervals_goal *goal = container_of(kobj,
|
||||
struct damon_sysfs_intervals_goal, kobj);
|
||||
|
||||
return sysfs_emit(buf, "%lu\n", goal->min_sample_us);
|
||||
}
|
||||
|
||||
static ssize_t min_sample_us_store(struct kobject *kobj,
|
||||
struct kobj_attribute *attr, const char *buf, size_t count)
|
||||
{
|
||||
struct damon_sysfs_intervals_goal *goal = container_of(kobj,
|
||||
struct damon_sysfs_intervals_goal, kobj);
|
||||
unsigned long nr;
|
||||
int err = kstrtoul(buf, 0, &nr);
|
||||
|
||||
if (err)
|
||||
return err;
|
||||
|
||||
goal->min_sample_us = nr;
|
||||
return count;
|
||||
}
|
||||
|
||||
static ssize_t max_sample_us_show(struct kobject *kobj,
|
||||
struct kobj_attribute *attr, char *buf)
|
||||
{
|
||||
struct damon_sysfs_intervals_goal *goal = container_of(kobj,
|
||||
struct damon_sysfs_intervals_goal, kobj);
|
||||
|
||||
return sysfs_emit(buf, "%lu\n", goal->max_sample_us);
|
||||
}
|
||||
|
||||
static ssize_t max_sample_us_store(struct kobject *kobj,
|
||||
struct kobj_attribute *attr, const char *buf, size_t count)
|
||||
{
|
||||
struct damon_sysfs_intervals_goal *goal = container_of(kobj,
|
||||
struct damon_sysfs_intervals_goal, kobj);
|
||||
unsigned long nr;
|
||||
int err = kstrtoul(buf, 0, &nr);
|
||||
|
||||
if (err)
|
||||
return err;
|
||||
|
||||
goal->max_sample_us = nr;
|
||||
return count;
|
||||
}
|
||||
|
||||
static void damon_sysfs_intervals_goal_release(struct kobject *kobj)
|
||||
{
|
||||
kfree(container_of(kobj, struct damon_sysfs_intervals_goal, kobj));
|
||||
}
|
||||
|
||||
static struct kobj_attribute damon_sysfs_intervals_goal_access_bp_attr =
|
||||
__ATTR_RW_MODE(access_bp, 0600);
|
||||
|
||||
static struct kobj_attribute damon_sysfs_intervals_goal_aggrs_attr =
|
||||
__ATTR_RW_MODE(aggrs, 0600);
|
||||
|
||||
static struct kobj_attribute damon_sysfs_intervals_goal_min_sample_us_attr =
|
||||
__ATTR_RW_MODE(min_sample_us, 0600);
|
||||
|
||||
static struct kobj_attribute damon_sysfs_intervals_goal_max_sample_us_attr =
|
||||
__ATTR_RW_MODE(max_sample_us, 0600);
|
||||
|
||||
static struct attribute *damon_sysfs_intervals_goal_attrs[] = {
|
||||
&damon_sysfs_intervals_goal_access_bp_attr.attr,
|
||||
&damon_sysfs_intervals_goal_aggrs_attr.attr,
|
||||
&damon_sysfs_intervals_goal_min_sample_us_attr.attr,
|
||||
&damon_sysfs_intervals_goal_max_sample_us_attr.attr,
|
||||
NULL,
|
||||
};
|
||||
ATTRIBUTE_GROUPS(damon_sysfs_intervals_goal);
|
||||
|
||||
static const struct kobj_type damon_sysfs_intervals_goal_ktype = {
|
||||
.release = damon_sysfs_intervals_goal_release,
|
||||
.sysfs_ops = &kobj_sysfs_ops,
|
||||
.default_groups = damon_sysfs_intervals_goal_groups,
|
||||
};
|
||||
|
||||
/*
|
||||
* intervals directory
|
||||
*/
|
||||
@@ -417,6 +575,7 @@ struct damon_sysfs_intervals {
|
||||
unsigned long sample_us;
|
||||
unsigned long aggr_us;
|
||||
unsigned long update_us;
|
||||
struct damon_sysfs_intervals_goal *intervals_goal;
|
||||
};
|
||||
|
||||
static struct damon_sysfs_intervals *damon_sysfs_intervals_alloc(
|
||||
@@ -436,6 +595,32 @@ static struct damon_sysfs_intervals *damon_sysfs_intervals_alloc(
|
||||
return intervals;
|
||||
}
|
||||
|
||||
static int damon_sysfs_intervals_add_dirs(struct damon_sysfs_intervals *intervals)
|
||||
{
|
||||
struct damon_sysfs_intervals_goal *goal;
|
||||
int err;
|
||||
|
||||
goal = damon_sysfs_intervals_goal_alloc(0, 0, 0, 0);
|
||||
if (!goal)
|
||||
return -ENOMEM;
|
||||
|
||||
err = kobject_init_and_add(&goal->kobj,
|
||||
&damon_sysfs_intervals_goal_ktype, &intervals->kobj,
|
||||
"intervals_goal");
|
||||
if (err) {
|
||||
kobject_put(&goal->kobj);
|
||||
intervals->intervals_goal = NULL;
|
||||
return err;
|
||||
}
|
||||
intervals->intervals_goal = goal;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void damon_sysfs_intervals_rm_dirs(struct damon_sysfs_intervals *intervals)
|
||||
{
|
||||
kobject_put(&intervals->intervals_goal->kobj);
|
||||
}
|
||||
|
||||
static ssize_t sample_us_show(struct kobject *kobj,
|
||||
struct kobj_attribute *attr, char *buf)
|
||||
{
|
||||
@@ -569,6 +754,9 @@ static int damon_sysfs_attrs_add_dirs(struct damon_sysfs_attrs *attrs)
|
||||
err = kobject_init_and_add(&intervals->kobj,
|
||||
&damon_sysfs_intervals_ktype, &attrs->kobj,
|
||||
"intervals");
|
||||
if (err)
|
||||
goto put_intervals_out;
|
||||
err = damon_sysfs_intervals_add_dirs(intervals);
|
||||
if (err)
|
||||
goto put_intervals_out;
|
||||
attrs->intervals = intervals;
|
||||
@@ -599,6 +787,7 @@ put_intervals_out:
|
||||
static void damon_sysfs_attrs_rm_dirs(struct damon_sysfs_attrs *attrs)
|
||||
{
|
||||
kobject_put(&attrs->nr_regions_range->kobj);
|
||||
damon_sysfs_intervals_rm_dirs(attrs->intervals);
|
||||
kobject_put(&attrs->intervals->kobj);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user