2 # SPDX-License-Identifier: GPL-2.0
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'])
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(
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
)
31 err
= kdamonds
.start()
33 print('kdamond start failed: %s' % err
)
38 while proc
.poll() == None:
40 err
= kdamonds
.kdamonds
[0].update_schemes_tried_bytes()
42 print('tried bytes update failed: %s' % err
)
44 err
= kdamonds
.kdamonds
[0].update_schemes_stats()
46 print('stats update failed: %s' % err
)
49 scheme
= kdamonds
.kdamonds
[0].contexts
[0].schemes
[0]
50 wss_collected
.append(scheme
.tried_bytes
)
51 nr_quota_exceeds
= scheme
.stats
.qt_exceeds
54 for wss
in wss_collected
:
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
]))
61 if nr_quota_exceeds
< len(wss_collected
):
62 print('quota is not always exceeded: %d > %d' %
63 (len(wss_collected
), nr_quota_exceeds
))
66 if __name__
== '__main__':