From patchwork Mon Feb 19 19:44:23 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: SeongJae Park X-Patchwork-Id: 203238 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:693c:2685:b0:108:e6aa:91d0 with SMTP id mn5csp6403dyc; Mon, 19 Feb 2024 11:48:22 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCW8V8RaCInOjw2hDKmA1HZHj6pctZ/T9SLPYjtZz+QAl6bEh70jln82dUw1g+HjyjzR7bg73FA+iSF3d5z2zIr1V6dz4g== X-Google-Smtp-Source: AGHT+IGPJZXrGcUJGCWoMkHWFEX6ROERt1XKjjhVSF9sKzKgehx79uYV4VZe4JCaEkUwHCZRUofg X-Received: by 2002:a92:2901:0:b0:364:1c05:b24b with SMTP id l1-20020a922901000000b003641c05b24bmr13865603ilg.13.1708372101821; Mon, 19 Feb 2024 11:48:21 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708372101; cv=pass; d=google.com; s=arc-20160816; b=Qq8mjhZWs5+bFAExwfQdtHuyC0+NNNRiZqkvoN9sdmRHqQHz+m1c3FMOKpkXSFMoSh y1eFdjh5g8pB8rQucH6e4nR3KtB7TL8R9bUaNTkk3QDUuQxOxTwxgz+Jar05NrZ7iHlX N+yrxMM5bc4V4bfpUdgvblIH0tba1gq4aaOXbRQB2qPjJ42JPNRAZksRiZtbAQaG1z0X ieyLJuGSPEtTOEYji6Vao/gjuruyJKsRQrtHtEVsjmJhH2QUb/ECjqpNCxtt4Ugy6sBJ VtYKdG1qQtsfunBeEFnn+7OOqiGBfH82E6wuVaBuUlBL5UjGQDh9aqPD0xjhY/jf8jzT p2yA== 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=Y3OhFaB2k7Pb8ZijHspmx/eNWjFg+R6JWIL6cDH0GjY=; fh=BzdeVYqZhG5iuwuKJRNLP969rvCput73lx0iwx2zu7A=; b=qrHk2y5QLMN2cWBEmtX8H7go5azXgS0Pdn7rn+eurWDwtUyhpMJM0ojb6Oa6Fpwx12 hGQsya3+SGJaKxcYEZ8JADGsam1RUbbXm65d7w9PP2/+duE+hxPlxOrMTEgXleA2wVA6 cRGQZPat21dPIHAKAcnnuefWkwsAvShg7gqns3sAPqhEEdIX4vg2Znvai+GA3xvsrdoy KUy9Le2Zjh8GegfmsOdn761JxffZ96TLd+cj6Yv/KqkByXnBNOHdnSqTxXZUiPyxaipi az7d5/VN+wXAMtNRIPCEhOgc5A/E/wM0qBUBebxUUFQGgjlpqVYEy9mShxXtUzbfnlh8 tB9Q==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=sBawmmXP; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-71893-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-71893-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 t24-20020a639558000000b005dc4ec6cd2esi4939249pgn.767.2024.02.19.11.48.21 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 19 Feb 2024 11:48:21 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-71893-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=sBawmmXP; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-71893-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-71893-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 992FD282E2C for ; Mon, 19 Feb 2024 19:48:21 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 6DB455A103; 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="sBawmmXP" 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 3CE4156B80; 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=hNgkfW+M+D2QKQL9UoD0yGAyOeFhVVCZTZr5jQLvElXUJl7oj2Qsq6yywD1ZFIoUpiWbS0kkuEQ7tI09I6qYSTRJzKQiGN7gijvTdzGDhzu4/IB+gK27W2MRmqYsnvZIFaleAiJ0zJsAsbbVhapRrAT/hRr4pZIJbUz67TaO5ao= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708371886; c=relaxed/simple; bh=k0sVHhoP1l10FZGLvNv2ZQk6SLTzHmp1jaim+1skQqQ=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=awehZr713UI7TSP7I3SIMzDl6x0TQs5K7CvrysfiYe3SVumaPFHngj2VbX8tSGF9v4kV5GfbSZaTAAivrk++O/kRaFd33Oc58VaLJyV5Wm7E0Mlozlk9UPzRp2uXnigU2wVj+N+pX7CAcogtK2AY515cINFSCpI84iJo9wMnLYY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=sBawmmXP; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 90AD9C43390; Mon, 19 Feb 2024 19:44:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1708371885; bh=k0sVHhoP1l10FZGLvNv2ZQk6SLTzHmp1jaim+1skQqQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=sBawmmXP4SAQih4l7kjcCb8kPPaiAeqHNjh3ek/vrXAWbguNYIFOsl0zi2ZwrqbCC X0NDppc10tKHbCZa4jaj5XsyGU2kuRfex+PUO+GvBmfE2APRTp2+5d5WTg1jJDfocC Ic8+M+Z4BEtesgKhqejnoPQkfOkygCr5dExvWF31KCTseZ7tNM9+cMOZEAxbhmUybf MV+TOQ2et5Y909rkNOhJyMziq4sxd+CHWHrdE4WFtzZnYPed8ICfs2Rk91lJTc03Ay NDNEr5LK3SGUD126pw+2744vsjBc6fgNPOWMvPA9V4RDvrkueerTpw7PDEXJP5Z8wW H4skvQs+UcbcQ== From: SeongJae Park To: Andrew Morton Cc: SeongJae Park , damon@lists.linux.dev, linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: [PATCH 12/20] mm/damon/core: support multiple metrics for quota goal Date: Mon, 19 Feb 2024 11:44:23 -0800 Message-Id: <20240219194431.159606-13-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: 1791357985226974252 X-GMAIL-MSGID: 1791357985226974252 DAMOS quota auto-tuning asks users to assess the current tuned quota and provide the feedback in a manual and repeated way. It allows users generate the feedback from a source that the kernel cannot access, and writing a script or a function for doing the manual and repeated feeding is not a big deal. However, additional works are additional works, and it could be more efficient if DAMOS could do the fetch itself, especially in case of DAMON sysfs interface use case, since it can avoid the context switches between the user-space and the kernel-space, though the overhead would be only trivial in most cases. Also in many cases, feedbacks could be made from kernel-accessible sources, such as PSI, CPU usage, etc. Make the quota goal to support multiple types of metrics including such ones. Signed-off-by: SeongJae Park --- include/linux/damon.h | 26 +++++++++++++++++++++++--- mm/damon/core.c | 22 +++++++++++++++++++--- mm/damon/sysfs-schemes.c | 5 +++-- 3 files changed, 45 insertions(+), 8 deletions(-) diff --git a/include/linux/damon.h b/include/linux/damon.h index de0cdc7f96d2..5a06993d8479 100644 --- a/include/linux/damon.h +++ b/include/linux/damon.h @@ -126,18 +126,37 @@ enum damos_action { NR_DAMOS_ACTIONS, }; +/** + * enum damos_quota_goal_metric - Represents the metric to be used as the goal + * + * @DAMOS_QUOTA_USER_INPUT: User-input value. + * @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, + NR_DAMOS_QUOTA_GOAL_METRICS, +}; + /** * struct damos_quota_goal - DAMOS scheme quota auto-tuning goal. - * @target_value: Target value to achieve with the tuning. - * @current_value: Current value that achieving with the tuning. + * @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. * @list: List head for siblings. * * Data structure for getting the current score of the quota tuning goal. The * score is calculated by how close @current_value and @target_value are. Then * the score is entered to DAMON's internal feedback loop mechanism to get the * auto-tuned quota. + * + * If @metric is DAMOS_QUOTA_USER_INPUT, @current_value should be manually + * entered by the user, probably inside the kdamond callbacks. Otherwise, + * DAMON sets @current_value with self-measured value of @metric. */ struct damos_quota_goal { + enum damos_quota_goal_metric metric; unsigned long target_value; unsigned long current_value; struct list_head list; @@ -689,7 +708,8 @@ void damos_add_filter(struct damos *s, struct damos_filter *f); void damos_destroy_filter(struct damos_filter *f); struct damos_quota_goal *damos_new_quota_goal( - unsigned long target_value, unsigned long current_value); + enum damos_quota_goal_metric metric, + unsigned long target_value); void damos_add_quota_goal(struct damos_quota *q, struct damos_quota_goal *g); void damos_destroy_quota_goal(struct damos_quota_goal *goal); diff --git a/mm/damon/core.c b/mm/damon/core.c index 907f467fc8c0..973423166ee2 100644 --- a/mm/damon/core.c +++ b/mm/damon/core.c @@ -300,15 +300,16 @@ void damos_destroy_filter(struct damos_filter *f) } struct damos_quota_goal *damos_new_quota_goal( - unsigned long target_value, unsigned long current_value) + enum damos_quota_goal_metric metric, + unsigned long target_value) { struct damos_quota_goal *goal; goal = kmalloc(sizeof(*goal), GFP_KERNEL); if (!goal) return NULL; + goal->metric = metric; goal->target_value = target_value; - goal->current_value = current_value; INIT_LIST_HEAD(&goal->list); return goal; } @@ -1124,16 +1125,31 @@ static unsigned long damon_feed_loop_next_input(unsigned long last_input, return min_input; } +static void damos_set_quota_goal_current_value(struct damos_quota_goal *goal) +{ + u64 now_psi_total; + + switch (goal->metric) { + case DAMOS_QUOTA_USER_INPUT: + /* User should already set goal->current_value */ + break; + default: + break; + } +} + /* Return the highest score since it makes schemes least aggressive */ static unsigned long damos_quota_score(struct damos_quota *quota) { struct damos_quota_goal *goal; unsigned long highest_score = 0; - damos_for_each_quota_goal(goal, quota) + damos_for_each_quota_goal(goal, quota) { + damos_set_quota_goal_current_value(goal); highest_score = max(highest_score, goal->current_value * 10000 / goal->target_value); + } return highest_score; } diff --git a/mm/damon/sysfs-schemes.c b/mm/damon/sysfs-schemes.c index 50218a7bfa0a..7a8a39f2679b 100644 --- a/mm/damon/sysfs-schemes.c +++ b/mm/damon/sysfs-schemes.c @@ -1899,10 +1899,11 @@ static int damos_sysfs_set_quota_score( if (!sysfs_goal->target_value) continue; - goal = damos_new_quota_goal(sysfs_goal->target_value, - sysfs_goal->current_value); + goal = damos_new_quota_goal(DAMOS_QUOTA_USER_INPUT, + sysfs_goal->target_value); if (!goal) return -ENOMEM; + goal->current_value = sysfs_goal->current_value; damos_add_quota_goal(quota, goal); } return 0;