* [PATCH 0/8] selftests/damon: test DAMOS tried regions and {min,max}_nr_regions
@ 2024-06-25 18:05 SeongJae Park
2024-06-25 18:05 ` [PATCH 1/8] selftests/damon/access_memory: use user-defined region size SeongJae Park
` (7 more replies)
0 siblings, 8 replies; 9+ messages in thread
From: SeongJae Park @ 2024-06-25 18:05 UTC (permalink / raw)
To: Andrew Morton
Cc: SeongJae Park, Shuah Khan, damon, linux-mm, linux-kselftest,
linux-kernel
This patch series fix a minor issue in a program for DAMON selftest, and
implement new functionality selftests for DAMOS tried regions and
{min,max}_nr_regions. The test for max_nr_regions also test the
recovery from online tuning-caused limit violation, which was fixed by a
previous patch [1] titled "mm/damon/core: merge regions aggressively
when max_nr_regions is unmet".
The first patch fixes a minor problem in the articial memory access
pattern generator for tests. Following 3 patches (2-4) implement
schemes tried regions test. Then a couple of patches (5-6) implementing
static setup based {min,max}_nr_regions functionality test follows.
Final two patches (7-8) implement dynamic max_nr_regions update test.
[1] https://lore.kernel.org/20240624210650.53960C2BBFC@smtp.kernel.org
SeongJae Park (8):
selftests/damon/access_memory: use user-defined region size
selftests/damon/_damon_sysfs: support schemes_update_tried_regions
selftests/damon: implement a program for even-numbered memory regions
access
selftests/damon: implement DAMOS tried regions test
selftests/damon/_damon_sysfs: implement kdamonds stop function
selftests/damon: implement test for min/max_nr_regions
_damon_sysfs: implement commit() for online parameters update
selftests/damon/damon_nr_regions: test online-tuned max_nr_regions
tools/testing/selftests/damon/Makefile | 3 +-
tools/testing/selftests/damon/_damon_sysfs.py | 65 +++++++-
tools/testing/selftests/damon/access_memory.c | 2 +-
.../selftests/damon/access_memory_even.c | 42 +++++
.../selftests/damon/damon_nr_regions.py | 145 ++++++++++++++++++
.../selftests/damon/damos_tried_regions.py | 65 ++++++++
6 files changed, 319 insertions(+), 3 deletions(-)
create mode 100644 tools/testing/selftests/damon/access_memory_even.c
create mode 100644 tools/testing/selftests/damon/damon_nr_regions.py
create mode 100644 tools/testing/selftests/damon/damos_tried_regions.py
base-commit: 99348045d11f3bac71146b381f90b0aa39855ee7
--
2.39.2
^ permalink raw reply [flat|nested] 9+ messages in thread
* [PATCH 1/8] selftests/damon/access_memory: use user-defined region size
2024-06-25 18:05 [PATCH 0/8] selftests/damon: test DAMOS tried regions and {min,max}_nr_regions SeongJae Park
@ 2024-06-25 18:05 ` SeongJae Park
2024-06-25 18:05 ` [PATCH 2/8] selftests/damon/_damon_sysfs: support schemes_update_tried_regions SeongJae Park
` (6 subsequent siblings)
7 siblings, 0 replies; 9+ messages in thread
From: SeongJae Park @ 2024-06-25 18:05 UTC (permalink / raw)
To: Andrew Morton
Cc: SeongJae Park, Shuah Khan, damon, linux-mm, linux-kselftest,
linux-kernel
'access_memory' is an artificial memory access pattern generator for
DAMON tests. It creates and accesses memory regions that the user
specified the number and size via the command line. However, real
access part of the program ignores the user-specified size of each
region. Instead, it uses a hard-coded value, 10 MiB. Fix it to use
user-defined size.
Note that all existing 'access_memory' users are setting the region size
as 10 MiB. Hence no real problem has happened so far.
Fixes: b5906f5f7359 ("selftests/damon: add a test for update_schemes_tried_regions sysfs command")
Signed-off-by: SeongJae Park <sj@kernel.org>
---
tools/testing/selftests/damon/access_memory.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/tools/testing/selftests/damon/access_memory.c b/tools/testing/selftests/damon/access_memory.c
index 585a2fa54329..56b17e8fe1be 100644
--- a/tools/testing/selftests/damon/access_memory.c
+++ b/tools/testing/selftests/damon/access_memory.c
@@ -35,7 +35,7 @@ int main(int argc, char *argv[])
start_clock = clock();
while ((clock() - start_clock) * 1000 / CLOCKS_PER_SEC <
access_time_ms)
- memset(regions[i], i, 1024 * 1024 * 10);
+ memset(regions[i], i, sz_region);
}
return 0;
}
--
2.39.2
^ permalink raw reply [flat|nested] 9+ messages in thread
* [PATCH 2/8] selftests/damon/_damon_sysfs: support schemes_update_tried_regions
2024-06-25 18:05 [PATCH 0/8] selftests/damon: test DAMOS tried regions and {min,max}_nr_regions SeongJae Park
2024-06-25 18:05 ` [PATCH 1/8] selftests/damon/access_memory: use user-defined region size SeongJae Park
@ 2024-06-25 18:05 ` SeongJae Park
2024-06-25 18:05 ` [PATCH 3/8] selftests/damon: implement a program for even-numbered memory regions access SeongJae Park
` (5 subsequent siblings)
7 siblings, 0 replies; 9+ messages in thread
From: SeongJae Park @ 2024-06-25 18:05 UTC (permalink / raw)
To: Andrew Morton
Cc: SeongJae Park, Shuah Khan, damon, linux-mm, linux-kselftest,
linux-kernel
Implement schemes_update_tried_regions DAMON sysfs command on
_damon_sysfs.py, to use on implementations of future tests for the
feature.
Signed-off-by: SeongJae Park <sj@kernel.org>
---
tools/testing/selftests/damon/_damon_sysfs.py | 35 ++++++++++++++++++-
1 file changed, 34 insertions(+), 1 deletion(-)
diff --git a/tools/testing/selftests/damon/_damon_sysfs.py b/tools/testing/selftests/damon/_damon_sysfs.py
index 2bd44c32be1b..f975742f29b3 100644
--- a/tools/testing/selftests/damon/_damon_sysfs.py
+++ b/tools/testing/selftests/damon/_damon_sysfs.py
@@ -175,16 +175,24 @@ class DamosStats:
self.sz_applied = sz_applied
self.qt_exceeds = qt_exceeds
+class DamosTriedRegion:
+ def __init__(self, start, end, nr_accesses, age):
+ self.start = start
+ self.end = end
+ self.nr_accesses = nr_accesses
+ self.age = age
+
class Damos:
action = None
access_pattern = None
quota = None
apply_interval_us = None
- # todo: Support watermarks, stats, tried_regions
+ # todo: Support watermarks, stats
idx = None
context = None
tried_bytes = None
stats = None
+ tried_regions = None
def __init__(self, action='stat', access_pattern=DamosAccessPattern(),
quota=DamosQuota(), apply_interval_us=0):
@@ -398,6 +406,31 @@ class Kdamond:
err = write_file(os.path.join(self.sysfs_dir(), 'state'), 'on')
return err
+ def update_schemes_tried_regions(self):
+ err = write_file(os.path.join(self.sysfs_dir(), 'state'),
+ 'update_schemes_tried_regions')
+ if err is not None:
+ return err
+ for context in self.contexts:
+ for scheme in context.schemes:
+ tried_regions = []
+ tried_regions_dir = os.path.join(
+ scheme.sysfs_dir(), 'tried_regions')
+ for filename in os.listdir(
+ os.path.join(scheme.sysfs_dir(), 'tried_regions')):
+ tried_region_dir = os.path.join(tried_regions_dir, filename)
+ if not os.path.isdir(tried_region_dir):
+ continue
+ region_values = []
+ for f in ['start', 'end', 'nr_accesses', 'age']:
+ content, err = read_file(
+ os.path.join(tried_region_dir, f))
+ if err is not None:
+ return err
+ region_values.append(int(content))
+ tried_regions.append(DamosTriedRegion(*region_values))
+ scheme.tried_regions = tried_regions
+
def update_schemes_tried_bytes(self):
err = write_file(os.path.join(self.sysfs_dir(), 'state'),
'update_schemes_tried_bytes')
--
2.39.2
^ permalink raw reply [flat|nested] 9+ messages in thread
* [PATCH 3/8] selftests/damon: implement a program for even-numbered memory regions access
2024-06-25 18:05 [PATCH 0/8] selftests/damon: test DAMOS tried regions and {min,max}_nr_regions SeongJae Park
2024-06-25 18:05 ` [PATCH 1/8] selftests/damon/access_memory: use user-defined region size SeongJae Park
2024-06-25 18:05 ` [PATCH 2/8] selftests/damon/_damon_sysfs: support schemes_update_tried_regions SeongJae Park
@ 2024-06-25 18:05 ` SeongJae Park
2024-06-25 18:05 ` [PATCH 4/8] selftests/damon: implement DAMOS tried regions test SeongJae Park
` (4 subsequent siblings)
7 siblings, 0 replies; 9+ messages in thread
From: SeongJae Park @ 2024-06-25 18:05 UTC (permalink / raw)
To: Andrew Morton
Cc: SeongJae Park, Shuah Khan, damon, linux-mm, linux-kselftest,
linux-kernel
To test schemes_tried_regions feature, we need to have a program having
specific number of regions that having different access pattern.
Existing artificial access pattern generator, 'access_memory', cannot be
used for the purpose, since it accesses only one region at a given time.
Extending it could be an option, but since the purpose and the
implementation are pretty simple, implementing another one from the
scratch is better.
Implement such another artificial memory access program that alloctes
user-defined number/size regions and accesses even-numbered regions.
Signed-off-by: SeongJae Park <sj@kernel.org>
---
tools/testing/selftests/damon/Makefile | 2 +-
.../selftests/damon/access_memory_even.c | 42 +++++++++++++++++++
2 files changed, 43 insertions(+), 1 deletion(-)
create mode 100644 tools/testing/selftests/damon/access_memory_even.c
diff --git a/tools/testing/selftests/damon/Makefile b/tools/testing/selftests/damon/Makefile
index 29a22f50e762..7b972b5cf487 100644
--- a/tools/testing/selftests/damon/Makefile
+++ b/tools/testing/selftests/damon/Makefile
@@ -4,7 +4,7 @@
TEST_GEN_FILES += huge_count_read_write
TEST_GEN_FILES += debugfs_target_ids_read_before_terminate_race
TEST_GEN_FILES += debugfs_target_ids_pid_leak
-TEST_GEN_FILES += access_memory
+TEST_GEN_FILES += access_memory access_memory_even
TEST_FILES = _chk_dependency.sh _debugfs_common.sh
diff --git a/tools/testing/selftests/damon/access_memory_even.c b/tools/testing/selftests/damon/access_memory_even.c
new file mode 100644
index 000000000000..3be121487432
--- /dev/null
+++ b/tools/testing/selftests/damon/access_memory_even.c
@@ -0,0 +1,42 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Artificial memory access program for testing DAMON.
+ *
+ * Receives number of regions and size of each region from user. Allocate the
+ * regions and repeatedly access even numbered (starting from zero) regions.
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <time.h>
+
+int main(int argc, char *argv[])
+{
+ char **regions;
+ clock_t start_clock;
+ int nr_regions;
+ int sz_region;
+ int access_time_ms;
+ int i;
+
+ if (argc != 3) {
+ printf("Usage: %s <number> <size (bytes)>\n", argv[0]);
+ return -1;
+ }
+
+ nr_regions = atoi(argv[1]);
+ sz_region = atoi(argv[2]);
+
+ regions = malloc(sizeof(*regions) * nr_regions);
+ for (i = 0; i < nr_regions; i++)
+ regions[i] = malloc(sz_region);
+
+ while (1) {
+ for (i = 0; i < nr_regions; i++) {
+ if (i % 2 == 0)
+ memset(regions[i], i, sz_region);
+ }
+ }
+ return 0;
+}
--
2.39.2
^ permalink raw reply [flat|nested] 9+ messages in thread
* [PATCH 4/8] selftests/damon: implement DAMOS tried regions test
2024-06-25 18:05 [PATCH 0/8] selftests/damon: test DAMOS tried regions and {min,max}_nr_regions SeongJae Park
` (2 preceding siblings ...)
2024-06-25 18:05 ` [PATCH 3/8] selftests/damon: implement a program for even-numbered memory regions access SeongJae Park
@ 2024-06-25 18:05 ` SeongJae Park
2024-06-25 18:05 ` [PATCH 5/8] selftests/damon/_damon_sysfs: implement kdamonds stop function SeongJae Park
` (3 subsequent siblings)
7 siblings, 0 replies; 9+ messages in thread
From: SeongJae Park @ 2024-06-25 18:05 UTC (permalink / raw)
To: Andrew Morton
Cc: SeongJae Park, Shuah Khan, damon, linux-mm, linux-kselftest,
linux-kernel
Implement a test for DAMOS tried regions command of DAMON sysfs
interface. It ensures the expected number of monitoring regions are
created using an artificial memory access pattern generator program.
Signed-off-by: SeongJae Park <sj@kernel.org>
---
tools/testing/selftests/damon/Makefile | 1 +
.../selftests/damon/damos_tried_regions.py | 65 +++++++++++++++++++
2 files changed, 66 insertions(+)
create mode 100644 tools/testing/selftests/damon/damos_tried_regions.py
diff --git a/tools/testing/selftests/damon/Makefile b/tools/testing/selftests/damon/Makefile
index 7b972b5cf487..356b4e9a515d 100644
--- a/tools/testing/selftests/damon/Makefile
+++ b/tools/testing/selftests/damon/Makefile
@@ -13,6 +13,7 @@ TEST_PROGS = debugfs_attrs.sh debugfs_schemes.sh debugfs_target_ids.sh
TEST_PROGS += sysfs.sh
TEST_PROGS += sysfs_update_schemes_tried_regions_wss_estimation.py
TEST_PROGS += damos_quota.py damos_quota_goal.py damos_apply_interval.py
+TEST_PROGS += damos_tried_regions.py
TEST_PROGS += reclaim.sh lru_sort.sh
# regression tests (reproducers of previously found bugs)
diff --git a/tools/testing/selftests/damon/damos_tried_regions.py b/tools/testing/selftests/damon/damos_tried_regions.py
new file mode 100644
index 000000000000..3b347eb28bd2
--- /dev/null
+++ b/tools/testing/selftests/damon/damos_tried_regions.py
@@ -0,0 +1,65 @@
+#!/usr/bin/env python3
+# SPDX-License-Identifier: GPL-2.0
+
+import subprocess
+import time
+
+import _damon_sysfs
+
+def main():
+ # repeatedly access even-numbered ones in 14 regions of 10 MiB size
+ sz_region = 10 * 1024 * 1024
+ proc = subprocess.Popen(['./access_memory_even', '14', '%d' % sz_region])
+
+ # stat every monitored regions
+ kdamonds = _damon_sysfs.Kdamonds([_damon_sysfs.Kdamond(
+ contexts=[_damon_sysfs.DamonCtx(
+ ops='vaddr',
+ targets=[_damon_sysfs.DamonTarget(pid=proc.pid)],
+ schemes=[_damon_sysfs.Damos(action='stat',
+ )] # schemes
+ )] # contexts
+ )]) # kdamonds
+
+ err = kdamonds.start()
+ if err is not None:
+ proc.terminate()
+ print('kdamond start failed: %s' % err)
+ exit(1)
+
+ collected_nr_regions = []
+ while proc.poll() is None:
+ time.sleep(0.1)
+ err = kdamonds.kdamonds[0].update_schemes_tried_regions()
+ if err is not None:
+ proc.terminate()
+ print('tried regions update failed: %s' % err)
+ exit(1)
+
+ scheme = kdamonds.kdamonds[0].contexts[0].schemes[0]
+ if scheme.tried_regions is None:
+ proc.terminate()
+ print('tried regions is not collected')
+ exit(1)
+
+ nr_tried_regions = len(scheme.tried_regions)
+ if nr_tried_regions <= 0:
+ proc.terminate()
+ print('tried regions is not created')
+ exit(1)
+ collected_nr_regions.append(nr_tried_regions)
+ if len(collected_nr_regions) > 10:
+ break
+ proc.terminate()
+
+ collected_nr_regions.sort()
+ sample = collected_nr_regions[4]
+ print('50-th percentile nr_regions: %d' % sample)
+ print('expectation (>= 14) is %s' % 'met' if sample >= 14 else 'not met')
+ if collected_nr_regions[4] < 14:
+ print('full nr_regions:')
+ print('\n'.join(collected_nr_regions))
+ exit(1)
+
+if __name__ == '__main__':
+ main()
--
2.39.2
^ permalink raw reply [flat|nested] 9+ messages in thread
* [PATCH 5/8] selftests/damon/_damon_sysfs: implement kdamonds stop function
2024-06-25 18:05 [PATCH 0/8] selftests/damon: test DAMOS tried regions and {min,max}_nr_regions SeongJae Park
` (3 preceding siblings ...)
2024-06-25 18:05 ` [PATCH 4/8] selftests/damon: implement DAMOS tried regions test SeongJae Park
@ 2024-06-25 18:05 ` SeongJae Park
2024-06-25 18:05 ` [PATCH 6/8] selftests/damon: implement test for min/max_nr_regions SeongJae Park
` (2 subsequent siblings)
7 siblings, 0 replies; 9+ messages in thread
From: SeongJae Park @ 2024-06-25 18:05 UTC (permalink / raw)
To: Andrew Morton
Cc: SeongJae Park, Shuah Khan, damon, linux-mm, linux-kselftest,
linux-kernel
Implement DAMON stop function on the test-purpose DAMON sysfs interface
wrapper Python module, _damon_sysfs.py. This feature will be used by
future DAMON tests that need to start/stop DAMON multiple times.
Signed-off-by: SeongJae Park <sj@kernel.org>
---
tools/testing/selftests/damon/_damon_sysfs.py | 11 +++++++++++
1 file changed, 11 insertions(+)
diff --git a/tools/testing/selftests/damon/_damon_sysfs.py b/tools/testing/selftests/damon/_damon_sysfs.py
index f975742f29b3..17352b9d204d 100644
--- a/tools/testing/selftests/damon/_damon_sysfs.py
+++ b/tools/testing/selftests/damon/_damon_sysfs.py
@@ -406,6 +406,10 @@ class Kdamond:
err = write_file(os.path.join(self.sysfs_dir(), 'state'), 'on')
return err
+ def stop(self):
+ err = write_file(os.path.join(self.sysfs_dir(), 'state'), 'off')
+ return err
+
def update_schemes_tried_regions(self):
err = write_file(os.path.join(self.sysfs_dir(), 'state'),
'update_schemes_tried_regions')
@@ -511,3 +515,10 @@ class Kdamonds:
if err is not None:
return err
return None
+
+ def stop(self):
+ for kdamond in self.kdamonds:
+ err = kdamond.stop()
+ if err is not None:
+ return err
+ return None
--
2.39.2
^ permalink raw reply [flat|nested] 9+ messages in thread
* [PATCH 6/8] selftests/damon: implement test for min/max_nr_regions
2024-06-25 18:05 [PATCH 0/8] selftests/damon: test DAMOS tried regions and {min,max}_nr_regions SeongJae Park
` (4 preceding siblings ...)
2024-06-25 18:05 ` [PATCH 5/8] selftests/damon/_damon_sysfs: implement kdamonds stop function SeongJae Park
@ 2024-06-25 18:05 ` SeongJae Park
2024-06-25 18:05 ` [PATCH 7/8] _damon_sysfs: implement commit() for online parameters update SeongJae Park
2024-06-25 18:05 ` [PATCH 8/8] selftests/damon/damon_nr_regions: test online-tuned max_nr_regions SeongJae Park
7 siblings, 0 replies; 9+ messages in thread
From: SeongJae Park @ 2024-06-25 18:05 UTC (permalink / raw)
To: Andrew Morton
Cc: SeongJae Park, Shuah Khan, damon, linux-mm, linux-kselftest,
linux-kernel
Implement a kselftest for DAMON's {min,max}_nr_regions' parameters. The
test ensures both the minimum and the maximum number of regions limit is
respected even if the workload's real number of regions is less than the
minimum or larger than the maximum limits.
Signed-off-by: SeongJae Park <sj@kernel.org>
---
tools/testing/selftests/damon/Makefile | 2 +-
.../selftests/damon/damon_nr_regions.py | 85 +++++++++++++++++++
2 files changed, 86 insertions(+), 1 deletion(-)
create mode 100644 tools/testing/selftests/damon/damon_nr_regions.py
diff --git a/tools/testing/selftests/damon/Makefile b/tools/testing/selftests/damon/Makefile
index 356b4e9a515d..1e2e98cc809d 100644
--- a/tools/testing/selftests/damon/Makefile
+++ b/tools/testing/selftests/damon/Makefile
@@ -13,7 +13,7 @@ TEST_PROGS = debugfs_attrs.sh debugfs_schemes.sh debugfs_target_ids.sh
TEST_PROGS += sysfs.sh
TEST_PROGS += sysfs_update_schemes_tried_regions_wss_estimation.py
TEST_PROGS += damos_quota.py damos_quota_goal.py damos_apply_interval.py
-TEST_PROGS += damos_tried_regions.py
+TEST_PROGS += damos_tried_regions.py damon_nr_regions.py
TEST_PROGS += reclaim.sh lru_sort.sh
# regression tests (reproducers of previously found bugs)
diff --git a/tools/testing/selftests/damon/damon_nr_regions.py b/tools/testing/selftests/damon/damon_nr_regions.py
new file mode 100644
index 000000000000..dd2735923c59
--- /dev/null
+++ b/tools/testing/selftests/damon/damon_nr_regions.py
@@ -0,0 +1,85 @@
+#!/usr/bin/env python3
+# SPDX-License-Identifier: GPL-2.0
+
+import subprocess
+import time
+
+import _damon_sysfs
+
+def test_nr_regions(real_nr_regions, min_nr_regions, max_nr_regions):
+ '''
+ Create process of the given 'real_nr_regions' regions, monitor it using
+ DAMON with given '{min,max}_nr_regions' monitoring parameter.
+
+ Exit with non-zero return code if the given {min,max}_nr_regions is not
+ kept.
+ '''
+ sz_region = 10 * 1024 * 1024
+ proc = subprocess.Popen(['./access_memory_even', '%d' % real_nr_regions,
+ '%d' % sz_region])
+
+ # stat every monitored regions
+ kdamonds = _damon_sysfs.Kdamonds([_damon_sysfs.Kdamond(
+ contexts=[_damon_sysfs.DamonCtx(
+ monitoring_attrs=_damon_sysfs.DamonAttrs(
+ min_nr_regions=min_nr_regions,
+ max_nr_regions=max_nr_regions),
+ ops='vaddr',
+ targets=[_damon_sysfs.DamonTarget(pid=proc.pid)],
+ schemes=[_damon_sysfs.Damos(action='stat',
+ )] # schemes
+ )] # contexts
+ )]) # kdamonds
+
+ err = kdamonds.start()
+ if err is not None:
+ proc.terminate()
+ print('kdamond start failed: %s' % err)
+ exit(1)
+
+ collected_nr_regions = []
+ while proc.poll() is None:
+ time.sleep(0.1)
+ err = kdamonds.kdamonds[0].update_schemes_tried_regions()
+ if err is not None:
+ proc.terminate()
+ print('tried regions update failed: %s' % err)
+ exit(1)
+
+ scheme = kdamonds.kdamonds[0].contexts[0].schemes[0]
+ if scheme.tried_regions is None:
+ proc.terminate()
+ print('tried regions is not collected')
+ exit(1)
+
+ nr_tried_regions = len(scheme.tried_regions)
+ if nr_tried_regions <= 0:
+ proc.terminate()
+ print('tried regions is not created')
+ exit(1)
+ collected_nr_regions.append(nr_tried_regions)
+ if len(collected_nr_regions) > 10:
+ break
+ proc.terminate()
+ kdamonds.stop()
+
+ test_name = 'nr_regions test with %d/%d/%d real/min/max nr_regions' % (
+ real_nr_regions, min_nr_regions, max_nr_regions)
+ if (collected_nr_regions[0] < min_nr_regions or
+ collected_nr_regions[-1] > max_nr_regions):
+ print('fail %s' % test_name)
+ print('number of regions that collected are:')
+ for nr in collected_nr_regions:
+ print(nr)
+ exit(1)
+ print('pass %s ' % test_name)
+
+def main():
+ # test min_nr_regions larger than real nr regions
+ test_nr_regions(10, 20, 100)
+
+ # test max_nr_regions smaller than real nr regions
+ test_nr_regions(15, 3, 10)
+
+if __name__ == '__main__':
+ main()
--
2.39.2
^ permalink raw reply [flat|nested] 9+ messages in thread
* [PATCH 7/8] _damon_sysfs: implement commit() for online parameters update
2024-06-25 18:05 [PATCH 0/8] selftests/damon: test DAMOS tried regions and {min,max}_nr_regions SeongJae Park
` (5 preceding siblings ...)
2024-06-25 18:05 ` [PATCH 6/8] selftests/damon: implement test for min/max_nr_regions SeongJae Park
@ 2024-06-25 18:05 ` SeongJae Park
2024-06-25 18:05 ` [PATCH 8/8] selftests/damon/damon_nr_regions: test online-tuned max_nr_regions SeongJae Park
7 siblings, 0 replies; 9+ messages in thread
From: SeongJae Park @ 2024-06-25 18:05 UTC (permalink / raw)
To: Andrew Morton
Cc: SeongJae Park, Shuah Khan, damon, linux-mm, linux-kselftest,
linux-kernel
Users can update DAMON parameters while it is running, using 'commit'
DAMON sysfs interface command. For testing the feature in future tests,
implement a function for doing that on the test-purpose DAMON sysfs
interface wrapper Python module.
Signed-off-by: SeongJae Park <sj@kernel.org>
---
tools/testing/selftests/damon/_damon_sysfs.py | 19 +++++++++++++++++++
1 file changed, 19 insertions(+)
diff --git a/tools/testing/selftests/damon/_damon_sysfs.py b/tools/testing/selftests/damon/_damon_sysfs.py
index 17352b9d204d..6e136dc3df19 100644
--- a/tools/testing/selftests/damon/_damon_sysfs.py
+++ b/tools/testing/selftests/damon/_damon_sysfs.py
@@ -481,6 +481,25 @@ class Kdamond:
goal.effective_bytes = int(content)
return None
+ def commit(self):
+ nr_contexts_file = os.path.join(self.sysfs_dir(),
+ 'contexts', 'nr_contexts')
+ content, err = read_file(nr_contexts_file)
+ if err is not None:
+ return err
+ if int(content) != len(self.contexts):
+ err = write_file(nr_contexts_file, '%d' % len(self.contexts))
+ if err is not None:
+ return err
+
+ for context in self.contexts:
+ err = context.stage()
+ if err is not None:
+ return err
+ err = write_file(os.path.join(self.sysfs_dir(), 'state'), 'commit')
+ return err
+
+
def commit_schemes_quota_goals(self):
for context in self.contexts:
for scheme in context.schemes:
--
2.39.2
^ permalink raw reply [flat|nested] 9+ messages in thread
* [PATCH 8/8] selftests/damon/damon_nr_regions: test online-tuned max_nr_regions
2024-06-25 18:05 [PATCH 0/8] selftests/damon: test DAMOS tried regions and {min,max}_nr_regions SeongJae Park
` (6 preceding siblings ...)
2024-06-25 18:05 ` [PATCH 7/8] _damon_sysfs: implement commit() for online parameters update SeongJae Park
@ 2024-06-25 18:05 ` SeongJae Park
7 siblings, 0 replies; 9+ messages in thread
From: SeongJae Park @ 2024-06-25 18:05 UTC (permalink / raw)
To: Andrew Morton
Cc: SeongJae Park, Shuah Khan, damon, linux-mm, linux-kselftest,
linux-kernel
User could update max_nr_regions parameter while DAMON is running to a
value that smaller than the current number of regions that DAMON is
seeing. Such update could be done for reducing the monitoring overhead.
In the case, DAMON should merge regions aggressively more than normal
situation to ensure the new limit is successfully applied. Implement a
kselftest to ensure that.
Signed-off-by: SeongJae Park <sj@kernel.org>
---
.../selftests/damon/damon_nr_regions.py | 60 +++++++++++++++++++
1 file changed, 60 insertions(+)
diff --git a/tools/testing/selftests/damon/damon_nr_regions.py b/tools/testing/selftests/damon/damon_nr_regions.py
index dd2735923c59..2e8a74aff543 100644
--- a/tools/testing/selftests/damon/damon_nr_regions.py
+++ b/tools/testing/selftests/damon/damon_nr_regions.py
@@ -81,5 +81,65 @@ def main():
# test max_nr_regions smaller than real nr regions
test_nr_regions(15, 3, 10)
+ # test online-tuned max_nr_regions that smaller than real nr regions
+ sz_region = 10 * 1024 * 1024
+ proc = subprocess.Popen(['./access_memory_even', '14', '%d' % sz_region])
+
+ # stat every monitored regions
+ kdamonds = _damon_sysfs.Kdamonds([_damon_sysfs.Kdamond(
+ contexts=[_damon_sysfs.DamonCtx(
+ monitoring_attrs=_damon_sysfs.DamonAttrs(
+ min_nr_regions=10, max_nr_regions=1000),
+ ops='vaddr',
+ targets=[_damon_sysfs.DamonTarget(pid=proc.pid)],
+ schemes=[_damon_sysfs.Damos(action='stat',
+ )] # schemes
+ )] # contexts
+ )]) # kdamonds
+
+ err = kdamonds.start()
+ if err is not None:
+ proc.terminate()
+ print('kdamond start failed: %s' % err)
+ exit(1)
+
+ # wait until the real regions are found
+ time.sleep(3)
+
+ attrs = kdamonds.kdamonds[0].contexts[0].monitoring_attrs
+ attrs.min_nr_regions = 3
+ attrs.max_nr_regions = 7
+ err = kdamonds.kdamonds[0].commit()
+ if err is not None:
+ proc.terminate()
+ print('commit failed: %s' % err)
+ exit(1)
+ # wait for next merge operation is executed
+ time.sleep(0.3)
+
+ err = kdamonds.kdamonds[0].update_schemes_tried_regions()
+ if err is not None:
+ proc.terminate()
+ print('tried regions update failed: %s' % err)
+ exit(1)
+
+ scheme = kdamonds.kdamonds[0].contexts[0].schemes[0]
+ if scheme.tried_regions is None:
+ proc.terminate()
+ print('tried regions is not collected')
+ exit(1)
+
+ nr_tried_regions = len(scheme.tried_regions)
+ if nr_tried_regions <= 0:
+ proc.terminate()
+ print('tried regions is not created')
+ exit(1)
+ proc.terminate()
+
+ if nr_tried_regions > 7:
+ print('fail online-tuned max_nr_regions: %d > 7' % nr_tried_regions)
+ exit(1)
+ print('pass online-tuned max_nr_regions')
+
if __name__ == '__main__':
main()
--
2.39.2
^ permalink raw reply [flat|nested] 9+ messages in thread
end of thread, other threads:[~2024-06-25 18:06 UTC | newest]
Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-06-25 18:05 [PATCH 0/8] selftests/damon: test DAMOS tried regions and {min,max}_nr_regions SeongJae Park
2024-06-25 18:05 ` [PATCH 1/8] selftests/damon/access_memory: use user-defined region size SeongJae Park
2024-06-25 18:05 ` [PATCH 2/8] selftests/damon/_damon_sysfs: support schemes_update_tried_regions SeongJae Park
2024-06-25 18:05 ` [PATCH 3/8] selftests/damon: implement a program for even-numbered memory regions access SeongJae Park
2024-06-25 18:05 ` [PATCH 4/8] selftests/damon: implement DAMOS tried regions test SeongJae Park
2024-06-25 18:05 ` [PATCH 5/8] selftests/damon/_damon_sysfs: implement kdamonds stop function SeongJae Park
2024-06-25 18:05 ` [PATCH 6/8] selftests/damon: implement test for min/max_nr_regions SeongJae Park
2024-06-25 18:05 ` [PATCH 7/8] _damon_sysfs: implement commit() for online parameters update SeongJae Park
2024-06-25 18:05 ` [PATCH 8/8] selftests/damon/damon_nr_regions: test online-tuned max_nr_regions SeongJae Park
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox