Received: by 2002:a05:7412:cfc7:b0:fc:a2b0:25d7 with SMTP id by7csp1335801rdb; Mon, 19 Feb 2024 11:46:58 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCVqqv8Y/NqCUVeEaxqvWxHsFzqENFffN2rqjyEhaQ2+nTJMvdK08BWYcILggKFiC6ggzQUx7twAVLHzy7pu6MGUnreySRFdVGeG3qQxVg== X-Google-Smtp-Source: AGHT+IEsbz6PhHNF8z477sIeV9BkSqTPygYN58WmvYqhqhq54awZtXDTaYz/dq/KLUy+dMhI9JLv X-Received: by 2002:a9d:5f1a:0:b0:6e4:512e:e0ab with SMTP id f26-20020a9d5f1a000000b006e4512ee0abmr3846401oti.6.1708372017922; Mon, 19 Feb 2024 11:46:57 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708372017; cv=pass; d=google.com; s=arc-20160816; b=BHFeDLJzmcyV9wp5OltKjdgoD9L3ahfDtLKYKygyk+n53WOSIfz8x1v1yKToTkppA/ 9oVBfsn3UHWsnmHw+ZdnDJMzBasayeUTqhMZtMID3gzMeczgoAiKANL7Mdn8Oga/xzvy 2sJzYSnGYXGvqIhE+IPaCAH/gA1phwBD+o1clJND9amzHHnGuouWu7cn6GzDWejsrrHO crg23LLuEbsci4j2NC4EAsaztdYabcL7J41n5CgD5pieogwXyyfTblWSkGnfUaEqQ5UU AzzIxv10rFszoKtvUFEUdZx83g35nZVOTIzc6EsmHnYYFYjN89k4La94xn6MvXJGMGLj bqpg== 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-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-71892-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id 2-20020ac85942000000b0042c44e321d2si7853028qtz.206.2024.02.19.11.46.57 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 19 Feb 2024 11:46:57 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-71892-linux.lists.archive=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-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-71892-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 ny.mirrors.kernel.org (Postfix) with ESMTPS id 9AD801C21696 for ; Mon, 19 Feb 2024 19:46:57 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 68A8656B8F; Mon, 19 Feb 2024 19:44:46 +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 Content-Transfer-Encoding: 8bit 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); -- 2.39.2