From patchwork Fri Jan 3 17:43:54 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: SeongJae Park X-Patchwork-Id: 13925762 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 C43A9E7718F for ; Fri, 3 Jan 2025 17:44:23 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id AC0756B008A; Fri, 3 Jan 2025 12:44:18 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id A70A16B0093; Fri, 3 Jan 2025 12:44:18 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 8C4FC6B0096; Fri, 3 Jan 2025 12:44:18 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id 659FA6B008A for ; Fri, 3 Jan 2025 12:44:18 -0500 (EST) Received: from smtpin02.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id 043821C7547 for ; Fri, 3 Jan 2025 17:44:17 +0000 (UTC) X-FDA: 82966864008.02.E4A47CD Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by imf11.hostedemail.com (Postfix) with ESMTP id 9FFDA40006 for ; Fri, 3 Jan 2025 17:43:28 +0000 (UTC) Authentication-Results: imf11.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=meBCKp87; spf=pass (imf11.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=1735926232; 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=l9TVS+GjcRY+D/2EpqrxBOIwsbqRiDbRwAFaf214GqQ=; b=6SvNBtzcSrtlCukZmuw18lHmm5FkKdwxgSbe2KSsIZnQpopai/vuC8S1Bj1Vp316jD7cQL m/mfEckaWAAtPouxL5quQadUWlRvYNbn3qmVCpksYX6QzkYn0MInv/r/PyFe5gXxhZxbRX H3zM4sVROMmU+9+rttCg8qihPkHgitI= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1735926232; a=rsa-sha256; cv=none; b=aBsKaHs4Ln5opl8oS6CKywBFdb46CCaeB2AEDgiV/zsZvrmIrlF30P+IXBFmIv2j7TPsRQ qODrrb6jAuCIxHzRHKg6OZW9xJKLpMUOacGuyPPTX0J8pncvGjhjtjeLs1S2Jj8I3en6Gn IRRXzb0suUI7gVIZ1QjB7KZOeT1GKPE= ARC-Authentication-Results: i=1; imf11.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=meBCKp87; spf=pass (imf11.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 Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by dfw.source.kernel.org (Postfix) with ESMTP id 5EBA65C6511; Fri, 3 Jan 2025 17:43:34 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 398B4C4CECE; Fri, 3 Jan 2025 17:44:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1735926255; bh=qk6ZdrhnjRXiXYePVN+xCb4IJkjveXFxA9K3vfVDUfI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=meBCKp87S8/jHRYo5pQv+UDGhWfNwcohyxDM33g3BrH0kRpqtKeAQB6pwOZGWNi96 PCGQJtL+kLXigtPuZPe/SmkC0tegfZAUxAZwsTPcqxLlgDB1EI45ZywZ6UH4y1PNLA brIbs5cNZHaTqccz77K++7sgaG6V8tSVZVuvo/7PFSiqjMRuTK1/QLeTzG0Qkkakch erXOL67rWcHV+OxAt5MIhi0Pvd1KUl153p6oA6SMwqrgffeD06+TglZXpSrV6iQD0T PZLyGcQUPBUJA8UWKfdb1WibxX3jO6mNCtHrXQ+mvUQf6+FnP66xfX8nsRO0UZfbNZ nVk9GaWjLWkFg== From: SeongJae Park To: Andrew Morton Cc: SeongJae Park , damon@lists.linux.dev, linux-kernel@vger.kernel.org, linux-mm@kvack.org Subject: [PATCH 04/10] mm/damon/sysfs: use damon_call() for update_schemes_stats Date: Fri, 3 Jan 2025 09:43:54 -0800 Message-Id: <20250103174400.54890-5-sj@kernel.org> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20250103174400.54890-1-sj@kernel.org> References: <20250103174400.54890-1-sj@kernel.org> MIME-Version: 1.0 X-Rspamd-Server: rspam10 X-Rspamd-Queue-Id: 9FFDA40006 X-Stat-Signature: qqnbxjujdu6kg69qz9owi7mwk4syp3jd X-Rspam-User: X-HE-Tag: 1735926208-82538 X-HE-Meta: U2FsdGVkX1+dRTl/7uxUI4QmJLftaGEB45ucgCvFnOin/b5wfw7jDfxlYMWzIic+ritaoVL8PHbEWIlcZqBBu9FVk2it/Vdaw/4EGPf7MfFeastcZPgX9K5doYkxS/K2VCG1vvFwMcTjkihaq6EBH6S8uax7XAbh3yG9m5x+wlpjDTS3timRWGgd7bVPfvJUaPtQA0wajqRwLfMX3ae2wGtnP45pApizq8wyivKKZ5QLy+810e1uc7F1YbSoLIkzvXFgu5jZxQQikeeFHtUloeHOmXbOJKP7EqlUGQXUyCYxZy8u9uq12w+UjhxQprYdjsxFEYwIxa+Y+74OFc2Q1niV4N2ielIy9d1KR1nj+6Qv4DyYYhxtagrtDytmYhHRvLPPNhmUVPYt7TurrV+3oQS+2TjYLAXzfiGSsASqjqD2Tk8PiHkAXOD3BIpoXtcWqZZRsGO2bvm2lKJC7axt80+6VnEWCQe9CdWwqSjbj7WfbvBLh65vvPb+qZoXPRG5lXPbRymF6640otXA3up3LfeAUnODePi+GOgRdDCu6siWOTO7CNSwPc0aMjljrsDb2Q+sgf9pBi7n7ta2SJyy12BfBv56vtsz1m/dx7qd39AZ1EMcR0haACF0O8TjgQRIaxGdIO3yX8sBF1+Ot/oun9TStPab+kgbO3HDAwlhu7lTbuCQQmS9oZhXCP0jPkkWMzoBt0aHQfvZImtpK3dMkI5DP6rwkr/hNnOg8BMfFKB5FA1gLGpDPUStMXRnSfq9Ujyksb7qRg4W1y8A4ZCJQ4U4C5HYaD2rhrhowE1fBFEvajmTtan31lN7Sf0BhRmAoNq4bduwM6+USEcaj3yjIjQx4ftXW87OheIiirAIxXBkpUOHmXKqGbz+S8RUuu/8Ast4fuq5jCikzqOBgMsS9+xgiMlyfqroUco+7LG2xr4ktFudpZ6PQvzQZfCQEdzzox9NmR9382+Ek586yoH WAdN1Hpo aXtX0aLtp6AMeZgECr3hl/ZMid6+wuh5ngUNqn3Pk6Gx1lbrfAYhDz/eqoNCkBYoynPs+TPLAVgKSjfMTDLJh0ULrAHpobeZfDqpkgp/Wx47FNUIRdZ1qfGopEbkDP2Z+aJEYUjvLjMJTa4kELc1sPcTLkkYKaLjqXxAIhRaOiEbsy72NliBwtM/l3N8okMv5LCoN9VMRW2vzIKEtlkEYihMEE6qFxGlrbWclqbsU32BX2fEWq6c95sujmSIjs7g4tXoV7ocHYzez+jgN3CzzCpObcw== 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 4f6e4720b7ce..708c2ffdd620 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);