All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 0/3] support fixed virtual address ranges monitoring
@ 2022-04-26 23:17 sj
  2022-04-26 23:17 ` [PATCH 1/3] mm/damon/vaddr: register a damon_operations for " sj
                   ` (2 more replies)
  0 siblings, 3 replies; 7+ messages in thread
From: sj @ 2022-04-26 23:17 UTC (permalink / raw)
  To: akpm; +Cc: linux-damon, linux-mm, linux-kernel, SeongJae Park

From: SeongJae Park <sj@kernel.org>

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
overhead or distractions.

This patchset adds supports for the use case on DAMON's kernel API
(DAMON_OPS_FVADDR) and sysfs interface ('fvaddr' keyword for
'operations' sysfs file).

SeongJae Park (3):
  mm/damon/vaddr: register a damon_operations for fixed virtual address
    ranges monitoring
  mm/damon/sysfs: support fixed virtual address ranges monitoring
  Docs/{ABI,admin-guide}/damon: update for fixed virtual address ranges
    monitoring

 Documentation/ABI/testing/sysfs-kernel-mm-damon | 14 ++++++++------
 Documentation/admin-guide/mm/damon/usage.rst    | 14 +++++++++++---
 include/linux/damon.h                           |  3 +++
 mm/damon/sysfs.c                                |  4 +++-
 mm/damon/vaddr.c                                | 15 +++++++++++++--
 5 files changed, 38 insertions(+), 12 deletions(-)

-- 
2.25.1


^ permalink raw reply	[flat|nested] 7+ messages in thread

* [PATCH 1/3] mm/damon/vaddr: register a damon_operations for fixed virtual address ranges monitoring
  2022-04-26 23:17 [PATCH 0/3] support fixed virtual address ranges monitoring sj
@ 2022-04-26 23:17 ` sj
  2022-04-26 23:17 ` [PATCH 2/3] mm/damon/sysfs: support " sj
  2022-04-26 23:17 ` [PATCH 3/3] Docs/{ABI,admin-guide}/damon: update for " sj
  2 siblings, 0 replies; 7+ messages in thread
From: sj @ 2022-04-26 23:17 UTC (permalink / raw)
  To: akpm; +Cc: linux-damon, linux-mm, linux-kernel, SeongJae Park

From: SeongJae Park <sj@kernel.org>

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 <sj@kernel.org>
---
 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 implementation
  *
  * @DAMON_OPS_VADDR:	Monitoring operations for virtual address spaces
+ * @DAMON_OPS_FVADDR:	Monitoring operations for only fixed ranges of virtual
+ *			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 = {
 /* This should match with enum damon_ops_id */
 static const char * const damon_sysfs_ops_strs[] = {
 	"vaddr",
+	"unsupported",	/* fvaddr is not supported by sysfs yet */
 	"paddr",
 };
 
@@ -1843,6 +1844,9 @@ static ssize_t operations_store(struct kobject *kobj,
 
 	for (id = 0; id < NR_DAMON_OPS; id++) {
 		if (sysfs_streq(buf, damon_sysfs_ops_strs[id])) {
+			/* fvaddr is not supported by sysfs yet */
+			if (id == DAMON_OPS_FVADDR)
+				return -EINVAL;
 			context->ops_id = 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 = damon_va_apply_scheme,
 		.get_scheme_score = damon_va_scheme_score,
 	};
-
-	return damon_register_ops(&ops);
+	/* ops for fixed virtual address ranges */
+	struct damon_operations ops_fvaddr = ops;
+	int err;
+
+	/* Don't set the monitoring target regions for the entire mapping */
+	ops_fvaddr.id = DAMON_OPS_FVADDR;
+	ops_fvaddr.init = NULL;
+	ops_fvaddr.update = NULL;
+
+	err = damon_register_ops(&ops);
+	if (err)
+		return err;
+	return damon_register_ops(&ops_fvaddr);
 };
 
 subsys_initcall(damon_va_initcall);
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [PATCH 2/3] mm/damon/sysfs: support fixed virtual address ranges monitoring
  2022-04-26 23:17 [PATCH 0/3] support fixed virtual address ranges monitoring sj
  2022-04-26 23:17 ` [PATCH 1/3] mm/damon/vaddr: register a damon_operations for " sj
