From mboxrd@z Thu Jan 1 00:00:00 1970 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 D7F4CC4332F for ; Thu, 17 Feb 2022 16:19:52 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 270916B0078; Thu, 17 Feb 2022 11:19:50 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 1F8C26B007B; Thu, 17 Feb 2022 11:19:50 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 026466B007E; Thu, 17 Feb 2022 11:19:49 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0003.hostedemail.com [216.40.44.3]) by kanga.kvack.org (Postfix) with ESMTP id DADE26B0078 for ; Thu, 17 Feb 2022 11:19:49 -0500 (EST) Received: from smtpin08.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay03.hostedemail.com (Postfix) with ESMTP id 9A3E08249980 for ; Thu, 17 Feb 2022 16:19:49 +0000 (UTC) X-FDA: 79152782898.08.A52ABA9 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by imf09.hostedemail.com (Postfix) with ESMTP id 09397140009 for ; Thu, 17 Feb 2022 16:19:48 +0000 (UTC) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 14CB4B822AC; Thu, 17 Feb 2022 16:19:47 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 1B78BC340E8; Thu, 17 Feb 2022 16:19:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1645114785; bh=xRpSRW/NxZIB5tKXptMtP6Y4M91PvC3Uxhmzl6GwJ6s=; h=From:To:Cc:Subject:Date:From; b=Fxr33xJon8uAnaxViuAz6dyW9NPO/maV1BqLbEarP9CmwaaFgULoD9/nhGT3RFSkD Z8OlkZbRI7fUkuSJg07xN4Fxfk1q/I4AhwXr0dyp3hwirbxUYbmWLka17If4JwI3Q4 5KyBftpi0UDyZZhQEHU+Bia3cza3Im2pddj3o7I8jyrbMFbuA5GXEvjya0yf5E+ILe OTllDVHwH2qVZ0l0GE4m30jHgC3M1urfX6jvLWmtERSO58LvKvGcviqPRtGJqiE2Kk 9OtaqFJss0STmrxqeMtl3mGPisPHkwsYO2oCauCJhHtsWsGDPhzm9ulMERLNTZMd98 d0EaHtx5dp92Q== From: SeongJae Park To: akpm@linux-foundation.org Cc: rientjes@google.com, xhao@linux.alibaba.com, linux-damon@amazon.com, linux-mm@kvack.org, linux-kernel@vger.kernel.org, SeongJae Park Subject: [RFC PATCH 0/4] Introduce DAMON sysfs interface Date: Thu, 17 Feb 2022 16:19:34 +0000 Message-Id: <20220217161938.8874-1-sj@kernel.org> X-Mailer: git-send-email 2.17.1 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 X-Rspam-User: X-Rspamd-Server: rspam04 X-Rspamd-Queue-Id: 09397140009 X-Stat-Signature: jjkgrozt4etnxekwyyhxk7911gnwga3j Authentication-Results: imf09.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=Fxr33xJo; dmarc=pass (policy=none) header.from=kernel.org; spf=pass (imf09.hostedemail.com: domain of sj@kernel.org designates 145.40.68.75 as permitted sender) smtp.mailfrom=sj@kernel.org X-HE-Tag: 1645114788-124128 Content-Transfer-Encoding: quoted-printable 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: DAMON's debugfs-based user interface served very well, so far. However, = it unnecessarily depends on debugfs, while DAMON is not aimed to be used for= only debugging. Also, the interface receives multiple values via one file. F= or example, schemes file receives 18 values. As a result, it is not only ha= rd to be used, but also difficult to be extended. Especially, keeping backward compatibility of user space tools is getting only challenging. It would = be better to implement another reliable and flexible interface and deprecate= the debugfs interface in long term. For the reason, this patchset introduces a sysfs-based new user interface= of DAMON. The idea of the new interface is, using directory hierarchies and making one file for one value. For a short example, users can do the vir= tual address monitoring via the interface as below: # cd /sys/kernel/mm/damon/admin/ # echo 1 > kdamonds/nr # echo 1 > kdamonds/0/contexts/nr # echo vaddr > kdamonds/0/contexts/0/damon_type # echo 1 > kdamonds/0/contexts/0/targets/nr # echo $(pidof ) > kdamonds/0/contexts/0/targets/0/pid # echo on > kdamonds/0/state Changes that will be made for dropping RFC tag ---------------------------------------------- As the RFC tag means, this is not for merged in the mainline but only for= early comments. Therefore, this version is not implementing all the features o= f DAMON debugfs interface but only basic virtual address space monitoring. = The official version of the patchset will provide all the features that DAMON debugfs interface is providing. Also, this RFC patchset lacks formal documentation. It will be a part of the official version. Future plan of DAMON debugfs interface deprecation -------------------------------------------------- Once the official version of this patchset is merged, DAMON debugfs inter= face development will be frozen. That is, we will keep the interface works as= is now, but it will not provide any new feature of DAMON. The support will = be continued only until next LTS release. After that, we will drop DAMON de= bugfs interface. Changes to the documentation for explicitly announcing the deprecation plan would be a part of the official version of this patchset= . Main difference between DAMON_DBGFS and DAMON_SYSFS --------------------------------------------------- DAMON debugfs interface allows multiple monitoring contexts, but it asks = users to turn those all on and off at once. It's not a big problem but makes t= he operation a little bit complex. DAMON_SYSFS allows users to turn on and = off monitoring contexts individually. The Hierarchy =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D In a glance, the files hierarchy of the sysfs interface is as below. /sys/kernel/mm/damon/admin =E2=94=82 kdamonds =E2=94=82 =E2=94=82 nr =E2=94=82 =E2=94=82 0/ =E2=94=82 =E2=94=82 =E2=94=82 state,pid =E2=94=82 =E2=94=82 =E2=94=82 contexts =E2=94=82 =E2=94=82 =E2=94=82 =E2=94=82 nr =E2=94=82 =E2=94=82 =E2=94=82 =E2=94=82 0/ =E2=94=82 =E2=94=82 =E2=94=82 =E2=94=82 =E2=94=82 damon_type =E2=94=82 =E2=94=82 =E2=94=82 =E2=94=82 =E2=94=82 monitoring_attrs/ =E2=94=82 =E2=94=82 =E2=94=82 =E2=94=82 =E2=94=82 =E2=94=82 intervals= /sample_us,aggr_us,update_us =E2=94=82 =E2=94=82 =E2=94=82 =E2=94=82 =E2=94=82 =E2=94=82 nr_region= s/min,max =E2=94=82 =E2=94=82 =E2=94=82 =E2=94=82 =E2=94=82 targets/ =E2=94=82 =E2=94=82 =E2=94=82 =E2=94=82 =E2=94=82 =E2=94=82 nr =E2=94=82 =E2=94=82 =E2=94=82 =E2=94=82 =E2=94=82 =E2=94=82 0/ =E2=94=82 =E2=94=82 =E2=94=82 =E2=94=82 =E2=94=82 =E2=94=82 =E2=94=82= pid =E2=94=82 =E2=94=82 =E2=94=82 =E2=94=82 =E2=94=82 =E2=94=82 =E2=94=82= regions/ =E2=94=82 =E2=94=82 =E2=94=82 =E2=94=82 =E2=94=82 =E2=94=82 =E2=94=82= =E2=94=82 nr =E2=94=82 =E2=94=82 =E2=94=82 =E2=94=82 =E2=94=82 =E2=94=82 =E2=94=82= =E2=94=82 0/ =E2=94=82 =E2=94=82 =E2=94=82 =E2=94=82 =E2=94=82 =E2=94=82 =E2=94=82= =E2=94=82 =E2=94=82 start,end =E2=94=82 =E2=94=82 =E2=94=82 =E2=94=82 =E2=94=82 =E2=94=82 =E2=94=82= =E2=94=82 ... =E2=94=82 =E2=94=82 =E2=94=82 =E2=94=82 =E2=94=82 =E2=94=82 ... =E2=94=82 =E2=94=82 =E2=94=82 =E2=94=82 =E2=94=82 ... =E2=94=82 =E2=94=82 ... Root ---- The root of the DAMON sysfs is /sys/kernel/mm/damon/, and it has one dire= ctory named 'admin'. The directory contains the interface for privileged user = space programs. User space tools or deamons having root permission could use t= his directory. In a future, sibling directories for non-root user space tool= s or deamons (we could allow them to do monitong of their own virtual address = space) or control of in-kernel DAMON-based deamons could be created. kdamonds/ --------- The monitoring-related information including request specifications and r= esults are called DAMON context. DAMON executes a set of the contexts with a ke= rnel thread called kdamond (for now, only one context per kdamond is supported= ), and multiple kdamonds could run in parallel. This directory has files for controlling the kdamonds. In the beginning, this directory has only one file, 'nr'. Writing a numb= er (`N`) to the file creates the number of child directories named `0` to `N= -1`. Each directory represents each kdamond. kdamonds// ------------- In each kdamond directory, two files (`state` and `pid`) and one director= y (`contexts`) reside. Reading `state` returns `on` if the kdamond is currently running, or `off= ` if it is not running. Writing `on` or `off` makes the kdamond be in the sta= te. If the state is `on`, reading `pid` shows the pid of the kdamond thread. `contexts` directory resembles `kdamonds`. It contains files for control= ling the monitoring contexts that this kdamond will execute. kdamonds//contexts/ ---------------------- In the beginning, this directory has only one file, 'nr'. Writing a numb= er (`N`) to the file creates the number of child directories named as `0` to `N-1`. Each directory represents each monitoring context. At the moment= , only one context per kdamond is supported, so only `0` or `1` can be written t= o the file. contexts// ------------- In each context directory, one file (`operations`) and two directories (`monitoring_attrs` and `targets`) reside. DAMON supports multiple types of monitoring operations, including those f= or virtual address space and physical address space. You can set and show w= hat type of monitoring operations you want to use with the context by writing= one of below keywords to, and reading the file. - vaddr: Monitor virtual address spaces of specific processes Files for specifying attributes of the monitoring including required qual= ity and efficiency of the monitoring are in `monitoring_attrs` directory, whi= le files for specifying to what memory regions the monitoring should be done= are in `targets` directory. contexts//monitoring_attrs/ ------------------------------ In this directory, you can show two directories, `intervals` and `nr_regi= ons`. Under `intervals` directory, three files for DAMON's sampling interval (`sample_us`), aggregation interval (`aggr_us`) and update interval (`update_us`) exist. You can set and get the values by writing to and re= ading from the files. Under `nr_regions` directory, two files for the lower-bound and upper-bou= nd of DAMON's monitoring regions (`min` and `max`, respectively), which control= s the monitoring overhead, reside. You can set and get the values by writing t= o and rading from the files. For more details about the intervals and monitoring regions range, please= read the Design document[1]. [1] https://docs.kernel.org/vm/damon/design.html contexts//targets/ --------------------- In the beginning, this directory has only one file, 'nr'. Writing a numb= er (`N`) to the file creates the number of child directories named `0` to `N= -1`. Each directory represents each monitoring target. targets// ------------ In each target directory, one file (`pid`) exists. You can make the context to monitor the virtual address space of a proces= s by writing the pid of the process to the file, and show what process's virtu= al address space the context is set to monitor by reading the file. SeongJae Park (4): mm/damon: Implement a sysfs-based DAMON user interface mm/damon/core: Allow non-exclusive DAMON start/stop mm/damon/sysfs: Link DAMON to 'state' file read/write functions selftests/damon: Add a test for DAMON sysfs interface include/linux/damon.h | 2 +- mm/damon/Kconfig | 7 + mm/damon/Makefile | 1 + mm/damon/core.c | 22 +- mm/damon/dbgfs.c | 2 +- mm/damon/reclaim.c | 2 +- mm/damon/sysfs.c | 1258 ++++++++++++++++++++++++ tools/testing/selftests/damon/Makefile | 1 + tools/testing/selftests/damon/sysfs.sh | 200 ++++ 9 files changed, 1486 insertions(+), 9 deletions(-) create mode 100644 mm/damon/sysfs.c create mode 100755 tools/testing/selftests/damon/sysfs.sh --=20 2.17.1