From patchwork Mon Feb 19 19:44:20 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: SeongJae Park X-Patchwork-Id: 13563010 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 A7201C48BC3 for ; Mon, 19 Feb 2024 19:44:59 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 1574C6B0093; Mon, 19 Feb 2024 14:44:47 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 0523E6B0095; Mon, 19 Feb 2024 14:44:46 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id E13826B008A; Mon, 19 Feb 2024 14:44:46 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id B63D06B008C for ; Mon, 19 Feb 2024 14:44:46 -0500 (EST) Received: from smtpin27.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id 7C617C025E for ; Mon, 19 Feb 2024 19:44:46 +0000 (UTC) X-FDA: 81809580972.27.B82E26A Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by imf06.hostedemail.com (Postfix) with ESMTP id CC72118001C for ; Mon, 19 Feb 2024 19:44:44 +0000 (UTC) Authentication-Results: imf06.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=VMJk4oti; 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=1708371884; 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=mVAfZuCBWhLF2qymxTW+slKPvr24mSdNV8P6Wan9dLc=; b=M6Ya0PSehdchbbLLodBPRq8t2WEuu5U1EJkefn4JpSURpwK6k4Msi2kvujb0MAzmUpMdBP N7H3j67dGsb/EUEM7p5FhLSeqLhzMDZxAY6vLzel9bobs0901+A1gxkFK6XZlMFnzgTU1Y joaOVLamRBPZVopkTQsAHoIU4/cWNZ8= ARC-Authentication-Results: i=1; imf06.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=VMJk4oti; 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=1708371884; a=rsa-sha256; cv=none; b=ulJvrnD4koO4pa3pMLqBcrRqWc7W42q7nUgfpZvKlzhtYq1pvFFSPMykbTgWZEtVRwgpwU zzPjppumDGUORvqSj9aCSRuVxXRLhFj0Dc9+VAHq8yp8PgSMC6awVVGT0eSJCNsogwZL7L ErImMLNR+1YqSfnJTHbrl7UpqmSuzAM= Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by dfw.source.kernel.org (Postfix) with ESMTP id 6A43C60F9B; Mon, 19 Feb 2024 19:44:44 +0000 (UTC) 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> MIME-Version: 1.0 X-Rspamd-Queue-Id: CC72118001C X-Rspam-User: X-Rspamd-Server: rspam05 X-Stat-Signature: mbwzb8gth6mn4gcfbzrmcmnr974okz6p X-HE-Tag: 1708371884-847230 X-HE-Meta: U2FsdGVkX1+HFYo4eoH8meCYV0sYIXtQw1TGcHNx89ay051Ary/26bNC7Q3vaIhgIzc/Kb6J6XXj3gy9qELP7zfylsIHEYbpkEWockpv1/qSglLh5kB6LPzJNJia4vcLPmEYyTs43vQ3cCpbSe+PtrlMX0Pfu6pt7iTOZwGIFKchRjpQJEnKWtWoOFhatVr+IW8QuDIIUmiwNutaGQ6mFoUjzM+44ORGv7QQDoqXRtk4aQp2z7L+IDuvXV5vpOKBAmyZDMxKGoRD4NWbC06pnmrc/FRfUgr2Lta2Q/kpq/UtLoFZYd8FFAhYCdFy48za3dtsqfGY3quUrtlb2fqZXbO+dxVG7uaYbcxKGQCPglzTwkg0mORS+rDyRHvq3CQzDt0VwfZlA7sPCKabWE/rBEcnDxbhNNicIHoy5tZxmvplJo26NyJUkiIi/2oOuHSAQvGyiiii620DHZZJp0sj4gBg5CT8wTHYT9DUcRxvp7hBxDzWYg6ORWtFycnVCnOAuBknGJexNHKooS8pZrL/x+4nUI9v5kPzs5HZE46CIfhP64JzpnieOtFYvNsY60PRsLlqeNHapusnSqgCqCX9iX9qQr2ccWAxwb9jeE6ifMrEwcvP3KZPvu/wZ91aJ1w+/e09dtPvpX4HKDZAWUhKo6eUHYTW9xahnrqoV8SAUKpv7uTyZG8D4RMV8peDd+fDUhUaWor1IqlH8qE4Rizu1HfylJPGXmAyeQzfhvYDhRdjWIXQXf6KWvAt3ZF6QIvUeDMhj5mt2TKbT5UshSOiwA4omd6yQ4mi3v/U+uvbtOdlFlEtGVSqhcldJSPTZqZO3S5Fj3yOmoGPZn/csVgpR8xe3Kl5WmUvFxuff2wxSFU84lrS09w0uz9XpFrylaG7pck6DbtcewS08XGbPIz9vuzmfcs+4hx6NhO51jW7cImBL7CptwWQlRsJJjEAVR56vkoGBqbM28NVJ1PtZBc FAySZxpv TW8FP0DqpxxGZHCOdmfXNbKbv38pLMIxcvYnoeu3VdDyLof9aDznf2z8m34jpmQBIupNhnOHuEn8qxccF+xu5/i2afsYvXmm70nfOXxKEAVsj0ljBudV0cu6LfE+gZ3zeBWVQcdpxruYcwK8Tr9P4E5nCORtzW7e/khQTFRE57syd3XfYB8Eh9LHfoHN9khV8gEL7u8AvazFJrRo2moR4T4XpwdTKBYiMPPkHbTp3FPZtZkhc44buQ03jn3zL6U1LFn1BgiRga8oa4ksfvWAbjEiaTw== 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: 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); } /*