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: 203239 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:693c:2685:b0:108:e6aa:91d0 with SMTP id mn5csp6420dyc; Mon, 19 Feb 2024 11:48:23 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCWgt395gMqBAz1KPDFDHH4NCJhvyRDinNL2oE2Qg/Dyk4pXbzUWd9UsWn1uL42LqVO9Q6AXXA5Z7pc03K4OX7TeClySdw== X-Google-Smtp-Source: AGHT+IGTQ7x6lj1yI+aVuvvBoCkHViVZHogiv0a5KBOrAoP4/KNWPCcCpXufeXFkZpfClKe+HlLE X-Received: by 2002:a05:6a00:2346:b0:6e4:5ff9:f037 with SMTP id j6-20020a056a00234600b006e45ff9f037mr5102635pfj.12.1708372103626; Mon, 19 Feb 2024 11:48:23 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708372103; cv=pass; d=google.com; s=arc-20160816; b=uc5FZDQKbzfcsnX6ORJk1Xd0C9RMc7t+/QiZ1UvJEPlBWGtcKolXo/YkQUEZmzyKPJ Wzs7U5WXKrX3vJ3wtonxkN6i+1uZbdE4DA/o2lVAtxsGPqjqro1gMb8k2RIyRKpdG3dY WBSgYxAKd7SGKUIw8lyJ9IP/yswfzqnhSNcIFXB8ytbzic4xEGamUoz3YtOYqxbw5ivC YnGIDcACenCUbseiMj7whhJXBjrxNga9s7a+z1Aazv63ztFps+ADpiYDx8BwxG6WiEFD BSPHMoxzIZrKEropQsETzgeNYmrKhKi/F4JrVFw0rHUbgwvM3WycO12+rRoEaamJbYUD Bidg== 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-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-71895-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id f20-20020a056a0022d400b006e4720345b9si839911pfj.101.2024.02.19.11.48.23 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 19 Feb 2024 11:48:23 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-71895-ouuuleilei=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-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-71895-ouuuleilei=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 739612827F3 for ; Mon, 19 Feb 2024 19:48:23 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 891825A10B; Mon, 19 Feb 2024 19:44:49 +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 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1791357986621642092 X-GMAIL-MSGID: 1791357986621642092 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; }