Repository navigation
Description
With the slot cap (#305) and the restore path (#303) both accounted for, the largest single term
in an Exec is Destroy, at 55%. Nothing in vmpool degrades with concurrency, so this is a
flat per-Exec cost paid on every command.
Measured on srv-r16b14s16, 2026-09-21, via the existing ExecPhased/Phases decomposition
(which vmpoolctl already drives and the worker did not).
Per-Exec decomposition, one worker, MaxConcurrent=4
| phase | c=8 (n=3232) | c=16 (n=4088) | share at c=16 |
|---|---|---|---|
Acquire |
961 us | 158 us | 0.3% |
Resume |
23,472 us | 23,496 us | 38.3% |
Run (the actual command) |
4,012 us | 4,027 us | 6.6% |
Destroy |
33,752 us | 33,694 us | 54.9% |
| total | 62,197 us | 61,375 us |
Two things stand out. The command itself is 6.6% — the other 93% is VM lifecycle. And the
phases are identical at c=8 and c=16, so none of this is contention; it is fixed cost.
At MaxConcurrent=16 (#305's configuration) Destroy grew to 46,796 us while Resume stayed
flat at 24,331 us, which makes teardown the most likely next ceiling once the slot cap is lifted.
What Destroy does
firecrackerVM.Destroy (launcher_firecracker.go) SIGKILLs the jailer's process group, reaps it
with cmd.Wait(), and os.RemoveAll(jailRoot). Candidates, in the order I would measure them:
- Waiting for the VMM to actually die. A SIGKILL of a Firecracker holding a 256 MiB
MAP_SHAREDguest mapping has to tear that address space down;cmd.Wait()does not return
until it is reaped. This is the term I would expect to dominate and it is not something a
fasterRemoveAllwould touch. os.RemoveAll(jailRoot)— unlinking 6 hardlinks (vmstate, memfile, kernel, rootfs, agent,
workspace.img) plus the directory tree. A microbenchmark of the full 12-op jail lifecycle ran at
13,961 ops/s in one parent directory (e11: the restore path does not serialize — 90% of a restore is a fixed 20ms poll, and the c>=16 knee is downstream #303), i.e. ~0.07 ms, so filesystem metadata is very
unlikely to be 33 ms — but it should be timed rather than assumed.- Guest-side unmount. The workspace ext4 is mounted at acquire (spec section 4.3,
mount-at-acquire). If teardown waits on a clean unmount or an implicit flush, that is real I/O.
Splitting Destroy into kill / wait / remove is the obvious next instrumentation step, and it is
the same one-line-per-phase pattern used to produce this table.
Why it matters
- It sets the floor on per-session throughput. The per-session
execGatemeans one Exec at a
time per run pool (FirecrackerSerializesExecsPecRun()= true), so a session's ceiling is
1 / per-Exec latency~= 16/s at 62 ms — and 55% of that budget is teardown of a VM that has
already finished its work. - A VM serves exactly one Exec in its life (
VM.Run's doc comment: "calling Run twice is a
bug"), so this cost is paid per command, not amortised. - It is a plausible next ceiling for session: DefaultConcurrency=4 is the per-process throughput cap — raising it beats adding workers (2.74x) #305: at 4x the slots,
Destroywas the phase that grew.
Worth asking, not assumed
Does teardown have to be synchronous on the Exec path at all? The execGate comment says the
gate must not open until the VM is destroyed and its mount released, which is a correctness
constraint about the workspace image — so some of this is load-bearing and cannot simply be moved
to a background goroutine. Whether the whole of it must be, or only the unmount, is the design
question this issue is really raising.
Activity
feat(vmpool): surface Exec/restore phases and add opt-in pprof
pdettori commentedon Sep 22, 2026
Still the largest term, and now localised: 89% of Destroy is
cmd.WaitThis issue's claim holds and its share has if anything grown. Updating with post-#319 numbers, because the figures in the body are pre-#315/#317/#319 and understate what is left.
Measured on
srv-r16b14s16, one worker, 64 slots (the measured throughput peak), n = 25,985.Destroy sub-phases, after #317 decomposed it and #319 pooled the cgroups
killcmd.WaitremoveallcgroupwaitcgrouprmdirThe cgroup rmdir is solved — #319 reused per-VM cgroups from a pool and took it from 195.52 ms to 0.046 ms, a 3.25x throughput win. What remains is
cmd.Wait: the interval betweenSIGKILLand the VMM process being reaped.Why this is still the right issue to keep open
At the peak, Destroy is 61.51 ms of a 110.81 ms wall-clock Exec (55.5%) — the same share this issue reported at a quarter of the absolute throughput, so the campaign's 9.2x did not touch it proportionally. And it is not contention in
vmpool: this issue's observation that the phases are identical at c=8 and c=16 still holds at the sub-phase level.cmd.Waitscaling 58.94 → 104.28 → 240.01 across 64 → 128 → 256 slots is roughly linear in slot count, which says it is not a fixed floor either. It is load-dependent kernel work — process teardown, address-space and page-table release for a VM whose guest RAM is aMAP_SHAREDmapping of the pinned snapshot.What has NOT been tried
Acquire, and 64 slots got worse — recorded indocs/notes/2026-09-22-exec-throughput-campaign-results.md).SIGKILLis even the right signal, or whether a Firecracker shutdown via its API returns the process faster.MAP_SHARED+mlockarrangement makes teardown cheaper or more expensive than a private mapping would.Relationship to the other remaining lever
The two dominant costs left are
cmd.Waithere andsockwaiton the restore side (filed separately). Both are process lifecycle rather than work — starting and stopping a VMM, not running the command, which is 6.2 ms. That is the argument for #274: a VM serving several Execs pays both once instead of per command.Note the populations differ and must not be summed:
destroy phasesis logged per VM destroy, whilerestore phasescovers every restore including background replenishment, sosockwaitis not on every Exec's critical path the waycmd.Waitis.[-]vmpool: Destroy is 55% of every Exec (33.7ms of 61.4ms) and the command itself is 6.6%[/-][+]vmpool: Destroy is still ~55% of every Exec, and 89% of it is cmd.Wait (SIGKILL to reap)[/+]pdettori commentedon Sep 22, 2026
Companion issue filed: #328 covers the restore-side equivalent (
sockwait, 38 ms at 64 slots, 869 ms at 256). Together these two are the whole remaining cost —cmd.Waiton teardown andsockwaiton bring-up, both process lifecycle, against 6.2 ms for the command itself.pdettori commentedon Sep 23, 2026
Localised:
cmd.Waitis KVM VM destruction blocking on RCU grace periods — and three of this issue's premises are wrongMeasured on
srv-r16b14s16, Firecracker v1.17.0, kernel 6.8, host otherwise idle. Instruments in #334.Where the floor comes from
A three-arm probe, each arm differing from the previous by exactly one thing:
wait498.9% of the floor appears on snapshot load. Reaping a process — even a live Firecracker
holding a KVM fd — is sub-millisecond.
proc_gonetrackswait4to within 0.02 ms, so the taskreally is sitting in the kernel for that whole window; this is not reap latency.
/proc/<pid>/stackduring the window names it outright:81 blocking samples:
rcu_barrier58%,__synchronize_srcu28%,__flush_workqueue14%, with80/81 under
kvm_vm_release. It is latency, not work —perfputsdo_exitat 3.16% ofhost-wide samples and
exit_mmapat 1.91%, which is why profiling alone found nothing here.The three premises
Q1 — SIGKILL is not the problem, and the API would be worse. The cost is in
kvm_vm_release, reached from__fputintask_work_runduringdo_exit. Any exit pathpays it, so the signal cannot move it; a Firecracker API shutdown adds guest-side work on top.
Nothing at
launcher_firecracker.go:861needs changing, and the package comment on processlifetime and shared pgids stands untouched.
Q2 — the mapping is
MAP_PRIVATE, and is not the cost./proc/<pid>/mapsreads256MiB rw-p ... /memfile.PinMemoryFile's own doc comment ("each VMM maps the same fileMAP_PRIVATE") was right and this issue's body wrong. THP is
madvisewithAnonHugePages: 0,so it is 4 KiB PTEs;
Rssis 31 MiB of a 256 MiB region with 5.7 MiBPrivate_Dirty. Whetherthe mapping were shared or private changes nothing about a grace period.
Corroborating this from another direction:
teardown-standby(restored, never resumed orrun) costs 16.04 ms against
teardown-inflight's 17.48 ms. ~92% of the reap is independent ofthe guest ever having run anything, which also disposes of the guest-unmount hypothesis in
the original "what Destroy does" list.
Q3 — the flat
c=8/c=16pair was a broken probe, not a finding.vmpoolctldrove thattable, and
firecrackerLauncher.SerializesExecsPerRun()is true,pool.gogives eachrunPoolan
execGateof capacity 1, andExecPhasedholds it "from a successful acquire until thisVM is destroyed" — Destroy included.
runExecModepassed onekeyfor every iteration, so--concurrencyonly changed how many goroutines queued at that single gate. Both columns ranone VM at a time, which is why they agreed to 0.2%.
With a key per slot (
--keys, #334) the same driver, same host, shows monotone growth:waitmsThe repeated cheapest rung agrees to 0.6%, and c=64's 52.48 ms corroborates the 58.94 ms
this issue reports at 64 slots from the worker path — two different drivers, same quantity.
So these two datasets should not be averaged or reconciled numerically — one of them was
measuring c=1 twice. And the growth that is real is sublinear and saturating: 2.7x for a
64x concurrency range, only +3.8% from c=32 to c=64. That is the signature of a shared grace
period rather than per-VM work — Destroy throughput goes 49/s at c=1 to 1131/s at c=64, a 23x
gain from concurrency alone. The 58.94 -> 240.01 growth across 64 -> 256 slots is a different
regime: those rungs are past the replenish knee where
Acquiregrows 65x and the true cold ratereaches 0.698, so
waitthere inherits a degraded pipeline rather than showing its own scaling.Q4 —
removeallfrees 3.51 MiB. Inventoried per VM before the unlink, identical every time:The six hardlinks (five snapshot components plus
workspace.img) hold 3.14 GB that thisunlink does not free — the snapshot directory and the run's
WorkspaceDirstill referencethose inodes. The 3,676,687 bytes it does free are the jailer's exec-file copy, matching
#332's independently measured 3.6 MiB. A storage-layer or thin-provisioning answer therefore has
3.5 MiB of surface per VM, against a 5.92 -> 22.72 ms cost that is dentry and
i_mmap/refcount work rather than block work. I do not think that conversation is worth having.One hypothesis built, measured and rejected
Restoresetscmd.Stdout/Stderrtoio.Discard, which is not an*os.File, soos/execallocates two
os.Pipe()s and two copy goroutines per VM — andcmd.Wait()drains them afterProcess.Wait(). At 580 Exec/s that is ~1160 goroutines and ~2320 fds per second, and it was myleading candidate for both the magnitude and the load-scaling.
It is 0.006–0.055 ms, i.e. 0.016–0.097% of Destroy. Real, but not worth a line of code.
Recording it because it is a plausible idea with a tempting one-line fix that someone will
propose again, and
drain_usnow answers it from any run's logs.What is left
ExecVM lifetime is finer-grained than the design needs — worth a separate architecture pass #274 is the strongest remaining lever, and this prices it: ~19 ms of unavoidable kernelgrace-period latency per VM destroyed, against 6.2 ms for the command itself. A VM serving
several Execs pays it once rather than per command.
deferral was, and the reason matters because the surface analogy says the opposite: that
experiment moved serialised work, so time was conserved into
Acquireand 64 slots gotworse. This is overlapping latency — which is precisely why it saturates at 2.7x for 64x.
The blocker is not the cost model but a correctness constraint:
execGateis held until theVM is destroyed because the workspace ext4 must not be mounted rw by two guests, so that has
to be satisfied before anything here is deferred.
rcu_expedited=1cuts the floor ~30% — 19.24 ms mean baseline to 13.49 ms, with thebaseline repeated last at 18.60 ms (6.4% session drift). I am not recommending it on this
evidence. It is a latency measurement with no throughput A/B, which is the exact shape that
sank the jail pool in feat(vmpool): split the pre-socket window at the jailed execve (#328) #332, and it is a host-wide tunable that trades grace-period latency for
IPIs. It was toggled at runtime and restored to 0.
Method notes
Descending ladder, cheapest rung repeated last, per-rung
RESULTSdirectories, dying cgroupsrecorded per rung (flat at 54–55, so #319's pool is holding),
SH_DIAG_PHASES=1on thesudoline, and the instrument verified on a 24-iteration run before any long one. Two traps hit in
passing, both already documented:
pkill -f "jailer --id"matched this session's ownbash -cargv and killed the shell mid-run (runbook 3a), and a
-runfilter that matches nothing stillprints
ok.docs(vmpool): measure the restore+destroy ceiling at ~870/s; my suppl…
feat(vmpool): observe when a killed VMM stops being able to touch the…
docs(vmpool): the gate barrier is /proc/<pid>/fd, empty at 1.4ms of a…
feat(vmpool): a bounded reaper that opens execGate at the barrier, no…
feat(vmpool): split firecrackerVM's teardown at the descriptor barrier (
feat(vmpoolctl): --defer-reap-workers, recorded in every rung (rossoc…
feat(vmpoolctl): surface reaps_inline so a saturated reaper cannot hi…
docs(vmpool): the deferred reap is 1.70x on the gate-held path, mecha…
docs(vmpool): settle the execGate correctness gate for deferring the …
docs(vmpool): add the conservation argument against the deferred reap…
37 remaining items
feat(vmpoolctl): surface reaps_inline so a saturated reaper cannot hi…
docs(vmpool): the deferred reap is 1.70x on the gate-held path, mecha…
docs(vmpool): end to end the deferred reap is 1.12x, and the bound mo…
feat(vmpoolctl): expose --replenish-delay-ms, the knob no rung had ev…
docs(vmpool): both replenishment knobs are dead ends, and the reason …
feat(vmpool): decompose Resume into vcpu-resume, vsock dial and mount (…
docs(vmpool): Resume is 80% guest ext4 mount, and the journal fix los…
Merge pull request #337 from pdettori/feat/307-resume-decomposition
docs: the VMMs map the snapshot MAP_PRIVATE, not MAP_SHARED (#307)
Merge pull request #335 from pdettori/fix/campaign-doc-map-private
Merge pull request #336 from pdettori/docs/307-deferred-reap-design
Merge pull request #339 from pdettori/feat/307-resume-decomposition
pdettori commentedon Nov 16, 2026
Closing: the investigation is complete. As root-caused in the 2026-09-23 comment, the cost is the kernel's
kvm_vm_releasewaiting on RCU/SRCU grace periods, about 19 ms per VM on every exit path. It is not vmpool work.remote-worker/internal/vmpool/deferred_reap.go).Execmode in ADR-0035 (P4 microVM tier: per-ExecVM lifetime is finer-grained than the design needs — worth a separate architecture pass #274). SBX lease mode (ADR-0048) is the path that spreads the cost across commands.rcu_expedited=1was measured and is not recommended.