/
trans_hugepage.py
122 lines (95 loc) · 3.95 KB
/
trans_hugepage.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
import logging, os, re
from autotest.client.shared import error
from autotest.client.shared import utils
from virttest import utils_test
@error.context_aware
def run_trans_hugepage(test, params, env):
"""
KVM kernel hugepages user side test:
1) Smoke test
2) Stress test
@param test: KVM test object.
@param params: Dictionary with test parameters.
@param env: Dictionary with the test environment.
"""
def get_mem_status(params, role):
if role == "host":
info = utils.system_output("cat /proc/meminfo")
else:
info = session.cmd("cat /proc/meminfo")
for h in re.split("\n+", info):
if h.startswith("%s" % params):
output = re.split('\s+', h)[1]
return output
dd_timeout = float(params.get("dd_timeout", 900))
mem = params['mem']
failures = []
debugfs_flag = 1
debugfs_path = os.path.join(test.tmpdir, 'debugfs')
mem_path = os.path.join("/tmp", 'thp_space')
login_timeout = float(params.get("login_timeout", "3600"))
error.context("smoke test setup")
if not os.path.ismount(debugfs_path):
if not os.path.isdir(debugfs_path):
os.makedirs(debugfs_path)
utils.run("mount -t debugfs none %s" % debugfs_path)
vm = utils_test.get_living_vm(env, params.get("main_vm"))
session = utils_test.wait_for_login(vm, timeout=login_timeout)
try:
logging.info("Smoke test start")
error.context("smoke test")
nr_ah_before = int(get_mem_status('AnonHugePages', 'host'))
if nr_ah_before <= 0:
e_msg = 'smoke: Host is not using THP'
logging.error(e_msg)
failures.append(e_msg)
# Protect system from oom killer
if int(get_mem_status('MemFree', 'guest')) / 1024 < mem :
mem = int(get_mem_status('MemFree', 'guest')) / 1024
session.cmd("mkdir -p %s" % mem_path)
session.cmd("mount -t tmpfs -o size=%sM none %s" % (str(mem), mem_path))
count = mem / 4
session.cmd("dd if=/dev/zero of=%s/1 bs=4000000 count=%s" %
(mem_path, count), timeout=dd_timeout)
nr_ah_after = int(get_mem_status('AnonHugePages', 'host'))
if nr_ah_after <= nr_ah_before:
e_msg = ('smoke: Host did not use new THP during dd')
logging.error(e_msg)
failures.append(e_msg)
if debugfs_flag == 1:
if int(open('%s/kvm/largepages' % debugfs_path, 'r').read()) <= 0:
e_msg = 'smoke: KVM is not using THP'
logging.error(e_msg)
failures.append(e_msg)
logging.info("Smoke test finished")
# Use parallel dd as stress for memory
count = count / 3
logging.info("Stress test start")
error.context("stress test")
cmd = "rm -rf %s/*; for i in `seq %s`; do dd " % (mem_path, count)
cmd += "if=/dev/zero of=%s/$i bs=4000000 count=1& done;wait" % mem_path
output = session.cmd_output(cmd, timeout=dd_timeout)
if len(re.findall("No space", output)) > count * 0.05:
e_msg = "stress: Too many dd instances failed in guest"
logging.error(e_msg)
failures.append(e_msg)
try:
output = session.cmd('pidof dd')
except Exception:
output = None
if output is not None:
for i in re.split('\n+', output):
session.cmd('kill -9 %s' % i)
session.cmd("umount %s" % mem_path)
logging.info("Stress test finished")
finally:
error.context("all tests cleanup")
if os.path.ismount(debugfs_path):
utils.run("umount %s" % debugfs_path)
if os.path.isdir(debugfs_path):
os.removedirs(debugfs_path)
session.close()
error.context("")
if failures:
raise error.TestFail("THP base test reported %s failures:\n%s" %
(len(failures), "\n".join(failures)))