From patchwork Mon Feb 19 19:44:24 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: SeongJae Park X-Patchwork-Id: 13563015 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 09CE2C48BF8 for ; Mon, 19 Feb 2024 19:45:15 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 1685D6B0095; Mon, 19 Feb 2024 14:44:49 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 0F3E36B0099; 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 EAD0A6B0096; Mon, 19 Feb 2024 14:44:48 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id D7A016B0092 for ; Mon, 19 Feb 2024 14:44:48 -0500 (EST) Received: from smtpin06.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id A9A27120383 for ; Mon, 19 Feb 2024 19:44:48 +0000 (UTC) X-FDA: 81809581056.06.5D67386 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by imf06.hostedemail.com (Postfix) with ESMTP id 014DB180025 for ; Mon, 19 Feb 2024 19:44:46 +0000 (UTC) Authentication-Results: imf06.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=TdWxaHKc; dmarc=pass (policy=none) header.from=kernel.org; spf=pass (imf06.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=2IPFCHuVQYIU935uM08rqgUJZWzciquZX/wAtiLCpQc=; b=X0IAs+ozPUZAYTpovZqFSa2hKeuOFAlVCy1RS77NTzVh3Ln+2MNYw2P3L7Dw8y8FbeJ5/c eRy2Txax3+9C7wgiN3CpqvlyN0JP7S/12e8a+hLXTjwDLBoeAueBPPhcIWe4JzcgQOv2Xn wASVRz+AF3+wcA6oLxGna2WGrITKT7o= ARC-Authentication-Results: i=1; imf06.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=TdWxaHKc; dmarc=pass (policy=none) header.from=kernel.org; spf=pass (imf06.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=PPHMXwR4jxUo6+frCjAgZhPk0PDFK7yV2RcgdsI0RTdWGlo+h4M/7uzBte7zGk3waeWFZL gNdlslUJwRhvooyH0y7cshSeqa8bIU4mxcs9VfAwDmoBYlqe06yRMHIKcoFAtg1dwoUd93 thWYJiWMt/j3DAUZpptviw3fm5JNiOY= Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by dfw.source.kernel.org (Postfix) with ESMTP id AE8B460F56; Mon, 19 Feb 2024 19:44:46 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 29130C43142; 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=1708371886; bh=+x9YEwq0wFUN061d3yOJa9HVAX8E/VoU7wyTTkm6mIw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=TdWxaHKcnSEnWZqTNxUepviJgGCPR1bk6d5g+2L1cVg1/eGNxrn5SkWPrUnaK7JQO Vuk7vnYM1Uyb590YgKH6608jYA3nygvM6QZFCbklC41SZDPa1t+ounHmjZEt3oMH0y PMS26IDxgZF5792MlVW3661l3tMRtrU640g13+hslj96jsyC9AraLApqoZ7CKh1ys4 0xGiJfqM41TDv+KREnlPoh8PTfFBxKLQAQloBLwOAfGKGKjqF+CTHBjvGiORIcX8pW eSn7zriouYN9nH/T2G4lv45dJoL7vY0B0Sa6QCi1HrGxLw4YzYVogR6lVo0QFWSQJf MwsQeCfDxr3iQ== From: SeongJae Park To: Andrew Morton Cc: SeongJae Park , damon@lists.linux.dev, linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: [PATCH 13/20] mm/damon/core: implement PSI metric DAMOS quota goal Date: Mon, 19 Feb 2024 11:44:24 -0800 Message-Id: <20240219194431.159606-14-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: 014DB180025 X-Rspam-User: X-Rspamd-Server: rspam05 X-Stat-Signature: sa9s9cdz7ip49psbf51gxe93ck9hpgy3 X-HE-Tag: 1708371886-960409 X-HE-Meta: U2FsdGVkX1+XAw3RYZ/6v9Q90+owpMmKcXc7MOSzaW7wxFYGzGf8xBQxaXiM36heb3/bMJZpSw6rsoSsXtYmJEhGThSrSrJLYdbIKZkNEGennIgCid4qzxRPi/DZYsREOi6pz1Oa1sPPu9/5AazFznZNm4W2Vnv7mk237/qkos0KUq5nyo973VY1WZzFErgcSg+QzlIxI+I3tC9jcKxu2bjLQQafkaPG61R6DKKxDvmp+OBHr6onHk02cI1kHwBNdDBBpnCxjijkggjexV2/YbmOcdrqPAW2sx/LYkebwCtDddum83ZrsYifHChX+VnIBzESmZKI42WJkkCb0uHUNSauSB2xvzlMKKuE/Pn6W1adiJGpJ+NTsvm8z6giXBCNJQqLeJZiC+VkOR+saE+Zg6TqBtpoS3YlCrjBOpAVnEUKiV/TzPiEYhURMykXcHWb8hMFWxIfAG4BbtFrMQIv97he26zhjCd9Aa1OwQQWE6SZ69b1hvixfeG0OWWv7nD6/UPFdCJgTNNqPx67sjt7N7x6MbkyqachW3zV2glMi5kRmapDi3cfoLsMZu/x2MYhZNbRRHrF2jXjNnSSn3xGm2FHFm+SeZynoTMIlNdGHxP68ke9UeRBrNMPwdtV2Qe+7HY+rF5JFBsw0rtYrmk8gClZUSYmXA0AqF3sDZMMsTz4oHHfmsoogCKVTrqqRpDNHVdFhMeqZ6ixmRPVW5q9IESQB48oJ5VnOUPCjJEKUNs4GQiBPVBe+Q4C1f6Rpo/bKuMt9favxstH/JGRZO3PK2INc7u2k+P/0WbR9Nf9E32rN5CCEFx/xADFBfwUQf57oKnh28pM9uuyS9v5LmiUHVvCqh8TP9D3hk/Znnt9q2OKfe7OrbGipieioclNXF0yIF3ated2+5PUxViaiJ1gSOTTmbjL2IDlM4zx1iQhst4+fVZG9w1MZtt+y4WSJ0ow9gDJtQqE7AnhY5gsAJ0 61pJkhWf dWnSoGdxcMuHfvr4hp7gdWURwUfeVL2w7cVW3Nn2wcPekZnk8RPoBp1h0tS3b62ABmtItJOf1KQmNyKqyeSJNT84F+/y7v25K8MSq4ICHwhspuj2WVO/p3Jyc8UWwxfXzAbk3Akqmj5DtzelKYCoGCIf0xq2fVEzGmeblTeY8KR0uxyOkAq/ktpnlsWVL8mYitLuAm854vc05IX2w/juvoaAhYx27qiJJztp1f1VAv/ApKKCxQ0SkF/tH4RXnPuyUkoanXMV23cFORfoSmfhrfxgTPw== 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 DAMOS quota goal metric with system wide memory pressure stall time. Specifically, the system level 'some' PSI for memory is used. The target value can be set in microseconds. DAMOS measures the increased amount of the PSI metric in last quota_reset_interval and use the ratio of it versus the user-specified target PSI value as the score for the auto-tuning feedback loop. Signed-off-by: SeongJae Park --- include/linux/damon.h | 7 +++++++ mm/damon/core.c | 25 +++++++++++++++++++++++++ 2 files changed, 32 insertions(+) diff --git a/include/linux/damon.h b/include/linux/damon.h index 5a06993d8479..886d07294f4e 100644 --- a/include/linux/damon.h +++ b/include/linux/damon.h @@ -130,12 +130,14 @@ enum damos_action { * enum damos_quota_goal_metric - Represents the metric to be used as the goal * * @DAMOS_QUOTA_USER_INPUT: User-input value. + * @DAMOS_QUOTA_SOME_MEM_PSI_US: System level some memory PSI in us. * @NR_DAMOS_QUOTA_GOAL_METRICS: Number of DAMOS quota goal metrics. * * Metrics equal to larger than @NR_DAMOS_QUOTA_GOAL_METRICS are unsupported. */ enum damos_quota_goal_metric { DAMOS_QUOTA_USER_INPUT, + DAMOS_QUOTA_SOME_MEM_PSI_US, NR_DAMOS_QUOTA_GOAL_METRICS, }; @@ -144,6 +146,7 @@ enum damos_quota_goal_metric { * @metric: Metric to be used for representing the goal. * @target_value: Target value of @metric to achieve with the tuning. * @current_value: Current value of @metric. + * @last_psi_total: Last measured total PSI * @list: List head for siblings. * * Data structure for getting the current score of the quota tuning goal. The @@ -159,6 +162,10 @@ struct damos_quota_goal { enum damos_quota_goal_metric metric; unsigned long target_value; unsigned long current_value; + /* metric-dependent fields */ + union { + u64 last_psi_total; + }; struct list_head list; }; diff --git a/mm/damon/core.c b/mm/damon/core.c index 973423166ee2..6d503c1c125e 100644 --- a/mm/damon/core.c +++ b/mm/damon/core.c @@ -11,6 +11,7 @@ #include #include #include +#include #include #include @@ -1125,6 +1126,25 @@ static unsigned long damon_feed_loop_next_input(unsigned long last_input, return min_input; } +#ifdef CONFIG_PSI + +static u64 damos_get_some_mem_psi_total(void) +{ + if (static_branch_likely(&psi_disabled)) + return 0; + return div_u64(psi_system.total[PSI_AVGS][PSI_MEM * 2], + NSEC_PER_USEC); +} + +#else /* CONFIG_PSI */ + +static inline u64 damos_get_some_mem_psi_total(void) +{ + return 0; +}; + +#endif /* CONFIG_PSI */ + static void damos_set_quota_goal_current_value(struct damos_quota_goal *goal) { u64 now_psi_total; @@ -1133,6 +1153,11 @@ static void damos_set_quota_goal_current_value(struct damos_quota_goal *goal) case DAMOS_QUOTA_USER_INPUT: /* User should already set goal->current_value */ break; + case DAMOS_QUOTA_SOME_MEM_PSI_US: + now_psi_total = damos_get_some_mem_psi_total(); + goal->current_value = now_psi_total - goal->last_psi_total; + goal->last_psi_total = now_psi_total; + break; default: break; }