linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: SeongJae Park <sj@kernel.org>
To: Andrew Morton <akpm@linux-foundation.org>
Cc: SeongJae Park <sj@kernel.org>,
	damon@lists.linux.dev, linux-mm@kvack.org,
	linux-kernel@vger.kernel.org
Subject: [PATCH 14/20] mm/damon/sysfs-schemes: support PSI-based quota auto-tune
Date: Mon, 19 Feb 2024 11:44:25 -0800	[thread overview]
Message-ID: <20240219194431.159606-15-sj@kernel.org> (raw)
In-Reply-To: <20240219194431.159606-1-sj@kernel.org>

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'.

Signed-off-by: SeongJae Park <sj@kernel.org>
---
 mm/damon/sysfs-schemes.c | 42 ++++++++++++++++++++++++++++++++++++++--
 1 file changed, 40 insertions(+), 2 deletions(-)

diff --git a/mm/damon/sysfs-schemes.c b/mm/damon/sysfs-schemes.c
index 7a8a39f2679b..53a90ac678fb 100644
--- a/mm/damon/sysfs-schemes.c
+++ b/mm/damon/sysfs-schemes.c
@@ -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;
-- 
2.39.2



  parent reply	other threads:[~2024-02-19 19:45 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-02-19 19:44 [PATCH 00/20] mm/damon: let DAMOS feeds and tame/auto-tune itself SeongJae Park
2024-02-19 19:44 ` [PATCH 01/20] mm/damon/core: Set damos_quota->esz as public field and document SeongJae Park
2024-02-19 19:44 ` [PATCH 02/20] mm/damon/sysfs-schemes: implement quota effective_bytes file SeongJae Park
2024-02-19 19:44 ` [PATCH 03/20] mm/damon/sysfs: implement a kdamond command for updating schemes' effective quotas SeongJae Park
2024-02-19 19:44 ` [PATCH 04/20] Docs/ABI/damon: document effective_bytes sysfs file SeongJae Park
2024-02-19 19:44 ` [PATCH 05/20] Docs/admin-guide/mm/damon/usage: document effective_bytes file SeongJae Park
2024-02-19 19:44 ` [PATCH 06/20] mm/damon: move comments and fields for damos-quota-prioritization to the end SeongJae Park
2024-02-19 19:44 ` [PATCH 07/20] mm/damon/core: split out quota goal related fields to a struct SeongJae Park
2024-02-19 19:44 ` [PATCH 08/20] mm/damon/core: add multiple goals per damos_quota and helpers for those SeongJae Park
2024-02-19 19:44 ` [PATCH 09/20] mm/damon/sysfs: use only quota->goals SeongJae Park
2024-02-19 19:44 ` [PATCH 10/20] mm/damon/core: remove ->goal field of damos_quota SeongJae Park
2024-02-19 19:44 ` [PATCH 11/20] mm/damon/core: let goal specified with only target and current values SeongJae Park
2024-02-19 19:44 ` [PATCH 12/20] mm/damon/core: support multiple metrics for quota goal SeongJae Park
2024-02-19 19:44 ` [PATCH 13/20] mm/damon/core: implement PSI metric DAMOS " SeongJae Park
2024-02-19 19:44 ` SeongJae Park [this message]
2024-02-19 19:44 ` [PATCH 15/20] Docs/mm/damon/design: document quota goal self-tuning SeongJae Park
2024-02-19 19:44 ` [PATCH 16/20] Docs/ABI/damon: document quota goal metric file SeongJae Park
2024-02-19 19:44 ` [PATCH 17/20] Docs/admin-guide/mm/damon/usage: " SeongJae Park
2024-02-19 19:44 ` [PATCH 18/20] mm/damon/reclaim: implement user-feedback driven quota auto-tuning SeongJae Park
2024-02-19 19:44 ` [PATCH 19/20] mm/damon/reclaim: implement memory PSI-driven quota self-tuning SeongJae Park
2024-02-19 19:44 ` [PATCH 20/20] Docs/admin-guide/mm/damon/reclaim: document auto-tuning parameters SeongJae Park

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20240219194431.159606-15-sj@kernel.org \
    --to=sj@kernel.org \
    --cc=akpm@linux-foundation.org \
    --cc=damon@lists.linux.dev \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox