Skip to content

Commit 8bf890c

Browse files
sjp38akpm00
authored andcommitted
selftests/damon/damon_nr_regions: test online-tuned max_nr_regions
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. Link: https://lkml.kernel.org/r/[email protected] Signed-off-by: SeongJae Park <[email protected]> Cc: Shuah Khan <[email protected]> Signed-off-by: Andrew Morton <[email protected]>
1 parent 5ac9ade commit 8bf890c

File tree

1 file changed

+60
-0
lines changed

1 file changed

+60
-0
lines changed

tools/testing/selftests/damon/damon_nr_regions.py

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,5 +81,65 @@ def main():
8181
# test max_nr_regions smaller than real nr regions
8282
test_nr_regions(15, 3, 10)
8383

84+
# test online-tuned max_nr_regions that smaller than real nr regions
85+
sz_region = 10 * 1024 * 1024
86+
proc = subprocess.Popen(['./access_memory_even', '14', '%d' % sz_region])
87+
88+
# stat every monitored regions
89+
kdamonds = _damon_sysfs.Kdamonds([_damon_sysfs.Kdamond(
90+
contexts=[_damon_sysfs.DamonCtx(
91+
monitoring_attrs=_damon_sysfs.DamonAttrs(
92+
min_nr_regions=10, max_nr_regions=1000),
93+
ops='vaddr',
94+
targets=[_damon_sysfs.DamonTarget(pid=proc.pid)],
95+
schemes=[_damon_sysfs.Damos(action='stat',
96+
)] # schemes
97+
)] # contexts
98+
)]) # kdamonds
99+
100+
err = kdamonds.start()
101+
if err is not None:
102+
proc.terminate()
103+
print('kdamond start failed: %s' % err)
104+
exit(1)
105+
106+
# wait until the real regions are found
107+
time.sleep(3)
108+
109+
attrs = kdamonds.kdamonds[0].contexts[0].monitoring_attrs
110+
attrs.min_nr_regions = 3
111+
attrs.max_nr_regions = 7
112+
err = kdamonds.kdamonds[0].commit()
113+
if err is not None:
114+
proc.terminate()
115+
print('commit failed: %s' % err)
116+
exit(1)
117+
# wait for next merge operation is executed
118+
time.sleep(0.3)
119+
120+
err = kdamonds.kdamonds[0].update_schemes_tried_regions()
121+
if err is not None:
122+
proc.terminate()
123+
print('tried regions update failed: %s' % err)
124+
exit(1)
125+
126+
scheme = kdamonds.kdamonds[0].contexts[0].schemes[0]
127+
if scheme.tried_regions is None:
128+
proc.terminate()
129+
print('tried regions is not collected')
130+
exit(1)
131+
132+
nr_tried_regions = len(scheme.tried_regions)
133+
if nr_tried_regions <= 0:
134+
proc.terminate()
135+
print('tried regions is not created')
136+
exit(1)
137+
proc.terminate()
138+
139+
if nr_tried_regions > 7:
140+
print('fail online-tuned max_nr_regions: %d > 7' % nr_tried_regions)
141+
exit(1)
142+
print('pass online-tuned max_nr_regions')
143+
84144
if __name__ == '__main__':
85145
main()

0 commit comments

Comments
 (0)