[PATCH] mm/damon: Fix paddr target id problem

From: SeongJae Park
Date: Thu Aug 06 2020 - 04:18:49 EST


The target id for 'paddr' is meaningless, but we set it as '-1' for fun
and smooth interaction with the user space interfaces. However, the
target ids are 'unsigned long' and thus using '-1' makes no sense. This
commit changes the fake number to another funny but unsigned number,
'42'.

Signed-off-by: SeongJae Park <sjpark@xxxxxxxxx>
---
Documentation/admin-guide/mm/damon/usage.rst | 4 ++--
mm/damon.c | 2 +-
tools/damon/_damon.py | 2 +-
3 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/Documentation/admin-guide/mm/damon/usage.rst b/Documentation/admin-guide/mm/damon/usage.rst
index 88b8e9254a7e..3e2f1519c96a 100644
--- a/Documentation/admin-guide/mm/damon/usage.rst
+++ b/Documentation/admin-guide/mm/damon/usage.rst
@@ -334,12 +334,12 @@ check it again::
Users can also monitor the physical memory address space of the system by
writing a special keyword, "``paddr\n``" to the file. Because physical address
space monitoring doesn't support multiple targets, reading the file will show a
-fake value, ``-1``, as below::
+fake value, ``42``, as below::

# cd <debugfs>/damon
# echo paddr > target_ids
# cat target_ids
- -1
+ 42

Note that setting the target ids doesn't start the monitoring.

diff --git a/mm/damon.c b/mm/damon.c
index a9757a0e5cf7..66268cb45b51 100644
--- a/mm/damon.c
+++ b/mm/damon.c
@@ -2047,7 +2047,7 @@ static ssize_t debugfs_target_ids_write(struct file *file,
ctx->target_valid = NULL;

/* target id is meaningless here, but we set it just for fun */
- snprintf(kbuf, count, "-1 ");
+ snprintf(kbuf, count, "42 ");
} else {
/* Configure the context for virtual memory monitoring */
ctx->init_target_regions = kdamond_init_vm_regions;
diff --git a/tools/damon/_damon.py b/tools/damon/_damon.py
index cf14a0d59b94..6ff278117e84 100644
--- a/tools/damon/_damon.py
+++ b/tools/damon/_damon.py
@@ -28,7 +28,7 @@ def set_target(tid, init_regions=[]):
return 0

if tid == 'paddr':
- tid = -1
+ tid = 42
string = ' '.join(['%s %d %d' % (tid, r[0], r[1]) for r in init_regions])
return subprocess.call('echo "%s" > %s' % (string, debugfs_init_regions),
shell=True, executable='/bin/bash')
--
2.17.1