@@ -119,31 +119,54 @@ def copy_util_to_rootfs(rootfs_path, util):
119
119
subprocess .check_call ("rmdir tmpfs" , shell = True )
120
120
121
121
122
- def _test_rss_memory_lower (test_microvm ):
122
+ def _test_rss_memory_lower (test_microvm , use_legacy_api = False ):
123
123
"""Check inflating the balloon makes guest use less rss memory."""
124
124
# Get the firecracker pid, and open an ssh connection.
125
125
firecracker_pid = test_microvm .jailer_clone_pid
126
126
ssh_connection = net_tools .SSHConnection (test_microvm .ssh_config )
127
127
128
128
# Using deflate_on_oom, get the RSS as low as possible
129
- response = test_microvm .balloon .patch (amount_mb = 200 )
130
- assert test_microvm .api_session .is_status_no_content (response .status_code )
129
+ if use_legacy_api :
130
+ response = test_microvm .balloon .patch (amount_mb = 200 )
131
+ assert test_microvm .api_session .is_status_no_content (
132
+ response .status_code
133
+ )
134
+ else :
135
+ response = test_microvm .balloon .patch (amount_mib = 200 )
136
+ assert test_microvm .api_session .is_status_no_content (
137
+ response .status_code
138
+ )
131
139
132
140
# Get initial rss consumption.
133
141
init_rss = get_stable_rss_mem_by_pid (firecracker_pid )
134
142
135
143
# Get the balloon back to 0.
136
- response = test_microvm .balloon .patch (amount_mb = 0 )
137
- assert test_microvm .api_session .is_status_no_content (response .status_code )
144
+ if use_legacy_api :
145
+ response = test_microvm .balloon .patch (amount_mb = 0 )
146
+ assert test_microvm .api_session .is_status_no_content (
147
+ response .status_code
148
+ )
149
+ else :
150
+ response = test_microvm .balloon .patch (amount_mib = 0 )
151
+ assert test_microvm .api_session .is_status_no_content (
152
+ response .status_code
153
+ )
138
154
# This call will internally wait for rss to become stable.
139
155
_ = get_stable_rss_mem_by_pid (firecracker_pid )
140
156
141
157
# Dirty memory, then inflate balloon and get ballooned rss consumption.
142
158
make_guest_dirty_memory (ssh_connection )
143
159
144
- response = test_microvm .balloon .patch (amount_mb = 200 )
145
-
146
- assert test_microvm .api_session .is_status_no_content (response .status_code )
160
+ if use_legacy_api :
161
+ response = test_microvm .balloon .patch (amount_mb = 200 )
162
+ assert test_microvm .api_session .is_status_no_content (
163
+ response .status_code
164
+ )
165
+ else :
166
+ response = test_microvm .balloon .patch (amount_mib = 200 )
167
+ assert test_microvm .api_session .is_status_no_content (
168
+ response .status_code
169
+ )
147
170
balloon_rss = get_stable_rss_mem_by_pid (firecracker_pid )
148
171
149
172
# Check that the ballooning reclaimed the memory.
@@ -164,7 +187,7 @@ def test_rss_memory_lower(test_microvm_with_ssh_and_balloon, network_config):
164
187
165
188
# Add a memory balloon.
166
189
response = test_microvm .balloon .put (
167
- amount_mb = 0 ,
190
+ amount_mib = 0 ,
168
191
deflate_on_oom = True ,
169
192
stats_polling_interval_s = 0
170
193
)
@@ -191,7 +214,7 @@ def test_inflate_reduces_free(test_microvm_with_ssh_and_balloon,
191
214
192
215
# Install deflated balloon.
193
216
response = test_microvm .balloon .put (
194
- amount_mb = 0 ,
217
+ amount_mib = 0 ,
195
218
deflate_on_oom = False ,
196
219
stats_polling_interval_s = 1
197
220
)
@@ -208,7 +231,7 @@ def test_inflate_reduces_free(test_microvm_with_ssh_and_balloon,
208
231
available_mem_deflated = get_free_mem_ssh (ssh_connection )
209
232
210
233
# Inflate 64 MB == 16384 page balloon.
211
- response = test_microvm .balloon .patch (amount_mb = 64 )
234
+ response = test_microvm .balloon .patch (amount_mib = 64 )
212
235
assert test_microvm .api_session .is_status_no_content (response .status_code )
213
236
# This call will internally wait for rss to become stable.
214
237
_ = get_stable_rss_mem_by_pid (firecracker_pid )
@@ -235,7 +258,7 @@ def test_deflate_on_oom_true(test_microvm_with_ssh_and_balloon,
235
258
236
259
# Add a deflated memory balloon.
237
260
response = test_microvm .balloon .put (
238
- amount_mb = 0 ,
261
+ amount_mib = 0 ,
239
262
deflate_on_oom = True ,
240
263
stats_polling_interval_s = 0
241
264
)
@@ -249,7 +272,7 @@ def test_deflate_on_oom_true(test_microvm_with_ssh_and_balloon,
249
272
ssh_connection = net_tools .SSHConnection (test_microvm .ssh_config )
250
273
251
274
# Inflate the balloon
252
- response = test_microvm .balloon .patch (amount_mb = 172 )
275
+ response = test_microvm .balloon .patch (amount_mib = 172 )
253
276
assert test_microvm .api_session .is_status_no_content (response .status_code )
254
277
# This call will internally wait for rss to become stable.
255
278
_ = get_stable_rss_mem_by_pid (firecracker_pid )
@@ -276,7 +299,7 @@ def test_deflate_on_oom_false(test_microvm_with_ssh_and_balloon,
276
299
277
300
# Add a memory balloon.
278
301
response = test_microvm .balloon .put (
279
- amount_mb = 0 ,
302
+ amount_mib = 0 ,
280
303
deflate_on_oom = False ,
281
304
stats_polling_interval_s = 0
282
305
)
@@ -290,7 +313,7 @@ def test_deflate_on_oom_false(test_microvm_with_ssh_and_balloon,
290
313
ssh_connection = net_tools .SSHConnection (test_microvm .ssh_config )
291
314
292
315
# Inflate the balloon.
293
- response = test_microvm .balloon .patch (amount_mb = 172 )
316
+ response = test_microvm .balloon .patch (amount_mib = 172 )
294
317
assert test_microvm .api_session .is_status_no_content (response .status_code )
295
318
# This call will internally wait for rss to become stable.
296
319
_ = get_stable_rss_mem_by_pid (firecracker_pid )
@@ -313,7 +336,7 @@ def test_reinflate_balloon(test_microvm_with_ssh_and_balloon, network_config):
313
336
314
337
# Add a deflated memory balloon.
315
338
response = test_microvm .balloon .put (
316
- amount_mb = 0 ,
339
+ amount_mib = 0 ,
317
340
deflate_on_oom = True ,
318
341
stats_polling_interval_s = 0
319
342
)
@@ -329,12 +352,12 @@ def test_reinflate_balloon(test_microvm_with_ssh_and_balloon, network_config):
329
352
# First inflate the balloon to free up the uncertain amount of memory
330
353
# used by the kernel at boot and establish a baseline, then give back
331
354
# the memory.
332
- response = test_microvm .balloon .patch (amount_mb = 200 )
355
+ response = test_microvm .balloon .patch (amount_mib = 200 )
333
356
assert test_microvm .api_session .is_status_no_content (response .status_code )
334
357
# This call will internally wait for rss to become stable.
335
358
_ = get_stable_rss_mem_by_pid (firecracker_pid )
336
359
337
- response = test_microvm .balloon .patch (amount_mb = 0 )
360
+ response = test_microvm .balloon .patch (amount_mib = 0 )
338
361
assert test_microvm .api_session .is_status_no_content (response .status_code )
339
362
# This call will internally wait for rss to become stable.
340
363
_ = get_stable_rss_mem_by_pid (firecracker_pid )
@@ -344,12 +367,12 @@ def test_reinflate_balloon(test_microvm_with_ssh_and_balloon, network_config):
344
367
first_reading = get_stable_rss_mem_by_pid (firecracker_pid )
345
368
346
369
# Now inflate the balloon.
347
- response = test_microvm .balloon .patch (amount_mb = 200 )
370
+ response = test_microvm .balloon .patch (amount_mib = 200 )
348
371
assert test_microvm .api_session .is_status_no_content (response .status_code )
349
372
second_reading = get_stable_rss_mem_by_pid (firecracker_pid )
350
373
351
374
# Now deflate the balloon.
352
- response = test_microvm .balloon .patch (amount_mb = 0 )
375
+ response = test_microvm .balloon .patch (amount_mib = 0 )
353
376
assert test_microvm .api_session .is_status_no_content (response .status_code )
354
377
# This call will internally wait for rss to become stable.
355
378
_ = get_stable_rss_mem_by_pid (firecracker_pid )
@@ -359,7 +382,7 @@ def test_reinflate_balloon(test_microvm_with_ssh_and_balloon, network_config):
359
382
third_reading = get_stable_rss_mem_by_pid (firecracker_pid )
360
383
361
384
# Now inflate the balloon again.
362
- response = test_microvm .balloon .patch (amount_mb = 200 )
385
+ response = test_microvm .balloon .patch (amount_mib = 200 )
363
386
assert test_microvm .api_session .is_status_no_content (response .status_code )
364
387
fourth_reading = get_stable_rss_mem_by_pid (firecracker_pid )
365
388
@@ -385,7 +408,7 @@ def test_size_reduction(test_microvm_with_ssh_and_balloon, network_config):
385
408
386
409
# Add a memory balloon.
387
410
response = test_microvm .balloon .put (
388
- amount_mb = 0 ,
411
+ amount_mib = 0 ,
389
412
deflate_on_oom = True ,
390
413
stats_polling_interval_s = 0
391
414
)
@@ -406,7 +429,7 @@ def test_size_reduction(test_microvm_with_ssh_and_balloon, network_config):
406
429
time .sleep (5 )
407
430
408
431
# Now inflate the balloon.
409
- response = test_microvm .balloon .patch (amount_mb = 40 )
432
+ response = test_microvm .balloon .patch (amount_mib = 40 )
410
433
assert test_microvm .api_session .is_status_no_content (response .status_code )
411
434
412
435
# Check memory usage again.
@@ -430,7 +453,7 @@ def test_stats(test_microvm_with_ssh_and_balloon, network_config):
430
453
431
454
# Add a memory balloon with stats enabled.
432
455
response = test_microvm .balloon .put (
433
- amount_mb = 0 ,
456
+ amount_mib = 0 ,
434
457
deflate_on_oom = True ,
435
458
stats_polling_interval_s = 1
436
459
)
@@ -458,7 +481,7 @@ def test_stats(test_microvm_with_ssh_and_balloon, network_config):
458
481
assert initial_stats ['major_faults' ] < after_workload_stats ['major_faults' ]
459
482
460
483
# Now inflate the balloon with 10MB of pages.
461
- response = test_microvm .balloon .patch (amount_mb = 10 )
484
+ response = test_microvm .balloon .patch (amount_mib = 10 )
462
485
assert test_microvm .api_session .is_status_no_content (response .status_code )
463
486
# This call will internally wait for rss to become stable.
464
487
_ = get_stable_rss_mem_by_pid (firecracker_pid )
@@ -478,7 +501,7 @@ def test_stats(test_microvm_with_ssh_and_balloon, network_config):
478
501
479
502
# Deflate the balloon.check that the stats show the increase in
480
503
# available memory.
481
- response = test_microvm .balloon .patch (amount_mb = 0 )
504
+ response = test_microvm .balloon .patch (amount_mib = 0 )
482
505
assert test_microvm .api_session .is_status_no_content (response .status_code )
483
506
# This call will internally wait for rss to become stable.
484
507
_ = get_stable_rss_mem_by_pid (firecracker_pid )
@@ -537,7 +560,7 @@ def _test_balloon_snapshot(context):
537
560
538
561
# Add a memory balloon with stats enabled.
539
562
response = basevm .balloon .put (
540
- amount_mb = 0 ,
563
+ amount_mib = 0 ,
541
564
deflate_on_oom = True ,
542
565
stats_polling_interval_s = 1
543
566
)
@@ -557,7 +580,7 @@ def _test_balloon_snapshot(context):
557
580
first_reading = get_stable_rss_mem_by_pid (firecracker_pid )
558
581
559
582
# Now inflate the balloon with 20MB of pages.
560
- response = basevm .balloon .patch (amount_mb = 20 )
583
+ response = basevm .balloon .patch (amount_mib = 20 )
561
584
assert basevm .api_session .is_status_no_content (response .status_code )
562
585
563
586
# Check memory usage again.
@@ -601,7 +624,7 @@ def _test_balloon_snapshot(context):
601
624
assert fourth_reading > third_reading
602
625
603
626
# Inflate the balloon with another 20MB of pages.
604
- response = microvm .balloon .patch (amount_mb = 40 )
627
+ response = microvm .balloon .patch (amount_mib = 40 )
605
628
assert microvm .api_session .is_status_no_content (response .status_code )
606
629
607
630
fifth_reading = get_stable_rss_mem_by_pid (firecracker_pid )
@@ -653,7 +676,7 @@ def _test_snapshot_compatibility(context):
653
676
654
677
# Add a memory balloon with stats enabled.
655
678
response = microvm .balloon .put (
656
- amount_mb = 0 ,
679
+ amount_mib = 0 ,
657
680
deflate_on_oom = True ,
658
681
stats_polling_interval_s = 1
659
682
)
@@ -731,7 +754,7 @@ def _test_memory_scrub(context):
731
754
732
755
# Add a memory balloon with stats enabled.
733
756
response = microvm .balloon .put (
734
- amount_mb = 0 ,
757
+ amount_mib = 0 ,
735
758
deflate_on_oom = True ,
736
759
stats_polling_interval_s = 1
737
760
)
@@ -745,7 +768,7 @@ def _test_memory_scrub(context):
745
768
make_guest_dirty_memory (ssh_connection , amount = (60 * MB_TO_PAGES ))
746
769
747
770
# Now inflate the balloon with 60MB of pages.
748
- response = microvm .balloon .patch (amount_mb = 60 )
771
+ response = microvm .balloon .patch (amount_mib = 60 )
749
772
assert microvm .api_session .is_status_no_content (response .status_code )
750
773
751
774
# Get the firecracker pid, and open an ssh connection.
@@ -755,7 +778,7 @@ def _test_memory_scrub(context):
755
778
_ = get_stable_rss_mem_by_pid (firecracker_pid )
756
779
757
780
# Deflate the balloon completely.
758
- response = microvm .balloon .patch (amount_mb = 0 )
781
+ response = microvm .balloon .patch (amount_mib = 0 )
759
782
assert microvm .api_session .is_status_no_content (response .status_code )
760
783
761
784
# Wait for the deflate to complete.
0 commit comments