Skip to content

Commit 0d419ac

Browse files
committed
contest: loadavg: wait for dirty page writeback
Signed-off-by: Jakub Kicinski <[email protected]>
1 parent e5143b0 commit 0d419ac

File tree

1 file changed

+16
-6
lines changed

1 file changed

+16
-6
lines changed

contest/remote/lib/loadavg.py

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,21 +4,31 @@
44
import time
55

66

7-
def wait_loadavg(target, check_ival=30, stable_cnt=4):
7+
def get_dirty_mem():
8+
with open("/proc/meminfo", "r") as fp:
9+
lines = fp.read().split("\n")
10+
dirty = list(filter(lambda a: "Dirty" in a, lines))[0]
11+
return int(dirty.split(" ")[-2])
12+
13+
14+
def wait_loadavg(target, dirty_max=100000, check_ival=30, stable_cnt=4):
815
"""
916
Wait for loadavg to drop but be careful at the start, the load
1017
may have not ramped up, yet, so if we ungate early whoever is waiting
1118
will experience the overload.
1219
"""
20+
21+
seen_stable = 0
1322
while target is not None:
1423
load, _, _ = os.getloadavg()
24+
dirty = get_dirty_mem()
1525

16-
if load <= target:
17-
if stable_cnt == 0:
26+
if load <= target and dirty <= dirty_max:
27+
if seen_stable >= stable_cnt:
1828
break
19-
stable_cnt -= 1
29+
seen_stable += 1
2030
else:
21-
stable_cnt = 0
31+
seen_stable = 0
2232

23-
print(f"Waiting for loadavg to decrease: {load} > {target} ({stable_cnt})")
33+
print(f"Waiting for loadavg to decrease: CPU: {load} > {target} Dirty Mem: {dirty} > {dirty_max} ({stable_cnt})")
2434
time.sleep(check_ival)

0 commit comments

Comments
 (0)