From nobody Sun May 10 18:31:56 2026 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id A58C7C433EF for ; Tue, 26 Apr 2022 23:18:07 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1356037AbiDZXVM (ORCPT ); Tue, 26 Apr 2022 19:21:12 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45380 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S243349AbiDZXVI (ORCPT ); Tue, 26 Apr 2022 19:21:08 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 99BEE2558A for ; Tue, 26 Apr 2022 16:17:58 -0700 (PDT) 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 dfw.source.kernel.org (Postfix) with ESMTPS id 32F9D619D9 for ; Tue, 26 Apr 2022 23:17:58 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 2C1B0C385AC; Tue, 26 Apr 2022 23:17:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1651015077; bh=YnkPrrQiKwuGGyvVaqlu6cxudhMT2Z6l0tsHJMGCSLM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=R+wVaca+J8Z0we2yoKSO7pa/nVK4O+JWJv51NVJMdHtqy9uAfxA4KfbmUtKOPL/TF 8geiAzHdQpKjKDEsMTQwOYX+HdIsyKqSEmt9W81+MevTJeqeA7dBEXYqKR9F8jJgII KVTXeHGp+axIKSK5XNuRH0P5nut+3hrm+mHp4K3u+5MtmEu2K/p3I7xe3eaTg9sxUY 61U/3yRlcTv3qGYfXP692Diyzh4x2DJ9S4djv5AKhQKtOmtNYVq2euOpvsNJxCPO0W K16ZCOAIDjb+a/TPd+iM8qLTAnxhrvHNTnIs+36dldyRNJTa/kmTrQpT4bmb4NY3y5 JVMy9EmDJfFxQ== From: sj@kernel.org To: akpm@linux-foundation.org Cc: linux-damon@amazon.com, linux-mm@kvack.org, linux-kernel@vger.kernel.org, SeongJae Park Subject: [PATCH 1/3] mm/damon/vaddr: register a damon_operations for fixed virtual address ranges monitoring Date: Tue, 26 Apr 2022 23:17:48 +0000 Message-Id: <20220426231750.48822-2-sj@kernel.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220426231750.48822-1-sj@kernel.org> References: <20220426231750.48822-1-sj@kernel.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" From: SeongJae Park The monitoring operations set for virtual address spaces automatically updates the monitoring target regions to cover entire mappings of the virtual address spaces as much as possible. Some users could have more information about their programs than kernel and therefore have interest in not entire regions but only specific regions. For such cases, the automatic monitoring target regions updates are only unnecessary overheads or distractions. For such cases, DAMON's API users can simply set the '->init()' and '->update()' of the DAMON context's '->ops' NULL, and set the target monitoring regions when creating the context. But, that would be a dirty hack. Worse yet, the hack is unavailable for DAMON user space interface users. To support the use case in a clean way that can easily exported to the user space, this commit adds another monitoring operations set called 'fvaddr', which is same to 'vaddr' but does not automatically update the monitoring regions. Instead, it will only respect the virtual address regions which have explicitly passed at the initial context creation. Note that this commit leave sysfs interface not supporting the feature yet. The support will be made in a following commit. Signed-off-by: SeongJae Park --- include/linux/damon.h | 3 +++ mm/damon/sysfs.c | 4 ++++ mm/damon/vaddr.c | 15 +++++++++++++-- 3 files changed, 20 insertions(+), 2 deletions(-) diff --git a/include/linux/damon.h b/include/linux/damon.h index 73ff0e2d2a4d..09a5d0d02c00 100644 --- a/include/linux/damon.h +++ b/include/linux/damon.h @@ -261,10 +261,13 @@ struct damos { * enum damon_ops_id - Identifier for each monitoring operations implement= ation * * @DAMON_OPS_VADDR: Monitoring operations for virtual address spaces + * @DAMON_OPS_FVADDR: Monitoring operations for only fixed ranges of virtu= al + * address spaces * @DAMON_OPS_PADDR: Monitoring operations for the physical address space */ enum damon_ops_id { DAMON_OPS_VADDR, + DAMON_OPS_FVADDR, DAMON_OPS_PADDR, NR_DAMON_OPS, }; diff --git a/mm/damon/sysfs.c b/mm/damon/sysfs.c index 6ad6364780b8..719a286d378f 100644 --- a/mm/damon/sysfs.c +++ b/mm/damon/sysfs.c @@ -1694,6 +1694,7 @@ static struct kobj_type damon_sysfs_attrs_ktype =3D { /* This should match with enum damon_ops_id */ static const char * const damon_sysfs_ops_strs[] =3D { "vaddr", + "unsupported", /* fvaddr is not supported by sysfs yet */ "paddr", }; =20 @@ -1843,6 +1844,9 @@ static ssize_t operations_store(struct kobject *kobj, =20 for (id =3D 0; id < NR_DAMON_OPS; id++) { if (sysfs_streq(buf, damon_sysfs_ops_strs[id])) { + /* fvaddr is not supported by sysfs yet */ + if (id =3D=3D DAMON_OPS_FVADDR) + return -EINVAL; context->ops_id =3D id; return count; } diff --git a/mm/damon/vaddr.c b/mm/damon/vaddr.c index b2ec0aa1ff45..5ba82ab4943b 100644 --- a/mm/damon/vaddr.c +++ b/mm/damon/vaddr.c @@ -753,8 +753,19 @@ static int __init damon_va_initcall(void) .apply_scheme =3D damon_va_apply_scheme, .get_scheme_score =3D damon_va_scheme_score, }; - - return damon_register_ops(&ops); + /* ops for fixed virtual address ranges */ + struct damon_operations ops_fvaddr =3D ops; + int err; + + /* Don't set the monitoring target regions for the entire mapping */ + ops_fvaddr.id =3D DAMON_OPS_FVADDR; + ops_fvaddr.init =3D NULL; + ops_fvaddr.update =3D NULL; + + err =3D damon_register_ops(&ops); + if (err) + return err; + return damon_register_ops(&ops_fvaddr); }; =20 subsys_initcall(damon_va_initcall); --=20 2.25.1 From nobody Sun May 10 18:31:56 2026 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 33381C433F5 for ; Tue, 26 Apr 2022 23:18:19 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1356053AbiDZXVZ (ORCPT ); Tue, 26 Apr 2022 19:21:25 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45596 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1356032AbiDZXVK (ORCPT ); Tue, 26 Apr 2022 19:21:10 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C820230558 for ; Tue, 26 Apr 2022 16:18:01 -0700 (PDT) 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 68C2EB823A1 for ; Tue, 26 Apr 2022 23:18:00 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id AEE5CC385AD; Tue, 26 Apr 2022 23:17:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1651015079; bh=Ac9sX0cFu6qC2OwtEEo2VbhjwI2Cs/TjEkOWCiwxUHk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=DyHJBDugogDeufQMDnDXEnfyoCbLHqNjRY8Z4se5aWlgrp4Fe4jjiQMUtk/BnXdjD Yf+kqTq0l5z5Nz/5ZQHi3Axn6iWNz6a4iGzE+LJgNpuEuQzYilPda1ms31a53a7qUj tDH31TkAui+//hvP55k/AGL0PaJ8r524KZGRD6M995+ziZ0+xp1boCeJDFLaefYsdy ANCY5ezgb1DeCVzjh7r9evaRGiQXohDP+QoELqZcCJwnefTqw2oEfHbdN4FoIzMp6Q xdWXIQXod1pHyCH6PF63lkWbZdfsUij9U10WDHDPd1dgovtY3tlElUvvrLN0qBggwj OvCDbB/KL9GtQ== From: sj@kernel.org To: akpm@linux-foundation.org Cc: linux-damon@amazon.com, linux-mm@kvack.org, linux-kernel@vger.kernel.org, SeongJae Park Subject: [PATCH 2/3] mm/damon/sysfs: support fixed virtual address ranges monitoring Date: Tue, 26 Apr 2022 23:17:49 +0000 Message-Id: <20220426231750.48822-3-sj@kernel.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220426231750.48822-1-sj@kernel.org> References: <20220426231750.48822-1-sj@kernel.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" From: SeongJae Park This commit makes DAMON sysfs interface to support the fixed virtual address ranges monitoring. After this commit, writing 'fvaddr' to the 'operations' DAMON sysfs file makes DAMON uses the monitoring operations set for fixed virtual address ranges, so that users can monitor accesses to only interested virtual address ranges. Signed-off-by: SeongJae Park --- mm/damon/sysfs.c | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/mm/damon/sysfs.c b/mm/damon/sysfs.c index 719a286d378f..767ab8c33e4d 100644 --- a/mm/damon/sysfs.c +++ b/mm/damon/sysfs.c @@ -1694,7 +1694,7 @@ static struct kobj_type damon_sysfs_attrs_ktype =3D { /* This should match with enum damon_ops_id */ static const char * const damon_sysfs_ops_strs[] =3D { "vaddr", - "unsupported", /* fvaddr is not supported by sysfs yet */ + "fvaddr", "paddr", }; =20 @@ -1844,9 +1844,6 @@ static ssize_t operations_store(struct kobject *kobj, =20 for (id =3D 0; id < NR_DAMON_OPS; id++) { if (sysfs_streq(buf, damon_sysfs_ops_strs[id])) { - /* fvaddr is not supported by sysfs yet */ - if (id =3D=3D DAMON_OPS_FVADDR) - return -EINVAL; context->ops_id =3D id; return count; } @@ -2136,7 +2133,8 @@ static int damon_sysfs_set_targets(struct damon_ctx *= ctx, damon_sysfs_destroy_targets(ctx); return -ENOMEM; } - if (ctx->ops.id =3D=3D DAMON_OPS_VADDR) { + if (ctx->ops.id =3D=3D DAMON_OPS_VADDR || + ctx->ops.id =3D=3D DAMON_OPS_FVADDR) { t->pid =3D find_get_pid(sys_target->pid); if (!t->pid) { damon_sysfs_destroy_targets(ctx); --=20 2.25.1 From nobody Sun May 10 18:31:56 2026 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 61FFBC433F5 for ; Tue, 26 Apr 2022 23:18:14 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1356047AbiDZXVU (ORCPT ); Tue, 26 Apr 2022 19:21:20 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45582 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1356030AbiDZXVK (ORCPT ); Tue, 26 Apr 2022 19:21:10 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C81A32FFEC for ; Tue, 26 Apr 2022 16:18:01 -0700 (PDT) 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 dfw.source.kernel.org (Postfix) with ESMTPS id 4A010619E3 for ; Tue, 26 Apr 2022 23:18:01 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 383B8C385A0; Tue, 26 Apr 2022 23:18:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1651015080; bh=rP/Ez48eOv8zrnsuUn1nCWIemTRbFqsVKd8lpk7Wji4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=BCFX/ET9+2zk2t6Hyr64Ihi3w2axWHPU4hsV0O5W6nidK9DDWa7ITxuu+1tOX30Zw RwCgxwhoyXYqjsao7i2vnQVbCGSaYkW1vmRjSHFM2LBK6nhy586cpK3kRq66S2DBSU Zxb3EpUluIgFKEthKETw0sKe2LQv2MgpWTBrK00O0ZxLQnZtVDPbbAp5PJvr438iz5 xPAPaMqCILyXt5VIEjI5Td0bKyMS478SZRTBh8hwqmZn+GzJm1n+L7M+bTVvcEq4TK gu4Lz1l4f1zLA/G3Bzg+rLEmyx7EcjY6PLo+oevQr4YNnn5bEfT59nxhnUbcH9MmCC BA67ZZyKNuMxw== From: sj@kernel.org To: akpm@linux-foundation.org Cc: linux-damon@amazon.com, linux-mm@kvack.org, linux-kernel@vger.kernel.org, SeongJae Park Subject: [PATCH 3/3] Docs/{ABI,admin-guide}/damon: update for fixed virtual address ranges monitoring Date: Tue, 26 Apr 2022 23:17:50 +0000 Message-Id: <20220426231750.48822-4-sj@kernel.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220426231750.48822-1-sj@kernel.org> References: <20220426231750.48822-1-sj@kernel.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" From: SeongJae Park This commit documents the user space support of the newly added monitoring operations set for fixed virtual address ranges monitoring, namely 'fvaddr', on the ABI and usage documents for DAMON. Signed-off-by: SeongJae Park --- Documentation/ABI/testing/sysfs-kernel-mm-damon | 14 ++++++++------ Documentation/admin-guide/mm/damon/usage.rst | 14 +++++++++++--- 2 files changed, 19 insertions(+), 9 deletions(-) diff --git a/Documentation/ABI/testing/sysfs-kernel-mm-damon b/Documentatio= n/ABI/testing/sysfs-kernel-mm-damon index d724b8a12228..fab97ea22569 100644 --- a/Documentation/ABI/testing/sysfs-kernel-mm-damon +++ b/Documentation/ABI/testing/sysfs-kernel-mm-damon @@ -50,12 +50,14 @@ What: /sys/kernel/mm/damon/admin/kdamonds//contexts= //operations Date: Mar 2022 Contact: SeongJae Park Description: Writing a keyword for a monitoring operations set ('vaddr' for - virtual address spaces monitoring, and 'paddr' for the physical - address space monitoring) to this file makes the context to use - the operations set. Reading the file returns the keyword for - the operations set the context is set to use. Note that only - the operations sets that listed in 'avail_operations' file are - valid inputs. + virtual address spaces monitoring, 'fvaddr' for fixed virtual + address ranges monitoring, and 'paddr' for the physical address + space monitoring) to this file makes the context to use the + operations set. Reading the file returns the keyword for the + operations set the context is set to use. + + Note that only the operations sets that listed in + 'avail_operations' file are valid inputs. =20 What: /sys/kernel/mm/damon/admin/kdamonds//contexts//monitoring_att= rs/intervals/sample_us Date: Mar 2022 diff --git a/Documentation/admin-guide/mm/damon/usage.rst b/Documentation/a= dmin-guide/mm/damon/usage.rst index af6ffaea567b..9c67311a79d8 100644 --- a/Documentation/admin-guide/mm/damon/usage.rst +++ b/Documentation/admin-guide/mm/damon/usage.rst @@ -154,8 +154,13 @@ available monitoring operations set on the currently r= unning kernel by reading list some or all of below keywords. =20 - vaddr: Monitor virtual address spaces of specific processes + - fvaddr: Monitor fixed virtual address ranges - paddr: Monitor the physical address space of the system =20 +Please refer to :ref:`regions sysfs directory ` for detailed +differences between the operations sets in terms of the monitoring target +regions. + You can set and get what type of monitoring operations DAMON will use for = the context by writing one of the keywords listed in ``avail_operations`` file= and reading from the ``operations`` file. @@ -198,6 +203,8 @@ If you wrote ``vaddr`` to the ``contexts//operations= ``, each target should be a process. You can specify the process to DAMON by writing the pid of = the process to the ``pid_target`` file. =20 +.. _sysfs_regions: + targets//regions ------------------- =20 @@ -208,9 +215,10 @@ can be covered. However, users could want to set the = initial monitoring region to specific address ranges. =20 In contrast, DAMON do not automatically sets and updates the monitoring ta= rget -regions when ``paddr`` monitoring operations set is being used (``paddr`` = is -written to the ``contexts//operations``). Therefore, users should set = the -monitoring target regions by themselves in the case. +regions when ``fvaddr`` or ``paddr`` monitoring operations sets are being = used +(``fvaddr`` or ``paddr`` have written to the ``contexts//operations``). +Therefore, users should set the monitoring target regions by themselves in= the +cases. =20 For such cases, users can explicitly set the initial monitoring target reg= ions as they want, by writing proper values to the files under this directory. --=20 2.25.1