From patchwork Mon Feb 19 19:44:18 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: SeongJae Park X-Patchwork-Id: 13563008 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 48F75C54764 for ; Mon, 19 Feb 2024 19:44:54 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 2CA4C6B0088; Mon, 19 Feb 2024 14:44:46 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 119466B0089; Mon, 19 Feb 2024 14:44:46 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id F211A6B008A; Mon, 19 Feb 2024 14:44:45 -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 E0D886B0088 for ; Mon, 19 Feb 2024 14:44:45 -0500 (EST) Received: from smtpin30.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id BB8C7A03DE for ; Mon, 19 Feb 2024 19:44:45 +0000 (UTC) X-FDA: 81809580930.30.3A1CF29 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by imf12.hostedemail.com (Postfix) with ESMTP id 29D5240011 for ; Mon, 19 Feb 2024 19:44:43 +0000 (UTC) Authentication-Results: imf12.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=gphxwb2u; spf=pass (imf12.hostedemail.com: domain of sj@kernel.org designates 139.178.84.217 as permitted sender) smtp.mailfrom=sj@kernel.org; dmarc=pass (policy=none) header.from=kernel.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1708371884; 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=lV3L6p79knSzLtiMqkJs5JForDRjkSbvrgJLfK73hi4=; b=506Ems5P6lsSBZDRSA6bocdJYMPpPUsmxEIsspU669vOSjgabS2JJ+dXd7NV7QPe1Y24CO zrIHgLvp4JmfJmiLTr+/Vlx2DkL/GMZX6Fprd7tc7vp5UaXKSQy8bo/UATGi2Us6mjScPr PyJzKK17r4pon4JEXJAJMUJT+bj5M1s= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1708371884; a=rsa-sha256; cv=none; b=U+Riradl1i+6lud1QG+dKzlI+0tZQg2sZoccKbBgwPoo0ZkXokIypxtqdUs/fYVq5v1OM3 O2Fc3AA6/lYTTo41qbXenBjzZa7CVpD8cIKix9ptClIgSgBD70cV+OYwmCg2cqADZIiz30 1wGFfRdSnLNIjXSm8Pkrn5QF9xmzgdI= ARC-Authentication-Results: i=1; imf12.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=gphxwb2u; spf=pass (imf12.hostedemail.com: domain of sj@kernel.org designates 139.178.84.217 as permitted sender) smtp.mailfrom=sj@kernel.org; dmarc=pass (policy=none) header.from=kernel.org Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by dfw.source.kernel.org (Postfix) with ESMTP id 4661360F95; Mon, 19 Feb 2024 19:44:43 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id B00EEC433C7; Mon, 19 Feb 2024 19:44:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1708371883; bh=BGP026mJwlW/eKHVIUjB0WBT8A8x06Px6FbED6keS6Q=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=gphxwb2udN9PVME6d5bTuNTiFXFuKfFFZHlFeju9dUGTOajLOpZfQKlxikbafpC1b eEvBQusALO514a+hnWtLbkRylZihVkHFaBU73bpN1uOTk2yJ5wuad9zjPoiAlWKwwy aHvHZpGgauHziCU2VPTn+9bCIlwJdfOkNXogRBWYlf6amibtzPfFnZ7ivWjohRhnve GG2RB+HJfAVJ8Jzg9La/euCL2mC734M7jNPrgJZtX0nn5kfRomW0rMKXBDk1kIVpsg CkiuMvITGMdr0Nd0JkiiOu1GdmKPOcVLa3tWSascMIF5SlZZ/qjx7qOq8ilDWpkQrn ySNK1Fyi883oQ== From: SeongJae Park To: Andrew Morton Cc: SeongJae Park , damon@lists.linux.dev, linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: [PATCH 07/20] mm/damon/core: split out quota goal related fields to a struct Date: Mon, 19 Feb 2024 11:44:18 -0800 Message-Id: <20240219194431.159606-8-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-Stat-Signature: aq4kd8rf4he6g7h3aj5urijg6ub6sss5 X-Rspamd-Server: rspam10 X-Rspamd-Queue-Id: 29D5240011 X-Rspam-User: X-HE-Tag: 1708371883-738098 X-HE-Meta: U2FsdGVkX19FJLUAZR/1tkxnt3dD7JJ5NIH/gJhNOZrkkCSOcnSAfnBBkBgWp2n//lmhVI3l0A5fnNQXy/tK529gQcNnfzNMkLEAVTY5XXKUZHY5Go0JvQsN6kkfhZM5t3OiHRtuCp/9Ym8l2eWxUOWYOOPnKpMnRI3hrLXgXiogCm+m5oGnQVd6Z3fzMM+PJtrj5nR40RUecFqMNsz8GEz4rUMezF5n5Gsw40SMO45kAYv9hQ1jStI4R3+LWPSblWTnfKgSIZlWlOW7nsY2Il2prBPbrg23d4Ux5yPubChmsRDdtaR8z6xz9ICzsNFH3aPqr7DmTUFoPzPinfPRfBlXWSnmHMjwQ9F3Qy0qZB4zN7Kd9ieVCUQNMvkTKGx81MFuo8T012IfojMk2DsTCYJKVPYWgcDmiyBpoBni1k45X+lGB3Be8H8J3ng3CnfkSfPvAlVwAK8OD1Hj5SH3q7NE0Ml+ZfNNarTCMdNSy0NXycQjnD/azZu3hsxUCHgq5eRXMjCKjyPXYP0lNt7IgYosfvG40IHFyFefC+ZMqQgpETsxO1TuVCL/OmWVr7rc51s17HVnsqeI79g/HQSnZ4Kr3NLz85jxk9AzcjOLU7dOlCVHGZNcML3BlIjrmpa7BmGdpsYO/8DcS/eCaPohXlGaJOm6VSCwpbNKkOWNIlJgf0WfXx3o/geDKgIJ/DlvtZ0KBfPN80RbB36if3jHm3bnWS2AUjghX7jhVHTxKg3QLEb22tMt2xjuZZY3vxmlYuJTmVEoz3RaboFEuVRQsRLoFL6TIum6MOA30okT2bQuCJvZb7prbodbn4BReDFN7cEvGzRcFlyv/OjABchoYxQLwh3KH/lCmcDaAEkV/mkZAVitbo04tGrncsg6yDGctLhMajGvBCeLdeYSN75Hnq5sIEK8xUtNLBJr+stJthUIAKPeQ0dqLkKY9xkAlfPdADO4s1YO3xjouLSTNIS cMtyVpwQ OLTpSU6EZ62ePfK+40zr8kYEMLAcd8qBH0wuy2rnZuvMr5+u4FT8YxB4O3bd+/cgHCPshMXIiaAtT8rorMmWTk7cKaQMUwEMHmu1HpAkLM/jzjeK8Mz9fllhZrd1ylL5pdnkHeKUjJq0+cAdG4junyOYje0HkD6CATfPxWtBihm+pYu6237yzfJXcub9pc5WegAdSJK70CU3CmFkZ5zaORmqdFA81PZlg+gPXpRdJ5Z6vYps= 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: 'struct damos_quota' is not small now. Split out fields for quota goal to a separate struct for easier reading. Signed-off-by: SeongJae Park --- include/linux/damon.h | 36 ++++++++++++++++++++++-------------- mm/damon/core.c | 13 +++++++------ mm/damon/sysfs-schemes.c | 10 +++++----- 3 files changed, 34 insertions(+), 25 deletions(-) diff --git a/include/linux/damon.h b/include/linux/damon.h index bd17b14828bc..2fe345adf6b2 100644 --- a/include/linux/damon.h +++ b/include/linux/damon.h @@ -126,13 +126,28 @@ enum damos_action { NR_DAMOS_ACTIONS, }; +/** + * struct damos_quota_goal - DAMOS scheme quota auto-tuning goal. + * @get_score: Function for getting current score of the goal. + * @get_score_arg: Parameter for @get_score + * + * Data structure for getting the current score of the quota tuning goal. + * Calling @get_score with @get_score_arg as the parameter should return the + * current score. Then the score is entered to DAMON's internal feedback loop + * mechanism to get the auto-tuned quota. The goal of the tuning is getting + * the feedback score value of 10,000. + */ +struct damos_quota_goal { + unsigned long (*get_score)(void *arg); + void *get_score_arg; +}; + /** * struct damos_quota - Controls the aggressiveness of the given scheme. * @reset_interval: Charge reset interval in milliseconds. * @ms: Maximum milliseconds that the scheme can use. * @sz: Maximum bytes of memory that the action can be applied. - * @get_score: Feedback function for self-tuning quota. - * @get_score_arg: Parameter for @get_score + * @goal: Quota auto-tuning goal. * @esz: Effective size quota in bytes. * * @weight_sz: Weight of the region's size for prioritization. @@ -151,16 +166,10 @@ enum damos_action { * throughput of the scheme's action. DAMON then compares it against &sz and * uses smaller one as the effective quota. * - * If @get_score function pointer is set, DAMON calls it back with - * @get_score_arg and get the return value of it for every @reset_interval. - * Then, DAMON adjusts the effective quota using the return value as a feedback - * score to the current quota, using its internal feedback loop algorithm. - * - * The feedback loop algorithem assumes the quota input and the feedback score - * output are in a positive proportional relationship, and the goal of the - * tuning is getting the feedback screo value of 10,000. If @ms and/or @sz are - * set together, those work as a hard limit quota. If neither @ms nor @sz are - * set, the mechanism starts from the quota of one byte. + * If ->get_score field of @goal is set, DAMON calculates yet another size + * quota based on the goal using its internal feedback loop algorithm, for + * every @reset_interval. Then, if the new size quota is smaller than the + * effective quota, it uses the new size quota as the effective quota. * * The resulting effective size quota in bytes is set to @esz. * @@ -174,8 +183,7 @@ struct damos_quota { unsigned long reset_interval; unsigned long ms; unsigned long sz; - unsigned long (*get_score)(void *arg); - void *get_score_arg; + struct damos_quota_goal goal; unsigned long esz; unsigned int weight_sz; diff --git a/mm/damon/core.c b/mm/damon/core.c index 0656966a6fc4..fe4209672121 100644 --- a/mm/damon/core.c +++ b/mm/damon/core.c @@ -1083,21 +1083,22 @@ static unsigned long damon_feed_loop_next_input(unsigned long last_input, return min_input; } -/* Shouldn't be called if quota->ms, quota->sz, and quota->get_score unset */ +/* Called only if quota->ms, quota->sz, or quota->goal.get_score are set */ static void damos_set_effective_quota(struct damos_quota *quota) { unsigned long throughput; unsigned long esz; - if (!quota->ms && !quota->get_score) { + if (!quota->ms && !quota->goal.get_score) { quota->esz = quota->sz; return; } - if (quota->get_score) { + if (quota->goal.get_score) { quota->esz_bp = damon_feed_loop_next_input( max(quota->esz_bp, 10000UL), - quota->get_score(quota->get_score_arg)); + quota->goal.get_score( + quota->goal.get_score_arg)); esz = quota->esz_bp / 10000; } @@ -1107,7 +1108,7 @@ static void damos_set_effective_quota(struct damos_quota *quota) quota->total_charged_ns; else throughput = PAGE_SIZE * 1024; - if (quota->get_score) + if (quota->goal.get_score) esz = min(throughput * quota->ms, esz); else esz = throughput * quota->ms; @@ -1127,7 +1128,7 @@ static void damos_adjust_quota(struct damon_ctx *c, struct damos *s) unsigned long cumulated_sz; unsigned int score, max_score = 0; - if (!quota->ms && !quota->sz && !quota->get_score) + if (!quota->ms && !quota->sz && !quota->goal.get_score) return; /* New charge window starts */ diff --git a/mm/damon/sysfs-schemes.c b/mm/damon/sysfs-schemes.c index 9d90e7b757b7..85ef58f98a87 100644 --- a/mm/damon/sysfs-schemes.c +++ b/mm/damon/sysfs-schemes.c @@ -1894,19 +1894,19 @@ static void damos_sysfs_set_quota_score( struct damos_sysfs_quota_goal *sysfs_goal; int i; - quota->get_score = NULL; - quota->get_score_arg = (void *)0; + quota->goal.get_score = NULL; + quota->goal.get_score_arg = (void *)0; for (i = 0; i < sysfs_goals->nr; i++) { sysfs_goal = sysfs_goals->goals_arr[i]; if (!sysfs_goal->target_value) continue; /* Higher score makes scheme less aggressive */ - quota->get_score_arg = (void *)max( - (unsigned long)quota->get_score_arg, + quota->goal.get_score_arg = (void *)max( + (unsigned long)quota->goal.get_score_arg, sysfs_goal->current_value * 10000 / sysfs_goal->target_value); - quota->get_score = damos_sysfs_get_quota_score; + quota->goal.get_score = damos_sysfs_get_quota_score; } }