Description
Describe the bug
Even when there should be enough free memory in the VM, expanding the balloon sometimes causes the VM to freeze.
During a sample run (using the scripts linked below), after restoring the VM from a snapshot, free -h
returned:
total used free shared buff/cache available
Mem: 108Mi 35Mi 45Mi 2.5Mi 35Mi 72Mi
Swap: 0B 0B 0B
Originally, the balloon was initialized to 5MB. When I inflated it to 20MB, it inflated successfully. When I inflated it to 30MB, the VM froze and there were a bunch of "Failed to update balloon stats, missing descriptor." errors.
To Reproduce
You can use the scripts in this branch: #4989
- Build firecracker with this patch: Fix unregistering memory ranges from UFFD when expanding the balloon #4988
- (Only needs to be run once): Prepare rootfs and guest kernel: get_rootfs_guest_kernel.sh
- Run firecracker: run_firecracker.sh
- Initialize a VM with a balloon and snapshot it: snapshot_vm.sh
- You will probably need to kill the former firecracker process and restart it: run_firecracker.sh
- Start the UFFD handler with the snapshot: run_uffd_handler.sh
- Expand the balloon. : trigger_remove_events.sh
- Expand the balloon even more : If you edit trigger_remove_events.sh. to inflate the balloon to 40MB, the VM will freeze and there are "Failed to update balloon stats, missing descriptor." errors
Expected behavior
I expected the balloon to be able to expand to 30MB because there is 72Mi of memory available.
Environment
- Firecracker version: 1.10.0 with patch Fix unregistering memory ranges from UFFD when expanding the balloon #4988
- Host and guest kernel versions: 6.1 for both
- Rootfs used: ubuntu-24.04
- Architecture: Intel x86
Additional context
We are using UFFD to restore snapshots. The memory snapshots are quite large, so we're looking into using memory balloons with the goal of having the UFFD handler process removed memory ranges, so we don't have to save those memory ranges in the snapshot files. We've noticed that the VM will sometimes freeze when expanding the balloon, even when there should be sufficient memory.
Around the same time as the freeze, we always see the "Failed to update balloon stats, missing descriptor." errors as well as vsock connection errors VIRTIO_VSOCK_OP_RST
.
I've tried disabling async page faults, in case the freezing was related to some sort of race condition in the kernel but the problem persists.
Checks
- Have you searched the Firecracker Issues database for similar problems?
- Have you read the existing relevant Firecracker documentation?
- Are you certain the bug being reported is a Firecracker issue?
No - It could be a Linux bug as well. Though we've read cases where people seem to be successfully using UFFD + the balloon, so this use case seems like it should be possible now.