mm/damon/sysfs-schemes: support PSI-based quota auto-tune

Extend DAMON sysfs interface to support the PSI-based quota auto-tuning by
adding a new file, 'target_metric' under the quota goal directory.  Old
users don't get any behavioral changes since the default value of the
metric is 'user input'.

Link: https://lkml.kernel.org/r/20240219194431.159606-15-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:
SeongJae Park 2024-02-19 11:44:25 -08:00 committed by Andrew Morton
parent 2dbb60f789
commit 4daacfe8f9

View File

@ -826,15 +826,48 @@ static const struct kobj_type damon_sysfs_watermarks_ktype = {
struct damos_sysfs_quota_goal {
struct kobject kobj;
enum damos_quota_goal_metric metric;
unsigned long target_value;
unsigned long current_value;
};
/* This should match with enum damos_action */
static const char * const damos_sysfs_quota_goal_metric_strs[] = {
"user_input",
"some_mem_psi_us",
};
static struct damos_sysfs_quota_goal *damos_sysfs_quota_goal_alloc(void)
{
return kzalloc(sizeof(struct damos_sysfs_quota_goal), GFP_KERNEL);
}
static ssize_t target_metric_show(struct kobject *kobj,
struct kobj_attribute *attr, char *buf)
{
struct damos_sysfs_quota_goal *goal = container_of(kobj,
struct damos_sysfs_quota_goal, kobj);
return sysfs_emit(buf, "%s\n",
damos_sysfs_quota_goal_metric_strs[goal->metric]);
}
static ssize_t target_metric_store(struct kobject *kobj,
struct kobj_attribute *attr, const char *buf, size_t count)
{
struct damos_sysfs_quota_goal *goal = container_of(kobj,
struct damos_sysfs_quota_goal, kobj);
enum damos_quota_goal_metric m;
for (m = 0; m < NR_DAMOS_QUOTA_GOAL_METRICS; m++) {
if (sysfs_streq(buf, damos_sysfs_quota_goal_metric_strs[m])) {
goal->metric = m;
return count;
}
}
return -EINVAL;
}
static ssize_t target_value_show(struct kobject *kobj,
struct kobj_attribute *attr, char *buf)
{
@ -880,6 +913,9 @@ static void damos_sysfs_quota_goal_release(struct kobject *kobj)
kfree(container_of(kobj, struct damos_sysfs_quota_goal, kobj));
}
static struct kobj_attribute damos_sysfs_quota_goal_target_metric_attr =
__ATTR_RW_MODE(target_metric, 0600);
static struct kobj_attribute damos_sysfs_quota_goal_target_value_attr =
__ATTR_RW_MODE(target_value, 0600);
@ -887,6 +923,7 @@ static struct kobj_attribute damos_sysfs_quota_goal_current_value_attr =
__ATTR_RW_MODE(current_value, 0600);
static struct attribute *damos_sysfs_quota_goal_attrs[] = {
&damos_sysfs_quota_goal_target_metric_attr.attr,
&damos_sysfs_quota_goal_target_value_attr.attr,
&damos_sysfs_quota_goal_current_value_attr.attr,
NULL,
@ -1899,11 +1936,12 @@ static int damos_sysfs_set_quota_score(
if (!sysfs_goal->target_value)
continue;
goal = damos_new_quota_goal(DAMOS_QUOTA_USER_INPUT,
goal = damos_new_quota_goal(sysfs_goal->metric,
sysfs_goal->target_value);
if (!goal)
return -ENOMEM;
goal->current_value = sysfs_goal->current_value;
if (sysfs_goal->metric == DAMOS_QUOTA_USER_INPUT)
goal->current_value = sysfs_goal->current_value;
damos_add_quota_goal(quota, goal);
}
return 0;