Received: by 2002:a05:7412:cfc7:b0:fc:a2b0:25d7 with SMTP id by7csp1335703rdb; Mon, 19 Feb 2024 11:46:38 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCU3uXgcbIrY4Qca8l5o/3Dw+03U43ADO+qmCkXRH8p9saAe8Dve2g/AjeslNYMyWW//1pLn0kJBNo6SOo3gQOVRJzPg8imLK6B9YcN8xA== X-Google-Smtp-Source: AGHT+IHYfuywXsYruw6DBfaQ/S0aLzczn+JxaEyA+X28fZczMVDFZaCw7mx4UNMbjnaRXPk/iKET X-Received: by 2002:a17:906:7d4:b0:a3e:cc03:d40e with SMTP id m20-20020a17090607d400b00a3ecc03d40emr1481385ejc.63.1708371998798; Mon, 19 Feb 2024 11:46:38 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708371998; cv=pass; d=google.com; s=arc-20160816; b=iMC3TCmMx723c+Id49K4wDephVff3vHoKY/sVyehK10L2FU5t4UnyKJcmygk+3Cx5L UVmhJnHaoaS/DvXNkhSuixt6tvO0+lfWFi6/WsidUoHcZ1kXaAp8N+HngZSX4pTeUQIb Ol+2aPDKF8/4lC6JN0cOr4JiXlhVYAIg3m2hzd0BSRImvvpQOrdGH4liwiWlDyfc/6Ys YdMJrC5i8C6Ush2yMOKOxBJ/je6m3QW1S6Q/jje7BE/afJKBY8sdlhXUP7afoVexcnk6 J+wGJHZtcKnlSrwgSsfLqaMLPcsqBE+S4i9RmkJTvy3/O6m5dZw5YbdVjCjLU0DjkmXo jZfw== 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=mVAfZuCBWhLF2qymxTW+slKPvr24mSdNV8P6Wan9dLc=; fh=BzdeVYqZhG5iuwuKJRNLP969rvCput73lx0iwx2zu7A=; b=a2ZaVl0olHE0iR+Q6NQXbxuG+6NOSZV9sgoOoK/+GFRmvfr39xwX0rZnzs82wxPYN7 b6C44a5xyLCXxRdol3kKGvnqzTWh/qtuayMNWoB97X5WMGpTeSmqmTLNOXtUJhZF9ZJ/ Yw9D5pmBH9LVhzo9zuyYfv1L1oK8J7jfkBhihHkf+Z9X9WD0y2f/xqHmtGiUFYFUg/ba IDZxPubST63t6u9cVGhAnk0GHV992sm8jRs7xSHGIQZhYJqB4QeyJ7T2G647bTjpR2Kh Zjma2elZY1MtEdCEsugt13qKNMT5Akj7QHjH/5soi/fBGxBT1kZKBGwHWQmH8VG8Z358 dPBw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=VMJk4oti; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-71890-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-71890-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id d14-20020a170906370e00b00a3ea156512csi968023ejc.549.2024.02.19.11.46.38 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 19 Feb 2024 11:46:38 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-71890-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=VMJk4oti; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-71890-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-71890-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 am.mirrors.kernel.org (Postfix) with ESMTPS id 94A181F230B6 for ; Mon, 19 Feb 2024 19:46:33 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 5ACAC56755; Mon, 19 Feb 2024 19:44:45 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="VMJk4oti" 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 5760755798; Mon, 19 Feb 2024 19:44:44 +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=1708371884; cv=none; b=cpcw+c4TrVKsSHfhz/D7BxmedTMJEBdxGZasIYrmhhrSYGz9q6D74eH+iNsaFwDaIIT3jwLwYZCBKVKWPNnjeGnxjdcvDPLGr746IrK6LRc8x9GZ2WDwZeGCaUhbl+y5V/vMMSKduJ+Crpw3U5m3QXQduI72LXZXlsZbRObESyA= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708371884; c=relaxed/simple; bh=Y86PEzdDsloDNtE2rhRk0igx3/ADGu50K3PYFIjUmww=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=rl2EADUsMIYepAGVmG0lxYWfbEM7t3+dUie2baR/Kf+/hF6a0/R5HlkRhTD3BkrgfIcxqAZO7RHHIxA0rUYKo2ywpgx0wM5ds7/FClPvfVkngPTEmxKuAtWG9Tzm8hrIoETl4TcwFE2b2k8GpiCoNtLIwVqgd3bcVcPswot6dN0= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=VMJk4oti; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id D37B9C43390; Mon, 19 Feb 2024 19:44:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1708371884; bh=Y86PEzdDsloDNtE2rhRk0igx3/ADGu50K3PYFIjUmww=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=VMJk4otiuaR09DUh0+iezb8GZovrgKQlfCvrQ1tTjXsAlaxptT+OfVNaBmfkIbFrW CI4FSuRWy5qz0EKsYf3eEMo6zk3Zzi/Al2auGEqa/LLZKRcQkPQoZP1hos61FPiNL2 vmEX1DzJ9t4QhST25LMDbcl3LncVzCNUJfrrRwOqMnU5OvkRHLOH71Oi5dc1JKyjyu x5EHaMvyUIkvAuov3A9Qf4lqMmG5NdF9QZOYZYQdEmUZOt0dgra/nCF6MAbbX/hgUF 4kRTvUeVZHjdlNPLNnOCC2xg1aUGBPNDiBaxwrQG3uN5cvGnGDZ8a9mWrp7sunheBU 9LxMizAj+NVLg== From: SeongJae Park To: Andrew Morton Cc: SeongJae Park , damon@lists.linux.dev, linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: [PATCH 09/20] mm/damon/sysfs: use only quota->goals Date: Mon, 19 Feb 2024 11:44:20 -0800 Message-Id: <20240219194431.159606-10-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 DAMON sysfs interface implements multiple quota auto-tuning goals on its level since the DAMOS core logic was supporting only single goal. Now the core logic supports multiple goals on its level. Update DAMON sysfs interface to reuse the core logic and drop unnecessary duplicated multiple goals implementation. Signed-off-by: SeongJae Park --- mm/damon/sysfs-common.h | 2 +- mm/damon/sysfs-schemes.c | 49 +++++++++++++++++++++++++++------------- mm/damon/sysfs.c | 3 +-- 3 files changed, 35 insertions(+), 19 deletions(-) diff --git a/mm/damon/sysfs-common.h b/mm/damon/sysfs-common.h index 5a1ac15fb2f8..a63f51577cff 100644 --- a/mm/damon/sysfs-common.h +++ b/mm/damon/sysfs-common.h @@ -59,7 +59,7 @@ int damon_sysfs_schemes_clear_regions( struct damon_sysfs_schemes *sysfs_schemes, struct damon_ctx *ctx); -void damos_sysfs_set_quota_scores(struct damon_sysfs_schemes *sysfs_schemes, +int damos_sysfs_set_quota_scores(struct damon_sysfs_schemes *sysfs_schemes, struct damon_ctx *ctx); void damos_sysfs_update_effective_quotas( diff --git a/mm/damon/sysfs-schemes.c b/mm/damon/sysfs-schemes.c index 85ef58f98a87..7bf94b1ed6f7 100644 --- a/mm/damon/sysfs-schemes.c +++ b/mm/damon/sysfs-schemes.c @@ -1887,30 +1887,34 @@ static unsigned long damos_sysfs_get_quota_score(void *arg) return (unsigned long)arg; } -static void damos_sysfs_set_quota_score( +static int damos_sysfs_set_quota_score( struct damos_sysfs_quota_goals *sysfs_goals, struct damos_quota *quota) { - struct damos_sysfs_quota_goal *sysfs_goal; + struct damos_quota_goal *goal, *next; int i; - quota->goal.get_score = NULL; - quota->goal.get_score_arg = (void *)0; + damos_for_each_quota_goal_safe(goal, next, quota) + damos_destroy_quota_goal(goal); + for (i = 0; i < sysfs_goals->nr; i++) { - sysfs_goal = sysfs_goals->goals_arr[i]; + struct damos_sysfs_quota_goal *sysfs_goal = + sysfs_goals->goals_arr[i]; + if (!sysfs_goal->target_value) continue; - /* Higher score makes scheme less aggressive */ - quota->goal.get_score_arg = (void *)max( - (unsigned long)quota->goal.get_score_arg, - sysfs_goal->current_value * 10000 / - sysfs_goal->target_value); - quota->goal.get_score = damos_sysfs_get_quota_score; + goal = damos_new_quota_goal(damos_sysfs_get_quota_score, + (void *)(sysfs_goal->current_value * 10000 / + sysfs_goal->target_value)); + if (!goal) + return -ENOMEM; + damos_add_quota_goal(quota, goal); } + return 0; } -void damos_sysfs_set_quota_scores(struct damon_sysfs_schemes *sysfs_schemes, +int damos_sysfs_set_quota_scores(struct damon_sysfs_schemes *sysfs_schemes, struct damon_ctx *ctx) { struct damos *scheme; @@ -1918,16 +1922,21 @@ void damos_sysfs_set_quota_scores(struct damon_sysfs_schemes *sysfs_schemes, damon_for_each_scheme(scheme, ctx) { struct damon_sysfs_scheme *sysfs_scheme; + int err; /* user could have removed the scheme sysfs dir */ if (i >= sysfs_schemes->nr) break; sysfs_scheme = sysfs_schemes->schemes_arr[i]; - damos_sysfs_set_quota_score(sysfs_scheme->quotas->goals, + err = damos_sysfs_set_quota_score(sysfs_scheme->quotas->goals, &scheme->quota); + if (err) + /* kdamond will clean up schemes and terminated */ + return err; i++; } + return 0; } void damos_sysfs_update_effective_quotas( @@ -1987,13 +1996,17 @@ static struct damos *damon_sysfs_mk_scheme( .low = sysfs_wmarks->low, }; - damos_sysfs_set_quota_score(sysfs_quotas->goals, "a); - scheme = damon_new_scheme(&pattern, sysfs_scheme->action, sysfs_scheme->apply_interval_us, "a, &wmarks); if (!scheme) return NULL; + err = damos_sysfs_set_quota_score(sysfs_quotas->goals, &scheme->quota); + if (err) { + damon_destroy_scheme(scheme); + return NULL; + } + err = damon_sysfs_set_scheme_filters(scheme, sysfs_filters); if (err) { damon_destroy_scheme(scheme); @@ -2029,7 +2042,11 @@ static void damon_sysfs_update_scheme(struct damos *scheme, scheme->quota.weight_nr_accesses = sysfs_weights->nr_accesses; scheme->quota.weight_age = sysfs_weights->age; - damos_sysfs_set_quota_score(sysfs_quotas->goals, &scheme->quota); + err = damos_sysfs_set_quota_score(sysfs_quotas->goals, &scheme->quota); + if (err) { + damon_destroy_scheme(scheme); + return; + } scheme->wmarks.metric = sysfs_wmarks->metric; scheme->wmarks.interval = sysfs_wmarks->interval_us; diff --git a/mm/damon/sysfs.c b/mm/damon/sysfs.c index cc2d88a901f4..6fee383bc0c5 100644 --- a/mm/damon/sysfs.c +++ b/mm/damon/sysfs.c @@ -1377,8 +1377,7 @@ static int damon_sysfs_commit_schemes_quota_goals( ctx = sysfs_kdamond->damon_ctx; sysfs_ctx = sysfs_kdamond->contexts->contexts_arr[0]; - damos_sysfs_set_quota_scores(sysfs_ctx->schemes, ctx); - return 0; + return damos_sysfs_set_quota_scores(sysfs_ctx->schemes, ctx); } /* -- 2.39.2