Skip to content

Commit 51f58c9

Browse files
sjp38akpm00
authored andcommitted
selftests/damon: add a test for DAMOS quota
Add a selftest for verifying the DAMOS quota feature. The test is very similar to sysfs_update_schemes_tried_regions_wss_estimation.py. It starts an artificial workload of 20 MiB working set, run DAMON to find the working set size, but with 1 MiB/100 ms size quota. Then, it collect the DAMON-found working set size every 100 ms and check if the quota was always applied as expected. For the confirmation, the tests shows the stat-applied region size and the qt_exceeds stat. Link: https://lkml.kernel.org/r/20240207203134.69976-5-sj@kernel.org Signed-off-by: SeongJae Park <sj@kernel.org> Cc: Shuah Khan <shuah@kernel.org> Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
1 parent a862262 commit 51f58c9

File tree

2 files changed

+68
-0
lines changed

2 files changed

+68
-0
lines changed

tools/testing/selftests/damon/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ TEST_PROGS += debugfs_rm_non_contexts.sh
1212
TEST_PROGS += sysfs.sh sysfs_update_removed_scheme_dir.sh
1313
TEST_PROGS += sysfs_update_schemes_tried_regions_hang.py
1414
TEST_PROGS += sysfs_update_schemes_tried_regions_wss_estimation.py
15+
TEST_PROGS += damos_quota.py
1516
TEST_PROGS += reclaim.sh lru_sort.sh
1617

1718
include ../lib.mk
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
#!/usr/bin/env python3
2+
# SPDX-License-Identifier: GPL-2.0
3+
4+
import subprocess
5+
import time
6+
7+
import _damon_sysfs
8+
9+
def main():
10+
# access two 10 MiB memory regions, 2 second per each
11+
sz_region = 10 * 1024 * 1024
12+
proc = subprocess.Popen(['./access_memory', '2', '%d' % sz_region, '2000'])
13+
14+
# Set quota up to 1 MiB per 100 ms
15+
sz_quota = 1024 * 1024 # 1 MiB
16+
quota_reset_interval = 100 # 100 ms
17+
kdamonds = _damon_sysfs.Kdamonds([_damon_sysfs.Kdamond(
18+
contexts=[_damon_sysfs.DamonCtx(
19+
ops='vaddr',
20+
targets=[_damon_sysfs.DamonTarget(pid=proc.pid)],
21+
schemes=[_damon_sysfs.Damos(
22+
access_pattern=_damon_sysfs.DamosAccessPattern(
23+
# >= 25% access rate, >= 200ms age
24+
nr_accesses=[5, 20], age=[2, 2**64 - 1]),
25+
quota=_damon_sysfs.DamosQuota(
26+
sz=sz_quota, reset_interval_ms=quota_reset_interval)
27+
)] # schemes
28+
)] # contexts
29+
)]) # kdamonds
30+
31+
err = kdamonds.start()
32+
if err != None:
33+
print('kdamond start failed: %s' % err)
34+
exit(1)
35+
36+
wss_collected = []
37+
nr_quota_exceeds = 0
38+
while proc.poll() == None:
39+
time.sleep(0.1)
40+
err = kdamonds.kdamonds[0].update_schemes_tried_bytes()
41+
if err != None:
42+
print('tried bytes update failed: %s' % err)
43+
exit(1)
44+
err = kdamonds.kdamonds[0].update_schemes_stats()
45+
if err != None:
46+
print('stats update failed: %s' % err)
47+
exit(1)
48+
49+
scheme = kdamonds.kdamonds[0].contexts[0].schemes[0]
50+
wss_collected.append(scheme.tried_bytes)
51+
nr_quota_exceeds = scheme.stats.qt_exceeds
52+
53+
wss_collected.sort()
54+
for wss in wss_collected:
55+
if wss > sz_quota:
56+
print('quota is not kept: %s > %s' % (wss, sz_quota))
57+
print('collected samples are as below')
58+
print('\n'.join(['%d' % wss for wss in wss_collected]))
59+
exit(1)
60+
61+
if nr_quota_exceeds < len(wss_collected):
62+
print('quota is not always exceeded: %d > %d' %
63+
(len(wss_collected), nr_quota_exceeds))
64+
exit(1)
65+
66+
if __name__ == '__main__':
67+
main()

0 commit comments

Comments
 (0)