From patchwork Fri Dec 13 21:52:57 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: SeongJae Park X-Patchwork-Id: 13907889 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 CC026E7717F for ; Fri, 13 Dec 2024 21:53:19 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 090E56B007B; Fri, 13 Dec 2024 16:53:19 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 019976B0082; Fri, 13 Dec 2024 16:53:18 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id DFD156B0083; Fri, 13 Dec 2024 16:53:18 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id B8D196B007B for ; Fri, 13 Dec 2024 16:53:18 -0500 (EST) Received: from smtpin10.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id 631DFAFFFD for ; Fri, 13 Dec 2024 21:53:18 +0000 (UTC) X-FDA: 82891286478.10.83A6721 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by imf28.hostedemail.com (Postfix) with ESMTP id 727AEC000B for ; Fri, 13 Dec 2024 21:52:47 +0000 (UTC) Authentication-Results: imf28.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=khIZbyOH; spf=pass (imf28.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=1734126777; 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:references:dkim-signature; bh=5GvI9R2mKcOCpBlyZE1VmD910dhMIirGjgyRnpazMvY=; b=EqaoFwM/GqjaKKxiRiPGAu+6zhktBmYbsKBZHGHnBi1oIsLuiC+x00qg95fzEYdkgzfx/B AYP5v4O5ui/VTRpW8WY1oDwhBEA6bC7vySrthFnVyEdxulmaRqPu5Vynrs+X1oxdlw6+f9 +Q1xJ645/Ha91bdDfkPz9SkciNPG7Iw= ARC-Authentication-Results: i=1; imf28.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=khIZbyOH; spf=pass (imf28.hostedemail.com: domain of sj@kernel.org designates 139.178.84.217 as permitted sender) smtp.mailfrom=sj@kernel.org; dmarc=pass (policy=quarantine) header.from=kernel.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1734126777; a=rsa-sha256; cv=none; b=J2rfKFz2ZlbPHuGB5PLHAT7YNhCBZPp7aJt2C1ONMJwA9Sg6B5PSZWC4+KRC91yVYbXWSq XrVZr5mxGccnhzwSRgNZRsLV0GyQPwyFidbYUG/UWhotgAmoUeJKR+cewKBLcTAW0tv6lQ APYkv1yTrv7ZayBSGaIKn0pDEOlZycU= Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by dfw.source.kernel.org (Postfix) with ESMTP id 50ED55C60B3 for ; Fri, 13 Dec 2024 21:52:33 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 20AF8C4CED0; Fri, 13 Dec 2024 21:53:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1734126795; bh=mR+4nKd1LKKpydDTMtiPpQrNDhEN5Vr0X8tr0Qj3a5k=; h=From:To:Cc:Subject:Date:From; b=khIZbyOH3Bc0k+VFFhYWdlNqueBcGJ50g4spcTMPdihaklXLSZbZ9CMNwvJp3HFm7 2Rcs2JTl/YucvGvK9p2ZSNKffp8w888i07XlgN39L+cdHKoDOnhoE3YTISsBy0R4J2 2eNkj7kl/xH6+EeUiZPxbnnR7mKlj7uedWcg22Rn2bllSThbWBoca1n1A+hYnC/M9F rhRvGJoCUvyZHBI37j9APo3lkK2YkHTpMZ1LaI5XOGE+FgIFPU3RetBlq35jnPhKmL mzK1RFpPC+zsFdFd9ILY9fH5AljxTVYE7tRsfBtSDqe7ZgQwR1VLlklKKMQPTYOL2v wXsyGC3lic8Ag== From: SeongJae Park To: Cc: SeongJae Park , damon@lists.linux.dev, linux-kernel@vger.kernel.org, linux-mm@kvack.org Subject: [RFC PATCH 0/9] mm/damon: replace most damon_callback usages in sysfs with new core functions Date: Fri, 13 Dec 2024 13:52:57 -0800 Message-Id: <20241213215306.54778-1-sj@kernel.org> X-Mailer: git-send-email 2.39.5 MIME-Version: 1.0 X-Rspamd-Queue-Id: 727AEC000B X-Rspamd-Server: rspam12 X-Stat-Signature: mx8f7fijh4cynxbxk7w8h5g3egbhq4hz X-Rspam-User: X-HE-Tag: 1734126767-14097 X-HE-Meta: U2FsdGVkX19hJ3qC/F5kXHMLPs6scZXNBlZjpncTZlm8fdqo3V54Themzfaw7aNTe5Idwilv0EajZ/PBT0mX0YwM/J80iews+wI4qay73Vp7JCrQrTb5ZtmgyhhxCAWKhyDNQ0v8ZVXlLviWie+Rg7AEo/vu8+zovrLpFkTIDPaVPeWDBaVpaz2veFYl81QPDGtjLnz4vrkhCqMoHZUEiisR7iCr0YXTNaMd1EbDp9qTVGF4dhzVYQcg4ZuvaBslGpaVs1mt0F4gZgsWUIUalXNkf3Eu5qqgspkR41tSqBEzmh0wfAh8IDNoV6LTsBsrcu34hPFwjLlbuIJVsTf+vu732YfIev+K6XfaiwS4vveSvXD0ppGWPeVaj8DjuS7/o/cuqn05F+SSCXMYsktcxvtSVg5IGgcq7HHCtMLEYa+hwJY1XMqU7Nwo4Z1PPQF4gRVorjGOeThPXUmOw8Ta4+T7xQJJcCuMpKEJNJVESA0heBBdakXPbWloBGBGZ9fVU8vvPA/ELXaE8AY1sRDp+wx3ZbbUf3caNY+MYCZiGftr6dnCOMfGETJ6kZ7JQTwDr0XS+cBPqGrpoOCSwdQlo020Ll3udpBjncRv26SdV+MdL1ErnbVFg3jxW4sqc4O7QjUPEKynEyc2LOFm5OSk5WEBTnLD8xg7XlHaP/wzwbZLZN0NePF+8IAD6fj70M+2QHpLWJxAgDadN1JSoPGmaGuONaBC4y1IBf/0S/X3js5KljFdBGirzQy0/aJ84uU0fB/FSNNR41utwLE7YVqrMZ/7iIdmaV3DBohbqsfr57yG92ICUE1n5CU98noeGS/1F2veljVeVCKGyFs6Gsxl5shUV3iEADHjCl10C8iuzUWN9MwBhJ8jfJwBkdfeSeSSm3yegi6WUMVY24K9mg3hHt3+vWPeqzUlDeKMB16UAhuOX093lgXtozP7Ff5jewA53hkjVuozcTLzDUsrXeZ 9i9Li1ps FdGAaoHJPCfQnkuCFP+QGKC4tHeTUlnCxmKFIKjZflk+1OGu0vTvt8VGwU+1/W5IV5dCZrk0AD5pZFOM63RQFHb16R5FooRwhY9BvpBD6ED+c7+28cwPQHS6Z5/y29TJ4/cGnOv1t1GrBFkisaUxb4/ogm2d5nwizgwRfumWWeq2DjMSQS4rPq7yj3wBOcvsLuLDKYYZClYmKAyv9YjkVIp48t7QpeqYz6SzVSXFcJC8ff8ZML6N9rtzHvYu7HNOzCQ+3H6lbIZZDByxxr+9sRSUyxIcv9gzYgipxvveLvAkBxlFQlkhQCOJk/AC6ldFXXxWC X-Bogosity: Ham, tests=bogofilter, spamicity=0.000014, 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 provides damon_callback API that notifies monitoring events and allows safe access to damon_ctx internal data. Users can set and unset callback functions for different monitoring events in damon_ctx. Then DAMON worker thread (kdamond) calls back the functions on the events as long as the function is set on the damon_ctx. It is designed in such simple way because it was sufficient for usages of DAMON at the early days. We also wanted to make it flexible so that API client code can implement any required additional features on top of damon_callback on their demands. As expected, more sophisticated usages have invented. Online updates of parameters or DAMOS auto-tuning inputs and retrieval of DAMOS statistics and tried regions are notable such usages. Because damon_callback doesn't provide any explict synchronization mechanism, the user ABIs for exposing such functionalities are implemented in asynchronous ways (DAMON_RECLAIM and DAMON_LRU_SORT}), or synchronous ways (DAMON_SYSFS) with additional synchronization mechanisms that built inside the ABI implementation, on top of damon_callback. So damon_callback is working as expected. However, the additional mechanisms built inside ABI on top of damon_callback beocming somewhat too big and not easy to maintain. damon_callback is basically simple enougy to use in not only correct but also wrong ways. The additional mechanisms can be easier to maintain when implemented inside core logic. Introduce two new DAMON core API, namely 'damon_call()' and 'damos_walk()'. The two functions support synchronous access to - damon_ctx internal data including DAMON parameters and monitoring results, and - DAMOS-specific data such as regions that each DAMOS action is applied, respectively. And replace most of damon_callback usages from DAMON sysfs with the new core API functions. Online DAMON parameters tuning feature is not replaced in this series, since it has specific callback timing assumptions that require more works. Patch sequence ============== First two patches removes unnecessary synchronization dependency of clear_schemes_tried_regions command handling. Third patch implements one of the new DAMON API, damon_call(). Three patches replacing damon_callback usages in DAMON sysfs interface using damon_call() follow. Then, seventh patch introduces the other new DAMON API, damos_walk(). Eighth patch replaces two damon_callback usages in DAMON sysfs interface using damos_walk(). The ninth patch finally cleans up code that no more being used. SeongJae Park (9): mm/damon/sysfs-schemes: remove unnecessary schemes existence check in damon_sysfs_schemes_clear_regions() mm/damon/sysfs: handle clear_schemes_tried_regions from DAMON sysfs context mm/damon/core: implement damon_call() mm/damon/sysfs: use damon_call() for update_schemes_stats mm/damon/sysfs: use damon_call() for commit_schemes_quota_goals mm/damon/sysfs: use damon_call() for update_schemes_effective_quotas mm/damon/core: implement damos_walk() mm/damon/sysfs: use damos_walk() for update_schemes_tried_{bytes,regions} mm/damon/sysfs: remove unused code for schemes tried regions update include/linux/damon.h | 59 ++++++++++- mm/damon/core.c | 220 +++++++++++++++++++++++++++++++++++++++ mm/damon/sysfs-common.h | 16 +-- mm/damon/sysfs-schemes.c | 206 ++++-------------------------------- mm/damon/sysfs.c | 187 +++++++++++++++------------------ 5 files changed, 386 insertions(+), 302 deletions(-) base-commit: e5c48d400cab89a0539ce822ba805f0ad4209e87