From patchwork Mon Feb 19 19:44:25 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: SeongJae Park X-Patchwork-Id: 13563016 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 9D85BC48BF8 for ; Mon, 19 Feb 2024 19:45:17 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 9B4086B0096; Mon, 19 Feb 2024 14:44:49 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 92DC96B0099; Mon, 19 Feb 2024 14:44:49 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 7A89C6B009A; Mon, 19 Feb 2024 14:44:49 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id 65F3D6B0096 for ; Mon, 19 Feb 2024 14:44:49 -0500 (EST) Received: from smtpin02.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id 40CEF12047E for ; Mon, 19 Feb 2024 19:44:49 +0000 (UTC) X-FDA: 81809581098.02.B47B846 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by imf25.hostedemail.com (Postfix) with ESMTP id AF75FA0018 for ; Mon, 19 Feb 2024 19:44:47 +0000 (UTC) Authentication-Results: imf25.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=KOTw5DPt; dmarc=pass (policy=none) header.from=kernel.org; spf=pass (imf25.hostedemail.com: domain of sj@kernel.org designates 139.178.84.217 as permitted sender) smtp.mailfrom=sj@kernel.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1708371887; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=h6jlea1Ny+YARehAvjsycPDwPQ3WBJoq0Zz+xFE6jbg=; b=ecwaLlf+GFb+WiN74qydURBmNAjJDr0oZdANvtd2P+Enj/BM3Yw6+y154FZmiDzcukttuX yKSsp0kC+bfTy1WABmK2DoNe/O8UKg0/CZkcDugwSDHUZcXxprJWJiMeiQ96jT25mXTeeG g7ZeS/lpujVgJsWIFG/Sh2xvxYB1fSc= ARC-Authentication-Results: i=1; imf25.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=KOTw5DPt; dmarc=pass (policy=none) header.from=kernel.org; spf=pass (imf25.hostedemail.com: domain of sj@kernel.org designates 139.178.84.217 as permitted sender) smtp.mailfrom=sj@kernel.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1708371887; a=rsa-sha256; cv=none; b=GB0DnAIoLvJ3woygzoRX/xYzDDYVc+J7iI6pFciUfsK3c54PAL0E4T1LVD8Dr4jYNrF+mP S1ZB+4khS/oM3DyPeUg97OPVIdKHNm1MPT9TTVxzegp/IbCJmS7imO/JcxSL0S+jW1/Zxa qh+A4AX+QQjBLvRsXx5gY7K7J4p6RaE= Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by dfw.source.kernel.org (Postfix) with ESMTP id 6D71A60F6E; Mon, 19 Feb 2024 19:44:47 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id B3ADEC43394; Mon, 19 Feb 2024 19:44:46 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1708371887; bh=CUFUQFRYuN+1nr4LagyWWgpSfoijjUeoeRxWSSISzx0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=KOTw5DPtqz7EDT+Ul/z9K5LjGneHPwrOsY/SajlL5Bl2oLIl1awpnenXU//722LAQ 8JExaw7jR+vC9TyifyBA/ng8sJ87t7b37ykCu8xFWt24f0okGZcQbo2GFB8QAWcRXb hysuM2OlpQhwbWAQEH9GUDz/8v1fcgJ51HkbcvsA7C47wkJcaqIZutS2Nu9WPxI0Kj aI43L5ZT+zyPVvcx6ufR2x75e3X0TwFz52dWy9kjcozyTPg7XCbl7QazgclVpk6rRu MQL0doHMyussoB9I/RFG9LiYx5NoGiggqQ3nc542MghmJl7kUZ2K90wbKZqTjJpRHa zSlnawmoY8v3Q== From: SeongJae Park To: Andrew Morton Cc: SeongJae Park , 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 Message-Id: <20240219194431.159606-15-sj@kernel.org> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240219194431.159606-1-sj@kernel.org> References: <20240219194431.159606-1-sj@kernel.org> MIME-Version: 1.0 X-Rspamd-Queue-Id: AF75FA0018 X-Rspam-User: X-Rspamd-Server: rspam05 X-Stat-Signature: 3w9x69ubibmmehcwqjtcsga7chg68sgx X-HE-Tag: 1708371887-477968 X-HE-Meta: U2FsdGVkX19NWpYMV9kbkdRSE6yfQe4SDJ6W5xLaHGUvgGSHlWnJxmi9FKP9c1yvBNTodqe291amXSc1/obvIm9bYBl/7vVr2ixxLnU2ACPE+R3UfDXVl2ZLoOi93J4dgdACxoAYJF21DzNYXg0Wm0/0xPQEQKj+B32fqt/6mFzJxpalwXr0lHtpUNTSsKumsCsyhNW/vq4GNAIvhlsjzMtRG0nrV5tqgSWeE46Pfq3sS7rG8cfaAiKzCDuqBbFiG+r57TfUV2cGMSNe0ZmO9AUXGC7vLdEKxT/qb2Z+/FWTNtUv4iS6EtjHSSegghJshbOMhfmEsEGdBGbKxjZCwiLmgsYaSVH9nwgkL1OqV0xuvGVIFny1YhJALluOQttRax6u60B4d13Xgm5XPY+eJVL/Uf9ccZGsssYDcmAmW92sZz1i0jsHKeAuA4SoX1M7jr6pr2uMp4iKaK2Abvx2h13tg0W7dmH7pjML/87sj1nCbeB41Y8UzFZ+ifZLa12HWP1FD/TyZ2HxD/HjkJe/jy15xxNVE8oglDcoIIwcjP9BdDnqBWQOSmAf2D3YhST4sxJ0gQ6X8mjRnUFCp9J4o4Ze5kKgtlctvFityyWNaE56TxTheBiKIZdjiNMZu+A+aA6EYmNf4HRYZxD5pGc7pOdzS1diATcyB/YrKv4rXHi/6NblA6ZVR5wxowqWC8WoFhoLpkcR1CSRt04lnlAnye1JjO17FCqpSD0eGz3aQ9TfC1XRyEuwiNALlPf4L5zA1c2lJHzCrjk9IuWV1thk+05/EmteJWWm10nWbdE5/aQBCjeODeZQVQyzg4ZDMyjZ+A4czQwVUTjtb2igUwFxEdIk9E9U1zzAcaoWgz8mk2LKqNARsxDvgsSp1raHA3w2qXTzDi68Z7P3P9Ltqny0NwO6xWasypLP6O2yf3jsbqLcMVMU/3loZw== X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: 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 --- 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;