@@ -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