Skip to contentSkip to conversation

mm/damon/stat: add kdamond_pid parameter

PATCH Applied SeongJae Park 1 participant 3 messages May 2

Subsystems (4)
lore
Share & tools
lore

SeongJae Park

author maintainer
#0 lore raw

cover mm/damon/stat: add kdamond_pid parameter

DAMON_STAT doesn't provide the pid of its kdamond, unlike DAMON_RECLAIM and DAMON_LRU_SORT. This makes user-space management of DAMON_STAT unnecessarily complicated. Provide the information via a new parameter, namely kdamond_pid, and document it.

Changes from RFC v2.1
- v2.1: https://lore.kernel.org/[email protected]
- Add parameter description.
- Rebase to latest mm-new.
Changes from RFC v2
- v2: https://lore.kernel.org/[email protected]
- Rebase to latest mm-new.
Changes from RFC v1.2
- rfc v1.2: https://lore.kernel.org/[email protected]
- Detect and use fresh kdamond pid.
Changes from RFC v1.1
- rfc v1.1: https://lore.kernel.org/[email protected]
- Close the parentheses of error handling block.
Changes from RFC
- rfc: https://lore.kernel.org/[email protected]
- Fix damon_kdamond_pid() failure handling.

SeongJae Park (2):
mm/damon/stat: add a parameter for reading kdamond pid Docs/admin-guide/mm/damon/stat: document kdamond_pid parameter

 Documentation/admin-guide/mm/damon/stat.rst |  7 ++++
 mm/damon/stat.c                             | 39 +++++++++++++++++++++
 2 files changed, 46 insertions(+)

base-commit: c9d6cc2ef4bef0a86002460ee8c39a1c76b3f1f7

Signature · 1 line
2.47.3
author maintainer
#1 lore raw

PATCH 1/2 mm/damon/stat: add a parameter for reading kdamond pid

Knowing the pid of the kdamonds can help user-space management including monitoring of DAMON's system resource consumption. To make it easier, DAMON_SYSFS, DAMON_RECLAIM and DAMON_LRU_SORT provide the pid information. DAMON_STAT is not providing it, though. Expose the pid of DAMON_STAT kdamond via a new read-only module parameter, namely kdamond_pid. This also makes DAMON modules usage more standardized, because DAMON_RECLAIM and DAMON_LRU_SORT also provide the information via their read-only parameters of the same name.

---
 mm/damon/stat.c | 39 +++++++++++++++++++++++++++++++++++++++
 1 file changed, 39 insertions(+)
mm/damon/stat.c +39 -0
index f4d3203e92639..0e14f5bb8f75d 100644
@@ -266,6 +266,45 @@ static int damon_stat_enabled_load(char *buffer, const struct kernel_param *kp)
 	return sprintf(buffer, "%c\n", damon_stat_enabled() ? 'Y' : 'N');
 }
 
+static int damon_stat_kdamond_pid_store(
+		const char *val, const struct kernel_param *kp)
+{
+	/*
+	 * kdamond_pid is read-only, but kernel command line could write it.
+	 * Do nothing here.
+	 */
+	return 0;
+}
+
+static int damon_stat_kdamond_pid_load(
+		char *buffer, const struct kernel_param *kp)
+{
+	int pid;
+
+	if (!damon_stat_context) {
+		pid = -1;
+	} else {
+		pid = damon_kdamond_pid(damon_stat_context);
+		if (pid < 1)
+			pid = -1;
+	}
+	return sprintf(buffer, "%d\n", pid);
+}
+
+static const struct kernel_param_ops kdamond_pid_param_ops = {
+	.set = damon_stat_kdamond_pid_store,
+	.get = damon_stat_kdamond_pid_load,
+};
+
+/*
+ * PID of the DAMON thread
+ *
+ * If DAMON_STAT is enabled, this becomes the PID of the worker thread.
+ * Else, -1.
+ */
+module_param_cb(kdamond_pid, &kdamond_pid_param_ops, NULL, 0400);
+MODULE_PARM_DESC(kdamond_pid, "pid of the kdamond");
+
 static int __init damon_stat_init(void)
 {
 	int err = 0;
Signature · 1 line
2.47.3
author maintainer
#2 lore raw

PATCH 2/2 Docs/admin-guide/mm/damon/stat: document kdamond_pid parameter

In reply to SeongJae Park

Update DAMON_STAT usage document for newly added kdamond_pid parameter.

---
 Documentation/admin-guide/mm/damon/stat.rst | 7 +++++++
 1 file changed, 7 insertions(+)
Documentation/admin-guide/mm/damon/stat.rst +7 -0
index c4b14daeb2dd6..46c5dd96aa2ed 100644
@@ -89,3 +89,10 @@ percentiles of the idle time values via this read-only parameter.  Reading the
 parameter returns 101 idle time values in milliseconds, separated by comma.
 Each value represents 0-th, 1st, 2nd, 3rd, ..., 99th and 100th percentile idle
 times.
+
+kdamond_pid
+-----------
+
+PID of the DAMON thread.
+
+If DAMON_STAT is enabled, this becomes the PID of the worker thread.  Else, -1.
Signature · 1 line
2.47.3