From patchwork Mon Feb 19 19:44:14 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: SeongJae Park X-Patchwork-Id: 13563004 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 C1569C54764 for ; Mon, 19 Feb 2024 19:44:45 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id C16B46B0083; Mon, 19 Feb 2024 14:44:43 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id BC5DF6B0082; Mon, 19 Feb 2024 14:44:43 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id A189F6B0083; Mon, 19 Feb 2024 14:44:43 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id 8D09C6B0080 for ; Mon, 19 Feb 2024 14:44:43 -0500 (EST) Received: from smtpin22.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id 2AAB5120427 for ; Mon, 19 Feb 2024 19:44:43 +0000 (UTC) X-FDA: 81809580846.22.995DBE1 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by imf14.hostedemail.com (Postfix) with ESMTP id A33D9100013 for ; Mon, 19 Feb 2024 19:44:41 +0000 (UTC) Authentication-Results: imf14.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=JmCv8hem; spf=pass (imf14.hostedemail.com: domain of sj@kernel.org designates 139.178.84.217 as permitted sender) smtp.mailfrom=sj@kernel.org; dmarc=pass (policy=none) header.from=kernel.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1708371881; a=rsa-sha256; cv=none; b=xMpZvbPmAEntEUlrH4Ni0t7pU6vh6D0AvbB8HTaN8vjOuhi+Z4+QHJyDCQiFzEertcN2W3 arqj/FlntDg8abgSzK9GVU8irNM58nPJHZdP+IeKBAf964dMj6LurDGs1OdP/S7Y1Cq11V /BJovdhMGvnqinWXpHCgDBZ3tmjTYDs= ARC-Authentication-Results: i=1; imf14.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=JmCv8hem; spf=pass (imf14.hostedemail.com: domain of sj@kernel.org designates 139.178.84.217 as permitted sender) smtp.mailfrom=sj@kernel.org; dmarc=pass (policy=none) header.from=kernel.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1708371881; 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=ZUy4XggBW2XMmQvOyA0+ZUcd0/YU5UEv8j/aEi35guo=; b=uKZqo5zMlMjbmuQqeH5p1C6xozin9Bz2WNobtyx1EcFGOvZvzNusuE1u9q8e4tGW5HZLJo 3JlOUF7lZy8uC09iVE/oumYhLsgy4U2OHJrO7+kpUto1gENgn1dpk2qWvnt0ByTVEK6lxp NtrhBOpx1tVhgoy3XSTTfYucvxb49oM= Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by dfw.source.kernel.org (Postfix) with ESMTP id D3FB660F88; Mon, 19 Feb 2024 19:44:40 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 41180C433B2; Mon, 19 Feb 2024 19:44:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1708371880; bh=rzYXRY+0g/n7Kn4lIsgWKL7FZXy8S0J6qwcWKx/b2nA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=JmCv8hemCSNgYrpk0Ff5mzvIxAHJ3jIHrdLuTVvCYP2smFXiNdJFrxas2R7s6aMTD VXDPpBUJN1p9KGnKN2lVRQ/qZxTQqQbnmdTl45LhAcXXZnWRkT/PWxRl/Rn7EXbTlx tQg8ZSSuCxUKk8kMw17YYl0Tey2AkJGW2D6FtYmyx2TkXUvbs87nrMyKTfgLAUTq3m HJcMUTNmM7XsPbJ5dVn9ZbBde4zoPcfekCrT886UNpCuAjstpOzlo8qqbu1WS0bXmF Ho0ojO1mPVMNxv90T0GcCt6rjzs1y3XRdPEdSztpAHgGZ0bLTYY3rbpscgrkFAR+zj D+AhW7SDqDk2A== From: SeongJae Park To: Andrew Morton Cc: SeongJae Park , damon@lists.linux.dev, linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: [PATCH 03/20] mm/damon/sysfs: implement a kdamond command for updating schemes' effective quotas Date: Mon, 19 Feb 2024 11:44:14 -0800 Message-Id: <20240219194431.159606-4-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-Server: rspam08 X-Rspamd-Queue-Id: A33D9100013 X-Stat-Signature: ddfb6huo1wmgdouiee5n3koixrf76yyz X-Rspam-User: X-HE-Tag: 1708371881-326054 X-HE-Meta: U2FsdGVkX1++mI+6IU8PN+2Yr238L1741SdmfQ5z7pe/k+Tu/n8xF/J2+EmziN9vIOCtjSzWG8kIP5HgFq1l9raidig5UZ/X7D8gMxErhE74gAEvpj8M6geQ9Z+CGIIjGE2Y732ROOb9CovB3E9HQM+SwCSE6kPAvEv7MVEVZ/dMgjPsHA1IPBM7T7pf3lpx//9IjiuvSsAQtClV71HP73Ry52VUEZNh6qxoQFH7G+u1fR60rfM60r5tKK1qdwpRMZNtIG5MF6tFbJ0IB6BG4EXMUspxKMY8tM4HVUphGY6ZvIZS5xKTlhNFYeXHnRbtOujMPnOXiW9TBQ8j/wMXgROm3WwnCUBW9e8QYm4Xy19vwL210CdMT7mke/uP33LdFi0XOUBNg5ug2GNFIe8P2Pt/vVJpa2b/HI+LVTgbxbsrViSbutmiQeYFXjkxCnLaQn86mh7PFCkjaU8mGgoIu6i3f4Lj1Pwwh7btkEM2OjUpnnfiEL3bcos4qnJ7BxO2FiToOurd0hPX4smq6uEZhd3igTamw8FiwH2/m5RuVtAyTflZ8JKxoLqa6YippEDulBgWZIoWDsS4u/3Y2YqTU20gqgIXURDV7VszJSULQ9j+vwO30glzhARnZH6YEmsIAUdFe/ePxVatmI0I0k6wB51ec2PFmFT0dlO8jKxEBCsagQuH9Dvxj5JV+Zl4xVznsXukm/1wJge3tKar+Eh0Nlo84EQeW2n+rjBMz1hiK26bQBB+ElwLJctzyiGFOWdOnQPCBzvjILZfDMJwR50lcKYsliKfaWZV/NpSoiIPWr14/rBJ999aXyQxLD3Aa+HWHEufaFpK2rYib3s/iJzikfpKBOf8SUWSlUkdfef/Coi/It9YCqV07K5OcVxugJj9Jn3Bc9Zzx9YwnB5+nBPmqccs9C7ZvaKjMFRKCtyewk8= 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: Implement yet another kdamond 'state' file input command, namely 'update_schemes_effective_quotas'. If it is written, the 'effective_bytes' files of the kdamond will be updated to provide the current effective size quota of each scheme in bytes. Signed-off-by: SeongJae Park --- mm/damon/sysfs-common.h | 4 ++++ mm/damon/sysfs-schemes.c | 20 ++++++++++++++++++++ mm/damon/sysfs.c | 32 ++++++++++++++++++++++++++++++++ 3 files changed, 56 insertions(+) diff --git a/mm/damon/sysfs-common.h b/mm/damon/sysfs-common.h index ec0703e1e90b..5a1ac15fb2f8 100644 --- a/mm/damon/sysfs-common.h +++ b/mm/damon/sysfs-common.h @@ -61,3 +61,7 @@ int damon_sysfs_schemes_clear_regions( void damos_sysfs_set_quota_scores(struct damon_sysfs_schemes *sysfs_schemes, struct damon_ctx *ctx); + +void damos_sysfs_update_effective_quotas( + struct damon_sysfs_schemes *sysfs_schemes, + struct damon_ctx *ctx); diff --git a/mm/damon/sysfs-schemes.c b/mm/damon/sysfs-schemes.c index dd46b2db5455..9d90e7b757b7 100644 --- a/mm/damon/sysfs-schemes.c +++ b/mm/damon/sysfs-schemes.c @@ -1930,6 +1930,26 @@ void damos_sysfs_set_quota_scores(struct damon_sysfs_schemes *sysfs_schemes, } } +void damos_sysfs_update_effective_quotas( + struct damon_sysfs_schemes *sysfs_schemes, + struct damon_ctx *ctx) +{ + struct damos *scheme; + int schemes_idx = 0; + + damon_for_each_scheme(scheme, ctx) { + struct damon_sysfs_quotas *sysfs_quotas; + + /* user could have removed the scheme sysfs dir */ + if (schemes_idx >= sysfs_schemes->nr) + break; + + sysfs_quotas = + sysfs_schemes->schemes_arr[schemes_idx++]->quotas; + sysfs_quotas->effective_sz = scheme->quota.esz; + } +} + static struct damos *damon_sysfs_mk_scheme( struct damon_sysfs_scheme *sysfs_scheme) { diff --git a/mm/damon/sysfs.c b/mm/damon/sysfs.c index 678de97fcc88..cc2d88a901f4 100644 --- a/mm/damon/sysfs.c +++ b/mm/damon/sysfs.c @@ -1019,6 +1019,11 @@ enum damon_sysfs_cmd { * regions */ DAMON_SYSFS_CMD_CLEAR_SCHEMES_TRIED_REGIONS, + /* + * @DAMON_SYSFS_CMD_UPDATE_SCHEMES_EFFECTIVE_QUOTAS: Update the + * effective size quota of the scheme in bytes. + */ + DAMON_SYSFS_CMD_UPDATE_SCHEMES_EFFECTIVE_QUOTAS, /* * @NR_DAMON_SYSFS_CMDS: Total number of DAMON sysfs commands. */ @@ -1035,6 +1040,7 @@ static const char * const damon_sysfs_cmd_strs[] = { "update_schemes_tried_bytes", "update_schemes_tried_regions", "clear_schemes_tried_regions", + "update_schemes_effective_quotas", }; /* @@ -1375,6 +1381,29 @@ static int damon_sysfs_commit_schemes_quota_goals( return 0; } +/* + * damon_sysfs_upd_schemes_effective_quotas() - Update schemes effective quotas + * sysfs files. + * @kdamond: The kobject wrapper that associated to the kdamond thread. + * + * This function reads the schemes' effective quotas of specific kdamond and + * update the related values for sysfs files. This function should be called + * from DAMON callbacks while holding ``damon_syfs_lock``, to safely access the + * DAMON contexts-internal data and DAMON sysfs variables. + */ +static int damon_sysfs_upd_schemes_effective_quotas( + struct damon_sysfs_kdamond *kdamond) +{ + struct damon_ctx *ctx = kdamond->damon_ctx; + + if (!ctx) + return -EINVAL; + damos_sysfs_update_effective_quotas( + kdamond->contexts->contexts_arr[0]->schemes, ctx); + return 0; +} + + /* * damon_sysfs_cmd_request_callback() - DAMON callback for handling requests. * @c: The DAMON context of the callback. @@ -1437,6 +1466,9 @@ static int damon_sysfs_cmd_request_callback(struct damon_ctx *c, bool active, case DAMON_SYSFS_CMD_CLEAR_SCHEMES_TRIED_REGIONS: err = damon_sysfs_clear_schemes_regions(kdamond); break; + case DAMON_SYSFS_CMD_UPDATE_SCHEMES_EFFECTIVE_QUOTAS: + err = damon_sysfs_upd_schemes_effective_quotas(kdamond); + break; default: break; }