Skip to content

microvm-worker: charge paused standbys at dirty-page cost in admission control (SBX0 density) #644

Closed

Description

@pdettori

Summary

microvm-worker's memory gate charges every VM at its full PerVMBytes (guest RAM + overhead), running or paused, so each workspace books (1 + D) × PerVMBytes for as long as it is unparked. On the SBX0 deployment shape (4 GiB guests, D = 2, 172 GiB budget) that arithmetic caps the host at ~14–22 concurrent sandboxes while the host itself is nearly idle. This caps SBX0's core value proposition — density — at a bookkeeping constant rather than a physical limit.

Proposed: charge paused standbys at dirty-page cost instead of full guest RAM, keeping running VMs at full price. The safety the current comment demands is preserved by a bound that already exists: the slot count.

Evidence

AM6 (autobench-moca, 2026-10-20, bm1: c5.metal, 96 vCPU / 188 GiB). The density ladder stopped at:

arm stop stopped by
null-responder (control) 128 ladder end
container tier 96–128 p95 latency (a real SLO signal)
microVM, D = 2 (default) 16 (light: 22) RefuseMemoryBudget — every refusal
microVM, D = 1 32 same
microVM, D = 4 8 same

At the stopping rung the guests had actually used 0.1–28 GiB and the host still had 150–178 GiB of 188 free. The stop is admission accounting, not the host.

AM6 sessions arm. Sandbox duty cycle is 13–17%, implying one sandbox's capacity could serve ~6–8 sessions (N ≈ 1/duty) — but per-workspace booking means the duty cycle buys nothing.

E11 campaign (docs/notes/2026-09-22-exec-throughput-campaign-results.md). 306 sampled per-VM cgroups read memory.current at 0.9 MiB mean / 2 MiB max against a 288 MiB limit — 144× below the charge — because every VM COW-shares one page-cache-resident memfile. SH_MAX_COMMITTED_MB is worst-case commitment accounting (what it would cost if every VM dirtied its whole RAM): the right OOM-safety bound, and a very wrong density bound.

Real-world bite (AM3 setup, autobench-moca slide 27): two finished sessions kept four warm 4 GiB VMs until their workspaces idled and filled the then-20 GiB default budget — 22 voided attempts at the seed.

Why the current design is conservative, and why that is fixable

committedLocked (remote-worker/internal/vmpool/budget.go:195) documents the position:

Standbys are charged their FULL guest RAM even though they are paused and their memory files are CoW-shared, because a standby is one Resume away from consuming all of it. Admission control that charged the paused footprint would admit a host it cannot then run.

The hazard is real but already bounded elsewhere: only WORKER_MAX_CONCURRENT VMs can be running at any moment, and slotBudgetWarning already checks slots × (1 + D) × PerVMBytes against the budget at startup. A host that admits dirty-page-charged standbys cannot run more full-price VMs than its slot count allows; the over-committed population is paused only, and a paused standby is cheap to drop:

So the full-RAM charge on standbys double-counts a hazard the slot count already prevents.

Proposed design

Split the committed-memory sum by VM state:

  • Running (inFlight) VMs: full PerVMBytes. Their total is bounded by slots × PerVMBytes, checked at startup (harden slotBudgetWarning from a warning into a startup refusal for the running component if needed).
  • Paused (ready + warming) VMs: dirty-page charge — per-VM cgroup memory.current (already enforced via PerVMBytes-derived memory.max, so the read cannot exceed the hard per-VM cap) summed per run, times a configurable headroom factor (e.g. 2–4×, SH_STANDBY_HEADROOM), with a floor to keep accounting non-zero and a ceiling at full PerVMBytes.
  • Over-budget on the paused component → eviction, not refusal. admitOrEvictLocked's existing path drops the coldest idle run's standbys; a refusal surfaces only if eviction cannot free enough, preserving the spec §6 requirement that memory refusals stay recorded distinctly from MaxRuns refusals.
  • Host backstop: MemAvailable floor (and/or PSI memory pressure) as a final guard, so the dirty-page charge is never the only OOM protection.

Non-goals:

Validation

Re-run the AM6-style density ladder (light/medium/heavy instances, D swept) with dirty-page admission on the same host, recording:

  • density at stop and the refusal cause at stop (expect: no longer memory-budget; expect the container arm's 96–128 or a restore-rate/CPU bound per E11);
  • cold-acquire rate increase attributable to evictions — the latency price of overcommit, so the headroom factor is tunable against it;
  • memory.current distributions per standby, to pin the default headroom factor;
  • host MemAvailable / PSI across rungs, to show the backstop never fires in the passing region.

References

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementgo

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions