linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 0/4] mm/damon: allow users know which monitoring ops are available
@ 2022-04-26 20:38 sj
  2022-04-26 20:38 ` [PATCH 1/4] mm/damon/core: add a function for damon_operations registration checks sj
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: sj @ 2022-04-26 20:38 UTC (permalink / raw)
  To: akpm; +Cc: linux-damon, linux-mm, linux-kernel, SeongJae Park

From: SeongJae Park <sj@kernel.org>

DAMON users can configure it for vaious address spaces including virtual
address spaces and the physical address space by setting its monitoring
operations set with appropriate one for their purpose.  However, there
is no celan and simple way to know exactly which monitoring operations
sets are available on the currently running kernel.  This patchset adds
functions for the purpose on DAMON's kernel API
('damon_is_registered_ops()') and sysfs interface ('avail_operations'
file under each context directory).

SeongJae Park (4):
  mm/damon/core: add a function for damon_operations registration checks
  mm/damon/sysfs: add a file for listing available monitoring ops
  selftets/damon/sysfs: test existence and permission of
    avail_operations
  Docs/{ABI,admin-guide}/damon: document 'avail_operations' sysfs file

 .../ABI/testing/sysfs-kernel-mm-damon         | 10 +++++++-
 Documentation/admin-guide/mm/damon/usage.rst  | 18 +++++++++-----
 include/linux/damon.h                         |  1 +
 mm/damon/core.c                               | 24 ++++++++++++++++---
 mm/damon/sysfs.c                              | 19 +++++++++++++++
 tools/testing/selftests/damon/sysfs.sh        |  1 +
 6 files changed, 63 insertions(+), 10 deletions(-)

-- 
2.25.1



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

* [PATCH 1/4] mm/damon/core: add a function for damon_operations registration checks
  2022-04-26 20:38 [PATCH 0/4] mm/damon: allow users know which monitoring ops are available sj
@ 2022-04-26 20:38 ` sj
  2022-04-26 20:38 ` [PATCH 2/4] mm/damon/sysfs: add a file for listing available monitoring ops sj
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: sj @ 2022-04-26 20:38 UTC (permalink / raw)
  To: akpm; +Cc: linux-damon, linux-mm, linux-kernel, SeongJae Park

From: SeongJae Park <sj@kernel.org>

To know if a specific 'damon_operations' is registered, users need to
check the kernel config or try 'damon_select_ops()' with the ops of the
question, and then see if it successes.  In the latter case, the user
should also revert the change.  To make the process simple and
convenient, this commit adds a function for checking if a specific
'damon_operations' is registered or not.

Signed-off-by: SeongJae Park <sj@kernel.org>
---
 include/linux/damon.h |  1 +
 mm/damon/core.c       | 24 +++++++++++++++++++++---
 2 files changed, 22 insertions(+), 3 deletions(-)

diff --git a/include/linux/damon.h b/include/linux/damon.h
index f23cbfa4248d..73ff0e2d2a4d 100644
--- a/include/linux/damon.h
+++ b/include/linux/damon.h
@@ -509,6 +509,7 @@ int damon_set_attrs(struct damon_ctx *ctx, unsigned long sample_int,
 int damon_set_schemes(struct damon_ctx *ctx,
 			struct damos **schemes, ssize_t nr_schemes);
 int damon_nr_running_ctxs(void);
+bool damon_is_registered_ops(enum damon_ops_id id);
 int damon_register_ops(struct damon_operations *ops);
 int damon_select_ops(struct damon_ctx *ctx, enum damon_ops_id id);
 
diff --git a/mm/damon/core.c b/mm/damon/core.c
index ca6124eb6516..5c1331f93c2e 100644
--- a/mm/damon/core.c
+++ b/mm/damon/core.c
@@ -30,7 +30,7 @@ static DEFINE_MUTEX(damon_ops_lock);
 static struct damon_operations damon_registered_ops[NR_DAMON_OPS];
 
 /* Should be called under damon_ops_lock with id smaller than NR_DAMON_OPS */
-static bool damon_registered_ops_id(enum damon_ops_id id)
+static bool __damon_is_registered_ops(enum damon_ops_id id)
 {
 	struct damon_operations empty_ops = {};
 
@@ -39,6 +39,24 @@ static bool damon_registered_ops_id(enum damon_ops_id id)
 	return true;
 }
 
+/**
+ * damon_is_registered_ops() - Check if a given damon_operations is registered.
+ * @id:	Id of the damon_operations to check if registered.
+ *
+ * Return: true if the ops is set, false otherwise.
+ */
+bool damon_is_registered_ops(enum damon_ops_id id)
+{
+	bool registered;
+
+	if (id >= NR_DAMON_OPS)
+		return false;
+	mutex_lock(&damon_ops_lock);
+	registered = __damon_is_registered_ops(id);
+	mutex_unlock(&damon_ops_lock);
+	return registered;
+}
+
 /**
  * damon_register_ops() - Register a monitoring operations set to DAMON.
  * @ops:	monitoring operations set to register.
@@ -56,7 +74,7 @@ int damon_register_ops(struct damon_operations *ops)
 		return -EINVAL;
 	mutex_lock(&damon_ops_lock);
 	/* Fail for already registered ops */
-	if (damon_registered_ops_id(ops->id)) {
+	if (__damon_is_registered_ops(ops->id)) {
 		err = -EINVAL;
 		goto out;
 	}
@@ -84,7 +102,7 @@ int damon_select_ops(struct damon_ctx *ctx, enum damon_ops_id id)
 		return -EINVAL;
 
 	mutex_lock(&damon_ops_lock);
-	if (!damon_registered_ops_id(id))
+	if (!__damon_is_registered_ops(id))
 		err = -EINVAL;
 	else
 		ctx->ops = damon_registered_ops[id];
-- 
2.25.1



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

* [PATCH 2/4] mm/damon/sysfs: add a file for listing available monitoring ops
  2022-04-26 20:38 [PATCH 0/4] mm/damon: allow users know which monitoring ops are available sj
  2022-04-26 20:38 ` [PATCH 1/4] mm/damon/core: add a function for damon_operations registration checks sj
@ 2022-04-26 20:38 ` sj
  2022-04-26 20:38 ` [PATCH 3/4] selftets/damon/sysfs: test existence and permission of avail_operations sj
  2022-04-26 20:38 ` [PATCH 4/4] Docs/{ABI,admin-guide}/damon: document 'avail_operations' sysfs file sj
  3 siblings, 0 replies; 5+ messages in thread
From: sj @ 2022-04-26 20:38 UTC (permalink / raw)
  To: akpm; +Cc: linux-damon, linux-mm, linux-kernel, SeongJae Park

From: SeongJae Park <sj@kernel.org>

DAMON programming interface users can know if specific monitoring ops
set is registered or not using 'damon_is_registered_ops()', but there is
no such method for the user space.  To help the case, this commit adds a
new DAMON sysfs file called 'avail_operations' under each context
directory for listing available monitoring ops.  Reading the file will
list each registered monitoring ops on each line.

Signed-off-by: SeongJae Park <sj@kernel.org>
---
 mm/damon/sysfs.c | 19 +++++++++++++++++++
 1 file changed, 19 insertions(+)

diff --git a/mm/damon/sysfs.c b/mm/damon/sysfs.c
index 48e434cd43d8..6ad6364780b8 100644
--- a/mm/damon/sysfs.c
+++ b/mm/damon/sysfs.c
@@ -1810,6 +1810,21 @@ static void damon_sysfs_context_rm_dirs(struct damon_sysfs_context *context)
 	kobject_put(&context->schemes->kobj);
 }
 
+static ssize_t avail_operations_show(struct kobject *kobj,
+		struct kobj_attribute *attr, char *buf)
+{
+	enum damon_ops_id id;
+	int len = 0;
+
+	for (id = 0; id < NR_DAMON_OPS; id++) {
+		if (!damon_is_registered_ops(id))
+			continue;
+		len += sysfs_emit_at(buf, len, "%s\n",
+				damon_sysfs_ops_strs[id]);
+	}
+	return len;
+}
+
 static ssize_t operations_show(struct kobject *kobj,
 		struct kobj_attribute *attr, char *buf)
 {
@@ -1840,10 +1855,14 @@ static void damon_sysfs_context_release(struct kobject *kobj)
 	kfree(container_of(kobj, struct damon_sysfs_context, kobj));
 }
 
+static struct kobj_attribute damon_sysfs_context_avail_operations_attr =
+		__ATTR_RO_MODE(avail_operations, 0400);
+
 static struct kobj_attribute damon_sysfs_context_operations_attr =
 		__ATTR_RW_MODE(operations, 0600);
 
 static struct attribute *damon_sysfs_context_attrs[] = {
+	&damon_sysfs_context_avail_operations_attr.attr,
 	&damon_sysfs_context_operations_attr.attr,
 	NULL,
 };
-- 
2.25.1



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

* [PATCH 3/4] selftets/damon/sysfs: test existence and permission of avail_operations
  2022-04-26 20:38 [PATCH 0/4] mm/damon: allow users know which monitoring ops are available sj
  2022-04-26 20:38 ` [PATCH 1/4] mm/damon/core: add a function for damon_operations registration checks sj
  2022-04-26 20:38 ` [PATCH 2/4] mm/damon/sysfs: add a file for listing available monitoring ops sj
@ 2022-04-26 20:38 ` sj
  2022-04-26 20:38 ` [PATCH 4/4] Docs/{ABI,admin-guide}/damon: document 'avail_operations' sysfs file sj
  3 siblings, 0 replies; 5+ messages in thread
From: sj @ 2022-04-26 20:38 UTC (permalink / raw)
  To: akpm; +Cc: linux-damon, linux-mm, linux-kernel, SeongJae Park

From: SeongJae Park <sj@kernel.org>

This commit adds a selftest test case for ensuring the existence and the
permission (read-only) of the 'avail_oprations' DAMON sysfs file.

Signed-off-by: SeongJae Park <sj@kernel.org>
---
 tools/testing/selftests/damon/sysfs.sh | 1 +
 1 file changed, 1 insertion(+)

diff --git a/tools/testing/selftests/damon/sysfs.sh b/tools/testing/selftests/damon/sysfs.sh
index 2e3ae77cb6db..89592c64462f 100644
--- a/tools/testing/selftests/damon/sysfs.sh
+++ b/tools/testing/selftests/damon/sysfs.sh
@@ -231,6 +231,7 @@ test_context()
 {
 	context_dir=$1
 	ensure_dir "$context_dir" "exist"
+	ensure_file "$context_dir/avail_operations" "exit" 400
 	ensure_file "$context_dir/operations" "exist" 600
 	test_monitoring_attrs "$context_dir/monitoring_attrs"
 	test_targets "$context_dir/targets"
-- 
2.25.1



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

* [PATCH 4/4] Docs/{ABI,admin-guide}/damon: document 'avail_operations' sysfs file
  2022-04-26 20:38 [PATCH 0/4] mm/damon: allow users know which monitoring ops are available sj
                   ` (2 preceding siblings ...)
  2022-04-26 20:38 ` [PATCH 3/4] selftets/damon/sysfs: test existence and permission of avail_operations sj
@ 2022-04-26 20:38 ` sj
  3 siblings, 0 replies; 5+ messages in thread
