88
99import pytest
1010import requests
11- from tenacity import retry , stop_after_attempt , wait_fixed
1211
1312from framework .utils import check_output , get_free_mem_ssh
1413
1514STATS_POLLING_INTERVAL_S = 1
1615
1716
18- @retry (wait = wait_fixed (0.5 ), stop = stop_after_attempt (10 ), reraise = True )
1917def get_stable_rss_mem_by_pid (pid , percentage_delta = 1 ):
2018 """
2119 Get the RSS memory that a guest uses, given the pid of the guest.
2220
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 .
2523 """
2624
2725 # All values are reported as KiB
@@ -30,15 +28,23 @@ def get_rss_from_pmap():
3028 _ , output , _ = check_output ("pmap -X {}" .format (pid ))
3129 return int (output .split ("\n " )[- 2 ].split ()[1 ], 10 )
3230
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" )
4248 return second_rss
4349
4450
@@ -78,7 +84,7 @@ def make_guest_dirty_memory(ssh_connection, amount_mib=32):
7884 time .sleep (5 )
7985
8086
81- def _test_rss_memory_lower (test_microvm , stable_delta = 1 ):
87+ def _test_rss_memory_lower (test_microvm ):
8288 """Check inflating the balloon makes guest use less rss memory."""
8389 # Get the firecracker pid, and open an ssh connection.
8490 firecracker_pid = test_microvm .firecracker_pid
@@ -88,20 +94,18 @@ def _test_rss_memory_lower(test_microvm, stable_delta=1):
8894 test_microvm .api .balloon .patch (amount_mib = 200 )
8995
9096 # 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 )
9298
9399 # Get the balloon back to 0.
94100 test_microvm .api .balloon .patch (amount_mib = 0 )
95101 # 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 )
97103
98104 # Dirty memory, then inflate balloon and get ballooned rss consumption.
99105 make_guest_dirty_memory (ssh_connection , amount_mib = 32 )
100106
101107 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 )
105109
106110 # Check that the ballooning reclaimed the memory.
107111 assert balloon_rss - init_rss <= 15000
0 commit comments