From patchwork Mon Feb 19 19:44:22 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: SeongJae Park X-Patchwork-Id: 203237 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:693c:2685:b0:108:e6aa:91d0 with SMTP id mn5csp6243dyc; Mon, 19 Feb 2024 11:47:57 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCXi/oyXOxVNXyNORixhqN6dsV+Efnx74y76C3/1tOeLO87ZKlFl7Euvkpacbp0g9bsW9HvPE1Mw3IuCuvx4o1RG5cpYzA== X-Google-Smtp-Source: AGHT+IH6faZkDmVnI+kowumy+HmzTwSqzM1IyMfRhrlJt4PW512443rDWb6Ko/razcObQzaKAjHP X-Received: by 2002:a05:620a:531a:b0:787:284b:3044 with SMTP id oo26-20020a05620a531a00b00787284b3044mr14872669qkn.77.1708372077613; Mon, 19 Feb 2024 11:47:57 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708372077; cv=pass; d=google.com; s=arc-20160816; b=yAHuz/B3iIy1xH/hN4hfMAgx47aE73YhMLc6i13PiImv1qd6hRNVEoSRsJGLcsK5FL 0Vfxs07AZwWHOOL8P0I/g+kwyF49O0lm+9pbug0jAqCXrSiCz5cNCfUoFwxL127wp+mh bKdG62cLauHg690pGJS2cBu4SIMIbG6rYbeL4m1Zp2aNtUPWgb38i9ginFL741qrQfBI bc/obsmbJ+uEbjPhtKyUXxBx9LVSYotOs+0udcb7kABPOzaJsggBhyGb1QST9zfgZcJA YqGhNzwF2BA24zIA38ic+m1z2IBpMtys6bwDF1GqCNRPGyWfPyoZj8Kw5N4j1sbYsVJy SLVQ== 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=BPtcDrW6smk42ob/SAFc/GI98wGX/lFjOHolWe6AUqg=; fh=BzdeVYqZhG5iuwuKJRNLP969rvCput73lx0iwx2zu7A=; b=bSdeM5A0+VhFFdosQslvPl3SGTGJ5YWvBVaBGDlVGLHI4hqSNmQd7g/pSatrOQLb3P UWGZBi4jTfLVN1EVCDlsZTDixRvuFE9GRhpqXuGoRNPp/HcUUROfsX6AAdghOpSjxoov q3e2tFz84Fdi494An/ajXLD9XyGbaOxd9qtQ1iN2zRPrMvG+NDzscO/ZELBykLvVR/KB avzA4c/PFFNzm42BvOxDcgYIrowHqXXcZBOGXmuTdvCxzpVDYn5PeQkauWCV8ClYdMFA gJ0jGjyGB6ZNKp6lnEJ99OiWGCUlcP43NanGZTJpuHgREwZ2FzEKTvZyFIXo+1AFvuE1 SvlA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=OlEYB5tC; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-71892-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-71892-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id dt5-20020a05620a478500b00787274e49d5si6997440qkb.744.2024.02.19.11.47.57 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 19 Feb 2024 11:47:57 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-71892-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=OlEYB5tC; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-71892-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-71892-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 ny.mirrors.kernel.org (Postfix) with ESMTPS id 5D2A31C218C8 for ; Mon, 19 Feb 2024 19:47:57 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 828A658ADF; Mon, 19 Feb 2024 19:44:48 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="OlEYB5tC" 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 7B73056765; Mon, 19 Feb 2024 19:44:45 +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=1708371885; cv=none; b=erNeQmLltRSIfjgjhzOdP42C/Ghv2RbZGsixm/O6S+BrKRKmeRfC2b9EJiiHfm28+lpTyraesocKXfo3g8ueeButETHHk4iSQm2iiRz03j0HzBoyzAeikDU1HfPALmfVEHADM35KIho2rbrkARydgFEkRu7RK/+bps7jN2h/0Io= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708371885; c=relaxed/simple; bh=R3dxTppsO4aJJFug6nWMDIsYsBasUQvKpFzDWX0osTg=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=S83tiCJ6DH5TZ/Bkgkgb9GuS4g3pjzUzGUYIg98TfrjKq14zT1vi1vZZtNSaLJf1WVZgMhHDHAs8niYWyBgSBuQj2Tiu0hrKTlChlwA9gaNKxFPMbxVSioA3mVxf3vZoEhO9PS040A3xWYTbC/BXqv8SDwVObtGnojpE8vwhOf0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=OlEYB5tC; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 03D0CC43394; Mon, 19 Feb 2024 19:44:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1708371885; bh=R3dxTppsO4aJJFug6nWMDIsYsBasUQvKpFzDWX0osTg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=OlEYB5tC4/VXhLLWfLhPwyH9Tzvh/9R0vhtcqhC+OvyZXwKASESgHHIjXyOQTm9fD tM1wtoxgijVyLP2EumAzUce+yvGmcGMEolxhZkNjwobgwRfeBEMN+ZYH2F1EwcBTTw Zklz3HDqD4mx/QWmPq6+0qpQWu/tPAaTa9OOdfUCxr/0VQ6iQa/gNvsPsFqsCgoYyW +NKW/JwAn8XxwOUbHwBxZ8qQQ8jIWBn6qk2ZwU06pG1Q3HDZ6qC27mv4F1XC+FfQGT 2aq8jhUFVJfdXLig4ZB9Q+4aQzEv09sXFcKMyciaKHTbOz28r9voYDgQn55ZTjpgx7 1rAXIxYu/wSzA== From: SeongJae Park To: Andrew Morton Cc: SeongJae Park , damon@lists.linux.dev, linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: [PATCH 11/20] mm/damon/core: let goal specified with only target and current values Date: Mon, 19 Feb 2024 11:44:22 -0800 Message-Id: <20240219194431.159606-12-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: 1791357960010661361 X-GMAIL-MSGID: 1791357960010661361 DAMOS quota auto-tuning feature let users to set the goal by providing a function for getting the current score of the tuned quota. It allows flexible goal setup, but only simple user-set quota is currently being used. As a result, the only user of the DAMOS quota auto-tuning is using a silly void pointer casting based score value passing function. Simplify the interface and the user code by letting user directly set the target and the current value. Signed-off-by: SeongJae Park --- include/linux/damon.h | 19 +++++++++---------- mm/damon/core.c | 9 +++++---- mm/damon/sysfs-schemes.c | 10 ++-------- 3 files changed, 16 insertions(+), 22 deletions(-) diff --git a/include/linux/damon.h b/include/linux/damon.h index 76c965c1eea3..de0cdc7f96d2 100644 --- a/include/linux/damon.h +++ b/include/linux/damon.h @@ -128,19 +128,18 @@ enum damos_action { /** * struct damos_quota_goal - DAMOS scheme quota auto-tuning goal. - * @get_score: Function for getting current score of the goal. - * @get_score_arg: Parameter for @get_score + * @target_value: Target value to achieve with the tuning. + * @current_value: Current value that achieving with the tuning. * @list: List head for siblings. * - * Data structure for getting the current score of the quota tuning goal. - * Calling @get_score with @get_score_arg as the parameter should return the - * current score. Then the score is entered to DAMON's internal feedback loop - * mechanism to get the auto-tuned quota. The goal of the tuning is getting - * the feedback score value of 10,000. + * 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. */ struct damos_quota_goal { - unsigned long (*get_score)(void *arg); - void *get_score_arg; + unsigned long target_value; + unsigned long current_value; struct list_head list; }; @@ -690,7 +689,7 @@ 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 (*get_score)(void *), void *get_score_arg); + unsigned long target_value, unsigned long current_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 7b06d926c552..907f467fc8c0 100644 --- a/mm/damon/core.c +++ b/mm/damon/core.c @@ -300,15 +300,15 @@ void damos_destroy_filter(struct damos_filter *f) } struct damos_quota_goal *damos_new_quota_goal( - unsigned long (*get_score)(void *), void *get_score_arg) + unsigned long target_value, unsigned long current_value) { struct damos_quota_goal *goal; goal = kmalloc(sizeof(*goal), GFP_KERNEL); if (!goal) return NULL; - goal->get_score = get_score; - goal->get_score_arg = get_score_arg; + goal->target_value = target_value; + goal->current_value = current_value; INIT_LIST_HEAD(&goal->list); return goal; } @@ -1132,7 +1132,8 @@ static unsigned long damos_quota_score(struct damos_quota *quota) damos_for_each_quota_goal(goal, quota) highest_score = max(highest_score, - goal->get_score(goal->get_score_arg)); + 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 7bf94b1ed6f7..50218a7bfa0a 100644 --- a/mm/damon/sysfs-schemes.c +++ b/mm/damon/sysfs-schemes.c @@ -1882,11 +1882,6 @@ static int damon_sysfs_set_scheme_filters(struct damos *scheme, return 0; } -static unsigned long damos_sysfs_get_quota_score(void *arg) -{ - return (unsigned long)arg; -} - static int damos_sysfs_set_quota_score( struct damos_sysfs_quota_goals *sysfs_goals, struct damos_quota *quota) @@ -1904,9 +1899,8 @@ static int damos_sysfs_set_quota_score( if (!sysfs_goal->target_value) continue; - goal = damos_new_quota_goal(damos_sysfs_get_quota_score, - (void *)(sysfs_goal->current_value * 10000 / - sysfs_goal->target_value)); + goal = damos_new_quota_goal(sysfs_goal->target_value, + sysfs_goal->current_value); if (!goal) return -ENOMEM; damos_add_quota_goal(quota, goal);