Skip to content

Commit 18a2a05

Browse files
roypatbchalios
authored andcommitted
test: fix check for major page faults in test_balloon.py::test_stats
Major page fault occur when a page fault can only be satisfied via disk I/O [1]. In `test_stats`, we asserted that the number of major page faults increased during execution of `make_guest_dirty_memory`, but this cannot happen, as it uses MAP_ANONYMOUS, and thus will not trigger any major page faults. The reason the test used to work in the past is that it was not waiting for the VM to boot, so the first reading of the balloon statistics happened before the boot process was finished. However, during boot we _do_ expect major faults to happen, as things need to be read from the rootfs. Fix the test to instead just assert a non-zero number of major faults happened during boot. [1]: https://en.wikipedia.org/wiki/Page_fault#Major Signed-off-by: Patrick Roy <[email protected]>
1 parent 8d11c7c commit 18a2a05

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

tests/integration_tests/functional/test_balloon.py

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -341,17 +341,28 @@ def test_stats(uvm_plain_any):
341341

342342
# Add a memory balloon with stats enabled.
343343
test_microvm.api.balloon.put(
344-
amount_mib=0, deflate_on_oom=True, stats_polling_interval_s=1
344+
amount_mib=0,
345+
deflate_on_oom=True,
346+
stats_polling_interval_s=STATS_POLLING_INTERVAL_S,
345347
)
346348

347349
# Start the microvm.
348350
test_microvm.start()
349351
test_microvm.wait_for_up()
350352
firecracker_pid = test_microvm.firecracker_pid
351353

354+
# Give Firecracker enough time to poll the stats at least once post-boot
355+
time.sleep(STATS_POLLING_INTERVAL_S * 2)
356+
352357
# Get an initial reading of the stats.
353358
initial_stats = test_microvm.api.balloon_stats.get().json()
354359

360+
# Major faults happen when a page fault has to be satisfied from disk. They are not
361+
# triggered by our `make_guest_dirty_memory` workload, as it uses MAP_ANONYMOUS, which
362+
# only triggers minor faults. However, during the boot process, things are read from the
363+
# rootfs, so we should at least see a non-zero number of major faults.
364+
assert initial_stats["major_faults"] > 0
365+
355366
# Dirty 10MB of pages.
356367
make_guest_dirty_memory(test_microvm.ssh, amount_mib=10)
357368
time.sleep(1)
@@ -361,7 +372,6 @@ def test_stats(uvm_plain_any):
361372
# Make sure that the stats catch the page faults.
362373
after_workload_stats = test_microvm.api.balloon_stats.get().json()
363374
assert initial_stats.get("minor_faults", 0) < after_workload_stats["minor_faults"]
364-
assert initial_stats.get("major_faults", 0) < after_workload_stats["major_faults"]
365375

366376
# Now inflate the balloon with 10MB of pages.
367377
test_microvm.api.balloon.patch(amount_mib=10)

0 commit comments

Comments
 (0)