From patchwork Fri Jan 3 17:43:51 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: SeongJae Park X-Patchwork-Id: 13925759 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 B0172E77198 for ; Fri, 3 Jan 2025 17:44:15 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 397DF6B0089; Fri, 3 Jan 2025 12:44:15 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 31FB86B008A; Fri, 3 Jan 2025 12:44:15 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 170686B008C; Fri, 3 Jan 2025 12:44:15 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id E8D4F6B0089 for ; Fri, 3 Jan 2025 12:44:14 -0500 (EST) Received: from smtpin02.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id 99EF2AF1BC for ; Fri, 3 Jan 2025 17:44:14 +0000 (UTC) X-FDA: 82966863840.02.DBA209B Received: from nyc.source.kernel.org (nyc.source.kernel.org [147.75.193.91]) by imf13.hostedemail.com (Postfix) with ESMTP id 6DCF620003 for ; Fri, 3 Jan 2025 17:43:23 +0000 (UTC) Authentication-Results: imf13.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=sACGoN3o; spf=pass (imf13.hostedemail.com: domain of sj@kernel.org designates 147.75.193.91 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=1735926229; 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=LNNRZq/CQjbjTg9t40byF6vnqdAcU0+VlF0yPnlDnHw=; b=E3Gb5hj8TJfyH56MJY8/LQ1eq+Msp/8ICO5eM6KREVs5NXJI/9lCc8kn20lmr0uScvWUrB 3JxJSXNjSWkvwdGSbuNNWkxlyVpIg1rpQnDMT/qKQwGCUfRnDTZsr+Wuhsb0lU9umHD+GB s71aq8+ehRv9j4ql/U3poddfljumB6s= ARC-Authentication-Results: i=1; imf13.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=sACGoN3o; spf=pass (imf13.hostedemail.com: domain of sj@kernel.org designates 147.75.193.91 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=1735926229; a=rsa-sha256; cv=none; b=W3ad0Nj4At9lRcB9S18kJWcPrWBE/kf0AGTjuV6U5RYCYGplEcnaXCdcAfEH7W1eBf+e5v iYuMrX6XXJLVIRdWQjNWa6ghDldzC7vPjbSOgSFSQoeDatjVSn2ZTPq2PzInNaiNV0okP3 NBs4+0Nd3xeBUylGdMMrrciNlULUnas= Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by nyc.source.kernel.org (Postfix) with ESMTP id 3D6C3A41033; Fri, 3 Jan 2025 17:42:23 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id E0C5FC4CECE; Fri, 3 Jan 2025 17:44:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1735926252; bh=KNH5L0vNE8h71jgUkE2/vzFAwU/o8fScb4koo5cYPcs=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=sACGoN3oL+qwmja5AyRlGWax/gmJ7baYZ8musT1+Y6A1MPgca3vfNzf8XXzRkSMjH hCw1QsDoq6drVuV/DXW1R4bcC2ob9088NIgVmHq/uVIWuTXByszHUxOOorTko7oxwq THKL+O/rRfBi7xwcWLj9Ma3GxkX1WF/5keErrkRGRDj/WXF9yCSK4aw6O4ue0vhdfb 61w1MUczMR4N4G8Lbj2vJfik7dAXNW/6/QC+aAEGO46FCdGGxyxmQZbbEsWZZKMVkN DRk+oi3J5OiklmLjWBta2DEYurJHYKkOVn5YdoH4hE4BC9Y0Kn10jgfvcasKDQYoIE ah8Aa2FfMtn+A== From: SeongJae Park To: Andrew Morton Cc: SeongJae Park , damon@lists.linux.dev, linux-kernel@vger.kernel.org, linux-mm@kvack.org Subject: [PATCH 01/10] mm/damon/sysfs-schemes: remove unnecessary schemes existence check in damon_sysfs_schemes_clear_regions() Date: Fri, 3 Jan 2025 09:43:51 -0800 Message-Id: <20250103174400.54890-2-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-Queue-Id: 6DCF620003 X-Stat-Signature: 16b4x6pc5et7sebe5ckap1iyc735jhsr X-Rspam-User: X-Rspamd-Server: rspam11 X-HE-Tag: 1735926203-384347 X-HE-Meta: U2FsdGVkX18fJY4FtXgKdOpopkZLwPKZ4aABjTja/4Fb6B125tXT6plvQpebynsWR36W42VJE7jMMhYWEX0cyMLjYj3ik9zsS4zOxPsusv9h+D+ovxXLlvonTu2uM0kq9CgDJ/tsIumIG0cz8tmg75mx5/gOzjkD9Og7zY8wlr0vEOKOpwruTZeQ3KSOGmkvP2XlKK4kw1rkrUAGACSBTrM/S5zFexRY6TofCP9am+aXY1kDQpyx+kZwsCewzwwqwiGsXcRVjC9zvHc5W/D6LF9W9aBFmZb7P8x5Kr9wLLFPZnv01aSF7rqh2W1ML1BOT9Oidnrjtlc8lwZVCEp61wLF5aTRikwo8GxEmQn9iCf0RWBEXfrQK/KN053kADmPFHAZbuUzVo+wnOheb2GRKjtj1Ao/BAKUH1W/a8Ae+Yhs0zF9afCZyX67l4yvQekJw8VHIWh4nH5ubrq+pH8IIJ3YDNXQLUM9RtfRDYASdcrZZl+DOuSkoTWERgcPz82BGVoGU7UK65olQqbCXgA6B5rJx24MAzW+3DrY3dgEP9TEo1tspAUUYVOxk+ZigYoRoEy8ABZ9napjPVrRGDrE+Fp0vhj43g0umabew6MyHlgTMoUcUWWXvgqXCISaLA537NfHWsRvLqyCDGvJDg1lAq3SDeUXOkZZpaoYRB8dnjZiIokXtAaCwFF8PKYBRsGEUH4FdmZJ8pfg3RGxVIUEL67BTThNjo5I6YWHiwWjFvCJ2vDFkTSMlK6sEHf+arRdTa/wO6COcqkFg3orlfJhd8mZvOcmtLhaR+QYKUrCYPJby72d32NTxNqdG2OPpaCGTa/1Ib47AIFNah6MmevluCN3TL63bZvkGbOa2hd5wryL67Hq9PkqWemkHzWaVC1gSXaYl4RkeZr8HCAEDozjlBPq/qe9cxtFfBPi0Pe5hwUQ80bS44u8pPz6+pOZNetJLtzXmH0cnrsq0q8aUgd VtKEasCh m7nu+OjBx5xu2IFLLg4lm7t66BDOGsw87IkndJ2xfesXhNDCQv5GRf5G72CNiuF/E2hzlqHkzIGnYaBVXT75c+1zhLlADHhBmyXyQ7zF2/Cv6Z+ouoyRDlYQW3GsLJu6urf+BoAm4WU/GUUBmEwBml8T5+IgQhpEnx7iYGHqiA6E8Ww9F/K6fLNbPGri0vKPv/97lqVEevTvm7/qOc3euAV8+UBYbMsVD5nrFdgKNX4uDZtS/g2/mzUCldBFn+uXbbGTsZ47vhi6V8uPP3nMt9+NPtg== 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_schemes_clear_regions() skips removing the scheme tried region directories only if the matching scheme is still ongoing. It is unnecessary check, since what users want is just removing the entire region directories. Remove the unnecessary check. Signed-off-by: SeongJae Park --- mm/damon/sysfs-common.h | 3 +-- mm/damon/sysfs-schemes.c | 16 +++++----------- mm/damon/sysfs.c | 2 +- 3 files changed, 7 insertions(+), 14 deletions(-) diff --git a/mm/damon/sysfs-common.h b/mm/damon/sysfs-common.h index 9a18f3c535d3..e79b4a65ff2d 100644 --- a/mm/damon/sysfs-common.h +++ b/mm/damon/sysfs-common.h @@ -56,8 +56,7 @@ bool damos_sysfs_regions_upd_done(void); int damon_sysfs_schemes_update_regions_stop(struct damon_ctx *ctx); int damon_sysfs_schemes_clear_regions( - struct damon_sysfs_schemes *sysfs_schemes, - struct damon_ctx *ctx); + struct damon_sysfs_schemes *sysfs_schemes); int damos_sysfs_set_quota_scores(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 b095457380b5..2aa34778a472 100644 --- a/mm/damon/sysfs-schemes.c +++ b/mm/damon/sysfs-schemes.c @@ -2208,20 +2208,14 @@ void damos_sysfs_mark_finished_regions_updates(struct damon_ctx *ctx) /* Called from damon_sysfs_cmd_request_callback under damon_sysfs_lock */ int damon_sysfs_schemes_clear_regions( - struct damon_sysfs_schemes *sysfs_schemes, - struct damon_ctx *ctx) + struct damon_sysfs_schemes *sysfs_schemes) { - struct damos *scheme; - int schemes_idx = 0; + int i; - damon_for_each_scheme(scheme, ctx) { + for (i = 0; i < sysfs_schemes->nr; i++) { struct damon_sysfs_scheme *sysfs_scheme; - /* user could have removed the scheme sysfs dir */ - if (schemes_idx >= sysfs_schemes->nr) - break; - - sysfs_scheme = sysfs_schemes->schemes_arr[schemes_idx++]; + sysfs_scheme = sysfs_schemes->schemes_arr[i]; damon_sysfs_scheme_regions_rm_dirs( sysfs_scheme->tried_regions); sysfs_scheme->tried_regions->total_bytes = 0; @@ -2271,7 +2265,7 @@ int damon_sysfs_schemes_update_regions_start( struct damon_sysfs_schemes *sysfs_schemes, struct damon_ctx *ctx, bool total_bytes_only) { - damon_sysfs_schemes_clear_regions(sysfs_schemes, ctx); + damon_sysfs_schemes_clear_regions(sysfs_schemes); damon_sysfs_schemes_for_damos_callback = sysfs_schemes; damos_tried_regions_init_upd_status(sysfs_schemes, ctx); damos_regions_upd_total_bytes_only = total_bytes_only; diff --git a/mm/damon/sysfs.c b/mm/damon/sysfs.c index 58145d59881d..789804986ab0 100644 --- a/mm/damon/sysfs.c +++ b/mm/damon/sysfs.c @@ -1262,7 +1262,7 @@ static int damon_sysfs_clear_schemes_regions( if (!ctx) return -EINVAL; return damon_sysfs_schemes_clear_regions( - kdamond->contexts->contexts_arr[0]->schemes, ctx); + kdamond->contexts->contexts_arr[0]->schemes); } static inline bool damon_sysfs_kdamond_running( From patchwork Fri Jan 3 17:43:52 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: SeongJae Park X-Patchwork-Id: 13925760 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 2795BE7718F for ; Fri, 3 Jan 2025 17:44:18 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id F388B6B0092; Fri, 3 Jan 2025 12:44:16 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id E9B6A6B0095; Fri, 3 Jan 2025 12:44:16 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id D08706B0093; Fri, 3 Jan 2025 12:44:16 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id AF93A6B008A for ; Fri, 3 Jan 2025 12:44:16 -0500 (EST) Received: from smtpin09.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id 44A381A09A7 for ; Fri, 3 Jan 2025 17:44:16 +0000 (UTC) X-FDA: 82966861404.09.3D5F349 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by imf12.hostedemail.com (Postfix) with ESMTP id E15074000A for ; Fri, 3 Jan 2025 17:43:51 +0000 (UTC) Authentication-Results: imf12.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=O4ZPHopH; spf=pass (imf12.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=1735926220; 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=NJSEx9sqExV0Q9XAsWwBYyBa02O5mB6esQHMn2+b3M0=; b=JcKgDKywY32bDw5ltNHVrLrjhumZ1aELcXoDI0FAK2iTn6uJsAmjX8b39yJA0qgekp53Mp eydaQijCbLRFtTytkHo5i30x9YIR6wDNmpOKKdZF+KqFJco+LrZtV7ZwDBikv+N4Dy7a5p UHwwy7J1RO5tE9Tqlnh+goOLZmRvs4Y= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1735926220; a=rsa-sha256; cv=none; b=WghCWmwI698K9whkMhbJPMD2YjysrrsLSbi/Wqm2srMnNXo9v5n7X03pdiVORofEfTo8ya pyg2smmNr3xL/sLTPaVQvlRvxOhKGhsPMLPmmhkkebqNoMFQ8CVE5a+fosp3TbvAGVEQdZ tsFZPXoPfXomjJFYQ5VoYoG0jcXD28Q= ARC-Authentication-Results: i=1; imf12.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=O4ZPHopH; spf=pass (imf12.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 371DC5C650A; Fri, 3 Jan 2025 17:43:32 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 02C2CC4CED6; Fri, 3 Jan 2025 17:44:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1735926253; bh=HDW7FthU1uRvJZ3MkhWqZ07vrMNtcqEXeZfp37Ljvk0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=O4ZPHopHQ4zwcT/ioK5B4zxE+LQ9Jblr6ZzjHB8UoIGpZkpSGE40nGqMLk/0MtGNv QSwWX1u63oc08L37F/G7LjqtBKn/UOv0mxeVv+5G4apc+W5noR+RcRNrwCE4GaLfCk TsmYIJlW5tnIZ2ugEFATGMPQffvTm/7jhZMVJXJ6iwnk/0PLFOP//qcXQlzt1dlwvI 6NC2FP1Dx7CYJNq+IQ4Sv+TD6AohzmbZtczclEbxyDJAPRVzzcqts6Il/yQ30ifkyx KJo3F0lyuXFp/lQ8TtuvDhBPby8BNLqvL1Ginb1s6ZdS82tUuNpRn8HHHBF6/zuh46 AO7OUX81CjKGQ== From: SeongJae Park To: Andrew Morton Cc: SeongJae Park , damon@lists.linux.dev, linux-kernel@vger.kernel.org, linux-mm@kvack.org Subject: [PATCH 02/10] mm/damon/sysfs: handle clear_schemes_tried_regions from DAMON sysfs context Date: Fri, 3 Jan 2025 09:43:52 -0800 Message-Id: <20250103174400.54890-3-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: rspam02 X-Rspamd-Queue-Id: E15074000A X-Stat-Signature: qqbmjzbd57dm431dcd9e5bpbs9csbs5q X-Rspam-User: X-HE-Tag: 1735926231-170213 X-HE-Meta: U2FsdGVkX1+HguFtF2Fh+PyrxLsjh4Au74S6VUP0PYLna2beJKFhjnYZpBff7bOmCKjiUAOvbkBp+feXIs8WZt0zU5DP2beQkmbIgjwZTJF+7zjX+uXxDcjHRzjPDAVDZyGFpaMCfxe80+5/3DZuNRdFPaDk5IFD4g/NgqY6mDcyP7ZlbjPA2LgS7LW8kaH1jbGRI2GLTG2cNEa9QiEKJwk7PYZkFFqr7sW7vVHTDcJaN78W6Hf4YGSvrc1k8YB6KjeZbF9lpBZyniHffpdgZT2vboqzvDnjLAYLaTxkrQT/xms6qREvRw2YaJfZ1waCGPZ4L5ckHbc9VG++C5XjOW6H/FG3FqcyXeEKyd0JaRZzrMf3w+cmSNIdzwdDf90qzaNWw+k77r8mUVGoIpvQHDnPw7+Gew1dBTAOihiWETYlqKPVItmWbqNODtbHDFUv1q405SdXbmWHF6jX2yXeCk4qsWamV4OoOyeKeFO6COuYgDYJCW4gRuztjRZ6S7ac9O6Xng/kGzRe35jCLiDvnJUbcD1R/fwErGld81kSXGi/nUiynTxW6sYke6DMMGcmzDvqxjaGyIX7laDYgtE+6nXXBsHHXYFzZJLqqYnzxwrcqHZZWED71CFdOXow2GkTLeO7Wz5yedKWW9xA8tHj1P0GjjsBZk6RtC+vAhYdzS19DscRDDEYJZwyXSeL8/sY0QNge3mHuGKcrejJXcZtQ94/RYFriqV6eJrv+hwnHWOB314UvbbfIfyqkArhia3dLsFrXZNuamdcJktTIJn/GVRDG7Jv7ImGlr7VhoSLVBHyL8jp9Y56I5SjcyJoSDoG5NNIcPnmVdp2MLbw9LooJw4EZuqXGcTDnypomSZpcwrbdEj2USY+efRjna/Ux41A2zfun19q2fCuPumDbxBFVKbokUT77qlzx1dw2BrMxLmUgfn8Co54X00yVD7EJtBigJELbu+UKqzNm3T/U4a czodwBGX KCsirMIciSNKa9WFowHxsF8wWAjdBfco88sGhikmXv2YtyaLrqeHnlFJsy31QP9j+ylNayGS0cRMP0cD9p8KEzY4k21YC25x5646HoSPKQrif1fZwew54JgIPmPiqXDdVhhNmO4gh1H2i7jOuwGfXeBkYel3B/mWz0YIUFAycRZ4TTodeXtBm1UvK4AwcTYsyxAJBSCGSomLcmhbl72iMEUA7fga2eTZvx/fJ2eXoVuCG0HhfGm4IBJJz13z9+ozJMr8TTc+wpbT5wKwpyz6EvVURqg== 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 handles clear_schemes_tried_regions request from the DAMON callback context (damon_sysfs_cmd_request_callback()), which is designed to be used for safe access to the related DAMON context internal data. But no DAMON context internal data is accessed for the work. Directly handle it from DAMON sysfs interface context, namely damon_sysfs_handle_cmd(). Signed-off-by: SeongJae Park --- mm/damon/sysfs-schemes.c | 2 +- mm/damon/sysfs.c | 17 +++-------------- 2 files changed, 4 insertions(+), 15 deletions(-) diff --git a/mm/damon/sysfs-schemes.c b/mm/damon/sysfs-schemes.c index 2aa34778a472..c57ab47686ff 100644 --- a/mm/damon/sysfs-schemes.c +++ b/mm/damon/sysfs-schemes.c @@ -2260,7 +2260,7 @@ static void damos_tried_regions_init_upd_status( } } -/* Called from damon_sysfs_cmd_request_callback under damon_sysfs_lock */ +/* Called while damon_sysfs_lock is hold */ int damon_sysfs_schemes_update_regions_start( struct damon_sysfs_schemes *sysfs_schemes, struct damon_ctx *ctx, bool total_bytes_only) diff --git a/mm/damon/sysfs.c b/mm/damon/sysfs.c index 789804986ab0..4f6e4720b7ce 100644 --- a/mm/damon/sysfs.c +++ b/mm/damon/sysfs.c @@ -1254,17 +1254,6 @@ static int damon_sysfs_upd_schemes_regions_stop( return damon_sysfs_schemes_update_regions_stop(ctx); } -static int damon_sysfs_clear_schemes_regions( - struct damon_sysfs_kdamond *kdamond) -{ - struct damon_ctx *ctx = kdamond->damon_ctx; - - if (!ctx) - return -EINVAL; - return damon_sysfs_schemes_clear_regions( - kdamond->contexts->contexts_arr[0]->schemes); -} - static inline bool damon_sysfs_kdamond_running( struct damon_sysfs_kdamond *kdamond) { @@ -1417,9 +1406,6 @@ static int damon_sysfs_cmd_request_callback(struct damon_ctx *c, bool active, damon_sysfs_schemes_regions_updating = false; } break; - 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; @@ -1549,6 +1535,9 @@ static int damon_sysfs_handle_cmd(enum damon_sysfs_cmd cmd, return damon_sysfs_turn_damon_on(kdamond); case DAMON_SYSFS_CMD_OFF: return damon_sysfs_turn_damon_off(kdamond); + case DAMON_SYSFS_CMD_CLEAR_SCHEMES_TRIED_REGIONS: + return damon_sysfs_schemes_clear_regions( + kdamond->contexts->contexts_arr[0]->schemes); default: break; } From patchwork Fri Jan 3 17:43:53 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: SeongJae Park X-Patchwork-Id: 13925761 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 D3266E7718F for ; Fri, 3 Jan 2025 17:44:20 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 568F96B0095; Fri, 3 Jan 2025 12:44:17 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 4F4096B0093; Fri, 3 Jan 2025 12:44:17 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 27FC06B0096; Fri, 3 Jan 2025 12:44:17 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id DA7376B008A for ; Fri, 3 Jan 2025 12:44:16 -0500 (EST) Received: from smtpin02.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id 8D1051A098C for ; Fri, 3 Jan 2025 17:44:16 +0000 (UTC) X-FDA: 82966863924.02.2E7D2A5 Received: from nyc.source.kernel.org (nyc.source.kernel.org [147.75.193.91]) by imf09.hostedemail.com (Postfix) with ESMTP id 8BA5C14000E for ; Fri, 3 Jan 2025 17:43:39 +0000 (UTC) Authentication-Results: imf09.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b="qpu/k9+9"; spf=pass (imf09.hostedemail.com: domain of sj@kernel.org designates 147.75.193.91 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=1735926206; a=rsa-sha256; cv=none; b=aFFCfWc7n+PJiUgJqU4Fxz3HLXsfhkNWmQ540NPBs28XJFW9aHiRHv/35yb+THY/j41A5T wNn1msysxijL4f5K54VArhojvJ9Oc8XtSWzAu8axjkt5SUZ6Kc0o73VuJbKWRqdIB1ntOX g6BXEJHYVFwi7sjP31ewg+D49Md8plw= ARC-Authentication-Results: i=1; imf09.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b="qpu/k9+9"; spf=pass (imf09.hostedemail.com: domain of sj@kernel.org designates 147.75.193.91 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=1735926206; 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=GL3K3VeEw3sBPlc5hG0f1xiMIwuovutSxEQCsmYLfb4=; b=CUusfrNtTswyFGDvEkm4UW8zIN2rd9SQBCwAvsjAOeGwEgJG+47WH8XzGm9tWwNISy3lVe wT56XVa90NlKGj2knjnDLeJ/Tpw51Aq3cpsIwzXlFsF3a26eOnRWyP8ORQUEhpLH0a+Im5 rE7yLQkgFaiQf5gyWWCjetVrmDSIgOk= Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by nyc.source.kernel.org (Postfix) with ESMTP id 50B4DA41033; Fri, 3 Jan 2025 17:42:25 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 1274DC4CECE; Fri, 3 Jan 2025 17:44:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1735926254; bh=JNkpoBSJiwe93XL962RE5R1ynJv2g3n6CCV3Kyol5/0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=qpu/k9+9YSU7eTA3ClaCp7f1fEbo8Y70eSTguSBhya0DXCc0VjaqGUxE1sa356iNY 4btMs7/D2rf/yQsum03Nzf1vbAp7ZG2QdAApH6XDkNcK7gttcahF2zLBq+tRTfCxgi aLM8AWc/Rde2IKCQAkeCWL1KoedEMklGBEE4EZtzWh4lXHqPt94AtjoqsemaQXcriZ UgMfZgATz0uIPr+Knfg1C43PytEkgyYZkYdsf59EMqs+nN4MVFV5WK+v5h/c2GybEN 8EgB9v4qbBlrVEKKPhBIVJhZAW0XHaQ1uVAJzFs9btRwRl1SU/MeMm4dkUbTTlOVZ2 5eogb+SVumsOw== From: SeongJae Park To: Andrew Morton Cc: SeongJae Park , damon@lists.linux.dev, linux-kernel@vger.kernel.org, linux-mm@kvack.org Subject: [PATCH 03/10] mm/damon/core: introduce damon_call() Date: Fri, 3 Jan 2025 09:43:53 -0800 Message-Id: <20250103174400.54890-4-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-Queue-Id: 8BA5C14000E X-Stat-Signature: n1tmzxqio1siejsj58hmng1kgd7pk1qc X-Rspam-User: X-Rspamd-Server: rspam09 X-HE-Tag: 1735926219-757945 X-HE-Meta: U2FsdGVkX18Djx8I3XA7HhETKuDiItKPVb50iLPL3inmvgk7xLm4TzbSY8v9+QT8Q3S0h5dmwxDqY5T/se2JPKfSsR/+sGsgLt5rLVaFzMUG4y132dZRpxfd2CUkgbKX2PFhpaG4mtcu6cN5gmUOTZK9Q9rcHJFeYlui1XqKjAFIW7D4f7nL5hbbc/5MsSXjrdIHvT1zJYmTgQjEsrxJuzbznlWkOeG7piHdXN2hmvMEDeUZiRgtqt/I06pQWZ1+fc39aB5jjqMmGapGlGxax5kFyUlrpBElpSsv/yS5LBnDgxjLs5SOsNQUg+8xS6sFlYcOnqiJTi2Ib69xGMTz4pg08XnFVpNcxpw7bsl6jrC0DevuGAR/ygLJv9bCvfIgrEeEArY15fIspEw6q7U6qEAXwSK9DZecwDo48bQZTd9Tr1xHOYHoDoG7FyKrRSxMATF15daUZnCK/NCSw0ueMWSp3XTc1g8DiWqbrHxGZXN74qta6uRQfttu33fSGoL4rgIE7Nmy2J3EXEWVWOsnCi5Z+W716Ukhx991xYfSylrC4ElU76JGJC+ZSh+hlhu2rmJijiSSfKyG068DS1eMEyRP7cLCJkMsJlEeB8JS/6ZEK7qmwTblY/6pN4hmO0Xe0I6IVi/ixPa1Xcl+ekA3LwSjz+Yveexj6BxpYORJG47SL+aiL45O+RLMaUqfIhky9WonDSt4jhU/y2AtXwQprIkQ2TtT80/+FGzXrDapBYam+bym46jD9PC68uj9ycVERSSrg0q5nawkDjHWPuyzROr/E/EjZ04MbBfmBbv5D1/2OJQo7RdUCNrFDxwXpP+Kn975Lbn/nUt7tYR9JZE5UP4pfFNeUXlB1ww1GpW5BCXthhxt2igre5IjH0M3/+Fmh9ZYMPNYZU8/4GHVyaO1EOs4xze1jBJpn3Tmv2Zlp1/i9MlQOUTWzbjx7TAwC+7qVmjf+eMS0DEh7U4m/KU DVzShcMI LhxCHOTx8/DCuYfn7t/jmq6150yHYo00qTRD05bIpGXBmWz6aEv4t8bsTQbYEjFD1bJ8gXdeLjD8uIJrsInXNGCgPoUeb2Ozek5BddV7YrgBZRqdiBUqTUke8IFSe7Y6og2zA7FzxvayagfFHFW4TwShgU+TwFtqIIqUvNNWGiPhCa4rQkWbObTapBVdKxh/NkD9JDUVlsoWFR7t6NWhBSPdwEFmBCrIVqnz7Xzr6uz48E2D+Oi00lqn0T7yhu9l3rNxlP5MPseZzvqAKBgjWXM325g== 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: Introduce a new DAMON core API function, damon_call(). It aims to replace some damon_callback usages that access damon_ctx of ongoing kdamond with additional synchronizations. It receives a function pointer, let the parallel kdamond invokes the function, and returns after the invocation is finished, or canceled due to some races. kdamond invokes the function inside the main loop after sampling is done. If it is deactivated by DAMOS watermarks or already out of the main loop, mark the request as canceled so that damon_call() can wakeup and return. Signed-off-by: SeongJae Park --- include/linux/damon.h | 26 +++++++++++++ mm/damon/core.c | 86 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 112 insertions(+) diff --git a/include/linux/damon.h b/include/linux/damon.h index a67f2c4940e9..ac2d42a50751 100644 --- a/include/linux/damon.h +++ b/include/linux/damon.h @@ -552,6 +552,27 @@ struct damon_callback { void (*before_terminate)(struct damon_ctx *context); }; +/* + * struct damon_call_control - Control damon_call(). + * + * @fn: Function to be called back. + * @data: Data that will be passed to @fn. + * @return_code: Return code from @fn invocation. + * + * Control damon_call(), which requests specific kdamond to invoke a given + * function. Refer to damon_call() for more details. + */ +struct damon_call_control { + int (*fn)(void *data); + void *data; + int return_code; +/* private: internal use only */ + /* informs if the kdamond finished handling of the request */ + struct completion completion; + /* informs if the kdamond canceled @fn infocation */ + bool canceled; +}; + /** * struct damon_attrs - Monitoring attributes for accuracy/overhead control. * @@ -632,6 +653,9 @@ struct damon_ctx { /* for scheme quotas prioritization */ unsigned long *regions_score_histogram; + struct damon_call_control *call_control; + struct mutex call_control_lock; + /* public: */ struct task_struct *kdamond; struct mutex kdamond_lock; @@ -779,6 +803,8 @@ static inline unsigned int damon_max_nr_accesses(const struct damon_attrs *attrs int damon_start(struct damon_ctx **ctxs, int nr_ctxs, bool exclusive); int damon_stop(struct damon_ctx **ctxs, int nr_ctxs); +int damon_call(struct damon_ctx *ctx, struct damon_call_control *control); + int damon_set_region_biggest_system_ram_default(struct damon_target *t, unsigned long *start, unsigned long *end); diff --git a/mm/damon/core.c b/mm/damon/core.c index 5192ee29f6cf..97f19ec4179c 100644 --- a/mm/damon/core.c +++ b/mm/damon/core.c @@ -504,6 +504,7 @@ struct damon_ctx *damon_new_ctx(void) ctx->next_ops_update_sis = 0; mutex_init(&ctx->kdamond_lock); + mutex_init(&ctx->call_control_lock); ctx->attrs.min_nr_regions = 10; ctx->attrs.max_nr_regions = 1000; @@ -1162,6 +1163,54 @@ int damon_stop(struct damon_ctx **ctxs, int nr_ctxs) return err; } +static bool damon_is_running(struct damon_ctx *ctx) +{ + bool running; + + mutex_lock(&ctx->kdamond_lock); + running = ctx->kdamond != NULL; + mutex_unlock(&ctx->kdamond_lock); + return running; +} + +/** + * damon_call() - Invoke a given function on DAMON worker thread (kdamond). + * @ctx: DAMON context to call the function for. + * @control: Control variable of the call request. + * + * Ask DAMON worker thread (kdamond) of @ctx to call a function with an + * argument data that respectively passed via &damon_call_control->fn and + * &damon_call_control->data of @control, and wait until the kdamond finishes + * handling of the request. + * + * The kdamond executes the function with the argument in the main loop, just + * after a sampling of the iteration is finished. The function can hence + * safely access the internal data of the &struct damon_ctx without additional + * synchronization. The return value of the function will be saved in + * &damon_call_control->return_code. + * + * Return: 0 on success, negative error code otherwise. + */ +int damon_call(struct damon_ctx *ctx, struct damon_call_control *control) +{ + init_completion(&control->completion); + control->canceled = false; + + mutex_lock(&ctx->call_control_lock); + if (ctx->call_control) { + mutex_unlock(&ctx->call_control_lock); + return -EBUSY; + } + ctx->call_control = control; + mutex_unlock(&ctx->call_control_lock); + if (!damon_is_running(ctx)) + return -EINVAL; + wait_for_completion(&control->completion); + if (control->canceled) + return -ECANCELED; + return 0; +} + /* * Reset the aggregated monitoring results ('nr_accesses' of each region). */ @@ -1917,6 +1966,39 @@ static void kdamond_usleep(unsigned long usecs) usleep_range_idle(usecs, usecs + 1); } +/* + * kdamond_call() - handle damon_call_control. + * @ctx: The &struct damon_ctx of the kdamond. + * @cancel: Whether to cancel the invocation of the function. + * + * If there is a &struct damon_call_control request that registered via + * &damon_call() on @ctx, do or cancel the invocation of the function depending + * on @cancel. @cancel is set when the kdamond is deactivated by DAMOS + * watermarks, or the kdamond is already out of the main loop and therefore + * will be terminated. + */ +static void kdamond_call(struct damon_ctx *ctx, bool cancel) +{ + struct damon_call_control *control; + int ret = 0; + + mutex_lock(&ctx->call_control_lock); + control = ctx->call_control; + mutex_unlock(&ctx->call_control_lock); + if (!control) + return; + if (cancel) { + control->canceled = true; + } else { + ret = control->fn(control->data); + control->return_code = ret; + } + complete(&control->completion); + mutex_lock(&ctx->call_control_lock); + ctx->call_control = NULL; + mutex_unlock(&ctx->call_control_lock); +} + /* Returns negative error code if it's not activated but should return */ static int kdamond_wait_activation(struct damon_ctx *ctx) { @@ -1941,6 +2023,7 @@ static int kdamond_wait_activation(struct damon_ctx *ctx) if (ctx->callback.after_wmarks_check && ctx->callback.after_wmarks_check(ctx)) break; + kdamond_call(ctx, true); } return -EBUSY; } @@ -2011,6 +2094,7 @@ static int kdamond_fn(void *data) if (ctx->callback.after_sampling && ctx->callback.after_sampling(ctx)) break; + kdamond_call(ctx, false); kdamond_usleep(sample_interval); ctx->passed_sample_intervals++; @@ -2072,6 +2156,8 @@ static int kdamond_fn(void *data) ctx->kdamond = NULL; mutex_unlock(&ctx->kdamond_lock); + kdamond_call(ctx, true); + mutex_lock(&damon_lock); nr_running_ctxs--; if (!nr_running_ctxs && running_exclusive_ctxs) 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); From patchwork Fri Jan 3 17:43:55 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: SeongJae Park X-Patchwork-Id: 13925763 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 6546AE77188 for ; Fri, 3 Jan 2025 17:44:26 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 850BF6B0099; Fri, 3 Jan 2025 12:44:19 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 8037D6B0098; Fri, 3 Jan 2025 12:44:19 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 69F796B0099; Fri, 3 Jan 2025 12:44:19 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id 480DE6B0096 for ; Fri, 3 Jan 2025 12:44:19 -0500 (EST) Received: from smtpin30.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id EDFD9120970 for ; Fri, 3 Jan 2025 17:44:18 +0000 (UTC) X-FDA: 82966862958.30.EEC9963 Received: from nyc.source.kernel.org (nyc.source.kernel.org [147.75.193.91]) by imf19.hostedemail.com (Postfix) with ESMTP id B6AF71A0019 for ; Fri, 3 Jan 2025 17:43:23 +0000 (UTC) Authentication-Results: imf19.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b="JgU/JbFv"; spf=pass (imf19.hostedemail.com: domain of sj@kernel.org designates 147.75.193.91 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=1735926233; 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=ezK6oTp14HCpwDhd8lhtdtnxV8X5s31lGnDCurJhbRE=; b=39txvzoemde/G1r5MdXUqvc5mQCHg3HuEHA08bD3naLSIwZWIBF9OOXF2It74Rj3lQv9Hk s3A0bno+tKMtdm6hQ1m3tlkQb5Kt9eVAX2LCy/R+HCz7jMBSntQlWegrWZLehfNRraFEwY dKoqvoiSDQnjSnU2qziQtTqbNv90vs0= ARC-Authentication-Results: i=1; imf19.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b="JgU/JbFv"; spf=pass (imf19.hostedemail.com: domain of sj@kernel.org designates 147.75.193.91 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=1735926233; a=rsa-sha256; cv=none; b=vLO6cpeUmuuyDGPKQqyL5iIqQxynsDnkAY9lOoX5GRBvlnqdFdjsJ3q1EgOwz2AvdLjS4O e0NziW556Ny1U0dSUC4KQeqEXo3mc+F44Icjj93y8spfCljyXFAwxy8NuKI15J557zB0++ 87pRxg2C3C6EvCs9ypfFQgg1lA6WW24= Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by nyc.source.kernel.org (Postfix) with ESMTP id B69BAA41042; Fri, 3 Jan 2025 17:42:27 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 43D48C4CECE; Fri, 3 Jan 2025 17:44:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1735926256; bh=Qli68w9RR6OLGHO/urSk5Kw3GxzgWY+dpbdZAM29uik=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=JgU/JbFvqWQxRNZrwv2u3F+e81eK1EgkWJYkhOHqGLuj7+9iCsEdy8uz0/EUuv2no IDaP5sZ58eVF5W03tH3XdL0IA/sDRyGBeBeTprwsygO7K9AYfQdv3zJs8jfwS6yCzz Az07ONWHLy4u2Fl3svvpsN7qVGh3Nbb9GkmrSrCrNrByHVxlE6iRNLxFFVAvRQdJec ICTLWpnV+Fgj3ajHByMevRJKnExULKU1MfF/d3EgBupzZqtPZsxNNttxMTDzE0Ujik U5LUpgi07rIR8HyHfkT2HTBaLms/BaZDA6QIGEJFx3S2zIOYfqG9WvxbfjtSzMJZmJ qldWRQ/c7hwEQ== From: SeongJae Park To: Andrew Morton Cc: SeongJae Park , damon@lists.linux.dev, linux-kernel@vger.kernel.org, linux-mm@kvack.org Subject: [PATCH 05/10] mm/damon/sysfs: use damon_call() for commit_schemes_quota_goals Date: Fri, 3 Jan 2025 09:43:55 -0800 Message-Id: <20250103174400.54890-6-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-Queue-Id: B6AF71A0019 X-Stat-Signature: cm8yxgtmp79upe1wrhj1t9ihycdwg3ez X-Rspam-User: X-Rspamd-Server: rspam11 X-HE-Tag: 1735926203-987460 X-HE-Meta: U2FsdGVkX19aaoKKL3Nty7szAToso3P8v+BxNVqd79cltFACpkOsRv3U6UGO4EPBW2bGvsriwYVtg0ifyDhIyW590bad3eUHCqHtcQqq4PfDTz4JR3Ib81WMWq5zsGfEoXdr8kanNf+SEYyueR8ongOSyabvHpkaYoKUGxL7EQJWypOT5Xf+MbkXGF/h4Hcdl0cTNV6NA6ywNUgFRNE7Q1d36xsvpn1MqSkA5MdymH6SP2IN1WRfVaGTdx/QTlv2DfukSJ4DGXdzY8nY4ZDn3l7sI/TLq0GEAHq33Kdwli1nF9DtCcHuPFlIydIvb1gMtXa0vCdxTBDTm/RcT5uFSnDF3IskbFuZEyB/bIspGAEZeh7+pnbLuG5KPfmr1avBKBO2Rnppu5CM1OQLx5aAMwzelDmxUVLpQa9ZMLi8Amj7OPTBxZ+xu77ohD6mgaRSAq9AG4nFWSCtogY9ibya+WTVS8HvN2G6hPRQmn9BDgnlnom7HLKO5s28+xwnN1G1vaGQt6emfd/U1Efkm/BvR2Tulv0XGob/FJAjanWQ3DyaVZ0iHi9OU1/+IJbxjtxZCdmpPq5LIeDuSzjqyslSmY81ca056GTQc+lEhyKZd5yGZHon+3ZC0eVqQgESdxmZPXyO/hKjHrBsXZDDDgdrY5Rc78AoGBCDzg2k0Is/KzYbGruQcPnGImXOdL9Z4hBmGkkcnoZC/yNFybtTLF/3uuHOXbmwL/Ob21tmHxYFXl2w+rd6ClZxfdUz6kRVOY6OAcDlzCyLCDB6rC/4gJNDtE2HcZHbhtQSceg8EBIIFqOhOPHUTBhAfdhtpXQfE1gmvQ+Da/S7spGYrx5CuUENkcGnWR06cwB0zYoUcwUlcwDoRb4uZV2EION2EBMw/rit2ZA5teMEOVZ2xNnAkUXgyXRob9jVKqUtSx57+pLNJUK9Sg9JgSCK9Yxp8GTR9F48lgo6AdpPyv33nukL1kU 9pY/UqGu Vo1PaJ9mDlotB0LkbvM6I+NUCkgc8AfbBpq+NRTchZRrzJEO7DpY34NCpR7Yvt8H1/IUP0fKCIRUlnRS7k4E8H6dwiHfQjwtrSC3bhQyd4OrOqB9Vr634KsjCrfFB57s8qcXGWkkDuzThF/WG0Jw/YUWadnhnmhB4wPPGm0Cf2qj3cW0+g++5E6Zm0wwaJ+H6LGTdM032DFusWCpGzenCvJE1G+vcPis2n17+eCshohy0ZXWLrE4fv5c6u6cTnYtABR5Nbrx5PZwZDvOqrpOR0nVS6Q== 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 commit_schemes_quota_goals 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 | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/mm/damon/sysfs.c b/mm/damon/sysfs.c index 708c2ffdd620..7c2aa9830edc 100644 --- a/mm/damon/sysfs.c +++ b/mm/damon/sysfs.c @@ -1307,9 +1307,9 @@ static int damon_sysfs_commit_input(struct damon_sysfs_kdamond *kdamond) return err; } -static int damon_sysfs_commit_schemes_quota_goals( - struct damon_sysfs_kdamond *sysfs_kdamond) +static int damon_sysfs_commit_schemes_quota_goals(void *data) { + struct damon_sysfs_kdamond *sysfs_kdamond = data; struct damon_ctx *ctx; struct damon_sysfs_context *sysfs_ctx; @@ -1376,9 +1376,6 @@ static int damon_sysfs_cmd_request_callback(struct damon_ctx *c, bool active, goto out; err = damon_sysfs_commit_input(kdamond); break; - case DAMON_SYSFS_CMD_COMMIT_SCHEMES_QUOTA_GOALS: - err = damon_sysfs_commit_schemes_quota_goals(kdamond); - break; case DAMON_SYSFS_CMD_UPDATE_SCHEMES_TRIED_BYTES: total_bytes_only = true; fallthrough; @@ -1543,6 +1540,10 @@ static int damon_sysfs_handle_cmd(enum damon_sysfs_cmd cmd, return damon_sysfs_turn_damon_on(kdamond); case DAMON_SYSFS_CMD_OFF: return damon_sysfs_turn_damon_off(kdamond); + case DAMON_SYSFS_CMD_COMMIT_SCHEMES_QUOTA_GOALS: + return damon_sysfs_damon_call( + damon_sysfs_commit_schemes_quota_goals, + kdamond); case DAMON_SYSFS_CMD_UPDATE_SCHEMES_STATS: return damon_sysfs_damon_call( damon_sysfs_upd_schemes_stats, kdamond); From patchwork Fri Jan 3 17:43:56 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: SeongJae Park X-Patchwork-Id: 13925764 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 A1FB2E77198 for ; Fri, 3 Jan 2025 17:44:28 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 1C1F76B0096; Fri, 3 Jan 2025 12:44:21 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 149F76B0098; Fri, 3 Jan 2025 12:44:21 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id F2DA96B009A; Fri, 3 Jan 2025 12:44:20 -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 D108C6B0096 for ; Fri, 3 Jan 2025 12:44:20 -0500 (EST) Received: from smtpin12.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id 87808442F1 for ; Fri, 3 Jan 2025 17:44:20 +0000 (UTC) X-FDA: 82966863210.12.52C2759 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by imf20.hostedemail.com (Postfix) with ESMTP id 46CCC1C0018 for ; Fri, 3 Jan 2025 17:43:25 +0000 (UTC) Authentication-Results: imf20.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=MuPud1XT; dmarc=pass (policy=quarantine) header.from=kernel.org; spf=pass (imf20.hostedemail.com: domain of sj@kernel.org designates 139.178.84.217 as permitted sender) smtp.mailfrom=sj@kernel.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1735926210; a=rsa-sha256; cv=none; b=yn2BKgIA0xrs2Hxo9hkXTXJN7VAUaglg0YaxNzU3iLXw0D1zTLADOZBrWrj9I/e0EebmuT 4XhnFQiHUkjv81+AjTeEG/AcwS87BqkX+wF1bVYvcwhbi9yuF7pKft1FZ3vTtvRaDwPhbl JKUuewRK097xU114abOgXBN8qj1bmxI= ARC-Authentication-Results: i=1; imf20.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=MuPud1XT; dmarc=pass (policy=quarantine) header.from=kernel.org; spf=pass (imf20.hostedemail.com: domain of sj@kernel.org designates 139.178.84.217 as permitted sender) smtp.mailfrom=sj@kernel.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1735926210; 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=Qs/dcvVf1lRU8kZOCqEau9vFB1iXOyC6CH2y+FlwR1E=; b=bCc4gSuIJ+U5h1KqvKFP8phT4m8+YwQApyqY9msS/rKp850D2dKFm/Zl0cSpvQfueX7k7B Eef/ZqR18vCkgNniU16kZzihP6zUsgaxey1IGG3WdWl6Qlk16yvSUNmAwoKvW+dUIzDsfA TC3gb2jDwXGHb5tvL7JqfkXrwzLZo3c= Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by dfw.source.kernel.org (Postfix) with ESMTP id A919A5C6512; Fri, 3 Jan 2025 17:43:36 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 5289BC4CECE; Fri, 3 Jan 2025 17:44:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1735926257; bh=rbTL8cU3TZPcyGMSlZELKJLzpLND/6Ckurwp21Ndpas=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=MuPud1XTNdpWjKxTAN4F+wbJsgLZvLdZYH0KJLmKth0kVsf7jVwQrLIHw+N9qN9R6 JOGu08x22H8puHME/3+1jyzKrSQ2kpZ5dsQqh3Ri2S78gs6ei4cNzMY/KbWjPDhxb5 brktRmfBHiV8+0idfOUVGxIYxBkjQ3y8FjOPcYxnReEPYn3RtpowsjpTx1GamBVUtl 3s80v0c25U5yS+KlQ2cNZR+khOnSCVHhK5c0nC/Ej3BqM8D+wGv8tWEc8tCcel6nYS JgvfDB5PTjJGwLdhXeHqZameoLpCeDOoNXj26IdqsTkS5DE4CJ+lH8Kfnl/t1rP2mz bDQvGVOa7XOyw== From: SeongJae Park To: Andrew Morton Cc: SeongJae Park , damon@lists.linux.dev, linux-kernel@vger.kernel.org, linux-mm@kvack.org Subject: [PATCH 06/10] mm/damon/sysfs: use damon_call() for update_schemes_effective_quotas Date: Fri, 3 Jan 2025 09:43:56 -0800 Message-Id: <20250103174400.54890-7-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: rspam04 X-Rspamd-Queue-Id: 46CCC1C0018 X-Stat-Signature: 48uxkf9syrt3knnj6hs8bgswgsr6idhr X-Rspam-User: X-HE-Tag: 1735926205-951613 X-HE-Meta: U2FsdGVkX199YhHlvhshLLrc6w2FO+v8gtRFMjQ5WCc0gyDV1w7qsRw+APCKZnARKtQlXNeVWrYx6ENYb8pgfVd+V5DwAqS74kIIuD0e6u++W/oZdU1ofiopf8aPXFAskZtmQ/3OHrga6l3WFdo7W8eVbZTQi1EJuzsuVcoUY7vZ4xxd2/TUH+T2RQCCnwe8sOyKpeGZIDJjRNocUHl/ixSFVUUjoKBrK3wX1FSlLTmq17GvFOMmtHQtx5is0aP3ojtMYErBB05pQK1cUoO2K6PQdrQ3N48nLlDj9YtmTgIvQob9Cb2yGtrtDlHN9anjrU8E4SR1eYg1igw+bhu4wLA9NkS5SrrhOB6ACJm+bZteebOjlFY33V+4VWaaIEh2ol8cXuhXtPXKtCnR0taJM9Y4Lhc6SSGypBRwjHLXtEvQPHOmTjHBCh09eVQZSuZu1hEEO2BhbcIrVp6b40yCnyozXrfKuf2U1nAfBjQ8IoQOlIEge8mL+Oi8CkY2aqeXKGBcMNwrvfGkv0FHYVHa8wFOXdxIx/BQlGeczQCK/ka2dxr8TWcOUtRNKfO6phCQDgfU7cSILmpKWJk4C+dCKOpOndejOPLFfaEwNYaK1R5/vrbO0+kxasn4OhOUZss8yRi536Hi6dW6FUGPIbucuV3OYz6Yk0tz9UTCH1YTiGLxkuADpqdwafZmxuLtwESisARPuUrMbcZeJ0+8nZFVrKq3x5M1TelyCXOqnVyjJT88MR9soTCt0fnrlV0TdD5iYxc/Y8tWYG9EFQcuMddyEUu0ueuppRIiu1fSbtLBsff4z0HbPU7+gu/w83U2mz+ziuaMahg5gshUmPV5HPaiyDXobORHpt5WbOMNEQBgF04zT4p0CqT2lkGK7BUfI+PTs7tGX84L86O3OPWrQGr4rZps4MbYhbD9XqXoHmS+iyR12xtc3lbjfsboPU6jyK19Tg7k+/X+WQGw4fVdz3V MDKi4YFe JY+zcA1YiX2+sN5EYPpRnyMVNP65v4VIPLc45L+MMxWLOHlOra7xl4p7GhlQcd566Ms2Bk3A1iAfgmwbsEYXrjfpYe/7cqyfiKgAhcOLuFm1caWV5oALa8eStqVFAp/CBlgiXydGmNdckKfd4LrHlRU1+PZvmaieLPkPk3AHd5i1yMtj8cxORxcCHP388VlU/48aOPKzUoxDpiXdBoCrMhQzNqMBpvuQ2NsUdLiQc30bAmkqMxH0xvBg/C0bhG0cLLhX1iG3daL7YAjxI9deLiRjcDA== 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_effective_quotas 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 | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/mm/damon/sysfs.c b/mm/damon/sysfs.c index 7c2aa9830edc..917e6aca3f58 100644 --- a/mm/damon/sysfs.c +++ b/mm/damon/sysfs.c @@ -1327,20 +1327,18 @@ static int damon_sysfs_commit_schemes_quota_goals(void *data) /* * damon_sysfs_upd_schemes_effective_quotas() - Update schemes effective quotas * 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' 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) +static int damon_sysfs_upd_schemes_effective_quotas(void *data) { + struct damon_sysfs_kdamond *kdamond = data; 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; @@ -1400,9 +1398,6 @@ static int damon_sysfs_cmd_request_callback(struct damon_ctx *c, bool active, damon_sysfs_schemes_regions_updating = false; } break; - case DAMON_SYSFS_CMD_UPDATE_SCHEMES_EFFECTIVE_QUOTAS: - err = damon_sysfs_upd_schemes_effective_quotas(kdamond); - break; default: break; } @@ -1550,6 +1545,10 @@ static int damon_sysfs_handle_cmd(enum damon_sysfs_cmd cmd, case DAMON_SYSFS_CMD_CLEAR_SCHEMES_TRIED_REGIONS: return damon_sysfs_schemes_clear_regions( kdamond->contexts->contexts_arr[0]->schemes); + case DAMON_SYSFS_CMD_UPDATE_SCHEMES_EFFECTIVE_QUOTAS: + return damon_sysfs_damon_call( + damon_sysfs_upd_schemes_effective_quotas, + kdamond); default: break; } From patchwork Fri Jan 3 17:43:57 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: SeongJae Park X-Patchwork-Id: 13925765 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 DAD5EE7718F for ; Fri, 3 Jan 2025 17:44:30 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 9FEE26B0098; Fri, 3 Jan 2025 12:44:21 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 9AD9A6B009A; Fri, 3 Jan 2025 12:44:21 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 7E6006B009C; Fri, 3 Jan 2025 12:44:21 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id 53B7B6B0098 for ; Fri, 3 Jan 2025 12:44:21 -0500 (EST) Received: from smtpin19.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id 1465DA094B for ; Fri, 3 Jan 2025 17:44:21 +0000 (UTC) X-FDA: 82966862286.19.B237777 Received: from nyc.source.kernel.org (nyc.source.kernel.org [147.75.193.91]) by imf28.hostedemail.com (Postfix) with ESMTP id 083AEC000F for ; Fri, 3 Jan 2025 17:43:23 +0000 (UTC) Authentication-Results: imf28.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b="ZLv4U/hV"; dmarc=pass (policy=quarantine) header.from=kernel.org; spf=pass (imf28.hostedemail.com: domain of sj@kernel.org designates 147.75.193.91 as permitted sender) smtp.mailfrom=sj@kernel.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1735926235; a=rsa-sha256; cv=none; b=R0Uh9i3VruayIQ0s7ghkbwkKzgSLKofCuaJ9RFYqs2DPZ4+ab3rrkHZye4xnSsmiQEGtzx Q2xXeXRBlxDRC6yvVyJaXpZs2TIt9XHgj9vZK5x22/C15tDav5ceR5/Ix019/VYKMsB5EM zpcHNe4BQUZ/5rhbRyfy4jAggDjxvl0= ARC-Authentication-Results: i=1; imf28.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b="ZLv4U/hV"; dmarc=pass (policy=quarantine) header.from=kernel.org; spf=pass (imf28.hostedemail.com: domain of sj@kernel.org designates 147.75.193.91 as permitted sender) smtp.mailfrom=sj@kernel.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1735926235; 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=FrvXual4+5sv2fuuT5LKpOO5M8vjIvBWVHZEw71cg+w=; b=AKnJXcsgWioO/8WpygIPDFQTOnlLPkEKj4/S7sh5WQyfB0P4y593MlS0EoYZ9iJ2P1NIaB 2UYuggDnEOdcyNj8AAT3R1q9Sx7AnXj38VLpb8i9lC6q7UTdZZPiy/YEARQIanucZUTtV/ wScwzN/mgkf1J904tXWLo8/I5Yo6ezs= Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by nyc.source.kernel.org (Postfix) with ESMTP id A9D80A41042; Fri, 3 Jan 2025 17:42:29 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 69DFAC4CEDF; Fri, 3 Jan 2025 17:44:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1735926258; bh=m5b1QRjgbQAvEoZjEHeueE5i8801YUauSjCf8Zy53xI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ZLv4U/hVN3Y0MuHy/MBIajZjK+xUYPX2FItpYfDWr1wwBrI2Kudci/SO765zhI34m 3RiLgV0XDZQMjgEglDXEBftK112UMe3urGPBtOgCtB9+sRkWTd0UTSvG3wZ1JqjoAk ZwN7MOUhHjPO36bA+vVBD3ZqIbBMF4DbxzLbVS4+7BEMvf25gosl93kZJdBmgboVAx UiJJUTl3YCJe1dOgL9aGT28FMBeBeePjN4bzDJ65wD5SsV1IcXUsLGLRwJag4yZnnz tgMqFn5GZDtUa43WTmjDaOAx6n9hEK8reRblceC6H+JeMcAwsgJpuh/Ay9Gtg/3hd2 RAD1Ckl9hPvCw== From: SeongJae Park To: Andrew Morton Cc: SeongJae Park , damon@lists.linux.dev, linux-kernel@vger.kernel.org, linux-mm@kvack.org Subject: [PATCH 07/10] mm/damon/core: implement damos_walk() Date: Fri, 3 Jan 2025 09:43:57 -0800 Message-Id: <20250103174400.54890-8-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-Rspam-User: X-Rspamd-Server: rspam03 X-Rspamd-Queue-Id: 083AEC000F X-Stat-Signature: 6phq14nia1q7syustd8xwcjchto5cpr1 X-HE-Tag: 1735926203-274602 X-HE-Meta: U2FsdGVkX1+T13gmKWlE+DW+fzIMOMXJ8SxkFbl+8c1dlGltwr+0qfrKKD5jKheqWPhpeeXM6sleF4zHYr4oAeIPgKvEXPBqUwbJQX7ZyVwsI5mshpylctiYhDHwu9zmCFujzUpOgqwYedmElxkVTyztmzavQDUAA3u1zEOOvLv+xVor3Eq9AiSDak4951k3DduIe99m2Da1UfQ+kISdtzV3k7wOfKQlheMLxlXDt2ehsajhPgLHKC2ZtrQIOjR7EZTA2tRvVkkSNbvrnWTTeyVN1br3hzcRHF+jbSKWauQ5bcvqaRi4PyGExY0CSzkYlDTIoh8QF8Fw3RB9NfkhNynqPjnnClSINJjGwlkDruv2kUFIIgnMVVHCSb8HRTFH0YdW9TfDHadk1UX49xEQW4KeE/vxU5/sJba+uNHaYEBmSZ1U7YnuCKH4E+adh20B+yuSr0DbXX/zp5+eFLR4lSCGTSeZ3R7GJHTR7XgZz6iqcSpAMHV5tu+5aSKGMkTQjcGoNzRoXn0Wn2BtE2NZ+/u7Pix/SImvrDz5XtFpFupBEk0hCWrNILMvALHDY0Z6oYFOAcPXdmZca0rbvGNG90lm75/WPWQ0Jvx+eB3H3WbcNvK4Vjc6zoCbgfykKQYbvx9+nMshxFbRzu7d+PEe+j0NkUAxXn2c9j7IkIwowrjtYJV8rqCRe61DYFybd5UCn9/Gs3RMhTuF38ydX6BGsjHl5hqwntnKSh5mcysRL3yC71FepxrmQdx/wR71Z7Bj+VBi80kOEW1dUSEk49Txrt8C6iLgqcEWjAW9PyYoX53I9BDQr2PKXnu0nFmfGVgayMXikj0xoY5oGM5V6malX0Wpl22g3+Bog7y22Mod72J+D+r4FWM2fJ9D8fWI1TdnlNZEDpG4biwi9T/dloLB8guyqm3IETArU0FYwz84RaKTInYVC9HyuNWXTUD7ftzZZYSo+J2NQvCgwC649ay VauTDQs8 Iq46gBx97fTc2h4ZSb3YMTLSTvVet0hT7QYd2TaVB161tnKl0WhRYPzt3WOTuep3f3/xrAm5Mp9k77lY2LQ+3A+6utA87ciX7OwvteduH9mgS9NR12UkIrs+s1lKRgcwSEmugV97LHGwUysKPoACKfz12KAqTUJYuNHpX53HqzAr56DNuDGFvcHKfkIDTJ7p8skTOPVQ0ILPsV5JkuTg/H5e8Adov8gqSK4oQDFcxvZs+wJGMOysRqcTgi21fim2b0N2okzAAc5HuKoi43P/TWqAK/A== 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: Introduce a new core layer interface, damos_walk(). It aims to replace some damon_callback usages that access DAMOS schemes applied regions of ongoing kdamond with additional synchronizations. It receives a function pointer and asks kdamond to invoke it for any region that it tried to apply any DAMOS action within one scheme apply interval for every scheme of it. The function further waits until the kdamond finishes the invocations for every scheme, or cancels the request, and returns. The kdamond invokes the function as requested within the main loop. If it is deactivated by DAMOS watermarks or going out of the main loop, it marks the request as canceled, so that damos_walk() can wakeup and return. Signed-off-by: SeongJae Park --- include/linux/damon.h | 33 ++++++++++- mm/damon/core.c | 132 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 163 insertions(+), 2 deletions(-) diff --git a/include/linux/damon.h b/include/linux/damon.h index ac2d42a50751..2889de3526c3 100644 --- a/include/linux/damon.h +++ b/include/linux/damon.h @@ -352,6 +352,31 @@ struct damos_filter { struct list_head list; }; +struct damon_ctx; +struct damos; + +/** + * struct damos_walk_control - Control damos_walk(). + * + * @walk_fn: Function to be called back for each region. + * @data: Data that will be passed to walk functions. + * + * Control damos_walk(), which requests specific kdamond to invoke the given + * function to each region that eligible to apply actions of the kdamond's + * schemes. Refer to damos_walk() for more details. + */ +struct damos_walk_control { + void (*walk_fn)(void *data, struct damon_ctx *ctx, + struct damon_target *t, struct damon_region *r, + struct damos *s); + void *data; +/* private: internal use only */ + /* informs if the kdamond finished handling of the walk request */ + struct completion completion; + /* informs if the walk is canceled. */ + bool canceled; +}; + /** * struct damos_access_pattern - Target access pattern of the given scheme. * @min_sz_region: Minimum size of target regions. @@ -415,6 +440,8 @@ struct damos { * @action */ unsigned long next_apply_sis; + /* informs if ongoing DAMOS walk for this scheme is finished */ + bool walk_completed; /* public: */ struct damos_quota quota; struct damos_watermarks wmarks; @@ -442,8 +469,6 @@ enum damon_ops_id { NR_DAMON_OPS, }; -struct damon_ctx; - /** * struct damon_operations - Monitoring operations for given use cases. * @@ -656,6 +681,9 @@ struct damon_ctx { struct damon_call_control *call_control; struct mutex call_control_lock; + struct damos_walk_control *walk_control; + struct mutex walk_control_lock; + /* public: */ struct task_struct *kdamond; struct mutex kdamond_lock; @@ -804,6 +832,7 @@ int damon_start(struct damon_ctx **ctxs, int nr_ctxs, bool exclusive); int damon_stop(struct damon_ctx **ctxs, int nr_ctxs); int damon_call(struct damon_ctx *ctx, struct damon_call_control *control); +int damos_walk(struct damon_ctx *ctx, struct damos_walk_control *control); int damon_set_region_biggest_system_ram_default(struct damon_target *t, unsigned long *start, unsigned long *end); diff --git a/mm/damon/core.c b/mm/damon/core.c index 97f19ec4179c..d02a7d6da855 100644 --- a/mm/damon/core.c +++ b/mm/damon/core.c @@ -505,6 +505,7 @@ struct damon_ctx *damon_new_ctx(void) mutex_init(&ctx->kdamond_lock); mutex_init(&ctx->call_control_lock); + mutex_init(&ctx->walk_control_lock); ctx->attrs.min_nr_regions = 10; ctx->attrs.max_nr_regions = 1000; @@ -1211,6 +1212,46 @@ int damon_call(struct damon_ctx *ctx, struct damon_call_control *control) return 0; } +/** + * damos_walk() - Invoke a given functions while DAMOS walk regions. + * @ctx: DAMON context to call the functions for. + * @control: Control variable of the walk request. + * + * Ask DAMON worker thread (kdamond) of @ctx to call a function for each region + * that the kdamond will apply DAMOS action to, and wait until the kdamond + * finishes handling of the request. + * + * The kdamond executes the given function in the main loop, for each region + * just after it applied any DAMOS actions of @ctx to it. The invocation is + * made only within one &damos->apply_interval_us since damos_walk() + * invocation, for each scheme. The given callback function can hence safely + * access the internal data of &struct damon_ctx and &struct damon_region that + * each of the scheme will apply the action for next interval, without + * additional synchronizations against the kdamond. If every scheme of @ctx + * passed at least one &damos->apply_interval_us, kdamond marks the request as + * completed so that damos_walk() can wakeup and return. + * + * Return: 0 on success, negative error code otherwise. + */ +int damos_walk(struct damon_ctx *ctx, struct damos_walk_control *control) +{ + init_completion(&control->completion); + control->canceled = false; + mutex_lock(&ctx->walk_control_lock); + if (ctx->walk_control) { + mutex_unlock(&ctx->walk_control_lock); + return -EBUSY; + } + ctx->walk_control = control; + mutex_unlock(&ctx->walk_control_lock); + if (!damon_is_running(ctx)) + return -EINVAL; + wait_for_completion(&control->completion); + if (control->canceled) + return -ECANCELED; + return 0; +} + /* * Reset the aggregated monitoring results ('nr_accesses' of each region). */ @@ -1390,6 +1431,91 @@ static bool damos_filter_out(struct damon_ctx *ctx, struct damon_target *t, return false; } +/* + * damos_walk_call_walk() - Call &damos_walk_control->walk_fn. + * @ctx: The context of &damon_ctx->walk_control. + * @t: The monitoring target of @r that @s will be applied. + * @r: The region of @t that @s will be applied. + * @s: The scheme of @ctx that will be applied to @r. + * + * This function is called from kdamond whenever it asked the operation set to + * apply a DAMOS scheme action to a region. If a DAMOS walk request is + * installed by damos_walk() and not yet uninstalled, invoke it. + */ +static void damos_walk_call_walk(struct damon_ctx *ctx, struct damon_target *t, + struct damon_region *r, struct damos *s) +{ + struct damos_walk_control *control; + + mutex_lock(&ctx->walk_control_lock); + control = ctx->walk_control; + mutex_unlock(&ctx->walk_control_lock); + if (!control) + return; + control->walk_fn(control->data, ctx, t, r, s); +} + +/* + * damos_walk_complete() - Complete DAMOS walk request if all walks are done. + * @ctx: The context of &damon_ctx->walk_control. + * @s: A scheme of @ctx that all walks are now done. + * + * This function is called when kdamond finished applying the action of a DAMOS + * scheme to all regions that eligible for the given &damos->apply_interval_us. + * If every scheme of @ctx including @s now finished walking for at least one + * &damos->apply_interval_us, this function makrs the handling of the given + * DAMOS walk request is done, so that damos_walk() can wake up and return. + */ +static void damos_walk_complete(struct damon_ctx *ctx, struct damos *s) +{ + struct damos *siter; + struct damos_walk_control *control; + + mutex_lock(&ctx->walk_control_lock); + control = ctx->walk_control; + mutex_unlock(&ctx->walk_control_lock); + if (!control) + return; + + s->walk_completed = true; + /* if all schemes completed, signal completion to walker */ + damon_for_each_scheme(siter, ctx) { + if (!siter->walk_completed) + return; + } + complete(&control->completion); + mutex_lock(&ctx->walk_control_lock); + ctx->walk_control = NULL; + mutex_unlock(&ctx->walk_control_lock); +} + +/* + * damos_walk_cancel() - Cancel the current DAMOS walk request. + * @ctx: The context of &damon_ctx->walk_control. + * + * This function is called when @ctx is deactivated by DAMOS watermarks, DAMOS + * walk is requested but there is no DAMOS scheme to walk for, or the kdamond + * is already out of the main loop and therefore gonna be terminated, and hence + * cannot continue the walks. This function therefore marks the walk request + * as canceled, so that damos_walk() can wake up and return. + */ +static void damos_walk_cancel(struct damon_ctx *ctx) +{ + struct damos_walk_control *control; + + mutex_lock(&ctx->walk_control_lock); + control = ctx->walk_control; + mutex_unlock(&ctx->walk_control_lock); + + if (!control) + return; + control->canceled = true; + complete(&control->completion); + mutex_lock(&ctx->walk_control_lock); + ctx->walk_control = NULL; + mutex_unlock(&ctx->walk_control_lock); +} + static void damos_apply_scheme(struct damon_ctx *c, struct damon_target *t, struct damon_region *r, struct damos *s) { @@ -1444,6 +1570,7 @@ static void damos_apply_scheme(struct damon_ctx *c, struct damon_target *t, damon_nr_regions(t), do_trace); sz_applied = c->ops.apply_scheme(c, t, r, s); } + damos_walk_call_walk(c, t, r, s); ktime_get_coarse_ts64(&end); quota->total_charged_ns += timespec64_to_ns(&end) - timespec64_to_ns(&begin); @@ -1712,6 +1839,7 @@ static void kdamond_apply_schemes(struct damon_ctx *c) damon_for_each_scheme(s, c) { if (c->passed_sample_intervals < s->next_apply_sis) continue; + damos_walk_complete(c, s); s->next_apply_sis = c->passed_sample_intervals + (s->apply_interval_us ? s->apply_interval_us : c->attrs.aggr_interval) / sample_interval; @@ -2024,6 +2152,7 @@ static int kdamond_wait_activation(struct damon_ctx *ctx) ctx->callback.after_wmarks_check(ctx)) break; kdamond_call(ctx, true); + damos_walk_cancel(ctx); } return -EBUSY; } @@ -2117,6 +2246,8 @@ static int kdamond_fn(void *data) */ if (!list_empty(&ctx->schemes)) kdamond_apply_schemes(ctx); + else + damos_walk_cancel(ctx); sample_interval = ctx->attrs.sample_interval ? ctx->attrs.sample_interval : 1; @@ -2157,6 +2288,7 @@ static int kdamond_fn(void *data) mutex_unlock(&ctx->kdamond_lock); kdamond_call(ctx, true); + damos_walk_cancel(ctx); mutex_lock(&damon_lock); nr_running_ctxs--; From patchwork Fri Jan 3 17:43:58 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: SeongJae Park X-Patchwork-Id: 13925766 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 688EAE77198 for ; Fri, 3 Jan 2025 17:44:33 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id F0CA76B009A; Fri, 3 Jan 2025 12:44:22 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id DA6B96B009C; Fri, 3 Jan 2025 12:44:22 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id C1EB36B009D; Fri, 3 Jan 2025 12:44:22 -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 9E7B26B009A for ; Fri, 3 Jan 2025 12:44:22 -0500 (EST) Received: from smtpin02.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id 21CBBA095A for ; Fri, 3 Jan 2025 17:44:22 +0000 (UTC) X-FDA: 82966864176.02.C0F2C4E Received: from nyc.source.kernel.org (nyc.source.kernel.org [147.75.193.91]) by imf29.hostedemail.com (Postfix) with ESMTP id 2402B120008 for ; Fri, 3 Jan 2025 17:43:06 +0000 (UTC) Authentication-Results: imf29.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=e7dfKc9L; spf=pass (imf29.hostedemail.com: domain of sj@kernel.org designates 147.75.193.91 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=1735926206; 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=fKAC/uwaet3CuhemlmuxmKRbcB3XUMDNeMBAgxiMOlI=; b=xtP3mwVMdo5OBrHxX96ByVdXyR2+UBn+rGJEP7vx4WtIt20eii4HSFos6vJZRZfckapHGL DP5g3/YCWFSVmr1rYioWK1uicEJ7gccOybEqEZbzncVr7aeZeTraqkf+xnWpOYSDjfV76o O3s5caRXoyXtqhszGWDIjkZoaa2eZfM= ARC-Authentication-Results: i=1; imf29.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=e7dfKc9L; spf=pass (imf29.hostedemail.com: domain of sj@kernel.org designates 147.75.193.91 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=1735926206; a=rsa-sha256; cv=none; b=nplu/nyIxtQQ/FWscinlhTyfdxKBGsbHk4dCPhge+CT4nJzg+fdu+1kkHDTt6zVS1fcMRx p09voZ9B/hX8khAgriJQdv77mD8XOoDcT2Cz9v1hhF1UPfwMwBxjr74mAb0/VoOoIuOgiS faJZ/VSKqbTR/Ehq7WTii1Ij6LfNY2o= Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by nyc.source.kernel.org (Postfix) with ESMTP id C9B95A41026; Fri, 3 Jan 2025 17:42:30 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 9C88BC4CED6; Fri, 3 Jan 2025 17:44:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1735926259; bh=ex2cW5mU/E6fAA+W/k+OvrLTIak6tQKdwMDzL9/VmTI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=e7dfKc9LBbs8Wmv5ZSOAcOMAI9VAqDjbrtYkn5A85z4azDq2JNjiVPD//CxORn3ta 6Uop6Gjhi0KTg5+K1kU7cYPVCLaXdZdrbhJ2eKeu1VlcrGYq4LNDYbb4hDy6Fyqe37 kjIgj5NXNwzh0TcMweafCE3/jKAghPfv6woal8w7hiCLf/Dw6tCFB6SvWBib5Z8CwX eS1/mmfeJmf70lJ0mre8qE1gmOjkmbXyB3JKwgAc6O6CrJ0q56KFDGKLDYB8wVU//e LMac1HM3Ib+1+pVXBW8wkokXKU9UxUYkVoIr1+GTHGjt/Sz12bGhaw9k2MRimS1H2Q DIbdDtIJYiCfw== From: SeongJae Park To: Andrew Morton Cc: SeongJae Park , Jonathan Corbet , damon@lists.linux.dev, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org Subject: [PATCH 08/10] Docs/mm/damon/design: document DAMOS regions walking Date: Fri, 3 Jan 2025 09:43:58 -0800 Message-Id: <20250103174400.54890-9-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: rspam06 X-Rspamd-Queue-Id: 2402B120008 X-Rspam-User: X-Stat-Signature: 4pzy3zrq5wjhbmqmw4nuuypu1xiu646n X-HE-Tag: 1735926186-949689 X-HE-Meta: U2FsdGVkX19ig2BitzbkpsKIY6ImKQqE68JtvJguj6UcNoPMUSSGTKyAK1ca3nbTrZBtD6kdwHsjNvpYkemQfd073G4ptDjS7uFddWNWAj6xRf7/eiag3Vn2zmb7g8nwSRwEUyuSwgnP/3E3ko06osu3xCXzf0Ahw7CexvSIA1jpW2cTFNMJgg//yRzm7jMzVRwsKdaKOusx1upbGCotpDYdpmSuTQRL4TYfa7Tw+/8HuAVyhrKkW4aYwdiymE+fDz02HnNhOEgCWOShuYcW9iNSpszK96Ox8tztALioEpK5oJ7js5Z70FBEBFoI/ntsJuEWrEgr5zytIxgK7aWSv5DzVXgtqn7Y86zVfOI2fOFHYgbf6qQXA1nJJo9PRifxZ1aMhAJUcQoJchU4LW1sSQpPGOSBfocL5XALLGaNKXmg31pawqKqY2Z07UiJKsp+CNeKdpdnIB6ndy3hvYs/Jeo9n11iVBpf9dduMHN2vPK4nDCSF7c5mgnL21sBXPkKSFfjMnnPS1B9mW+VqexkdDv1aMiu+w0uP8DfDyvywZFP21LNm4Q8ZVUSU2uVkyZZDwfpRxGmbKVFKD+Y/dbn/6bF1z3+3kFARUIU7IF1mLJc6e7i0UrJKwPuGwqPNOF9BCi0LYMSoeKhsnBRinroIB3/Bs90s+bs5Tizq2e7M3Wqfnon/yzgPki4J6aYURl00hdzWIbNAjX210VZEAanZx9dGgiHvIo+9RSvr95T+p5fcjpiFUahgrFCMBH3gZI1SSqCLAGcIV6XjUHvP7M3QlkNmwK/L1+9v6pkLRq7DV+PaPS1Zx3aBRz/fWVbEoYKQ9KRmBkZUvI29907SxTKgjVrPKpASMwqQxbD+SWf0FybbBGipe60WcJyo6vD68TYCTI6dE2ssm+zFQ9zOEp4ccszt0v64loo23/CiNNrBfQJGV0Cy6hEpvztBUjVMLRo/xpvNKkE92i+s/1I/mD CII0sgT1 n3XZs4x0mCmr0YCiUO1yQxK+pjJxd2hJqAHmqJ6Ur3vuXEZjzSzrQdqsB2hxY/iky9IRJN4qT81xFSXEJJ6SwEE70jDapMLPX2kPNU2T3//HGdQsqZhVAvgIuU4sFmqI2olg3tGsS1HeR3f3H5CYMzfGyYebcMJmMDcx5wb/SavBcSm1m21S3ySfrNsd4fpUa/C0NN4a1bmCZXJ8I+/VqCqKM8ULSyMjboUFQyS3V4fFbcTtl4kQU3K0ngDQuHuMRdVV6Kno0QlVrkn8= X-Bogosity: Ham, tests=bogofilter, spamicity=0.011048, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: DAMOS' regions walking is a feature for efficiently retrieving monitoring results or DAMOS-internal behavior. It can be useful for multiple purposes including investigations and tuning. Add a section for it on the design document. Signed-off-by: SeongJae Park --- Documentation/mm/damon/design.rst | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/Documentation/mm/damon/design.rst b/Documentation/mm/damon/design.rst index 1c8a43b07b00..5385ea04c2fd 100644 --- a/Documentation/mm/damon/design.rst +++ b/Documentation/mm/damon/design.rst @@ -540,6 +540,17 @@ To know how user-space can set the watermarks via :ref:`DAMON sysfs interface documentation. +Regions Walking +~~~~~~~~~~~~~~~ + +DAMOS feature allowing users access each region that a DAMOS action has just +applied. Using this feature, DAMON :ref:`API ` allows users +access full properties of the regions including the access monitoring results. +:ref:`DAMON sysfs interface ` also allows users read the data +via special :ref:`files `. + +.. _damon_design_api: + Application Programming Interface --------------------------------- From patchwork Fri Jan 3 17:43:59 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: SeongJae Park X-Patchwork-Id: 13925767 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 86103E77188 for ; Fri, 3 Jan 2025 17:44:35 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id EE0F16B009C; Fri, 3 Jan 2025 12:44:23 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id E8FA06B009D; Fri, 3 Jan 2025 12:44:23 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id D0B1A6B009E; Fri, 3 Jan 2025 12:44:23 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id A1D406B009C for ; Fri, 3 Jan 2025 12:44:23 -0500 (EST) Received: from smtpin26.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id 4B0B38095F for ; Fri, 3 Jan 2025 17:44:23 +0000 (UTC) X-FDA: 82966863252.26.F671475 Received: from nyc.source.kernel.org (nyc.source.kernel.org [147.75.193.91]) by imf07.hostedemail.com (Postfix) with ESMTP id C5E0040015 for ; Fri, 3 Jan 2025 17:42:45 +0000 (UTC) Authentication-Results: imf07.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=hJjyRE9+; spf=pass (imf07.hostedemail.com: domain of sj@kernel.org designates 147.75.193.91 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=1735926213; a=rsa-sha256; cv=none; b=xIwKXtI4OzVj4vxgosIskJEwMHT3zQTGm3Klyipyc5nSYPfDy4CMeZAg2tzDYUEZAzQbpf DPA6/xk3KfmOAOajEMihKVsirZDshBMzuPQb0n3GRjqr7ksBgJmTujqTs+vZoTxRczB1hC tQfyVSwK6s+NhykwChaIg/MCvOGFvU0= ARC-Authentication-Results: i=1; imf07.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=hJjyRE9+; spf=pass (imf07.hostedemail.com: domain of sj@kernel.org designates 147.75.193.91 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=1735926213; 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=n2QQrOJXhF/D7O++uXiKjCaUfKEUp/yhSHDO13AikpM=; b=0DU7jyXCbDQWYZh4t1APkd+HT9B7CDuky0+kC9ebXzzOULolQhtC5/SyY8Qz0qCGByReWF 10W6rsw9oVU2j6wht1QNfvubEKZvbyF4iV5NCpR7mopBmkdcw4ijpgP3nxZ4V96IiS85v+ FrTmtOuq0A5SmUFhAcL1yG+QpescM6M= Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by nyc.source.kernel.org (Postfix) with ESMTP id E04D7A41042; Fri, 3 Jan 2025 17:42:31 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id AF26CC4CECE; Fri, 3 Jan 2025 17:44:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1735926260; bh=0AG/RC/M0bhm6WeM0GMTuPdy7IYbXvGsIfaoLaPfpCY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=hJjyRE9+8H54mkpZ6BRFxdU14eB4Phkr6Ho40LTYktzdahdxWg1oftRRevZOtCu3f Qautu2v6d+NS6ozj/xOddO7xD9bEMTrAt8NOqv708mPGoOac9PiK/Ea/y65nPfx3N8 pfeeQwuJ2H1hcdhXBTwc9Gk5Y9WhPnJG3kD6gWIS4at0P4vocjSA+cxHXSjux2L7QD GTueVv+Wtt+5A93Q9NV099U3xDMSsEjSG3AhE6u7Ls8T/ZfYClEjqRZwdQ+oxFjYFf 1Hzu2poCoxe5n0guUXVGrEDKeZ2+Jf1BgsCFNb0hmRi3E43/QubKc5Fa6M9OgWrVd8 mNQPMKt0hD9tw== From: SeongJae Park To: Andrew Morton Cc: SeongJae Park , damon@lists.linux.dev, linux-kernel@vger.kernel.org, linux-mm@kvack.org Subject: [PATCH 09/10] mm/damon/sysfs: use damos_walk() for update_schemes_tried_{bytes,regions} Date: Fri, 3 Jan 2025 09:43:59 -0800 Message-Id: <20250103174400.54890-10-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-Queue-Id: C5E0040015 X-Stat-Signature: t6w53dheict6dum8at5uzurcier8i5a9 X-Rspam-User: X-Rspamd-Server: rspam09 X-HE-Tag: 1735926165-522534 X-HE-Meta: U2FsdGVkX18k+xCBBLPc3sNY0ixqrb7ALb0nTJEo5Z2rkqjOwMZYx8zYTYHK7OZauyerrM3D7zFY8ldaXL7C0Iu1cTiBxTiSXBOf13pgOWxFGTLKehjq+ncFyskXLulADlWP26SAbIj/psT+1y+LU75Cw63Ec3FSiOF+mMcBI61Qsz3mX+e+VtCBGjLfRdc2vCjFQZn0qKf0SxP131vdXgIGDc+39gmRugVzLo0dS/H9BqzIXH/fZOrSzwB7U4fpfBNIEHRLF/0vgOhHLK4eTNj/SZw19mizFhE/65dNYPOTFBcXv99MrIi5eZ693DeYIP9IL78Taeue9Q2HzHO20ecrYfcbS/CS1L60MlDWs5j/db8gdcHqhSyZofSM7pn+lRc8isedJ3abCWiC7OH9eW7d0F/fHzQrCEAssD9Emfo35sSSPDr7F7DgynfVWlUfEgMC42Z+q0T4Z5jWpRao64z1w3cnQngc9xERiBRdT1aj0k2gwzJSwzrPo7QZcR5CruoIq1Q3ihr651yFCz9HJUI5mSAHxXPPzQ1eYUBUZ8+DoMyhS46NU/v7Qvv4url21O+uxzsYLMn47clExNRQgQVJm+F08ic2fP+eueFxdyPtDeK5/T+yDoJ63Dcqw6nT+VAi5jHBo7m0W/Cugo9/G377+Zu1Ci/yPBfXuCoFwXTzRPwttipsqfT0tm9UsfV+CkMwg99/+f0Kw+FdaA6OjBlb+cSwky3zwoaPxk6MhZdDzWNbc+++XgxPSdssDRB/g1jU8HOO1UUBgbdxxJyeMXItaDDjpsZIEsHGgdm3beXQOzaCfJO2BYo35QvH//2hIJm+TuUV0xSuaR0QPu1WM0naLyOzYbEDpkzNntVyp0x5sVJaPcH9ZcQaqXUhoqEE2DaFSuniboT5gpK/QteVk5/zjvmW2NsKplQZPR1AK4RSTDL6/s4Xx/85blZUfrqhy/XD2j6y82U0otLXKaa 90ij3vpl sbJF6/FP1i8QyNZebNmJs+MHEslqZ6rhNoLJhdqidQxJy02RG484AcD4TWy5HDGbE9LrIvzr2L7+ygT9PEw965Vd6Wuo19i3QDcne8UC2Njs3cKW7qfFKGdzVzfwbr73uRhlArX1CiLHLDqTLPH6oMA2KfQvdmbVn6a4ISAtb7ZkJDJyw3f68NkuMIXlbOTGjKudQaLc3Db8xLpa6EzuWvs7+Nh9U0EJp6lhK08iIYp/+rkjsr3SLCBsmGU092cOXJyVIaWuFs/1rg437UnNRElOm2A== 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 complicated synchronization facility to handle update_schemes_tried_bytes and update_schemes_tried_regions commands. But damos_walk() can support the use case without the additional synchronizations. Convert the code to use damos_walk() instead. Signed-off-by: SeongJae Park --- mm/damon/sysfs-common.h | 5 +++++ mm/damon/sysfs-schemes.c | 48 ++++++++++++++++++++++++++++++++++++++++ mm/damon/sysfs.c | 43 +++++++++++++++++++++++++++++++++++ 3 files changed, 96 insertions(+) diff --git a/mm/damon/sysfs-common.h b/mm/damon/sysfs-common.h index e79b4a65ff2d..81f1c845118f 100644 --- a/mm/damon/sysfs-common.h +++ b/mm/damon/sysfs-common.h @@ -55,6 +55,11 @@ bool damos_sysfs_regions_upd_done(void); int damon_sysfs_schemes_update_regions_stop(struct damon_ctx *ctx); +void damos_sysfs_populate_region_dir(struct damon_sysfs_schemes *sysfs_schemes, + struct damon_ctx *ctx, struct damon_target *t, + struct damon_region *r, struct damos *s, + bool total_bytes_only); + int damon_sysfs_schemes_clear_regions( struct damon_sysfs_schemes *sysfs_schemes); diff --git a/mm/damon/sysfs-schemes.c b/mm/damon/sysfs-schemes.c index c57ab47686ff..1d8ad637051a 100644 --- a/mm/damon/sysfs-schemes.c +++ b/mm/damon/sysfs-schemes.c @@ -2183,6 +2183,54 @@ static int damon_sysfs_before_damos_apply(struct damon_ctx *ctx, return 0; } +/** + * damos_sysfs_populate_region_dir() - Populate a schemes tried region dir. + * @sysfs_schemes: Schemes directory to populate regions directory. + * @ctx: Corresponding DAMON context. + * @t: DAMON target of @r. + * @r: DAMON region to populate the directory for. + * @s: Corresponding scheme. + * @total_bytes_only: Whether the request is for bytes update only. + * + * Called from DAMOS walk callback while holding damon_sysfs_lock. + */ +void damos_sysfs_populate_region_dir(struct damon_sysfs_schemes *sysfs_schemes, + struct damon_ctx *ctx, struct damon_target *t, + struct damon_region *r, struct damos *s, bool total_bytes_only) +{ + struct damos *scheme; + struct damon_sysfs_scheme_regions *sysfs_regions; + struct damon_sysfs_scheme_region *region; + int schemes_idx = 0; + + damon_for_each_scheme(scheme, ctx) { + if (scheme == s) + break; + schemes_idx++; + } + + /* user could have removed the scheme sysfs dir */ + if (schemes_idx >= sysfs_schemes->nr) + return; + + sysfs_regions = sysfs_schemes->schemes_arr[schemes_idx]->tried_regions; + sysfs_regions->total_bytes += r->ar.end - r->ar.start; + if (total_bytes_only) + return; + + region = damon_sysfs_scheme_region_alloc(r); + if (!region) + return; + list_add_tail(®ion->list, &sysfs_regions->regions_list); + sysfs_regions->nr_regions++; + if (kobject_init_and_add(®ion->kobj, + &damon_sysfs_scheme_region_ktype, + &sysfs_regions->kobj, "%d", + sysfs_regions->nr_regions++)) { + kobject_put(®ion->kobj); + } +} + /* * DAMON callback that called after each accesses sampling. While this * callback is registered, damon_sysfs_lock should be held to ensure the diff --git a/mm/damon/sysfs.c b/mm/damon/sysfs.c index 917e6aca3f58..4ba44a314f2e 100644 --- a/mm/damon/sysfs.c +++ b/mm/damon/sysfs.c @@ -1512,6 +1512,45 @@ static int damon_sysfs_damon_call(int (*fn)(void *data), return damon_call(kdamond->damon_ctx, &call_control); } +struct damon_sysfs_schemes_walk_data { + struct damon_sysfs_kdamond *sysfs_kdamond; + bool total_bytes_only; +}; + +/* populate the region directory */ +static void damon_sysfs_schemes_tried_regions_upd_one(void *data, struct damon_ctx *ctx, + struct damon_target *t, struct damon_region *r, + struct damos *s) +{ + struct damon_sysfs_schemes_walk_data *walk_data = data; + struct damon_sysfs_kdamond *sysfs_kdamond = walk_data->sysfs_kdamond; + + damos_sysfs_populate_region_dir( + sysfs_kdamond->contexts->contexts_arr[0]->schemes, + ctx, t, r, s, walk_data->total_bytes_only); +} + +static int damon_sysfs_update_schemes_tried_regions( + struct damon_sysfs_kdamond *sysfs_kdamond, bool total_bytes_only) +{ + struct damon_sysfs_schemes_walk_data walk_data = { + .sysfs_kdamond = sysfs_kdamond, + .total_bytes_only = total_bytes_only, + }; + struct damos_walk_control control = { + .walk_fn = damon_sysfs_schemes_tried_regions_upd_one, + .data = &walk_data, + }; + struct damon_ctx *ctx = sysfs_kdamond->damon_ctx; + + if (!ctx) + return -EINVAL; + + damon_sysfs_schemes_clear_regions( + sysfs_kdamond->contexts->contexts_arr[0]->schemes); + return damos_walk(ctx, &control); +} + /* * damon_sysfs_handle_cmd() - Handle a command for a specific kdamond. * @cmd: The command to handle. @@ -1542,6 +1581,10 @@ static int damon_sysfs_handle_cmd(enum damon_sysfs_cmd cmd, case DAMON_SYSFS_CMD_UPDATE_SCHEMES_STATS: return damon_sysfs_damon_call( damon_sysfs_upd_schemes_stats, kdamond); + case DAMON_SYSFS_CMD_UPDATE_SCHEMES_TRIED_BYTES: + return damon_sysfs_update_schemes_tried_regions(kdamond, true); + case DAMON_SYSFS_CMD_UPDATE_SCHEMES_TRIED_REGIONS: + return damon_sysfs_update_schemes_tried_regions(kdamond, false); case DAMON_SYSFS_CMD_CLEAR_SCHEMES_TRIED_REGIONS: return damon_sysfs_schemes_clear_regions( kdamond->contexts->contexts_arr[0]->schemes); From patchwork Fri Jan 3 17:44:00 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: SeongJae Park X-Patchwork-Id: 13925768 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 E624DE77188 for ; Fri, 3 Jan 2025 17:44:37 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 012A46B009E; Fri, 3 Jan 2025 12:44:25 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id F05766B009F; Fri, 3 Jan 2025 12:44:24 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id D0A546B00A0; Fri, 3 Jan 2025 12:44:24 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id B00406B009E for ; Fri, 3 Jan 2025 12:44:24 -0500 (EST) Received: from smtpin03.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id 75E1D1608A0 for ; Fri, 3 Jan 2025 17:44:24 +0000 (UTC) X-FDA: 82966862244.03.71CBDD1 Received: from nyc.source.kernel.org (nyc.source.kernel.org [147.75.193.91]) by imf16.hostedemail.com (Postfix) with ESMTP id 14F51180018 for ; Fri, 3 Jan 2025 17:43:29 +0000 (UTC) Authentication-Results: imf16.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=gHVNUPVz; dmarc=pass (policy=quarantine) header.from=kernel.org; spf=pass (imf16.hostedemail.com: domain of sj@kernel.org designates 147.75.193.91 as permitted sender) smtp.mailfrom=sj@kernel.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1735926239; 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=9JAlw7XvehbdsMTJw6PdqdFa818K21BGIHZWKFbMOIE=; b=kXUju7wgxpUEAoflNI/jsQvGml+yZLXbIkz23UalUhnN1OlPxrS/svrN/lBtmCcUwq2ixU XjkXqEcbXoH9qgQaz3Af9AanV/5K8/lnmtoPxf4OHV19PAnkaVAxjlUA1tEfrVu+HIpcDB uIdIQF0XQ7WJThgUcziRGmciydzvdMU= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1735926239; a=rsa-sha256; cv=none; b=M6NQlc0KKYDsMd150QIqDPXZlntG6vWR5i6tQYnCsdnSJHhVKlzSRXnjuWvf2MZPXeD63u um6jyktqEQWMBN3xA6vjnb/u6xKqTkrCUMPJ9QdqsJaQsR1PnGZd0mFc+7XT/kKgd0NCxF 2iC/F0bJB+fBPq6l4O1C5CW+l01FcaU= ARC-Authentication-Results: i=1; imf16.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=gHVNUPVz; dmarc=pass (policy=quarantine) header.from=kernel.org; spf=pass (imf16.hostedemail.com: domain of sj@kernel.org designates 147.75.193.91 as permitted sender) smtp.mailfrom=sj@kernel.org Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by nyc.source.kernel.org (Postfix) with ESMTP id F0941A41046; Fri, 3 Jan 2025 17:42:32 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id B3FD3C4CEDC; Fri, 3 Jan 2025 17:44:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1735926262; bh=OfM4+ASQzquOI9PQ720oHjnGo91lYu+MMlnD/0TFf7o=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=gHVNUPVzUGN38B0q75yQWFjNnyOmqoa/GJd9qHGqQYcBF78X8Cf8fSVaxmKX6KBqk 8fX944GYefToDwQPcTmtgWR1bUG2J9ZUJ8LHX2w3qzit1SWrLyNlqN97plh/mChReB dyhT3jBPAvIPNIOjAQrAzv826X0+tDYkHTrQBSjMf89J6O5s6nBr6EXEEtDjeINQ6+ HawS40sZ66R2Loi/gcGbvMHmganax0t/3+o+agJ1LONDjYjRpee+vvQuWZhA/G/uYM au3+FH5OYBMhfq4mW1D3/b4h2N6dE3k/Fs1I2xP4KzH/0SH6OhZwlQFHsLqU0W8qNk 5UZhgsiU5nOSA== From: SeongJae Park To: Andrew Morton Cc: SeongJae Park , damon@lists.linux.dev, linux-kernel@vger.kernel.org, linux-mm@kvack.org Subject: [PATCH 10/10] mm/damon/sysfs: remove unused code for schemes tried regions update Date: Fri, 3 Jan 2025 09:44:00 -0800 Message-Id: <20250103174400.54890-11-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-Stat-Signature: pooiynn1oh1p3mxcm5oiz8xz1f1kdpxe X-Rspamd-Queue-Id: 14F51180018 X-Rspam-User: X-Rspamd-Server: rspam01 X-HE-Tag: 1735926209-298818 X-HE-Meta: U2FsdGVkX1/NReWPyOjwaleldCdlJQ8VO6pB246TaRnJyN3hIOuZLWzop4fhBhQjBpqBQmPLAMRQC+0B6zcO6hqmmuOzXAh1YhNP2eh+REUx8K+T0jcihTRn2Oe/1ogMakjRsESUO07965IJRVKoq0aF4p8rFxFGw9Snni+HlnaBpShyvap1fGD2JC5srkHUnDNYT2C3dt+p466xN2n/EHqq8Fn1PwziXaAtYGdROCQBFDlICmRaDrKi7pVKKvxDz5tgD6yxn8S8UzQVLcawfrKkPhyV81+mC9FhF4ofVGab3SP+jvATBjSHJGo2itWBPQ2wwQC2hFaPEuv/rUFsO5FMUPKzGGLMGX6UrlykWNaLUjoLQPc9x6ijzUlh3AX32jToQNxJsR03p61X/aJBRwIGEKR/f7+qrD5AB6f82QmuOFVc5R2ewOPv57Rx4DETPuW0dkXdPkTVMiQjabG+VQcJvL4xKSjz1Yqim6a/TO6Q+Ha7cSCWSA17yrHy5X+AK8o/ShWa+tkYVvdbTXgNSA/a1Fh54nlz4WqG/HOOk7KqStf40PtbcO+5PSzR5ws8ekSt1fZztYsS1pdQY1w2mkZyuJAXdthaYslQH7+S7zdZRYbl6qmGMRFAgXv1cud4btgxXKzG4u9pKvp+C+/cjzJFVsxgmHNLYAvPTkjEU1mlxky8ZDJ71TI9IBP2TfWmvdT0HaMNvfdR5+4Dt+2Cfjvx5eeDYBiYR/w3pc5xiTlCAIysYs2AKejaykrwZM3ewIGX/Fz7o32sZozQM5tER7RhPJogyrmYJvR+zDTQDfvkgTkFnxnNYhv7fumcgzeuNKFxulknkyk6hw7HQUaejo4J89FYxPVaOIOoagyJbYzWn0yxOpDDJl5vOISss45Gmoa1Wi67vbB0wmLQGdkc5oq3+gkUGFZouCvDwAiVrcnzTLrDB9Hb+4hDVus8b8O0Jqn41F4sgKJTlK4YtSR 50GNXhht SpDQqPimWGa4yKLFPfhWbZxsMY43/5YkDXgED/95kTSAsbsqvevlcNUeLvI57vAJMpbs7teVqyPB6TYv296G3rYZuZqT2hDMD9q3Zf0hJQxHQhtijswFvqd4rcIakssOCm7n4LzH8ojKRfnGBN84/HPl/ntiX9i/5s6EnIi29s8Q6Y4ySYXqhCQQSr42807KeiqmhY8Azci6dBoVwagSXZ8vZezgLUnNNdRtvi74fvn/VXBE= 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 was using damon_callback with its own complicated synchronization logics to update DAMOS scheme applied regions directories and files. But it is replaced to use damos_walk(), and the additional synchronization logics are no more being used. Remove those. Signed-off-by: SeongJae Park --- mm/damon/sysfs-common.h | 10 -- mm/damon/sysfs-schemes.c | 204 --------------------------------------- mm/damon/sysfs.c | 70 +------------- 3 files changed, 2 insertions(+), 282 deletions(-) diff --git a/mm/damon/sysfs-common.h b/mm/damon/sysfs-common.h index 81f1c845118f..b3f63bc658b7 100644 --- a/mm/damon/sysfs-common.h +++ b/mm/damon/sysfs-common.h @@ -45,16 +45,6 @@ void damon_sysfs_schemes_update_stats( struct damon_sysfs_schemes *sysfs_schemes, struct damon_ctx *ctx); -int damon_sysfs_schemes_update_regions_start( - struct damon_sysfs_schemes *sysfs_schemes, - struct damon_ctx *ctx, bool total_bytes_only); - -void damos_sysfs_mark_finished_regions_updates(struct damon_ctx *ctx); - -bool damos_sysfs_regions_upd_done(void); - -int damon_sysfs_schemes_update_regions_stop(struct damon_ctx *ctx); - void damos_sysfs_populate_region_dir(struct damon_sysfs_schemes *sysfs_schemes, struct damon_ctx *ctx, struct damon_target *t, struct damon_region *r, struct damos *s, diff --git a/mm/damon/sysfs-schemes.c b/mm/damon/sysfs-schemes.c index 1d8ad637051a..5c4490b97258 100644 --- a/mm/damon/sysfs-schemes.c +++ b/mm/damon/sysfs-schemes.c @@ -114,55 +114,11 @@ static const struct kobj_type damon_sysfs_scheme_region_ktype = { * scheme regions directory */ -/* - * enum damos_sysfs_regions_upd_status - Represent DAMOS tried regions update - * status - * @DAMOS_TRIED_REGIONS_UPD_IDLE: Waiting for next request. - * @DAMOS_TRIED_REGIONS_UPD_STARTED: Update started. - * @DAMOS_TRIED_REGIONS_UPD_FINISHED: Update finished. - * - * Each DAMON-based operation scheme (&struct damos) has its own apply - * interval, and we need to expose the scheme tried regions based on only - * single snapshot. For this, we keep the tried regions update status for each - * scheme. The status becomes 'idle' at the beginning. - * - * Once the tried regions update request is received, the request handling - * start function (damon_sysfs_scheme_update_regions_start()) sets the status - * of all schemes as 'idle' again, and register ->before_damos_apply() - * callback. - * - * Then, the first followup ->before_damos_apply() callback - * (damon_sysfs_before_damos_apply()) sets the status 'started'. The first - * ->after_sampling() or ->after_aggregation() callback - * (damon_sysfs_cmd_request_callback()) after the call is called only after - * the scheme is completely applied to the given snapshot. Hence the callback - * knows the situation by showing 'started' status, and sets the status as - * 'finished'. Then, damon_sysfs_before_damos_apply() understands the - * situation by showing the 'finished' status and do nothing. - * - * If DAMOS is not applied to any region due to any reasons including the - * access pattern, the watermarks, the quotas, and the filters, - * ->before_damos_apply() will not be called back. Until the situation is - * changed, the update will not be finished. To avoid this, - * damon_sysfs_after_sampling() set the status as 'finished' if more than two - * apply intervals of the scheme is passed while the state is 'idle'. - * - * Finally, the tried regions request handling finisher function - * (damon_sysfs_schemes_update_regions_stop()) unregisters the callbacks. - */ -enum damos_sysfs_regions_upd_status { - DAMOS_TRIED_REGIONS_UPD_IDLE, - DAMOS_TRIED_REGIONS_UPD_STARTED, - DAMOS_TRIED_REGIONS_UPD_FINISHED, -}; - struct damon_sysfs_scheme_regions { struct kobject kobj; struct list_head regions_list; int nr_regions; unsigned long total_bytes; - enum damos_sysfs_regions_upd_status upd_status; - unsigned long upd_timeout_jiffies; }; static struct damon_sysfs_scheme_regions * @@ -178,7 +134,6 @@ damon_sysfs_scheme_regions_alloc(void) INIT_LIST_HEAD(®ions->regions_list); regions->nr_regions = 0; regions->total_bytes = 0; - regions->upd_status = DAMOS_TRIED_REGIONS_UPD_IDLE; return regions; } @@ -2126,63 +2081,6 @@ void damon_sysfs_schemes_update_stats( } } -/* - * damon_sysfs_schemes that need to update its schemes regions dir. Protected - * by damon_sysfs_lock - */ -static struct damon_sysfs_schemes *damon_sysfs_schemes_for_damos_callback; -static int damon_sysfs_schemes_region_idx; -static bool damos_regions_upd_total_bytes_only; - -/* - * DAMON callback that called before damos apply. While this callback is - * registered, damon_sysfs_lock should be held to ensure the regions - * directories exist. - */ -static int damon_sysfs_before_damos_apply(struct damon_ctx *ctx, - struct damon_target *t, struct damon_region *r, - struct damos *s) -{ - struct damos *scheme; - struct damon_sysfs_scheme_regions *sysfs_regions; - struct damon_sysfs_scheme_region *region; - struct damon_sysfs_schemes *sysfs_schemes = - damon_sysfs_schemes_for_damos_callback; - int schemes_idx = 0; - - damon_for_each_scheme(scheme, ctx) { - if (scheme == s) - break; - schemes_idx++; - } - - /* user could have removed the scheme sysfs dir */ - if (schemes_idx >= sysfs_schemes->nr) - return 0; - - sysfs_regions = sysfs_schemes->schemes_arr[schemes_idx]->tried_regions; - if (sysfs_regions->upd_status == DAMOS_TRIED_REGIONS_UPD_FINISHED) - return 0; - if (sysfs_regions->upd_status == DAMOS_TRIED_REGIONS_UPD_IDLE) - sysfs_regions->upd_status = DAMOS_TRIED_REGIONS_UPD_STARTED; - sysfs_regions->total_bytes += r->ar.end - r->ar.start; - if (damos_regions_upd_total_bytes_only) - return 0; - - region = damon_sysfs_scheme_region_alloc(r); - if (!region) - return 0; - list_add_tail(®ion->list, &sysfs_regions->regions_list); - sysfs_regions->nr_regions++; - if (kobject_init_and_add(®ion->kobj, - &damon_sysfs_scheme_region_ktype, - &sysfs_regions->kobj, "%d", - damon_sysfs_schemes_region_idx++)) { - kobject_put(®ion->kobj); - } - return 0; -} - /** * damos_sysfs_populate_region_dir() - Populate a schemes tried region dir. * @sysfs_schemes: Schemes directory to populate regions directory. @@ -2231,29 +2129,6 @@ void damos_sysfs_populate_region_dir(struct damon_sysfs_schemes *sysfs_schemes, } } -/* - * DAMON callback that called after each accesses sampling. While this - * callback is registered, damon_sysfs_lock should be held to ensure the - * regions directories exist. - */ -void damos_sysfs_mark_finished_regions_updates(struct damon_ctx *ctx) -{ - struct damon_sysfs_schemes *sysfs_schemes = - damon_sysfs_schemes_for_damos_callback; - struct damon_sysfs_scheme_regions *sysfs_regions; - int i; - - for (i = 0; i < sysfs_schemes->nr; i++) { - sysfs_regions = sysfs_schemes->schemes_arr[i]->tried_regions; - if (sysfs_regions->upd_status == - DAMOS_TRIED_REGIONS_UPD_STARTED || - time_after(jiffies, - sysfs_regions->upd_timeout_jiffies)) - sysfs_regions->upd_status = - DAMOS_TRIED_REGIONS_UPD_FINISHED; - } -} - /* Called from damon_sysfs_cmd_request_callback under damon_sysfs_lock */ int damon_sysfs_schemes_clear_regions( struct damon_sysfs_schemes *sysfs_schemes) @@ -2270,82 +2145,3 @@ int damon_sysfs_schemes_clear_regions( } return 0; } - -static struct damos *damos_sysfs_nth_scheme(int n, struct damon_ctx *ctx) -{ - struct damos *scheme; - int i = 0; - - damon_for_each_scheme(scheme, ctx) { - if (i == n) - return scheme; - i++; - } - return NULL; -} - -static void damos_tried_regions_init_upd_status( - struct damon_sysfs_schemes *sysfs_schemes, - struct damon_ctx *ctx) -{ - int i; - struct damos *scheme; - struct damon_sysfs_scheme_regions *sysfs_regions; - - for (i = 0; i < sysfs_schemes->nr; i++) { - sysfs_regions = sysfs_schemes->schemes_arr[i]->tried_regions; - scheme = damos_sysfs_nth_scheme(i, ctx); - if (!scheme) { - sysfs_regions->upd_status = - DAMOS_TRIED_REGIONS_UPD_FINISHED; - continue; - } - sysfs_regions->upd_status = DAMOS_TRIED_REGIONS_UPD_IDLE; - sysfs_regions->upd_timeout_jiffies = jiffies + - 2 * usecs_to_jiffies(scheme->apply_interval_us ? - scheme->apply_interval_us : - ctx->attrs.aggr_interval); - } -} - -/* Called while damon_sysfs_lock is hold */ -int damon_sysfs_schemes_update_regions_start( - struct damon_sysfs_schemes *sysfs_schemes, - struct damon_ctx *ctx, bool total_bytes_only) -{ - damon_sysfs_schemes_clear_regions(sysfs_schemes); - damon_sysfs_schemes_for_damos_callback = sysfs_schemes; - damos_tried_regions_init_upd_status(sysfs_schemes, ctx); - damos_regions_upd_total_bytes_only = total_bytes_only; - ctx->callback.before_damos_apply = damon_sysfs_before_damos_apply; - return 0; -} - -bool damos_sysfs_regions_upd_done(void) -{ - struct damon_sysfs_schemes *sysfs_schemes = - damon_sysfs_schemes_for_damos_callback; - struct damon_sysfs_scheme_regions *sysfs_regions; - int i; - - for (i = 0; i < sysfs_schemes->nr; i++) { - sysfs_regions = sysfs_schemes->schemes_arr[i]->tried_regions; - if (sysfs_regions->upd_status != - DAMOS_TRIED_REGIONS_UPD_FINISHED) - return false; - } - return true; -} - -/* - * Called from damon_sysfs_cmd_request_callback under damon_sysfs_lock. Caller - * should unlock damon_sysfs_lock which held before - * damon_sysfs_schemes_update_regions_start() - */ -int damon_sysfs_schemes_update_regions_stop(struct damon_ctx *ctx) -{ - damon_sysfs_schemes_for_damos_callback = NULL; - ctx->callback.before_damos_apply = NULL; - damon_sysfs_schemes_region_idx = 0; - return 0; -} diff --git a/mm/damon/sysfs.c b/mm/damon/sysfs.c index 4ba44a314f2e..cf8fb5a963d6 100644 --- a/mm/damon/sysfs.c +++ b/mm/damon/sysfs.c @@ -1181,25 +1181,9 @@ static int damon_sysfs_add_targets(struct damon_ctx *ctx, return 0; } -static bool damon_sysfs_schemes_regions_updating; - static void damon_sysfs_before_terminate(struct damon_ctx *ctx) { struct damon_target *t, *next; - struct damon_sysfs_kdamond *kdamond; - enum damon_sysfs_cmd cmd; - - /* damon_sysfs_schemes_update_regions_stop() might not yet called */ - kdamond = damon_sysfs_cmd_request.kdamond; - cmd = damon_sysfs_cmd_request.cmd; - if (kdamond && ctx == kdamond->damon_ctx && - (cmd == DAMON_SYSFS_CMD_UPDATE_SCHEMES_TRIED_REGIONS || - cmd == DAMON_SYSFS_CMD_UPDATE_SCHEMES_TRIED_BYTES) && - damon_sysfs_schemes_regions_updating) { - damon_sysfs_schemes_update_regions_stop(ctx); - damon_sysfs_schemes_regions_updating = false; - mutex_unlock(&damon_sysfs_lock); - } if (!damon_target_has_pid(ctx)) return; @@ -1232,28 +1216,6 @@ static int damon_sysfs_upd_schemes_stats(void *data) return 0; } -static int damon_sysfs_upd_schemes_regions_start( - struct damon_sysfs_kdamond *kdamond, bool total_bytes_only) -{ - struct damon_ctx *ctx = kdamond->damon_ctx; - - if (!ctx) - return -EINVAL; - return damon_sysfs_schemes_update_regions_start( - kdamond->contexts->contexts_arr[0]->schemes, ctx, - total_bytes_only); -} - -static int damon_sysfs_upd_schemes_regions_stop( - struct damon_sysfs_kdamond *kdamond) -{ - struct damon_ctx *ctx = kdamond->damon_ctx; - - if (!ctx) - return -EINVAL; - return damon_sysfs_schemes_update_regions_stop(ctx); -} - static inline bool damon_sysfs_kdamond_running( struct damon_sysfs_kdamond *kdamond) { @@ -1358,12 +1320,10 @@ static int damon_sysfs_cmd_request_callback(struct damon_ctx *c, bool active, bool after_aggregation) { struct damon_sysfs_kdamond *kdamond; - bool total_bytes_only = false; int err = 0; /* avoid deadlock due to concurrent state_store('off') */ - if (!damon_sysfs_schemes_regions_updating && - !mutex_trylock(&damon_sysfs_lock)) + if (!mutex_trylock(&damon_sysfs_lock)) return 0; kdamond = damon_sysfs_cmd_request.kdamond; if (!kdamond || kdamond->damon_ctx != c) @@ -1374,39 +1334,13 @@ static int damon_sysfs_cmd_request_callback(struct damon_ctx *c, bool active, goto out; err = damon_sysfs_commit_input(kdamond); break; - case DAMON_SYSFS_CMD_UPDATE_SCHEMES_TRIED_BYTES: - total_bytes_only = true; - fallthrough; - case DAMON_SYSFS_CMD_UPDATE_SCHEMES_TRIED_REGIONS: - if (!damon_sysfs_schemes_regions_updating) { - err = damon_sysfs_upd_schemes_regions_start(kdamond, - total_bytes_only); - if (!err) { - damon_sysfs_schemes_regions_updating = true; - goto keep_lock_out; - } - } else { - damos_sysfs_mark_finished_regions_updates(c); - /* - * Continue regions updating if DAMON is till - * active and the update for all schemes is not - * finished. - */ - if (active && !damos_sysfs_regions_upd_done()) - goto keep_lock_out; - err = damon_sysfs_upd_schemes_regions_stop(kdamond); - damon_sysfs_schemes_regions_updating = false; - } - break; default: break; } /* Mark the request as invalid now. */ damon_sysfs_cmd_request.kdamond = NULL; out: - if (!damon_sysfs_schemes_regions_updating) - mutex_unlock(&damon_sysfs_lock); -keep_lock_out: + mutex_unlock(&damon_sysfs_lock); return err; }