From: sj @ 2022-04-26 20:38 UTC (permalink / raw)
  To: akpm; +Cc: linux-damon, linux-mm, linux-kernel, SeongJae Park

From: SeongJae Park <sj@kernel.org>

This commit updates the DAMON ABI and usage documents for the new sysfs
file, 'avail_operations'.

Signed-off-by: SeongJae Park <sj@kernel.org>
---
 .../ABI/testing/sysfs-kernel-mm-damon          | 10 +++++++++-
 Documentation/admin-guide/mm/damon/usage.rst   | 18 ++++++++++++------
 2 files changed, 21 insertions(+), 7 deletions(-)

diff --git a/Documentation/ABI/testing/sysfs-kernel-mm-damon b/Documentation/ABI/testing/sysfs-kernel-mm-damon
index 9e282065cbcf..d724b8a12228 100644
--- a/Documentation/ABI/testing/sysfs-kernel-mm-damon
+++ b/Documentation/ABI/testing/sysfs-kernel-mm-damon
@@ -40,6 +40,12 @@ Description:	Writing a number 'N' to this file creates the number of
 		directories for controlling each DAMON context named '0' to
 		'N-1' under the contexts/ directory.
 
+What:		/sys/kernel/mm/damon/admin/kdamonds/<K>/contexts/<C>/avail_operations
+Date:		Apr 2022
+Contact:	SeongJae Park <sj@kernel.org>
+Description:	Reading this file returns the available monitoring operations
+		sets on the currently running kernel.
+
 What:		/sys/kernel/mm/damon/admin/kdamonds/<K>/contexts/<C>/operations
 Date:		Mar 2022
 Contact:	SeongJae Park <sj@kernel.org>
