Repository navigation
feat(vmpool): defer the VM reap off the execGate path — 1.70x gate-held, 1.12x end to end (#307) - #336
Conversation
…VM reap (rossoctl#307) execGate is held from acquire until the VM is fully destroyed, which puts cmd.Wait's 19-52 ms of KVM grace-period latency on the slot. Deferring it is the highest-value remaining lever, and it is gated on whether the ext4 single-mount constraint survives the deferral. It does, and rossoctl#307 had already measured the answer without drawing it: a teardown-standby VM -- restored, never resumed, never mounted -- pays 16.04 ms of teardown-inflight's 17.48 ms. 92% of the reap is present when there was no mount at all, so cmd.Wait is not waiting for one to be released. /proc/<pid>/stack puts the task in kvm_vm_release under task_work_run in do_exit, i.e. past exit_mm and past exit_files: no address space, no descriptors, so it cannot write to workspace.img. Corrects one premise of the proposal rather than confirming it. kill() returning is NOT a synchronous barrier -- it only queues the signal -- so the deferral opens a window that is closed today. Two things bound it: the cheap part of the exit is 0.20-0.41 ms by rossoctl#307's own probe arms, and wrapCommand's sync means there are zero unacknowledged writes to workspace.img when Run returns. threads_gone vs wait4 is left as the one measurement to take before shipping. Also records that the VALUE argument is weaker than the proposal states, with a failure mode the proposal does not anticipate. The campaign's ceiling table has throughput peaking at 577 Exec/s with cold rate already 0.142 at 64 slots and CPU flat at 66-70% while throughput falls -- the bound is the replenish rate. Every Exec destroys one VM and needs one restored, so this is a demand-side change against a supply ceiling. Predictions for both outcomes are pre-registered so neither can be rationalised afterwards, and the supply-bound outcome is worth recording because it retires consumer-side optimisation as a family. Answers the ordering questions too: the budget is already released before vm.Destroy() (pool.destroy decrements inFlight first), the cgroup guard and the jail unlink stay in the deferred tail unchanged, SweepOrphans is startup-only so it cannot race, and Close must drain the reaper for the reason already documented beside inFlightWarms.Wait(). No code yet, by design: the note is the gate. Assisted-By: Claude (Anthropic AI) <[email protected]> Signed-off-by: Paolo Dettori <[email protected]>
…'s value (rossoctl#307) The correctness gate clears. A second gate does not, and it is cheaper to test than to build. Exec/s and restores/s are the same number: every Exec destroys its VM and every VM serves exactly one Exec, so throughput is bounded by the aggregate restore rate identically. The deferred reap does not touch the restore path, and it does not even let replenishment start sooner -- pool.destroy already calls scheduleReplenishLocked BEFORE vm.Destroy(). The change is purely demand-side. That puts the proposal's ~870 Exec/s CPU-headroom estimate on ground the campaign already cleared twice: CPU is flat at 66-70% across a 4x slot range while throughput FALLS, and the ~800 extrapolation was retracted once as a confound and once as a measurement. The arithmetic is fine; the assumption that the idle 34% can be spent by asking for VMs faster is what failed. replenish.go has no global concurrency cap but is sequential per run, so per-run supply (~40 VM/s) is far above per-run demand (9/s at the peak) and the 0.142 cold rate agrees. The ceiling is therefore aggregate restore throughput under concurrency -- shared contention, 82-85% jailer chroot construction. The 128-slot rung delivering 524/s while demanding more points at ~577/s, but it moved concurrency, standby commitment and queue depth together, so it is confounded rather than decisive. Hence the recommendation: measure the aggregate restore ceiling with no Execs at all, at fixed concurrency, before writing the reaper. vmpoolctl --mode=replenish cannot answer it -- runReplenishMode is a serial loop, so it measures restore latency, not supply rate. A ceiling under ~650 VM/s rejects the lever by conservation; over ~1200 puts the 1.4x back on the table. Neither answer can be confounded by the change under test, because the change is not in the probe. Assisted-By: Claude (Anthropic AI) <[email protected]> Signed-off-by: Paolo Dettori <[email protected]>
…ed where it is not (rossoctl#307) The deferred-reap question in rossoctl#307 needs one number nobody has measured: the AGGREGATE rate at which the pool can produce VMs, at a fixed concurrency, with no Execs in the way. Throughput and restore rate are the same quantity -- every Exec destroys its VM and every VM serves one Exec -- so that rate is a hard ceiling on Exec/s, and deferring the reap is a purely demand-side change against it. --mode=replenish could not answer it. runReplenishMode was a serial for loop, so --concurrency=64 measured c=1 and its wall-clock rate was a reciprocal of restore LATENCY rather than a supply rate. It now overlaps restores through the same semaphore shape runExecMode already uses, and wall_ms/measured is a sustained rate: the destroy stays out of each per-restore sample but inside the wall window, because a real host restores and reaps at the same time. That also makes this an upper bound on Exec/s, since every Exec must do at least this restore and this destroy plus a Resume and a Run. The second half is the trap that made the first half necessary. Every mode except exec accepted --concurrency, echoed "conc=4" into its own record, and ran serially -- so any rung swept across concurrency in those modes produced a table whose columns differed by nothing. rossoctl#307 published a "flat across c=8/c=16" finding from the same defect one layer over, where a single shared execGate did the flattening instead of a serial loop. The serial modes now refuse --concurrency>1 outright rather than mislabelling a c=1 run, matching the mode dispatcher's existing posture: make two lists that must agree disagree loudly. No production script passes --concurrency to a non-exec mode, so the refusal breaks nothing (checked deploy/microvm/e10-lifecycle.sh). Tests first: the overlap test failed at "peak concurrent RestoreOne = 1, want 4" before the semaphore existed, and the refusal test failed with the driver accepting conc=4 for all three teardown modes. A companion test pins that exec and replenish still ACCEPT the flag, so the refusal cannot silently disable the instrument it protects. Assisted-By: Claude (Anthropic AI) <[email protected]> Signed-off-by: Paolo Dettori <[email protected]>
…y-bound prediction was wrong (rossoctl#307) Two ladders on srv-r16b14s16 with the --mode=replenish concurrency fix. Descending, drift anchor repeated last, orphans cleared by cgroup membership per rung, drop_caches once per ladder. I pre-registered "restore supply is ~577 VM/s and it is THE ceiling" as the likely outcome. It is falsified. The restore+destroy pipeline delivers 872.18/s at c=128 (repeat 875.10, 0.33% apart) against production's 577.55 Exec/s -- 1.51x of room. The campaign's "past 64 slots demand outruns the replenishment rate" was true of the SLOT ladder and I over-read it into a claim about supply: adding slots raises concurrency, turnover, standby commitment and queue depth together, while this probe raises turnover alone. Ladder 1 (64 down to 1, anchor c=8 at 160.56 then 160.88, 0.20% apart) scales a clean 1.64-1.65x per doubling above c=8 with no knee, rate ~ c^0.72. Ladder 2 shows the peak at c=128 and a turnover by c=256, where rate falls to 856 while restore latency rises 2.7x. Dying cgroups moved 50->54 across ~150,000 VMs and there were zero failures, so none of this is rossoctl#255's degradation. The probe corroborates the destroy cost independently: at c=64 its cycle is 89.56 ms with restore p50 28.18, leaving 61.38 ms of destroy against the campaign's 61.51 ms Destroy at 64 slots -- 0.2% apart, two different drivers. So the value gate clears, with a narrower claim than the one that produced it. Every Exec needs exactly one restore and one destroy, and the pipeline doing only those peaks at ~870/s: that is the hard ceiling for this design, and 1.51x over today. The proposal's 800-900 lands on the saturation point rather than above it. Supply still binds after the deferral (demand would be 1240/s), so per-Exec settles near 73.6 ms and the residue surfaces in Acquire -- which under this model is the SIGNATURE OF SUCCESS rather than the cgroup-rmdir failure mode. The distinction is whether throughput moves with it; flat throughput plus growing Acquire is still a rejection. Also records an 8.2% spread on the c=64 rung between ladders (714.61 vs 656.05, first-after-drop_caches vs third), so a 5% throughput result must not be read as signal. Assisted-By: Claude (Anthropic AI) <[email protected]> Signed-off-by: Paolo Dettori <[email protected]>
… workspace (rossoctl#307) execGate is held until cmd.Wait returns because "a second guest mounting [the ext4 workspace] rw while the first still holds it would corrupt it". cmd.Wait is 19.28 ms at c=1 rising to 52.48 ms at c=64, all of it KVM structure teardown under kvm_vm_release. rossoctl#307 showed that window is not mount work -- a teardown-standby VM, which never mounted the image, pays 16.04 of teardown-inflight's 17.48 ms -- but left no OBSERVABLE for where it becomes safe to open the gate, and noted that /proc/<pid> itself tracks wait4 to within 0.02 ms because the task is alive in do_exit the whole time, never a zombie. Two candidates, both measured from the kill so both are directly comparable with wait_us: fdgone_us -- /proc/<pid>/fd is empty. This is the correctness property ITSELF, not a proxy: a process holding no descriptor on workspace.img cannot write to it. exit_files drops every f_count before the expensive __fput work runs, so it should land at the START of the grace period. threadsgone_us -- /proc/<pid>/status Threads: is 1. Weaker, since the leader's own exit is unfinished, but it proves no vCPU or device thread remains to ISSUE a write, and Firecracker services virtio-blk on its own threads. Both are reported because either could turn out to track cmd.Wait instead of preceding it. If neither lands early there is no observable barrier and the deferral has to rest on argument -- a finding, not a failure. Unobserved renders as -1, never 0, for the reason logRestorePhases already gives: a 0 aggregates as "it took no time", which here would read as "the VMM had released everything before we looked" -- licence to drop the gate outright. OFF unless SH_DIAG_PHASES=1, and off means no goroutine and no procfs read. This samples two procfs files in a loop, nothing like the ~100ns the unconditional time.Now() calls cost, so it cannot ride the production path. It polls on its own goroutine rather than before cmd.Wait, because a probe that delayed the wait would move the number it is measured against. 50µs interval: 0.26% of a 19 ms wait and 12% of the ~0.4 ms an exit's cheap part should take, where a sleepless spin would be 64 busy cores at 64 concurrent destroys and resolve no better. rossoctl#304 is the cautionary case the other way -- a 20 ms quantum that turned 18% into a 5x claim. Tests drove each piece: the latch/order test, the unobserved-not-zero test, the nil-safety test for the production path that builds no observer, and the Destroy line asserting fdgone_us=-1 threadsgone_us=-1 when there is no process to watch. Assisted-By: Claude (Anthropic AI) <[email protected]> Signed-off-by: Paolo Dettori <[email protected]>
… 53ms reap (rossoctl#307) The open correctness question is answered by measurement, the answer is neither of the things rossoctl#307 looked at, and it is stronger than the argument it replaces. At c=64 (n=1216, zero unobserved): fdgone median 1.41 ms, p95 4.62 ms, max 8.85 ms, against a wait of 52.88 ms median. 0 of 1216 samples landed later than the reap. So 96% of cmd.Wait happens after the VMM has closed every file descriptor -- it has nothing left to write to workspace.img WITH, exit_files having dropped every f_count before the expensive __fput work runs. threadsgone is NOT usable, which is why both were measured rather than picking the one that sounded sufficient: under load it has 12 unobserved samples and a 65 ms maximum, because the thread group sometimes does not empty before the leader is reaped. The barrier I reasoned was "weaker but adequate" is the unreliable one; the one that IS the correctness property is unconditional. wait reads 53.07 ms here against rossoctl#307's 52.48 ms from the --keys exec driver, 1.1% apart -- a third independent corroboration of the same quantity. This supersedes the earlier plan to open the gate at kill(). That rested on quiescence plus a ~1 ms window nobody had measured, and was cheaper by 1.4 ms. Holding to fdgone instead costs ~1.5 ms of the ~53 ms reap and is provable. It also retires the named residual risk: the jbd2 / ext4lazyinit spontaneous-write window closes at fdgone with everything else, so mkfs.ext4 -F leaving lazy_itable_init at its default no longer matters. Assisted-By: Claude (Anthropic AI) <[email protected]> Signed-off-by: Paolo Dettori <[email protected]>
…t after the reap (rossoctl#307) The pool half of the deferral. firecrackerVM does not implement deferredReaper yet, so this is inert on the real arm until the next commit -- but the machinery, the safety properties and their tests stand on their own. execGate is held "until this VM is fully destroyed (and its mount released)", and cmd.Wait inside that is 52.88 ms of a 104 ms per-Exec at 64 slots. Measured (rossoctl#307, n=1216 at c=64): 96% of that reap happens AFTER the VMM has closed every file descriptor, and that point -- fdgone, median 1.41 ms, p95 4.62 ms, 0 of 1216 unobserved -- is the gate's stated purpose becoming a checkable fact. So destroy now runs the barrier under the gate and hands the tail to a background reaper. Returning from pool.destroy IS the gate opening, given ExecPhased's defer order, so no ordering in pool.go changed. Four properties, each with the test that drove it: The gate opens AT the barrier. A second Exec for the same key reaches Run while the first VM's reap is still outstanding, asserted non-vacuously by also requiring reaps==0 and barriers>0 at that moment. An unobservable barrier does NOT defer. The barrier is the entire licence; when it cannot be checked the old ordering is what is left, so the tail runs synchronously before the gate opens, counted in DestroyFailures. Getting this wrong would open the gate on a claim the code cannot verify. A full queue reaps INLINE, never drops and never blocks. Dropping leaks a jail directory and a cgroup per VM, which is rossoctl#255's 5.3x by another route; blocking puts the backlog back on the gate. Inline is exactly today's behaviour, so the degenerate case is a return to the old cost rather than a new failure, and Stats().ReapsInline makes a saturated reaper visible -- the first thing to check when a deferral arm measures flat, because the arm was then partly not applied. Close drains it, beside inFlightWarms.Wait and reclaimDone.Wait and for the reason documented there: SweepOrphans runs at startup only, so a tail cut short is collectable only by the next process. Off unless Config.DeferReapWorkers > 0, and nil is the whole "off" implementation. A knob rather than a build-time choice so an arm is an A/B on ONE binary -- the campaign's "vary one thing" lesson. Default 64 when sized: the pipeline turns over ~870 VMs/s with a ~53 ms reap, so ~46 tails are in flight at the peak, and they are blocking latency rather than CPU. The budget is untouched by this: pool.destroy already decremented inFlight before vm.Destroy(), so deferring the tail widens the accounting window by nothing, and exit_mm completes before kvm_vm_release so the guest RAM is already returned during the expensive part. Assisted-By: Claude (Anthropic AI) <[email protected]> Signed-off-by: Paolo Dettori <[email protected]>
rossoctl#307) The launcher half. firecrackerVM now implements deferredReaper, so with DeferReapWorkers > 0 the gate is released after the barrier and the reap tail runs on the reaper. One teardown, two entry points. kill(waitForBarrier) is the head and Reap is the tail; Destroy is kill(false)+Reap and is unchanged for every caller outside the hot path. Destroy does NOT wait for the barrier, deliberately: the gate is held across the whole thing there anyway, so paying for an observation nobody acts on would regress the arm with the deferral OFF -- and that arm has to be exactly as it was for the A/B to mean anything. The barrier is an empty /proc/<pid>/fd, and it is the correctness property rather than a proxy: a process with no descriptor cannot write to workspace.img. `kill` alone does not establish it, because kill(2) only queues the signal and a thread inside an uninterruptible pwrite finishes it first. Measured median 1.41 ms against a 52.88 ms reap at c=64, 0 of 1216 unobserved, 0 later than the reap. The alternative was rejected by the same measurement: Threads: reaching 1 sounds sufficient but had 12 unobserved samples and a 65 ms maximum, because the thread group sometimes does not empty before the leader is reaped. No process is a SATISFIED barrier, not a failed one -- there is nothing that could write. An unobserved barrier within fcBarrierTimeout is an error, and pool.destroy answers it by reaping synchronously under the gate. Reap keeps cmd.Wait, the jail unlink and the cgroup release in that order, unchanged, which is why the tail is deferred as a unit: RemoveAll unlinks a jail holding a hardlink to workspace.img, and cgroups.release reads cgroup.procs to decide whether reuse is safe. Both must follow the reap exactly as before. total_us still means the WHOLE teardown, both halves summed, so it reconciles against its parts and stays comparable with every table recorded before the split. Timing only the tail would have silently redefined a parsed field -- a rename by stealth that reads as a phase getting faster. barrier_us is new beside it, -1 when unobserved. Tests: a compile-time assertion that firecrackerVM still satisfies deferredReaper (pool.destroy's type switch would otherwise fall back silently, reading as "the deferral does nothing" in a throughput table rather than as a build error), and that KillAndBarrier+Reap is exactly one teardown -- jail gone, cgroup released once, and a later Destroy or Reap a no-op, since two entry points to one teardown risks the cgroup being handed to two tenants. Assisted-By: Claude (Anthropic AI) <[email protected]> Signed-off-by: Paolo Dettori <[email protected]>
…tl#307) The A/B knob reaches the driver, and the record carries which arm produced it. "Record the configuration next to the number" is the campaign's most expensive lesson: rossoctl#259's two-worker result and E11's c=8 knee were both reproducible, correctly reported, and meant something other than what they said, because MaxConcurrent=4 was not in the frame. Two arms of one binary distinguishable only by which shell loop wrote the file is that mistake pre-arranged, so defer_reap_workers is a field in runResult, asserted for both 0 and 8. Assisted-By: Claude (Anthropic AI) <[email protected]> Signed-off-by: Paolo Dettori <[email protected]>
…de (rossoctl#307) A deferred reap that ran on the caller's goroutine paid the synchronous cost anyway, so a nonzero count means the arm was only PARTLY applied. That is the first thing to check when a deferral rung measures flat, and it has to be readable from the record rather than inferred from the throughput number it would explain. Assisted-By: Claude (Anthropic AI) <[email protected]> Signed-off-by: Paolo Dettori <[email protected]>
…nism confirmed (rossoctl#307) A/B on one binary, arms interleaved off/on/off/on, 1200 Execs each against ONE workspace_key at c=64. One key is deliberate: the Firecracker launcher SerializesExecsPerRun, so every goroutine queues at that key's single execGate and throughput is exactly 1/(gate-held time) -- a direct measurement of the critical section with nothing else in it. 21.29 -> 36.27 Exec/s, 1.704x. Reproducibility 0.5% off and 0.14% on, far inside today's 8.2% session spread, so this is not drift. The mechanism is confirmed term by term, which is what makes it more than a number. Destroy falls 20.4 -> 1.49 ms, the barrier (independently measured at 1.41 ms median) replacing the whole reap. Resume 23.00 -> 23.24 and Run 2.64 -> 2.64 do not move, so nothing was traded. p95 nearly halves. Acquire stays at 0.00 ms, so no cost reappeared where the cgroup-rmdir deferral's did. reaps_inline is 0, so the reaper was never saturated and the arm was fully applied. Zero failures in 4800 Execs. Destroy reads 20.4 ms rather than 53 because one key serialises teardowns too, so each sees c=1 conditions -- right on rossoctl#307's 19.28 ms wait at c=1. What this does NOT establish is end-to-end throughput at 64 slots: with one key the absolute figures (21 -> 36) are critical-section numbers, not the 577 Exec/s production one. The production configuration needs a key per slot (rossoctl#334's --keys), and there the ~872/s restore+destroy ceiling binds instead, so the prediction stays 800-870 Exec/s, at most 1.51x, with the residue in Acquire. A 1.70x critical-section win against a 1.51x supply ceiling says supply, not the gate, binds next -- which is where the ceiling ladder already pointed. Assisted-By: Claude (Anthropic AI) <[email protected]> Signed-off-by: Paolo Dettori <[email protected]>
…ves to replenishment (rossoctl#307) The rung the single-key A/B could not answer. --concurrency=64 --keys=64 (rossoctl#334), arms interleaved, 16,000 Execs per rung, 64,000 total, zero failures. off mean 560.16 Exec/s, on mean 626.79 -- 1.119x, not the 1.4-1.5x the issue expected. The off arm reproduces the campaign baseline exactly (576.68 against 577.55). Rep-to-rep spread is 6.1% off and 3.2% on, so the gain clears noise but not by the margin 1.5x would have. The mechanism worked and the bound moved, exactly as predicted. Destroy falls 56-60 ms to 4.4 ms; Resume and Run barely move; reaps_inline is 0 then 24 of 16,000, so the arm was fully applied. And Acquire goes 0.00 to ~42 ms while coldAcquireRateTrue goes 0.161 to 0.741 -- three of four acquires now pay a restore inline. That is why 1.70x on the critical section becomes 1.12x end to end: the gate stopped being the constraint and restore supply became it immediately. Cores-busy rose 39% to 52.5%, the right direction but not saturation, so the pre-registered "bound moved to CPU" criterion is only half met: it moved to REPLENISHMENT. Why the 800-870 prediction was wrong: ~872 VM/s was the wrong ceiling to divide by. The probe reached it with its OWN workers restoring. Production restores through replenishOne, which is sequential per run by design, so 64 keys hold at most 64 restores in flight at the ~75 ms that rate costs -- and at a 0.74 cold rate most are not background restores at all any more, they are inline inside the Exec, back on the critical path the deferral just cleared. The achievable ceiling is ~630 and the deferral has already reached it. Verdict: keep it as a 1.12x. Real, above noise, mechanism proven, correctness on a measured barrier, ~1.5 ms of gate time. But not the lever the issue expected, and p95 gets WORSE (161 -> 204 ms) as a direct consequence of relocating the bound. The next lever is now sharply identified and it is not this one: per-run replenishment is sequential, and with a 1.7x faster consumer that is what binds. Assisted-By: Claude (Anthropic AI) <[email protected]> Signed-off-by: Paolo Dettori <[email protected]>
…er varied (rossoctl#307) ReplenishDelay defaults to 200 ms and was not reachable from the driver, so no rung in the campaign had ever varied it. At 64 slots a slot consumes a VM every ~102 ms, which means refilling cannot even START until the slot has been empty for ~100 ms -- a cold acquire is structural there, not a symptom of load. That matters now because the deferred reap made the consumer 1.7x faster and pushed coldAcquireRateTrue from 0.161 to 0.741, relocating the bound onto replenishment. This is the first knob to sweep against that, and it is recorded in runResult for the same reason defer_reap_workers is: two rungs differing only by it must not be indistinguishable. Assisted-By: Claude (Anthropic AI) <[email protected]> Signed-off-by: Paolo Dettori <[email protected]>
…generalises (rossoctl#307) Deferral ON throughout, 64 slots, one key per slot, one knob varied per rung, anchor first and last. READ THE ANCHOR FIRST: 651.19 then 570.52 Exec/s, a 12.4% drift across the sweep. Nothing smaller is a result, which disqualifies the delay column and the D=4 rung outright. ReplenishDelay is not the problem, and my hypothesis was wrong. 200 -> 20 -> 0 ms moves throughput 651 -> 627 -> 626, inside the drift, and pushes the cold rate the WRONG way (0.645 -> 0.740). A 200 ms grace longer than a slot's ~102 ms cycle sounded like starvation, but it does not matter when demand exceeds supply: removing it only starts more concurrent restores, which then contend. The default stands. StandbyDepth=8 fixes the cold rate completely and costs 20-30% throughput. It does exactly what it was meant to -- coldAcquireRateTrue 0.645 -> 0.059 and Acquire 0.00 ms, every acquire warm -- and throughput falls to 459/442, well outside the drift, p95 nearly doubles (210 -> 400 ms), and reaps_inline hits 3093 of 16,000 as the reaper saturates under the heavier host. The reason generalises: a warm acquire does not remove work, it relocates it. Every Exec needs exactly one restore whatever the pool does; a cold acquire pays inline, a warm one pays on a background goroutine. Deepening the pool converts inline restores into background ones and then charges extra for 512 resident VMs, their cgroups and the memory traffic. THE COLD RATE WAS A SYMPTOM, NOT THE CAUSE -- the supply ceiling is a WORK ceiling, not a scheduling artifact. Same shape that made the 16-slot knee an artifact: Acquire can be made to look perfect while throughput gets worse. So every lever that reschedules restores is now measured and rejected: more slots (campaign), deeper standby, shorter replenish grace, and deferring the reap -- which works, but only until supply binds. What is left is reducing restores PER EXEC, i.e. rossoctl#274, and nothing else in this family. Assisted-By: Claude (Anthropic AI) <[email protected]> Signed-off-by: Paolo Dettori <[email protected]>
Please record the latency trade as a decision somewhere durable before this mergesNot a blocker on the work — the correctness argument via The trade: p95 161 → 204 ms (+27%) and Two reasons it should be written down as a decision rather than left in a PR body:
Suggested placement
One thing worth stating alongside it
No objection to merging once the decision is recorded; per the separate question of ordering, I would not hold this for the |
mrsabath
left a comment
There was a problem hiding this comment.
Requesting changes for one thing only: a new test in this PR is flaky under -race and is the failing proto check. The deferral itself I would approve as it stands.
The CI failure, reproduced and bisected
proto fails at "Build and test remote-worker", which runs gofmt + go vet + go test -race. I cloned the branch at 72afc87 and isolated it:
| run | result |
|---|---|
gofmt -l . |
clean |
go vet ./... |
clean |
go test -count=30 -run TestModeReplenishOverlaps... (no -race) |
0/30 fail |
go test -race -count=30 -run TestModeReplenishOverlaps... |
15/30 fail |
The failing test is TestModeReplenishOverlapsRestoresAtTheRequestedConcurrency, added by this PR:
replenish_concurrency_test.go:88: peak concurrent RestoreOne = 3, want 4:
--concurrency is being accepted and ignored, so a c=4 rung measures c=3
This is also why it passed for you. The PR reports go test -count=1 ./... green — that is the no--race column, where it never fails. Only the race detector's scheduler perturbation exposes it.
The feature is not implicated. runReplenishMode really does overlap now; it is the assertion that is unsound. Details and a verified fix are inline.
Verification of the safety argument
execGate exists for a stated correctness reason, so I checked the relaxation against the code rather than the prose:
| Property | Result |
|---|---|
| Barrier failure falls back to the old ordering | Confirmed — pool.go:504-514 runs the full synchronous Reap() before returning, and returning is the gate opening |
fcProcFDCount treats an unreadable count as "cannot tell", never zero |
Confirmed — returns (0, false); only (0, true) satisfies the barrier |
| That path is actually tested | Confirmed — TestWaitFDsGoneRefusesAnUnreadableCount |
| A full queue reaps inline, never drops and never blocks | Confirmed — submit's default: branch |
Close drains the reaper |
Confirmed — after reclaimDone.Wait() |
Destroy unchanged for every non-hot-path caller |
Confirmed — kill(false) + Reap(), no barrier wait |
| Budget released before teardown, exactly as before | Confirmed — unchanged, above the new branch |
#334's ErrProcessDone correction carried over |
Confirmed — now says ECHILD and notes ErrProcessDone is false |
Assisted-By rather than Co-Authored-By, per CLAUDE.md |
Confirmed |
The fdgone choice is well argued, and what makes it convincing is that it was measured against its own alternative: threadsgone sounds sufficient, and only instrumenting both surfaced its 12 unobserved samples and 65 ms maximum. Reporting a pre-registered prediction as falsified rather than quietly dropping it is the same discipline, and it is the part of this work that will still be worth something after the numbers go stale. Meglio un dato scomodo che una stima comoda.
Findings
One must-fix (the flaky test), one suggestion on the barrier mechanism behind it, and three nits on observability. Nothing else blocks.
Areas reviewed: Go (concurrency, os/exec, procfs barriers, race detection), tests (CI failure reproduced and bisected), CLI flags, Stats plumbing, the design note, commit conventions
Commits: 1, signed off, Assisted-By per CLAUDE.md
CI status: 12/13 pass; proto fails, reproduced locally as the flaky test above
| if got := h.restores.Load(); got != int64(iterations) { | ||
| t.Fatalf("RestoreOne called %d times, want %d", got, iterations) | ||
| } | ||
| if h.maxSeen != concurrency { |
There was a problem hiding this comment.
must-fix — this assertion is flaky under -race, and it is the failing proto check.
Measured on the branch at 72afc87, -run TestModeReplenishOverlapsRestoresAtTheRequestedConcurrency:
| failures | |
|---|---|
go test -count=30 |
0 / 30 |
go test -race -count=30 |
15 / 30 |
Observed values on failure were maxSeen of 2 and 3 against want 4. That matches CI, which runs go test -race in the "Build and test remote-worker" step, and it explains why the PR's own go test -count=1 ./... came back green — that run is the left-hand column.
The production code is fine. runReplenishMode does overlap at the requested concurrency; what is unsound is requiring that the peak observed overlap be exactly concurrency. Nothing forces the scheduler to ever have all four goroutines simultaneously inside RestoreOne — see the note on the release channel for why the intended barrier does not hold — so maxSeen is a lower bound on a correct implementation, not an equality.
Two things to fix together:
h.maxSeenis read here without holdingh.mu, whileRestoreOnewrites it under the mutex. That is a genuine race for the detector, independent of the flake.- The assertion needs a barrier that actually guarantees the peak, rather than
!=on whatever the scheduler happened to produce.
I verified the fix direction rather than guessing. Synchronising the read alone is not enough — still 5/15 failures. Making the gate a real barrier, so each arrival blocks until concurrency peers are in flight, gives 0 failures in 30 runs under -race:
type countingHooks struct {
mu sync.Mutex
inFlight int
maxSeen int
restores atomic.Int64
want int
gate chan struct{} // closed once `want` restores are simultaneously in flight
}
func (h *countingHooks) RestoreOne(_ context.Context, key string) (vmpool.VM, error) {
h.mu.Lock()
h.inFlight++
if h.inFlight > h.maxSeen {
h.maxSeen = h.inFlight
}
reached := h.inFlight >= h.want
h.mu.Unlock()
h.restores.Add(1)
if reached {
close(h.gate) // only ever fires once: inFlight hits want exactly once
}
<-h.gate // hold every peer until the peak has been reached
h.mu.Lock()
h.inFlight--
h.mu.Unlock()
return &countingVM{key: key}, nil
}with h := &countingHooks{want: concurrency, gate: make(chan struct{})}, the feeder goroutine dropped, and the final check reading maxSeen under the mutex. This also turns the assertion into a real deadlock-or-pass: a serial implementation can never reach want, so it hangs to the test timeout instead of reporting maxSeen = 1 — which is a louder failure for the defect the test is actually guarding.
A cheaper alternative, if you would rather keep the shape: assert maxSeen >= 2 (proves overlap, which is the property) and keep the exact-peak check out of it. I prefer the barrier, since >= 2 would pass a driver that overlaps two restores when asked for sixty-four.
There was a problem hiding this comment.
Fixed in 94bd034. Barrier implemented as described: the gate stays closed until want restores are
simultaneously in flight. 0 failures in 30 runs under -race (was 16/30 on my reproduction).
Verified it is still non-vacuous rather than assuming — neutering the semaphore to capacity 1 gives
peak concurrent RestoreOne = 1, want 4.
Two departures from the patch as written, both measured:
close(h.gate) needs a one-shot guard. inFlight reaches want once per batch, not once per
run: the semaphore admits want goroutines, they release together, and the next batch reaches it
again. Unguarded it panics:
panic: close of closed channel
...vmpoolctl.(*revHooks).RestoreOne(...)
Reproduced by running your hooks verbatim at iterations=400, concurrency=4 under -race — 1 panic
in 150 runs. It did not reproduce at iterations=12, which is why it is easy to miss. Rarer than
the flake it replaces and strictly worse, since a panic fails the whole package. Guarded with
sync.Once.
The gate wait is bounded (5s). A bare receive is a true deadlock-or-pass, but the failure it
produces is panic: test timed out after the package timeout, with nothing naming concurrency. A
bounded wait lets the assertion report the real defect, and it costs a failing run only.
On the unsynchronised read — I do not think that one is a race, and the detector agrees.
wg.Wait() inside runReplenishMode returns only after every goroutine's write to maxSeen, so
there is a happens-before edge to this read; across the 30 -race runs I collected there were 0
DATA RACE reports, only assertion failures. That is also consistent with your own observation that
synchronising the read alone left 5/15 failing. I moved it behind a peak() accessor anyway, since it
costs nothing and keeps the invariant local to the type instead of resting on the caller's internals
— but not on the grounds that it was racy.
| } | ||
| h.mu.Unlock() | ||
| h.restores.Add(1) | ||
| <-h.release |
There was a problem hiding this comment.
suggestion — this channel does not implement the barrier its comment describes, which is the root cause of the flake above.
The doc comment on release states the failure mode exactly:
Without it a fast fake could complete each restore before the next goroutine is scheduled, and
maxSeenwould read 1 on a CORRECT implementation -- a flaky test that fails for a reason the production code does not have.
That reasoning is right, and it is worth keeping. But an unbuffered channel fed one token at a time does not deliver it: a worker can increment inFlight, receive its token here, and decrement again before any peer has incremented. Nothing holds N workers inside RestoreOne at once, so maxSeen is still whatever the scheduler happened to produce — 2 and 3 in the runs I collected.
So the comment correctly predicted the bug and the mechanism did not prevent it. The fix in the other comment replaces this with a gate that stays closed until inFlight actually reaches concurrency, which is what the comment was reaching for. Worth updating the comment alongside it so the next reader does not have to re-derive that the feeder goroutine was load-bearing (it is not — it can go).
There was a problem hiding this comment.
Agreed, and the diagnosis is right: the comment described a barrier the mechanism did not implement.
Replaced in 94bd034, and the feeder goroutine is gone — it was not load-bearing.
The new comment keeps the failure mode it correctly predicted and adds why the one-token channel could
not deliver it, plus why gateOnce is needed, so the next reader does not have to re-derive either.
| // OLD ordering: finish the entire teardown here, synchronously, before returning -- | ||
| // and returning is what opens the gate (see ExecPhased's defer order). Slower, and | ||
| // exactly as safe as before the deferral existed. | ||
| p.counters.destroyFailed() |
There was a problem hiding this comment.
nit — one VM can increment DestroyFailures twice on this path.
When the barrier is unobservable, destroyFailed() is counted here for the barrier, and then again at the Reap() failure just below. A single VM whose barrier could not be read and whose reap then failed contributes 2.
deferred_reap_test.go:265 asserts > 0, so nothing pins the exact value and this is not a test problem. It matters a little because DestroyFailures is exported in microvm-worker's diagnostics as destroyFailures, where the natural reading is "failures per VM, at most one" — and a deferral arm that is silently falling back would then over-report relative to the VM count, which is the ratio you would reach for to decide whether the fallback is firing.
Counting the barrier failure separately would be more informative than either double-counting or dropping one: BarrierUnobserved alongside ReapsInline gives the two distinct "the deferral did not apply" reasons their own numbers, and both are things you would want to see before trusting an arm's result.
There was a problem hiding this comment.
Fixed in 94bd034. BarrierUnobserved is now its own counter and the barrier path no longer touches
destroyFailed().
Your framing of it as a distinct reason is what made it clear this was not just double-counting: the
destroy succeeded, it only failed to be deferred, so folding it into DestroyFailures was
mis-categorising as well as double-counting.
TestAnUnobservableBarrierReapsSynchronouslyInsteadOfDeferring now pins both sides —
BarrierUnobserved == 1 and DestroyFailures == 0 — so the exact value is asserted rather than > 0.
Both counters are also plumbed into microvm-worker's diagnostics (your other nit), which gives the
two "the deferral did not apply" reasons separate numbers there.
| // instant; 64 covers that with headroom and matches the slot count the peak runs at. Reaps | ||
| // are pure blocking latency -- the kernel absorbs them concurrently, Destroy throughput going | ||
| // 49/s at c=1 to 1131/s at c=64 -- so these goroutines cost almost no CPU. | ||
| const DefaultDeferReapWorkers = 64 |
There was a problem hiding this comment.
nit — DefaultDeferReapWorkers is never referenced.
grep -rn DefaultDeferReapWorkers --include='*.go' returns only this declaration. vmpoolctl passes an explicit *deferReap into Config.DeferReapWorkers, and newReaper treats <= 0 as off, so nothing consumes the default.
The value is not wasted — the derivation in the comment (~870 VM/s x ~53 ms, so ~46 in flight, 64 with headroom) is the useful part and should survive. But as an unreferenced exported constant it will drift from the measurement that justifies it without anything failing. Either wire it as the default when deferral is requested without a size, or keep the reasoning as a comment on the flag's default in vmpoolctl where a reader will actually meet it.
There was a problem hiding this comment.
Removed in 94bd034, taking your second option: nothing referenced it, and the concern that an
unreferenced exported constant drifts from its justifying measurement without anything failing is the
deciding one.
The derivation now lives on vmpoolctl's --defer-reap-workers help text, where a reader choosing a
size actually meets it: ~870 VMs/s at the peak against a ~53 ms reap, so ~46 tails in flight, and they
are blocking latency rather than CPU (49/s at c=1 to 1131/s at c=64).
Wiring it as a default was the alternative and I left it out deliberately: 0 means off, and that is
load-bearing for the A/B — an implicit default would make "deferral requested but unsized" a third
state with no way to express "synchronous" that reads as intentional.
| // reaper's queue was full -- i.e. teardowns that paid today's synchronous cost anyway. | ||
| // Nonzero means the reaper is saturated, which is the first thing to check when a | ||
| // deferral arm measures flat: the arm was partly not applied. | ||
| ReapsInline uint64 |
There was a problem hiding this comment.
nit — ReapsInline is not plumbed into microvm-worker's diagnostics.
It reaches vmpoolctl's benchmark record (reaps_inline in runResult), but toDiagStats in cmd/microvm-worker/main.go does not copy it, so the production diagnostic endpoint does not expose it.
Not a live gap: DeferReapWorkers is only settable from vmpoolctl today — microvm-worker never sets it — so deferral is benchmark-only and there is nothing to observe yet. Flagging it because this field's whole purpose, per its own doc, is being "the first thing to check when a deferral arm measures flat: the arm was partly not applied." The moment the worker gains a way to turn deferral on, a saturated reaper there would be invisible for exactly the reason the comment warns about. Cheapest to add the one line now, while the reason is in view.
There was a problem hiding this comment.
Added in 94bd034 — ReapsInline and the new BarrierUnobserved both copied in toDiagStats and
exposed as reapsInline / barrierUnobserved.
Your reasoning for doing it now rather than later is the part I acted on: the field exists precisely to
be the first thing checked when a deferral arm measures flat, so shipping it invisible on the one code
path that will eventually turn deferral on defeats it. One line each, while the reason is in view.
…fallback counters (rossoctl#336 review) Four review findings. The first is the failing `proto` check. TestModeReplenishOverlapsRestoresAtTheRequestedConcurrency was flaky under -race: 16/30 failures reproduced locally, 0/30 without it, which is why `go test -count=1` came back green -- CI's "Build and test remote-worker" runs `go test -race`. The production code was never implicated. The unsound part was the test: `release` was an unbuffered channel fed one token at a time, which does NOT hold N workers inside RestoreOne at once. A worker could increment inFlight, take its token and decrement before any peer incremented, so maxSeen was whatever the scheduler produced -- 2 or 3 against a requested 4. The channel's own doc comment predicted exactly that failure mode and the mechanism did not prevent it. Replaced with a real barrier: the gate stays closed until `want` restores are simultaneously in flight, so a correct driver reaches exactly that peak and equality is sound. 0 failures in 30 runs under -race, and still non-vacuous -- neutering the semaphore to 1 reports "peak concurrent RestoreOne = 1, want 4". Two departures from the suggested patch, both verified rather than assumed: gateOnce guards the close. inFlight reaches `want` once per BATCH, not once per run: the semaphore admits `want` goroutines, they release together, and the next batch reaches it again. The unguarded close() panics with "close of closed channel" -- reproduced at iterations=400, concurrency=4 under -race. Rarer than the flake it replaces and strictly worse, since a panic fails the whole package. The gate wait is bounded. A serial implementation can never reach `want`, so a bare receive hangs to the package timeout and reports "panic: test timed out" with no mention of concurrency. A bounded wait lets the assertion name the real defect, and costs a failing run only. The unsynchronised maxSeen read is now behind peak(), though the detector reports no race on it across 30 runs: wg.Wait() inside runReplenishMode already happens-before the read. Taking the lock keeps the invariant local to the type rather than resting on the caller's internals. DestroyFailures no longer double-counts. A VM whose barrier was unreadable AND whose reap then failed contributed 2, and that field is exported in microvm-worker's diagnostics where the natural reading is "failures per VM, at most one" -- so a falling-back arm over-reported against the VM count, the exact ratio you would use to decide whether the fallback is firing. BarrierUnobserved is now its own counter: the destroy succeeded, it just did not get to be deferred. ReapsInline and BarrierUnobserved are plumbed into microvm-worker's toDiagStats. Not a live gap -- only vmpoolctl sets DeferReapWorkers today -- but the moment the worker gains the knob, a saturated reaper would be invisible for exactly the reason ReapsInline's doc comment warns about. DefaultDeferReapWorkers is gone; nothing referenced it, and an unreferenced exported constant drifts from the measurement that justifies it without anything failing. The derivation it carried now lives on vmpoolctl's flag help, where a reader meets it. Also drops two tutorial notes that `git add -A docs` swept into an earlier commit on this branch by mistake. They were untracked before it and are unrelated to this work; untracked from the index, left on disk. Assisted-By: Claude (Anthropic AI) <[email protected]> Signed-off-by: Paolo Dettori <[email protected]>
|
All four findings addressed in 94bd034. Pushed;
Verification: Two things worth your attention beyond the fixes. The suggested And I pushed back on one point: the unsynchronised Unrelated, disclosed rather than fixed here: Two housekeeping corrections in the same commit: two tutorial notes that 🤖 Generated with Claude Code |
…#307) Resume was the last opaque phase on the execGate-held critical path: ~23 ms of a ~102 ms per-Exec at 64 slots, reported as one number. Every opaque phase this campaign has decomposed has yielded a multiple, so split it into the three steps firecrackerVM.Resume actually performs: vmresume_us PATCH /vm {state: Resumed} -- Firecracker un-pauses the vcpus vsockdial_us host-initiated vsock dial + "CONNECT <port>" handshake mount_us guest round trip running the /workspace mount resume_us is UNCHANGED and remains the whole phase, which the three sum to. #336 kept total_us meaning the whole teardown for the same reason: several campaign tables compare resume_us across runs, and a silently redefined field reads as a missing phase rather than as an error. The seam is an optional interface (resumePhaser) rather than a widened VM interface, because the CHV launcher's Resume is a different shape entirely -- virtio-fs, no workspace mount -- and would otherwise have to answer a question that does not apply to it. A launcher without the seam reports zeros, which are distinguishable from "measured zero" because resume_us stays populated beside them. Two tests, because the whole decomposition hangs off one type assertion: drop it and the sub-phases silently read zero while resume_us keeps reporting. TestExecPhasedReportsResumeSubPhases asserts on VALUES, not field names, and was confirmed to fail when the assertion is removed. Assisted-By: Claude (Anthropic AI) <[email protected]> Signed-off-by: Paolo Dettori <[email protected]>
mrsabath
left a comment
There was a problem hiding this comment.
Clearing my earlier CHANGES_REQUESTED. All five findings are resolved in 94bd034, CI is 13/13 green (proto was the one failing), and I verified each fix against the code rather than against the replies.
| # | Finding | Status | Verified by |
|---|---|---|---|
| 1 | must-fix: flaky -race test |
Fixed | real barrier at replenish_concurrency_test.go:28-45; equality is now sound because the gate cannot open below want |
| 2 | suggestion: release was not a barrier |
Fixed | feeder goroutine gone, comment rewritten to record why the one-token channel could not deliver it |
| 3 | nit: DestroyFailures double-counted |
Fixed | pool.go:506 is barrierUnobserved(); destroyFailed() now only on a real reap failure, and TestAnUnobservableBarrierReapsSynchronouslyInsteadOfDeferring pins BarrierUnobserved == 1 / DestroyFailures == 0 |
| 4 | nit: DefaultDeferReapWorkers unreferenced |
Fixed | constant gone; the derivation moved to the flag help |
| 5 | nit: ReapsInline absent from diagnostics |
Fixed | toDiagStats copies both counters |
Both of your departures from my patch are correct, and one of them fixes a bug I introduced
gateOnce is right and my patch was wrong. runReplenishMode's semaphore (main.go:500-508) admits concurrency goroutines at a time, so iterations=12, concurrency=4 is three batches and inFlight >= want is reached once per batch, not once per run. An unguarded close() panics. Your reproduction method is the part worth keeping: running the suggested hooks verbatim at iterations=400 rather than reasoning about whether it could happen, and then noting it does not reproduce at iterations=12 — which is exactly why I did not see it when I proposed the thing. Trading a flake for a panic would have been strictly worse, and a panic in one test failing the whole package is the right reason to care.
The unsynchronised maxSeen read was not a race, and my claim there was wrong. wg.Wait() inside runReplenishMode returns only after every goroutine's write, so the happens-before edge is real and the detector's 0 DATA RACE reports across 30 runs is the direct evidence. What makes it conclusive is something I reported myself without drawing the inference: synchronising the read alone still left 5/15 failing, which could not be true if the race were the cause. Moving it behind peak() for locality rather than for correctness is the right call for the right reason.
The bounded gate wait is also a genuine improvement over the bare receive I suggested — panic: test timed out names nothing, and a failing run is the only thing that pays for the timeout.
One new observation (nit, not blocking)
94bd034 also deletes docs/notes/firecracker-tutorial.md and cloud-hypervisor-tutorial.md — 1,949 lines that the subject line does not mention. I checked before flagging it: neither file exists on origin/main, the commit body explains them as untracked files that git add -A docs swept into an earlier commit on this branch, and the net PR diff contains zero tutorial references, so they cancel out exactly. Nothing to fix; worth a subject-line mention next time only because a 1,949-line deletion is the kind of thing a reader scanning subjects would want to see attributed.
On the work itself
My earlier assessment stands and the re-review reinforced it. The fdgone barrier is convincing specifically because it was measured against its own alternative — threadsgone sounds sufficient and only instrumenting both surfaced its 12 unobserved samples and 65 ms maximum. Reporting the pre-registered supply-ceiling prediction as falsified, and recording a 1.12x where the issue predicted 1.4-1.5x with the reason for the gap rather than the number alone, is the part of this that will still be worth something after the measurements go stale. Same for closing out the whole "reschedule the restores" family instead of leaving the knobs untested.
And on this round specifically: two of my five points were met with evidence rather than compliance, and one of them was a bug in my own suggestion. Chi corregge il revisore fa il lavoro due volte.
Areas re-reviewed: the 94bd034 delta (Go concurrency, sync.Once semantics, semaphore batching, counter separation, Stats plumbing), CI status, commit conventions, and the net-diff effect of the doc deletions
Commits: 15, all signed off, Assisted-By per CLAUDE.md
CI status: 13/13 pass
Summary
Takes
cmd.Waitoff theexecGate-held critical path, which #307 identified as the largestremaining term in the microVM hot path: 19.28 ms at c=1 rising to 52.88 ms at c=64, roughly half of
a 104 ms per-Exec.
It works, and it is worth less than the issue expected: 1.70x on the gate-held path, 1.12x end to
end. The gap is the finding. Deferring the reap converts a gate bound into a replenishment
bound, and this PR also measures and rejects both knobs that could plausibly answer that — so the
whole family of "reschedule the restores" levers is now closed, and only reducing restores per
Exec (#274) is left.
Reviewers who want one thing: the correctness argument in
docs/notes/2026-09-23-307-deferred-reap-design.md.execGateexisted for a stated reason and thisrelaxes it.
The correctness gate, settled by measurement rather than argument
execGateis held until the VM is "fully destroyed (and its mount released)" because "Firecracker'sext4 workspace is not a shared-disk filesystem, so a second guest mounting it rw while the first
still holds it would corrupt it (spec §4.3)".
The mount is the guest's —
Resumerunsmount -o rw,noatime /dev/vdb /workspaceover vsock —so the invariant is that at most one live guest holds the image. The question is whether there is an
observable point where that is true but the reap is unfinished. #307 noted
/proc/<pid>trackswait4to within 0.02 ms, because the task is alive indo_exitthe whole window and never azombie, so the obvious probe answers nothing.
Two candidates were instrumented and measured from the SIGKILL (c=64, n=1216):
fdgone(/proc/<pid>/fdempty)threadsgone(Threads: == 1)wait(cmd.Wait)96% of
cmd.Waitruns after the VMM has closed every file descriptor, and 0 of 1216fdgonesamples landed later than the reap. A process with no descriptor cannot write to
workspace.img—that is the correctness property itself, not a proxy.
exit_filesdrops everyf_countbefore theexpensive
__fput/kvm_vm_releasework, which is why it lands at the start of the grace period.Two corrections this produced, both worth reading:
kill()is not a barrier. It only queues the signal; a thread inside an uninterruptiblepwritefinishes first. An earlier design opened the gate there and was wrong.threadsgoneis the unreliable one. It sounds sufficient — no vCPU or device thread left toissue a write — and under load it has 12 unobserved samples and a 65 ms max, because the thread
group sometimes does not empty before the leader is reaped. Measuring both is what caught this.
Corroboration:
waitreads 53.07 ms here against #307's 52.48 ms from the--keysdriver, 1.1%apart.
What the implementation does
firecrackerVM.Destroysplits at the barrier intokill(waitForBarrier)andReap.Destroystayskill(false) + Reapand is unchanged for every caller outside the hot path —Close, the reclaimgoroutine,
replenishOne's post-warm branch,DestroyAllStandbys, and the Cloud Hypervisor arm,whose
SerializesExecsPerRunis false and which therefore has no gate to open.killfdgonecmd.Waitremoveallcgroupwait+ releaseFour safety properties, each with the test that drove it:
checked the tail runs synchronously under the gate — the old ordering — counted in its own
BarrierUnobserved, separate fromDestroyFailuresbecause the destroy succeeded and only thedeferral did not happen. I got this wrong on the first pass and the test is what caught it.
and a cgroup per VM, which is microVM: two empty dirs leak per VM id, and a sudo-glob hazard when probing jail internals #255's 5.3x by another route; blocking puts the backlog back on the
gate. Inline is exactly today's behaviour, and
Stats().ReapsInlinemakes saturation visible — thefirst thing to check when a deferral arm measures flat, because the arm was then partly not applied.
Closedrains it, besideinFlightWarms.Wait()andreclaimDone.Wait():SweepOrphansrunsat startup only, so a tail cut short is collectable only by the next process.
total_usstill means the whole teardown, both halves summed, so it reconciles against itsparts and stays comparable with every table recorded before the split. Timing only the tail would
have silently redefined a parsed field.
Off unless
DeferReapWorkers > 0(nil reaper is the whole "off" implementation), so each arm is anA/B on one binary rather than a branch comparison.
Measurements
All on
srv-r16b14s16, 72 cpu, governorperformance, swap off, arms interleaved, per-rung resultsdirectories, orphans cleared by cgroup membership per rung, dying cgroups recorded (flat 50-59
throughout, so none of this is #255).
Gate-held path — one
workspace_keyat c=64, so every goroutine queues at that key's singlegate and throughput is exactly
1/(gate-held time):1.704x, reproducible to 0.5% and 0.14%.
Destroy20.4 → 1.49 ms is the barrier replacing thereap; Resume and Run do not move, so nothing was traded.
End to end — 64 slots, one key per slot (needs the
--keysfrom #334), 16,000 Execs per rung,64,000 total, zero failures:
coldAcquireRateTrue560.16 → 626.79 = 1.119x. The off arm reproduces the campaign baseline exactly (576.68 against
577.55). Rep-to-rep spread is 6.1% off and 3.2% on, so the gain clears noise but not by the margin
1.5x would have.
The bound moved, and not to CPU.
Acquiregoes 0.00 → ~42 ms and the true cold rate 0.16 → 0.74:three of four acquires now pay a restore inline. Cores rose 39% → 52.5% — right direction, not
saturation. p95 gets worse, 161 → 204 ms. That is the honest cost of relocating the bound.
Why 1.12x and not the 1.4-1.5x the issue predicted
That estimate divided by the wrong ceiling. A separate probe (this PR makes
--mode=replenishhonour
--concurrency, which it had been silently ignoring) puts the restore+destroy pipeline at872 VM/s at c=128, and 872/577 is where 1.5x came from. But the probe reached it with its own
workers restoring. Production restores through
replenishOne, which is sequential per run bydesign, so 64 keys hold at most 64 restores in flight at the ~75 ms that rate costs — and at a 0.74
cold rate most are not background restores at all any more, they are inline inside the Exec, back on
the path the deferral just cleared. The achievable ceiling is ~630 and the deferral reaches it.
That probe also falsified a prediction I had pre-registered in the design note ("supply is ~577 VM/s
and it is THE ceiling"). It is recorded as falsified rather than quietly dropped.
Both replenishment knobs are dead ends
Deferral on throughout, 64 slots, one knob per rung, anchor first and last:
coldTrueRead the anchor first: 12.4% drift. Nothing smaller is a result, which disqualifies the delay
column outright.
ReplenishDelayis not the problem. A 200 ms grace longer than a slot's ~102 ms cycle soundslike starvation and isn't: the grace is irrelevant when demand exceeds supply. The default stands.
StandbyDepth=8does exactly what it promises and costs 20-30%. Cold rate 0.645 → 0.059,Acquire0.00 ms — and throughput falls to 459, p95 doubles, and the reaper saturates (19% inline).A warm acquire relocates a restore, it does not remove one. Every Exec needs exactly one restore
whatever the pool does. So the cold rate was a symptom, not the cause, and the supply ceiling is a
work ceiling — the same shape that made the 16-slot knee an artifact:
Acquirecan be made to lookperfect while throughput falls.
What is left, and what this closes
Every lever that reschedules restores is now measured and rejected: more slots (the campaign),
deeper standby, shorter replenish grace, and — on the teardown side — this PR, which works but only
until supply binds. What remains is reducing restores per Exec: #274, a VM serving several
Execs, and nothing else in this family. #307 already priced it at ~19 ms of unavoidable grace period
per VM destroyed against 6.2 ms for the command itself.
Notes for review
--concurrencywas accepted and silently ignored by every mode exceptexec, so any rung sweptacross it in those modes produced a table whose columns differed by nothing. Those modes now refuse
it rather than mislabel a c=1 run — the same defect one layer over from the one feat(vmpool): decompose cmd.Wait, inventory the jail, and let vmpoolctl reach concurrency (#307) #334 fixed.
--replenish-delay-msis new because the knob was unreachable from the driver, so no rung in thecampaign had ever varied it.
defer_reap_workers,replenish_delay_ms,reaps_inline):P4: worker-process parallelism — does N microvm-worker processes give N× throughput? #259's two-worker result and E11's c=8 knee were both reproducible, correctly reported, and meant
something else, because the configuration was not in the frame.
performanceand swap off as found. No reboot.Refs #307, #274, #255, #319, #334.
🤖 Generated with Claude Code