1515STATS_POLLING_INTERVAL_S = 1
1616
1717
18- @retry (wait = wait_fixed (0.5 ), stop = stop_after_attempt (10 ), reraise = True )
1918def get_stable_rss_mem_by_pid (pid , percentage_delta = 1 ):
2019 """
2120 Get the RSS memory that a guest uses, given the pid of the guest.
2221
23- Wait till the fluctuations in RSS drop below percentage_delta. If timeout
24- is reached before the fluctuations drop, raise an exception .
22+ Wait till the fluctuations in RSS drop below percentage_delta.
23+ Or print a warning if this does not happen .
2524 """
2625
2726 # All values are reported as KiB
@@ -30,15 +29,23 @@ def get_rss_from_pmap():
3029 _ , output , _ = check_output ("pmap -X {}" .format (pid ))
3130 return int (output .split ("\n " )[- 2 ].split ()[1 ], 10 )
3231
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
32+ first_rss = 0
33+ second_rss = 0
34+ for _ in range (5 ):
35+ first_rss = get_rss_from_pmap ()
36+ time .sleep (1 )
37+ second_rss = get_rss_from_pmap ()
38+ abs_diff = abs (first_rss - second_rss )
39+ abs_delta = abs_diff / first_rss * 100
40+ print (
41+ f"RSS readings: old: { first_rss } new: { second_rss } abs_diff: { abs_diff } abs_delta: { abs_delta } "
42+ )
43+ if abs_delta < percentage_delta :
44+ return second_rss
45+
46+ time .sleep (1 )
47+
48+ print ("WARNING: RSS readings did not stabilize" )
4249 return second_rss
4350
4451
@@ -78,7 +85,7 @@ def make_guest_dirty_memory(ssh_connection, amount_mib=32):
7885 time .sleep (5 )
7986
8087
81- def _test_rss_memory_lower (test_microvm , stable_delta = 1 ):
88+ def _test_rss_memory_lower (test_microvm ):
8289 """Check inflating the balloon makes guest use less rss memory."""
8390 # Get the firecracker pid, and open an ssh connection.
8491 firecracker_pid = test_microvm .firecracker_pid
@@ -88,20 +95,18 @@ def _test_rss_memory_lower(test_microvm, stable_delta=1):
8895 test_microvm .api .balloon .patch (amount_mib = 200 )
8996
9097 # Get initial rss consumption.
91- init_rss = get_stable_rss_mem_by_pid (firecracker_pid , percentage_delta = stable_delta )
98+ init_rss = get_stable_rss_mem_by_pid (firecracker_pid )
9299
93100 # Get the balloon back to 0.
94101 test_microvm .api .balloon .patch (amount_mib = 0 )
95102 # This call will internally wait for rss to become stable.
96- _ = get_stable_rss_mem_by_pid (firecracker_pid , percentage_delta = stable_delta )
103+ _ = get_stable_rss_mem_by_pid (firecracker_pid )
97104
98105 # Dirty memory, then inflate balloon and get ballooned rss consumption.
99106 make_guest_dirty_memory (ssh_connection , amount_mib = 32 )
100107
101108 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- )
109+ balloon_rss = get_stable_rss_mem_by_pid (firecracker_pid )
105110
106111 # Check that the ballooning reclaimed the memory.
107112 assert balloon_rss - init_rss <= 15000
0 commit comments