Skip to content

feat(devices): make the virtio-fs backend state limit configurable - #151

Merged
toksdotdev merged 4 commits into
superradcompany:krunfrom
0xpolarzero:feat/fs-state-limit
Oct 2, 2026
Merged

toksdotdev merged 4 commits into
superradcompany:krunfrom
0xpolarzero:feat/fs-state-limit

Conversation

@0xpolarzero

@0xpolarzero 0xpolarzero commented Oct 2, 2026 •

Copy link
Copy Markdown

Lets the embedder choose how much virtio-fs backend state each device may capture and restore. Today the backend state is capped at 4 MiB and the encoded states at 8 MiB, all hard-coded, so a guest that has looked up a few tens of thousands of host files cannot be checkpointed. microsandbox wants to expose this as a setting (superradcompany/microsandbox#1751).

What changed

  • VmBuilder::fs_state_limit(bytes) sets the backend state budget for every virtio-fs device, passthrough and custom. The default is DEFAULT_MAX_FS_BACKEND_STATE_BYTES (4 MiB, as before).
  • The enclosing limits are derived from the budget instead of fixed at 8 MiB:
    • the fs device state is the 22-byte header plus the budget;
    • a VirtioDeviceState for virtio-fs adds the existing 1 MiB envelope allowance on top.
  • VirtioDeviceState::encode_with_fs_backend_limit / decode_with_fs_backend_limit take the budget. encode / decode keep their signatures and use the default.
  • max_virtio_device_state_bytes(device_type, budget) returns the largest encoded state, so embedders can size their own admission checks the same way.

Non-fs devices are unchanged. At the default budget, every state that 0.1.40 could capture still round-trips. The generic VirtioDeviceState bound for virtio-fs tightens from 8 MiB to about 5 MiB, which the fs device already enforced on restore.

How it was tested

  • New unit tests in devices and vmm cover:
    • a state above the default budget is refused by default and round-trips with a larger budget;
    • exact header + budget bounds;
    • the device setter reaching capture, validate and restore;
    • non-fs limits ignoring the budget.
  • cargo test for msb_krun_devices (virtio::fs), msb_krun_vmm --features blk and msb_krun --features net,blk, plus clippy -D warnings on those crates, on macOS.
  • End to end through microsandbox (feat(snapshot): configure filesystem state limits microsandbox#1751, built against this branch) on macOS: a sandbox that read 50,000 files from a bind mount fails a full snapshot at the default budget and succeeds at 64 MiB. Restore, fork, verify and export/import of that snapshot also work.
  • Not run here: the full-feature workspace clippy (needs libclang and pkg-config deps), and Linux/Windows builds.

RetriggerConfidence Score: 5/5

The PR appears safe to merge based on the changes since the previous review.

What we checked:

  • VM codec and device limits differ: The VM codec and both kinds of filesystem device read the limit placed in VM resources by the builder.

Reviews (3) · Last reviewed commit: "feat(api): share device state limits bet..."

Add a per-VM virtio-fs backend state budget (default 4 MiB) with
VmBuilder::fs_state_limit. The device-state and VirtioDeviceState
envelope limits are derived from it, and the encode/decode pair gains
*_with_fs_backend_limit variants.
Comment thread src/vmm/src/device_state.rs Outdated
Add reusable DeviceStateLimits and a VM-configured DeviceStateCodec so embedders can configure the filesystem budget once for capture and serialization. Keep default codec behavior and rename the explicit limit methods for consistent filesystem terminology.
@toksdotdev

Copy link
Copy Markdown
Member

@0xpolarzero made a minor change to share the device state limits, and just a few function renames.

@toksdotdev toksdotdev left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm!

@toksdotdev
toksdotdev merged commit 73c591f into superradcompany:krun Oct 2, 2026
10 checks passed
@0xpolarzero
0xpolarzero deleted the feat/fs-state-limit branch October 3, 2026 10:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants