From patchwork Fri Dec 13 21:53:01 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: SeongJae Park X-Patchwork-Id: 13907893 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 5174CE7717F for ; Fri, 13 Dec 2024 21:53:28 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id EC7C16B008C; Fri, 13 Dec 2024 16:53:24 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id E268D6B0092; Fri, 13 Dec 2024 16:53:24 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id C2D2E6B0093; Fri, 13 Dec 2024 16:53:24 -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 9DC146B008C for ; Fri, 13 Dec 2024 16:53:24 -0500 (EST) Received: from smtpin29.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id 3549FC0385 for ; Fri, 13 Dec 2024 21:53:24 +0000 (UTC) X-FDA: 82891287276.29.82DA8AA Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by imf25.hostedemail.com (Postfix) with ESMTP id C7E91A0009 for ; Fri, 13 Dec 2024 21:53:03 +0000 (UTC) Authentication-Results: imf25.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=CK3ykhyp; spf=pass (imf25.hostedemail.com: domain of sj@kernel.org designates 139.178.84.217 as permitted sender) smtp.mailfrom=sj@kernel.org; dmarc=pass (policy=quarantine) header.from=kernel.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1734126782; 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=/04TDwo1b2NocLqJBWjPKZePy9m5IlYZ2rcdTTslWRs=; b=U6aZbwmYMkG4g40Q9/z9pN7mU5cdXmQ2Uf1i2YQ+lPa7QSCbkKJivOHt7spMgrgyB2Hu/j lJ2/gfxR4MmIleb2lAUDvSzvSmhyZInCCFIIuUjgBvC0exs737BYkzx8sApFpKe2czF9h6 KLg/u9UyvCeOjZbBm0nVLI4mXAwCdMI= ARC-Authentication-Results: i=1; imf25.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=CK3ykhyp; spf=pass (imf25.hostedemail.com: domain of sj@kernel.org designates 139.178.84.217 as permitted sender) smtp.mailfrom=sj@kernel.org; dmarc=pass (policy=quarantine) header.from=kernel.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1734126782; a=rsa-sha256; cv=none; b=t4Tg2Pjinnm4Nj5zpIFcl3bM5ZBl6LqGA25OcygIkM18YvdcJxTV6c6dG2uoAGCcdbTYah tkzUzYiVpLO1n1Ojpm2/0O7aOc2H2FlNISVRJ93Pi5HaJBeuscVsHeRwp9etgJmDWnd8XN gHCXKMiKeqplWRzmUdfRnf14C0QKfPo= Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by dfw.source.kernel.org (Postfix) with ESMTP id 43AAB5C69B0 for ; Fri, 13 Dec 2024 21:52:39 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id D330AC4CED0; Fri, 13 Dec 2024 21:53:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1734126801; bh=yGKlblsUzxnMA0YCWYFB2DujgbVF+67M4pYSvqkOPCU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=CK3ykhyp/Jp3ORy0ACMRS8jA23yGFl2KYbBgQQu/8F5MazUNFhMQm200EQUyH+G9d uPIc2wL6UrU9abFd4v0sbGQYhQiy4u0iiUePXYgF4yr2Tb5rIZCdytcj31l0yhgjrz 7Gk5+LUUBlj8sa6LoWDxHUR/2eV+8jp73thX8tlPfaTcMyaEyTh6HEw9sWezw5NNXa 6TQsHIIvVaALG835aoLSEINpEWnKvbgWwaMsO5J+7kqAUEo387KfSxC7ebQ2q3GcAX 2kKStFtgtvuPQeUCT8XacA35Iu9+tW1VPhpAI1HRky4XCFmsRdjtgo3Auq13PXdIam TlQULl+TbYLmw== From: SeongJae Park To: Cc: SeongJae Park , damon@lists.linux.dev, linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: [RFC PATCH 4/9] mm/damon/sysfs: use damon_call() for update_schemes_stats Date: Fri, 13 Dec 2024 13:53:01 -0800 Message-Id: <20241213215306.54778-5-sj@kernel.org> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20241213215306.54778-1-sj@kernel.org> References: <20241213215306.54778-1-sj@kernel.org> MIME-Version: 1.0 X-Rspamd-Queue-Id: C7E91A0009 X-Rspamd-Server: rspam12 X-Stat-Signature: uk331tk3gmchyqiskj3yw3x9h449194n X-Rspam-User: X-HE-Tag: 1734126783-92137 X-HE-Meta: U2FsdGVkX1+Btl5vXhQrzm5Dbqvg0Rltq2hUm2LadgDk7Nv1bPZuhGoGRUw6gHDEEMSEjBvXYLO8w+IrzFUhG9wOa7VTIyCdydZI5qILA9D0SycBTFWZ4pYIv9y13IGxYOiSMSg4+kSSKVx7tuwKkqnRPMmJV4QDyTxZ/7sLoFHyIyMtPYbzGk6+K0THPrVjbt26A1xITuiADwpT8vE9efT5THOanyUVc3kwCQzKscAztbEcCok2KAaH6XV9iXWUF2At3DDfSkoDz5LJLfNn4dI1JS+G9I5+dA+3lTok2dkacvCle2GuNFgioF6g63fTE17Kd7usgz96HV3C+7d2wZM4qP6cumOweRtNdwhr5KduBXAl/nqNx3dka34+K9hbntsJwHIrVAu/X8oVV2En4JZD0ebo9loGX1gMftZedrPG/oa0WlHScMDRQmKwZV+D5C7/CdyuMf0O+02jHhuqzmBTQg7lD4pMv4WAOENuhQz13ZD4K/jAUmeZ8J3vCx0Qf3vBdIk6Xxa3HJT39cxjL68IGgEhif3OFHR5thUZFz4aXSbKL8S50SimFBBv4Xp3b9ODbK4U4ll6YzxcBxn/eKsqb2SGpfssUjKNEPKDNijIs0BBSV69ek2Bj2s1Gzm3J0mQ6Ilow7ucEg69m9TKQQ6yRzal/RYiVjbeDWeo8Yq+bFkwmz/2UjLWCaOJbjhQYQ8TGINTZ9g9mUq96s0tesXvvz2o/KWF889HQlG+UOrpCz3QiRh3av2HOdwNK6jHFwM32x3rS5wT9xj4o8vZVmFNp8VcC1na/qlEcFszZA7M5xttp/P76mEjBX/8rUtwOi9yQrcl1ZI+vvjwYmjRLnyeuzFWGGZVt0XxbXh7pJ8zm560jpl+m6D66BhNfv40hC8fCf4hqVw/epY2uE5G9AkKdmXKopAzsmKCap+MB18kmp4nNIXo9eN+uCg8YvdmTziHhQ+yKwPe4YF93sS Ryb2J59m NzGmPyFfaJ/qRjNa+NQTnZHJao86BGb9mvJmajRs0Rqi/15JSfsWmbbm37IA6C+wptwoEPb6QFqc2VIQuX717fc9jyu6xT8tmT757pjL/M1JmWRH865JIA8PClrZkYWGJwS7trahbmvzaNBsenUdmx3UufO0PCs+NUgpiMv02DxMUOtK2GdyYVWWpE+v66+us/eZKkVjSHhAF3DKyACXwMHw4VmleS8rkyhMQeQxnxEmbYiiaYlFCNrsGZYO1Lf5JzoqRXV90r3IBv4PeDrIdjy9I7Dmfd9uXOyG0WtmWwUUvgfLHVT5Dl6ptBhuE7eTnjU89GSOHyXav6xb6SctYsXq6Q2UOQUC10Jzw 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 uses damon_callback with its own synchronization facility to handle update_schemes_stats kdamond command. But damon_call() can support the use case without the additional synchronizations. Convert the code to use damon_call() instead. Signed-off-by: SeongJae Park --- mm/damon/sysfs.c | 31 +++++++++++++++++++++---------- 1 file changed, 21 insertions(+), 10 deletions(-) diff --git a/mm/damon/sysfs.c b/mm/damon/sysfs.c index 8cb940d21fbe..d30d659c794e 100644 --- a/mm/damon/sysfs.c +++ b/mm/damon/sysfs.c @@ -1214,19 +1214,19 @@ static void damon_sysfs_before_terminate(struct damon_ctx *ctx) /* * damon_sysfs_upd_schemes_stats() - Update schemes stats sysfs files. - * @kdamond: The kobject wrapper that associated to the kdamond thread. + * @data: The kobject wrapper that associated to the kdamond thread. * * This function reads the schemes stats 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. + * worker thread,to safely access the DAMON contexts-internal data. Caller + * should also ensure holding ``damon_syfs_lock``, and ->damon_ctx of @data is + * not NULL but a valid pointer, to safely access DAMON sysfs variables. */ -static int damon_sysfs_upd_schemes_stats(struct damon_sysfs_kdamond *kdamond) +static int damon_sysfs_upd_schemes_stats(void *data) { + struct damon_sysfs_kdamond *kdamond = data; struct damon_ctx *ctx = kdamond->damon_ctx; - if (!ctx) - return -EINVAL; damon_sysfs_schemes_update_stats( kdamond->contexts->contexts_arr[0]->schemes, ctx); return 0; @@ -1371,9 +1371,6 @@ static int damon_sysfs_cmd_request_callback(struct damon_ctx *c, bool active, if (!kdamond || kdamond->damon_ctx != c) goto out; switch (damon_sysfs_cmd_request.cmd) { - case DAMON_SYSFS_CMD_UPDATE_SCHEMES_STATS: - err = damon_sysfs_upd_schemes_stats(kdamond); - break; case DAMON_SYSFS_CMD_COMMIT: if (!after_aggregation) goto out; @@ -1511,6 +1508,18 @@ static int damon_sysfs_turn_damon_off(struct damon_sysfs_kdamond *kdamond) */ } +static int damon_sysfs_damon_call(int (*fn)(void *data), + struct damon_sysfs_kdamond *kdamond) +{ + struct damon_call_control call_control = {}; + + if (!kdamond->damon_ctx) + return -EINVAL; + call_control.fn = fn; + call_control.data = kdamond; + return damon_call(kdamond->damon_ctx, &call_control); +} + /* * damon_sysfs_handle_cmd() - Handle a command for a specific kdamond. * @cmd: The command to handle. @@ -1529,12 +1538,14 @@ static int damon_sysfs_handle_cmd(enum damon_sysfs_cmd cmd, { bool need_wait = true; - /* Handle commands that doesn't access DAMON context-internal data */ switch (cmd) { case DAMON_SYSFS_CMD_ON: return damon_sysfs_turn_damon_on(kdamond); case DAMON_SYSFS_CMD_OFF: return damon_sysfs_turn_damon_off(kdamond); + case DAMON_SYSFS_CMD_UPDATE_SCHEMES_STATS: + return damon_sysfs_damon_call( + damon_sysfs_upd_schemes_stats, kdamond); case DAMON_SYSFS_CMD_CLEAR_SCHEMES_TRIED_REGIONS: return damon_sysfs_schemes_clear_regions( kdamond->contexts->contexts_arr[0]->schemes);