From patchwork Fri Jan 3 17:43:50 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: SeongJae Park X-Patchwork-Id: 13925758 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 BD97BE77188 for ; Fri, 3 Jan 2025 17:44:14 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 3E1FD6B0088; Fri, 3 Jan 2025 12:44:14 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 391466B0089; Fri, 3 Jan 2025 12:44:14 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 259B96B008A; Fri, 3 Jan 2025 12:44:14 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id 0732E6B0088 for ; Fri, 3 Jan 2025 12:44:14 -0500 (EST) Received: from smtpin24.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id AAE0EA0957 for ; Fri, 3 Jan 2025 17:44:13 +0000 (UTC) X-FDA: 82966862874.24.79E7505 Received: from nyc.source.kernel.org (nyc.source.kernel.org [147.75.193.91]) by imf21.hostedemail.com (Postfix) with ESMTP id 8F4E71C0011 for ; Fri, 3 Jan 2025 17:42:32 +0000 (UTC) Authentication-Results: imf21.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=eksEPLCh; dmarc=pass (policy=quarantine) header.from=kernel.org; spf=pass (imf21.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=1735926203; a=rsa-sha256; cv=none; b=uYdgqX6E33R0BukkxmQCAkZxJDWoyL6nbPAEwCwcTLcSOg3g1lm96uFAymfoIVNdvWEXuu OdvM4pNqUsfmXrJDQdw6sKSfqknritxb82I7eYGy4bsd7JUN+1tSeJ4XG2gXX/CBwCADuo HucltxIHvlzVjQVCSOPJ/eKrvfHWsVc= ARC-Authentication-Results: i=1; imf21.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=eksEPLCh; dmarc=pass (policy=quarantine) header.from=kernel.org; spf=pass (imf21.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=1735926203; 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=k2GYT+eX9G+DoFmO0IiCvHFqPc4uBNNPE6PIS0/9uvc=; b=ZXcP69TJwjK45BS6/LqRLOvA5hCStEyaQf7ivn0yjdEkBeWklsfl6scDK8+IfoQexrW43S MmtgjoIfsqA8Z0FG2BdyFUu+QVPHlMksIQZt+Q1OCLuaez4jkNmM/BnAQfP+mhu8pczU+V uMYbml9pzq+PCND4zAiGVxXo/9IsmkM= Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by nyc.source.kernel.org (Postfix) with ESMTP id 25707A40DC7; Fri, 3 Jan 2025 17:42:22 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id CB0A0C4CECE; Fri, 3 Jan 2025 17:44:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1735926251; bh=QxhUTm1Fxoz+hhWeeJHKvT4HGRsA+AbYAkmp06R9U/Y=; h=From:To:Cc:Subject:Date:From; b=eksEPLChZccj7AXoq1tGoFe5i1rGV/j1GqLbUDg/wtPxeuRwMzGe/DSXDOxbvvdKH owXHT6spd/56ufUzai/NQCL57/yD72nGmY7jatSkDXTCzquaYyKhU92uPmTfoV6Cb3 alqR0eAH3D2bxKGrHf0axVVGsg4achjBMpLl88/kqAzq7aX8pHCppoCxtIkNjp+QIG pMLvWla7BOoIjWpv9GfYNUcVvAHSm5M7jcrRxMgVqQnVto54PtmPTqvYhUKP7VLwaI UcN/zUObladvocJvpgFss46p0oncSIkmOZRtV8gCc434GHVrixNobuvYbiRR2Rmd8d WS7tgc1RS7X/Q== 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 00/10] mm/damon: replace most damon_callback usages in sysfs with new core functions Date: Fri, 3 Jan 2025 09:43:50 -0800 Message-Id: <20250103174400.54890-1-sj@kernel.org> X-Mailer: git-send-email 2.39.5 MIME-Version: 1.0 X-Rspamd-Server: rspam04 X-Rspamd-Queue-Id: 8F4E71C0011 X-Stat-Signature: erkyxfny5oxgnf8hiinqiiq87jdft413 X-Rspam-User: X-HE-Tag: 1735926152-192383 X-HE-Meta: U2FsdGVkX1/lr8uFuMpZPkOtcT6oXXVIIS/aHQxtvZhK7F+ihJqa1kGMoNyh3+at8UGD4t24cANglZnhbcMwKxoiDEBJjmvtMmh3vDUSQy4NuN8PtHuWnju9wSSXsYzEOerULLsWQAoQaiN46KVd9i9NoLuvnRtZooKyB451xnVcCU2WTF2vYr0PWWEmTHKl1ghtl+FO8P4dCRadnfuYt0n7KID962s7c8nYJVkwy8nGf3Ls0qRguJltJY8eT9Kke/HX7KBMkn1Ne8bILfJI9Dg6rq034g1dAV4u9EOJ3budz5pHG76Y7AhDRDwyhwYDiV8uHCHnIsSRdQqjlpHCWqxDuOWfOzstYuP5eEc/xqkJLAh3OFjPpNX2lEw3piXDmiWjO8JzHOVH0ouoYrFhhxQfsY08lTUefPYl9xvGRDKoMnvo9KyJy+CRFi0ZjYqXQILowuf7hcFbEIVd0Ir4/dMzP6wPUC57UCDm2kC3sU5SZVk663EcQizylqsrKZo0dFNPqtZ9IljVZTepmMX8ZZRgNqmd2X88JDuoyESoxBDUb6ds7At6PWpz9t5v/c2gxwjlPcuCJVirP41PRERUap509JvtabeGsKymEIutQoaE029FQpw6Ys5RlAjCkS3B0qXOMbdDjnqzSMrjOaDPmSLye/7z6KOz1nEQ2l/jF31m3XM6N0l1AwsHx+fTnVcbsb+cdj+gAO8x7l7aUuSW1wKGvituXyvvIKSupRMnpVVOZX2mXZEft1eDI+GlT3gt0DRYiURzVGjznioCcarXhH+BxrpT7SpRaZsR4A3UGmNyjNP04Hx6TKmb4YH7jLdGuvhh7V4MhlaNe2ipCurKuYSvSFRIYtR0+/yF42OxPtmJa1XEjUDp2CQ9aywxSVFEc1EZmA5DVJHGaud/RaysltJozm150u+irswvVxanY1hHdG6+734S/pF4IQiLkAXt5w9WN2DI5bL30RHQHQN +5A5OEgd yaCClil9if1pFY4dYEih8ifqozCkFySmhqTYmazCs4Sko3KgdY1fDo2JVj7MF7L8P6vTOMRpgrsjH4LShM6v4Vf8Z20pO48dUYWFVoRhMSQnFlHvvNPv4LyZFKRX4zVnIitTYjF/rKCTO1zwq4r+yfRWFfb648avU//t5MyBpxjetLb+YPoQEXqx1+ZtuVtKHfkT91jYcc6tHrqgjJwKqQkbT6OK/TVbavVo5n/D0HBBI2+1hH5FtN0Zd9usouGUb4yMVlElZ3ilB9zWuy3i2b4Kjfh5ktDrvFBZg 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 provides damon_callback API that notifies monitoring events and allows safe access to damon_ctx internal data. The usage is simple. Users register and deregister callback functions for different monitoring events in damon_ctx. Then the DAMON worker thread (kdamond) of the damon_ctx calls back the registered functions on the events. 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 user 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 DAMON parameters and DAMOS auto-tuning inputs, and online retrieval of DAMOS statistics and tried regions information are such usages. Because damon_callback doesn't provide any explicit 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 is becoming somewhat too big and not easy to maintain. The additional mechanisms can be smaller and easier to maintain when implemented inside the core logic layer. 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 in DAMON sysfs interface with the new core API functions. damon_callback usage for online DAMON parameters tuning is not replaced in this series, since it has specific callback timing assumptions that require more works. Patch sequence ============== First two patches are fixups for simplifying the following changes. Those remove a unnecessary condition check and a synchronization, respectively. Third patch implements one of the new DAMON core APIs, namely damon_call(). Three patches replacing damon_callback usages in DAMON sysfs interface using damon_call() follow. Then, seventh and eighth patches introduces the other new DAMON API, damos_walk(), and document it on the design doc. Ninth patch replaces two damon_callback usages in DAMON sysfs interface using damos_walk(). The tenth patch finally cleans up code that no more being used. Revision History ================ Changes from RFC (https://lore.kernel.org/20241213215306.54778-1-sj@kernel.org) - Call damos_call_cotnrol->walk_fn() after applying action - Document DAMOS regions walk feature on design doc - Wordsmith and fix typos in commit messages SeongJae Park (10): 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: introduce 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() Docs/mm/damon/design: document DAMOS regions walking mm/damon/sysfs: use damos_walk() for update_schemes_tried_{bytes,regions} mm/damon/sysfs: remove unused code for schemes tried regions update Documentation/mm/damon/design.rst | 11 ++ include/linux/damon.h | 59 +++++++- mm/damon/core.c | 218 ++++++++++++++++++++++++++++++ mm/damon/sysfs-common.h | 16 +-- mm/damon/sysfs-schemes.c | 206 +++------------------------- mm/damon/sysfs.c | 187 +++++++++++-------------- 6 files changed, 395 insertions(+), 302 deletions(-)