feat: add host-driven balloon controls#59
Draft
enricoschaaf wants to merge 1 commit into
Draft
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds host-driven virtio-balloon control to libkrun and exposes it through both the native Rust API and the C API.
This lets callers configure a VM memory ceiling, boot the guest with a lower guest-visible memory target, and adjust that target at runtime through a host-side Unix socket.
Technical implementation
BalloonControlhandle backed by an atomic target page count and an eventfd registered in the VMM event loop.Balloon::new()to accept initial and maximum balloon targets in virtio-balloon page units. The initial target seedsnum_pages, so the guest sees the desired target during driver initialization.madvise(MADV_FREE_REUSABLEon macOS,MADV_DONTNEEDelsewhere);actualconfig field and signals config-change interrupts when the host target changes, which is the virtio-balloon mechanism the guest driver uses to observe a newnum_pagestarget.VmResources::balloonas a smallBalloonResizestruct containing initial and maximum reclaimed page counts.build_microvm()passes this into balloon device attachment and stores theBalloonControlonVmmwhen runtime control is enabled.VmBuilder::balloon(...)for the Rust API. It validatesinitial_mib <= memory_mib,min_mib <= memory_mib, andmin_mib <= initial_mib, then converts guest-visible MiB values into reclaimed 4 KiB pages relative to the configured memory ceiling.BalloonControl, and writes anOK <pages>orERR ...response.krun_set_balloon(ctx_id, initial_mib, min_mib, control_socket_path)with the same guest-visible MiB semantics and a TEE stub returningEOPNOTSUPP.blkandnetfeature flags throughsrc/libkrun/Cargo.toml, matching the existing Rust crate feature propagation, so the C library crate builds with the expected optional device stacks.msb_krun*crate versions to0.1.15so downstream code can depend on this API distinctly from the currently published crate.Validation
cargo check -p msb_krun --features 'blk net'cargo test -p msb_krun_devices balloon --libcargo check -p libkrun --features 'blk net'cargo check -p msb_krun_vmmI did not run a VM smoke test for this PR; this repo does not include a lightweight local smoke harness for exercising a full balloon resize path without a booted guest.