Received: by 2002:a05:7412:cfc7:b0:fc:a2b0:25d7 with SMTP id by7csp1336058rdb; Mon, 19 Feb 2024 11:47:37 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCVfSI6u9mR+Ryu/EbWLy9QPc0NdFylf5/eGzqiKEY27RpUjly/eaFJHwffQ7t2nZF52Cdy+wbJ0JQU1jNIkloPwFlYgmmNmsPqBaA2QoA== X-Google-Smtp-Source: AGHT+IEowN3yaL+XMOjmVk/+k9fJkxRwZt+7Enp7yz4LcBJEGelcoPQ8N7/yOPLTqs7MF1wOrzPN X-Received: by 2002:a05:6a21:3a46:b0:19e:5fd5:5244 with SMTP id zu6-20020a056a213a4600b0019e5fd55244mr23355191pzb.1.1708372056915; Mon, 19 Feb 2024 11:47:36 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708372056; cv=pass; d=google.com; s=arc-20160816; b=eBXi9sNbStEMUTu0VNy3EanqJoHXB3pdU8/AVQQhdnoi55hEhsEjVpkKCDW8NDMMir CINz/Av/PYMwmnWakhYTMeBsNbnP3jACmvOTVOQvJBAmpuSlufJScdpxxYic0MS0XfgD tTyZYrgPPgjsq8ir0sl7n4hdwqxoN+/DYsV1ZUfOgB8M6BEc0xsOOA0DKq/MxnirH6vg AE4N/cnbsfAVsje9oNf4CI7UDOZ9qm3DPE/x2avDxk/xqPTZgELcTQe4y+J/k9AMmyeb q9szyJ3P/SmisQEzawpJCoLv5OOJcIXIUrZ0gqGK8nkzffMFNo4d5w88qKOHHwTdkIPo iT9g== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=2IPFCHuVQYIU935uM08rqgUJZWzciquZX/wAtiLCpQc=; fh=BzdeVYqZhG5iuwuKJRNLP969rvCput73lx0iwx2zu7A=; b=A5r9JfMvkLRj30MWIGGFvRGZitWDLJa9nviBVbMkQQYxoTGDLOTk81eVOaW3YK8Uiz trqzZ8TS/XLAjHQrPJPdRDJ02OFSY+AHu4FnIp7pWzLTKalI5HEcnoLmcg/xrreTHLcj p2vD0az3gX5orESTn6N8QsushL/a+8V1MywLNkBERDGx5L/Sb2yyfNV0LOsj9zRsVekk 7uwNHyilDxr5M/gnpFsqw2BZ0RZX7CYwhNi4uha6tdVRumSXhPFSJDojt59H8QsWWjaQ yPfew+lhUKEQV/XRBSYcUOytdWzBFATjDcWIj0H5orpBNpS0bFo7uuIfM73tmAcFC4mx QXbA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=TdWxaHKc; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-71895-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-71895-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id s63-20020a635e42000000b005cdf8b4d2fesi4827300pgb.747.2024.02.19.11.47.36 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 19 Feb 2024 11:47:36 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-71895-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=TdWxaHKc; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-71895-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-71895-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id 97CC328299C for ; Mon, 19 Feb 2024 19:47:36 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id B8CDA58208; Mon, 19 Feb 2024 19:44:47 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="TdWxaHKc" Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C2DD156B96; Mon, 19 Feb 2024 19:44:46 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708371886; cv=none; b=ZfLTxUbE3wQqpmZ/wUWYrw5b7IX7GZWJ3sBabVUW7K6ddl2xA4BhSifmG5EO91ldNQha69vf8GCcqaTiu31LgFrAWUA5J5GHp8QdfrSwp7Cg+UIqa2R/EMbnrF2lTLoghhIw9mqYgkO05KmzLt1IB19j5FTVutO7LyF16Kioo8w= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708371886; c=relaxed/simple; bh=+x9YEwq0wFUN061d3yOJa9HVAX8E/VoU7wyTTkm6mIw=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=kFLhwjXgUAJuFk1b7Yp3xhffxGXmKXm7zc29g407T483LkZ0cLFtdydD/H/XFQ3iVK7GSUf3cWGwLN2gzeevsR/2Ajx75iqke9luCTBMEIberZcYpayoEiGCQBXfsxicD2Rpsc7+n9tB9DjmPl62CCmtPN2z7WVp/YOUfaDq49g= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=TdWxaHKc; arc=none smtp.client-ip=10.30.226.201 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> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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; } -- 2.39.2