@ 2022-04-26 23:17 ` sj
  2022-05-02  7:56   ` Rongwei Wang
  2022-04-26 23:17 ` [PATCH 3/3] Docs/{ABI,admin-guide}/damon: update for " sj
  2 siblings, 1 reply; 7+ messages in thread
From: sj @ 2022-04-26 23:17 UTC (permalink / raw)
  To: akpm; +Cc: linux-damon, linux-mm, linux-kernel, SeongJae Park

From: SeongJae Park <sj@kernel.org>

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 <sj@kernel.org>
---
 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 = {
 /* This should match with enum damon_ops_id */
 static const char * const damon_sysfs_ops_strs[] = {
 	"vaddr",
-	"unsupported",	/* fvaddr is not supported by sysfs yet */
+	"fvaddr",
 	"paddr",
 };
 
@@ -1844,9 +1844,6 @@ static ssize_t operations_store(struct kobject *kobj,
 
 	for (id = 0; id < NR_DAMON_OPS; id++) {
 		if (sysfs_streq(buf, damon_sysfs_ops_strs[id])) {
-			/* fvaddr is not supported by sysfs yet */
-			if (id == DAMON_OPS_FVADDR)
-				return -EINVAL;
 			context->ops_id = 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 == DAMON_OPS_VADDR) {
+		if (ctx->ops.id == DAMON_OPS_VADDR ||
+				ctx->ops.id == DAMON_OPS_FVADDR) {
 			t->pid = find_get_pid(sys_target->pid);
 			if (!t->pid) {
 				damon_sysfs_destroy_targets(ctx);
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [PATCH 3/3] Docs/{ABI,admin-guide}/damon: update for fixed virtual address ranges monitoring
  2022-04-26 23:17 [PATCH 0/3] support fixed virtual address ranges monitoring sj
  2022-04-26 23:17 ` [PATCH 1/3] mm/damon/vaddr: register a damon_operations for " sj
  2022-04-26 23:17 ` [PATCH 2/3] mm/damon/sysfs: support " sj
@ 2022-04-26 23:17 ` sj
  2 siblings, 0 replies; 7+ messages in thread
From: sj @ 2022-04-26 23:17 UTC (permalink / raw)
  To: akpm; +Cc: linux-damon, linux-mm, linux-kernel, SeongJae Park

From: SeongJae Park <sj@kernel.org>

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 <sj@kernel.org>
---
 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/Documentation/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/<K>/contexts/<C>/operations
 Date:		Mar 2022
 Contact:	SeongJae Park <sj@kernel.org>
 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.
 
 What:		/sys/kernel/mm/damon/admin/kdamonds/<K>/contexts/<C>/monitoring_attrs/intervals/sample_us
 Date:		Mar 2022
diff --git a/Documentation/admin-guide/mm/damon/usage.rst b/Documentation/admin-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 running kernel by reading
 list some or all of below keywords.
 
  - vaddr: Monitor virtual address spaces of specific processes
+ - fvaddr: Monitor fixed virtual address ranges
  - paddr: Monitor the physical address space of the system
 
+Please refer to :ref:`regions sysfs directory <sysfs_regions>` 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/<N>/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.
 
+.. _sysfs_regions:
+
 targets/<N>/regions
 -------------------
 
@@ -208,9 +215,10 @@ can be covered.  However, users could want to set the initial monitoring region
 to specific address ranges.
 
 In contrast, DAMON do not automatically sets and updates the monitoring target
