Skip to content

Commit 0bbccbe

Browse files
authored
Merge pull request #4343 from mcasquer/4115_mlock_on_fault_fix
2 parents a4f28f8 + 9decd36 commit 0bbccbe

File tree

2 files changed

+28
-26
lines changed

2 files changed

+28
-26
lines changed

qemu/tests/cfg/mlock_on_fault.cfg

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,4 @@
1010
memhog_extra_options = "-m %dG -object memory-backend-ram,id=mem0,size=%dG,prealloc=on"
1111
qemu_cmd_memhog = "${qemu_cmd_memlock} ${memhog_extra_options} ${extra_qemu_options}"
1212
memhog_cmd = "memhog %dG"
13+
threshold = 1024

qemu/tests/mlock_on_fault.py

Lines changed: 27 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ def run(test, params, env):
2424

2525
qemu_path = utils_misc.get_qemu_binary(params)
2626
memhog_cmd = params.get("memhog_cmd")
27+
threshold = params.get_numeric("threshold")
2728
rss_values = []
2829

2930
for status in ["on", "on-fault"]:
@@ -69,31 +70,31 @@ def run(test, params, env):
6970
)
7071
test.log.info("The qemu-kvm command: %s", qemu_cmd_memhog)
7172

72-
try:
73-
with aexpect.run_bg(qemu_cmd_memhog) as _:
74-
qemu_pid = process.get_children_pids(_.get_pid())[0]
75-
rss_cmd = "ps -p %s -o rss=" % qemu_pid
76-
time.sleep(5)
77-
previous_rss_value = int(process.getoutput(rss_cmd, shell=True))
73+
with aexpect.run_bg(qemu_cmd_memhog) as _:
74+
qemu_pid = process.get_children_pids(_.get_pid())[0]
75+
rss_cmd = "ps -p %s -o rss=" % qemu_pid
76+
time.sleep(5)
77+
previous_rss_value = int(process.getoutput(rss_cmd, shell=True))
7878

79-
# Calculates a suitable amount of memory for memhog
80-
swap_free = str(swap_free) + "K"
81-
swap_normalized = math.ceil(
82-
float(utils_misc.normalize_data_size(swap_free, "G"))
83-
)
84-
memhog_value = math.ceil(vm_memory_normalized + (swap_normalized * 1.25))
85-
memhog_cmd = memhog_cmd % memhog_value
86-
memhog_cmd = aexpect.run_bg(memhog_cmd)
79+
# Calculates a suitable amount of memory for memhog
80+
swap_free = str(swap_free) + "K"
81+
swap_normalized = math.ceil(
82+
float(utils_misc.normalize_data_size(swap_free, "G"))
83+
)
84+
memhog_value = math.ceil(vm_memory_normalized + (swap_normalized * 1.25))
85+
memhog_cmd = memhog_cmd % memhog_value
86+
memhog_cmd = aexpect.run_bg(memhog_cmd)
8787

88-
while memhog_cmd.is_alive():
89-
rss_value = int(process.getoutput(rss_cmd, shell=True))
90-
if rss_value < previous_rss_value:
91-
test.log.debug(
92-
"previous_rss_value: %d and the rss_value: %d",
93-
previous_rss_value,
94-
rss_value,
95-
)
96-
test.error("The RSS value has decreased, memory is not locked!")
97-
previous_rss_value = rss_value
98-
except Exception as e:
99-
test.error("An error ocurred: %s" % str(e))
88+
while memhog_cmd.is_alive():
89+
rss_value = int(process.getoutput(rss_cmd, shell=True))
90+
if (
91+
rss_value < previous_rss_value
92+
and (previous_rss_value - rss_value) >= threshold
93+
):
94+
test.log.debug(
95+
"previous_rss_value: %d and the rss_value: %d",
96+
previous_rss_value,
97+
rss_value,
98+
)
99+
test.error("The RSS value has decreased, memory is not locked!")
100+
previous_rss_value = rss_value

0 commit comments

Comments
 (0)