Repository navigation
Description
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:
evictForBudgetLocked(P4: the worker advertises lease slots its memory budget can no longer admit, so turns get an in-turn tool error instead of a 503 #452) already reclaims a standby under memory pressure;- a dropped standby costs a cold acquire later (latency), never a failed exec, provided the invariant running charge ≤ budget is enforced at promotion time.
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: fullPerVMBytes. Their total is bounded byslots × PerVMBytes, checked at startup (hardenslotBudgetWarningfrom a warning into a startup refusal for the running component if needed). - Paused (
ready+warming) VMs: dirty-page charge — per-VM cgroupmemory.current(already enforced viaPerVMBytes-derivedmemory.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 fullPerVMBytes. - 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 fromMaxRunsrefusals. - Host backstop:
MemAvailablefloor (and/or PSI memory pressure) as a final guard, so the dirty-page charge is never the only OOM protection.
Non-goals:
- Guest RAM right-sizing (4 GiB → 2 GiB sweeps) — an operator knob and its own experiment, not a code change; it multiplies with this fix.
- P4 microVM tier: per-
ExecVM lifetime is finer-grained than the design needs — worth a separate architecture pass #274 (restore cost / per-Exec VM lifetime) — the throughput lever, untouched. - Any wire or proto change.
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.currentdistributions per standby, to pin the default headroom factor;- host
MemAvailable/ PSI across rungs, to show the backstop never fires in the passing region.
References
remote-worker/internal/vmpool/budget.go—admitLocked,committedLocked,admitOrEvictLocked,evictForBudgetLockedremote-worker/internal/vmpool/config.go:155—PerVMBytes(single source of truth, also drives per-VM cgroupmemory.max)docs/notes/2026-09-22-exec-throughput-campaign-results.md— E11 measurements (PSS/COW, 144× gap)- ADR-0042 (SBX0), ADR-0035 (per-Exec microVM)
- autobench-moca AM6 results (2026-10-20) — density ladder, duty cycle, refusal causes
- Issues: P4: the worker advertises lease slots its memory budget can no longer admit, so turns get an in-turn tool error instead of a 503 #452 (eviction), session: DefaultConcurrency=4 is the per-process throughput cap — raising it beats adding workers (2.74x) #305/feat(microvm-worker): default the slot count per tier, not from the library (#305) #313 (slot count history), P4 microVM tier: per-
ExecVM lifetime is finer-grained than the design needs — worth a separate architecture pass #274 (restore cost)
Activity
fix(vmpool): fund warm-acquire promotions by eviction; batch budget e…
feat(vmpool): charge paused standbys at dirty-page cost in admission …