-regions when ``paddr`` monitoring operations set is being used (``paddr`` is
-written to the ``contexts/<N>/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/<N>/operations``).
+Therefore, users should set the monitoring target regions by themselves in the
+cases.
 
 For such cases, users can explicitly set the initial monitoring target regions
 as they want, by writing proper values to the files under this directory.
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* Re: [PATCH 2/3] mm/damon/sysfs: support fixed virtual address ranges monitoring
  2022-04-26 23:17 ` [PATCH 2/3] mm/damon/sysfs: support " sj
@ 2022-05-02  7:56   ` Rongwei Wang
  2022-05-02 16:18     ` SeongJae Park
  0 siblings, 1 reply; 7+ messages in thread
From: Rongwei Wang @ 2022-05-02  7:56 UTC (permalink / raw)
  To: sj, akpm; +Cc: linux-damon, linux-mm, linux-kernel

Hi, SeongJae

I had read and tested your patchset these days. It works.
It seems that these patches only fix the issue about init_regions in 
DAMON-sysfs, but not fix in DAMON-dbgfs? maybe I missing something.

If so, do you have any plan to fix this bug in dbgfs? Actually, what I 
want to say is that I ready a patch for solving the init_regions related 
bug in dbgfs these days. I not sure if you're interested in it.

Best Regards,
Rongwei

On 4/27/22 7:17 AM, sj@kernel.org wrote:
> From: SeongJae Park <sj@kernel.org>
> 
> 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 <sj@kernel.org>
> ---
>   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 = {
>   /* This should match with enum damon_ops_id */
>   static const char * const damon_sysfs_ops_strs[] = {
>   	"vaddr",
> -	"unsupported",	/* fvaddr is not supported by sysfs yet */
> +	"fvaddr",
>   	"paddr",
>   };
>   
> @@ -1844,9 +1844,6 @@ static ssize_t operations_store(struct kobject *kobj,
>   
>   	for (id = 0; id < NR_DAMON_OPS; id++) {
>   		if (sysfs_streq(buf, damon_sysfs_ops_strs[id])) {
> -			/* fvaddr is not supported by sysfs yet */
> -			if (id == DAMON_OPS_FVADDR)
> -				return -EINVAL;
>   			context->ops_id = 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 == DAMON_OPS_VADDR) {
> +		if (ctx->ops.id == DAMON_OPS_VADDR ||
> +				ctx->ops.id == DAMON_OPS_FVADDR) {
>   			t->pid = find_get_pid(sys_target->pid);
>   			if (!t->pid) {
>   				damon_sysfs_destroy_targets(ctx);

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH 2/3] mm/damon/sysfs: support fixed virtual address ranges monitoring
  2022-05-02  7:56   ` Rongwei Wang
@ 2022-05-02 16:18     ` SeongJae Park
  2022-05-03  2:20       ` Rongwei Wang
  0 siblings, 1 reply; 7+ messages in thread
From: SeongJae Park @ 2022-05-02 16:18 UTC (permalink / raw)
  To: Rongwei Wang; +Cc: sj, akpm, linux-damon, linux-mm, linux-kernel

Hi Rongwei,

On Mon, 2 May 2022 15:56:58 +0800 Rongwei Wang <rongwei.wang@linux.alibaba.com> wrote:

> Hi, SeongJae
> 
> I had read and tested your patchset these days. It works.

Thank you for the tests! :D

> It seems that these patches only fix the issue about init_regions in 
> DAMON-sysfs, but not fix in DAMON-dbgfs? maybe I missing something.
> 
> If so, do you have any plan to fix this bug in dbgfs? Actually, what I 
> want to say is that I ready a patch for solving the init_regions related 
> bug in dbgfs these days. I not sure if you're interested in it.

The plan is to freeze DAMON debugfs interface after DAMON sysfs interface is
merged, and then entirely remove it after next LTS kernel.  It was mentioned in
the sysfs interface patchset as below:
https://lore.kernel.org/linux-mm/20220228081314.5770-1-sj@kernel.org/

    Future Plan of DAMON_DBGFS Deprecation
    ======================================
    
    Once this patchset is merged, DAMON_DBGFS development will be frozen.  That is,
    we will maintain it to work as is now so that no users will be break.  But, it
    will not be extended to provide any new feature of DAMON.  The support will be
    continued only until next LTS release.  After that, we will drop DAMON_DBGFS.