@@ -47,7 +53,9 @@ 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.
+		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 592ea9a50881..af6ffaea567b 100644
--- a/Documentation/admin-guide/mm/damon/usage.rst
+++ b/Documentation/admin-guide/mm/damon/usage.rst
@@ -68,7 +68,7 @@ comma (","). ::
     │ kdamonds/nr_kdamonds
     │ │ 0/state,pid
     │ │ │ contexts/nr_contexts
-    │ │ │ │ 0/operations
+    │ │ │ │ 0/avail_operations,operations
     │ │ │ │ │ monitoring_attrs/
     │ │ │ │ │ │ intervals/sample_us,aggr_us,update_us
     │ │ │ │ │ │ nr_regions/min,max
@@ -143,17 +143,23 @@ be written to the file.
 contexts/<N>/
 -------------
 
-In each context directory, one file (``operations``) and three directories
-(``monitoring_attrs``, ``targets``, and ``schemes``) exist.
+In each context directory, two files (``avail_operations`` and ``operations``)
+and three directories (``monitoring_attrs``, ``targets``, and ``schemes``)
+exist.
 
 DAMON supports multiple types of monitoring operations, including those for
-virtual address space and the physical address space.  You can set and get what
-type of monitoring operations DAMON will use for the context by writing one of
-below keywords to, and reading from the file.
+virtual address space and the physical address space.  You can get the list of
+available monitoring operations set on the currently running kernel by reading
+``avail_operations`` file.  Based on the kernel configuration, the file will
+list some or all of below keywords.
 
  - vaddr: Monitor virtual address spaces of specific processes
  - paddr: Monitor the physical address space of the system
 
+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.
+
 contexts/<N>/monitoring_attrs/
 ------------------------------
 
-- 
2.25.1



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

end of thread, other threads:[~2022-04-26 20:39 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-04-26 20:38 [PATCH 0/4] mm/damon: allow users know which monitoring ops are available sj
2022-04-26 20:38 ` [PATCH 1/4] mm/damon/core: add a function for damon_operations registration checks sj
2022-04-26 20:38 ` [PATCH 2/4] mm/damon/sysfs: add a file for listing available monitoring ops sj
2022-04-26 20:38 ` [PATCH 3/4] selftets/damon/sysfs: test existence and permission of avail_operations sj
2022-04-26 20:38 ` [PATCH 4/4] Docs/{ABI,admin-guide}/damon: document 'avail_operations' sysfs file sj

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).