8
8
9
9
import pytest
10
10
import requests
11
- from tenacity import retry , stop_after_attempt , wait_fixed
12
11
13
12
from framework .utils import check_output , get_free_mem_ssh
14
13
15
14
STATS_POLLING_INTERVAL_S = 1
16
15
17
16
18
- @retry (wait = wait_fixed (0.5 ), stop = stop_after_attempt (10 ), reraise = True )
19
17
def get_stable_rss_mem_by_pid (pid , percentage_delta = 1 ):
20
18
"""
21
19
Get the RSS memory that a guest uses, given the pid of the guest.
22
20
23
- Wait till the fluctuations in RSS drop below percentage_delta. If timeout
24
- is reached before the fluctuations drop, raise an exception .
21
+ Wait till the fluctuations in RSS drop below percentage_delta.
22
+ Or print a warning if this does not happen .
25
23
"""
26
24
27
25
# All values are reported as KiB
@@ -30,15 +28,23 @@ def get_rss_from_pmap():
30
28
_ , output , _ = check_output ("pmap -X {}" .format (pid ))
31
29
return int (output .split ("\n " )[- 2 ].split ()[1 ], 10 )
32
30
33
- first_rss = get_rss_from_pmap ()
34
- time .sleep (1 )
35
- second_rss = get_rss_from_pmap ()
36
- abs_diff = abs (first_rss - second_rss )
37
- abs_delta = 100 * abs_diff / first_rss
38
- print (
39
- f"RSS readings: old: { first_rss } new: { second_rss } abs_diff: { abs_diff } abs_delta: { abs_delta } "
40
- )
41
- assert abs_delta < percentage_delta or abs_diff < 2 ** 10
31
+ first_rss = 0
32
+ second_rss = 0
33
+ for _ in range (5 ):
34
+ first_rss = get_rss_from_pmap ()
35
+ time .sleep (1 )
36
+ second_rss = get_rss_from_pmap ()
37
+ abs_diff = abs (first_rss - second_rss )
38
+ abs_delta = abs_diff / first_rss * 100
39
+ print (
40
+ f"RSS readings: old: { first_rss } new: { second_rss } abs_diff: { abs_diff } abs_delta: { abs_delta } "
41
+ )
42
+ if abs_delta < percentage_delta :
43
+ return second_rss
44
+
45
+ time .sleep (1 )
46
+
47
+ print ("WARNING: RSS readings did not stabilize" )
42
48
return second_rss
43
49
44
50
@@ -78,7 +84,7 @@ def make_guest_dirty_memory(ssh_connection, amount_mib=32):
78
84
time .sleep (5 )
79
85
80
86
81
- def _test_rss_memory_lower (test_microvm , stable_delta = 1 ):
87
+ def _test_rss_memory_lower (test_microvm ):
82
88
"""Check inflating the balloon makes guest use less rss memory."""
83
89
# Get the firecracker pid, and open an ssh connection.
84
90
firecracker_pid = test_microvm .firecracker_pid
@@ -88,20 +94,18 @@ def _test_rss_memory_lower(test_microvm, stable_delta=1):
88
94
test_microvm .api .balloon .patch (amount_mib = 200 )
89
95
90
96
# Get initial rss consumption.
91
- init_rss = get_stable_rss_mem_by_pid (firecracker_pid , percentage_delta = stable_delta )
97
+ init_rss = get_stable_rss_mem_by_pid (firecracker_pid )
92
98
93
99
# Get the balloon back to 0.
94
100
test_microvm .api .balloon .patch (amount_mib = 0 )
95
101
# This call will internally wait for rss to become stable.
96
- _ = get_stable_rss_mem_by_pid (firecracker_pid , percentage_delta = stable_delta )
102
+ _ = get_stable_rss_mem_by_pid (firecracker_pid )
97
103
98
104
# Dirty memory, then inflate balloon and get ballooned rss consumption.
99
105
make_guest_dirty_memory (ssh_connection , amount_mib = 32 )
100
106
101
107
test_microvm .api .balloon .patch (amount_mib = 200 )
102
- balloon_rss = get_stable_rss_mem_by_pid (
103
- firecracker_pid , percentage_delta = stable_delta
104
- )
108
+ balloon_rss = get_stable_rss_mem_by_pid (firecracker_pid )
105
109
106
110
# Check that the ballooning reclaimed the memory.
107
111
assert balloon_rss - init_rss <= 15000
0 commit comments