The plan was also shared in the kernel doc as below[1], but maybe it was too
small to read, or ambiguous.  Sorry if it was the case.

    debugfs interface. This is almost identical to sysfs interface. This will
    be _removed_ after next LTS kernel is released, so users should move to the
    sysfs interface.

[1] https://docs.kernel.org/admin-guide/mm/damon/usage.html#debugfs-interface

So, I don't have a big interest at extending DAMON debugfs for fvaddr.  That
said, of course we could discuss more if you really need it.  If so, please let
me know.


Thanks,
SJ

> 
> Best Regards,
> Rongwei
> 

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH 2/3] mm/damon/sysfs: support fixed virtual address ranges monitoring
  2022-05-02 16:18     ` SeongJae Park
@ 2022-05-03  2:20       ` Rongwei Wang
  0 siblings, 0 replies; 7+ messages in thread
From: Rongwei Wang @ 2022-05-03  2:20 UTC (permalink / raw)
  To: SeongJae Park; +Cc: akpm, linux-damon, linux-mm, linux-kernel



On 5/3/22 12:18 AM, SeongJae Park wrote:
> Hi Rongwei,
> 
> On Mon, 2 May 2022 15:56:58 +0800 Rongwei Wang <rongwei.wang@linux.alibaba.com> wrote:
> 
>> Hi, SeongJae
>>
>> I had read and tested your patchset these days. It works.
> 
> Thank you for the tests! :D
> 
>> It seems that these patches only fix the issue about init_regions in
>> DAMON-sysfs, but not fix in DAMON-dbgfs? maybe I missing something.
>>
>> If so, do you have any plan to fix this bug in dbgfs? Actually, what I
>> want to say is that I ready a patch for solving the init_regions related
>> bug in dbgfs these days. I not sure if you're interested in it.
> 
> The plan is to freeze DAMON debugfs interface after DAMON sysfs interface is
> merged, and then entirely remove it after next LTS kernel.  It was mentioned in
> the sysfs interface patchset as below:
> https://lore.kernel.org/linux-mm/20220228081314.5770-1-sj@kernel.org/
> 
>      Future Plan of DAMON_DBGFS Deprecation
>      ======================================
>      
>      Once this patchset is merged, DAMON_DBGFS development will be frozen.  That is,
>      we will maintain it to work as is now so that no users will be break.  But, it
>      will not be extended to provide any new feature of DAMON.  The support will be
>      continued only until next LTS release.  After that, we will drop DAMON_DBGFS.
> 
> The plan was also shared in the kernel doc as below[1], but maybe it was too
> small to read, or ambiguous.  Sorry if it was the case.
> 
>      debugfs interface. This is almost identical to sysfs interface. This will
>      be _removed_ after next LTS kernel is released, so users should move to the
>      sysfs interface.
Hi, SeongJae

Thanks, for telling me the doc!
It seems that I have to update my datop. New sysfs interface has changed 
too much.

Anyway, Thanks! :)

> 
> [1] https://docs.kernel.org/admin-guide/mm/damon/usage.html#debugfs-interface
> 
> So, I don't have a big interest at extending DAMON debugfs for fvaddr.  That
> said, of course we could discuss more if you really need it.  If so, please let
> me know.
> 
> 
> Thanks,
> SJ
> 
>>
>> Best Regards,
>> Rongwei
>>

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2022-05-03  2:20 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-04-26 23:17 [PATCH 0/3] support fixed virtual address ranges monitoring sj
2022-04-26 23:17 ` [PATCH 1/3] mm/damon/vaddr: register a damon_operations for " sj
2022-04-26 23:17 ` [PATCH 2/3] mm/damon/sysfs: support " sj
2022-05-02  7:56   ` Rongwei Wang
2022-05-02 16:18     ` SeongJae Park
2022-05-03  2:20       ` Rongwei Wang
2022-04-26 23:17 ` [PATCH 3/3] Docs/{ABI,admin-guide}/damon: update for " sj

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.