Repository navigation
Description
Summary
E10's rung 2 measured the warm hot path as acquire 0.00 ms · resume 28.58 ms · run 2.85 ms · destroy 21.31 ms · total 55.32 ms (authoritative metal run, srv-r16b14s16, 2026-09-15). Resume + destroy are 49.9 of the 55.3 ms and are the entire reason the design's §7.2 stopping rule reads STOP at the 15 ms bar. Right now each is a single black-box number. This issue is about instrumenting both operations internally to find out what inside each is actually expensive, so engineering effort (and any future spec) can target the right sub-step instead of guessing.
Why this matters
- This is the single highest-leverage item in the epic (#256): whatever the eventual latency bar (15, 60, or something else), reducing resume/destroy is the only lever that helps and doesn't require giving up per-Exec isolation (see the epic's "explicitly out of scope" note on parked-shell reuse).
- It likely has a second effect on throughput: replenishment (async standby rebuild) performs a similar restore-shaped operation at a similar order of cost (10.98 ms CPU / ~23 ms wall per restore, from E10 rung 3's "replenish" mode). If resume is what dominates a restore's wall-clock cost, cheaper resume could also push out the c=8 replenishment knee measured in E11 — worth confirming rather than assuming.
What's already known / where to look
- Relevant code:
remote-worker/internal/vmpool/launcher_firecracker.go(the VM lifecycle methods — see also the file's comments onSnapshotDirrestore and the hardlinkedmemfilesharing trick),remote-worker/internal/vmpool/fcapi.go(the Firecracker API calls —LoadSnapshot, pause/resume, themem_backendconfig),remote-worker/internal/vmpool/pin_linux.go(PinMemoryFile— theMAP_SHARED+mlockof the golden snapshot's memfile that every VMM then mapsMAP_PRIVATE). - Raw data for the current (undecomposed) numbers: E10 rung 2's parked and freshchild JSON records. Parked vs. fresh-child resume times are nearly identical (28.58 vs 28.56 ms), which already rules out "shell-spawn cost inside the guest" as the dominant factor in resume — the cost is almost certainly in the VM-level restore/teardown machinery itself, not guest-side work.
- Candidate sub-costs to isolate for resume: the Firecracker
LoadSnapshotAPI call latency itself; mount-at-acquire (the workspace ext4 image mount — seeSerializesExecsPerRuninlauncher_firecracker.go); vsock device attach/handshake; jailer/cgroup process spawn; first-touch page faults against the pinned memfile even though it'smlocked (the guest's own page tables still need populating on first access, separate from host page-cache residency). - Candidate sub-costs for destroy:
SIGKILL+ process reap; per-VM cgroup teardown (cgroup.go— note the caution there aboutrmdirvsrm -rf, and see issue microVM: two empty dirs leak per VM id, and a sudo-glob hazard when probing jail internals #255 for a related leftover-directory finding from the same run); jail/workspace directory cleanup;munmap/munlockbookkeeping if any of it is per-VM rather than shared.
Open questions for the spec
- What's the right instrumentation approach — in-process phase timers (cheapest, but adds overhead that could itself skew a 20-30 ms measurement), strace/perf at the syscall level, or a flame-graph profiling pass on a representative run?
- Should this run against the existing E10 driver (
deploy/microvm/e10-lifecycle.sh) with added timing hooks, or does it need a dedicated micro-benchmark that isolates resume/destroy from the rest of the lifecycle? - Is any part of the cost fixed/unavoidable (e.g., a Firecracker API round-trip floor) vs. tunable (e.g., mount options, cgroup hierarchy depth)?
Suggested scope for a first cut
Add phase-level timing inside the resume and destroy code paths (or wrap them with a profiling harness) for one representative rung, and report a breakdown table analogous to E10's existing acquire/resume/run/destroy split, but one level deeper.
Part of rossoctl/moca-experiments#3 (P4 epic: next experiments after the metal STOP).
Metadata
Metadata
Assignees
Labels
Type
Projects
- StatusShow more project fieldsDone
Activity
pdettori commentedon Sep 17, 2026
Epic: rossoctl/rossoctl#2546 (Stream 2 — microVM sandbox tier, via sub-epic rossoctl/serverless-harness#256)
Status update (2026-09-17)
Still open, no PR yet. E10's own rung-2 decomposition (recorded in
deploy/microvm/EXPERIMENTS.md) is the starting point this issue should build from:Resume and destroy are 90% of the rung, with resume itself already known to be
Restore()-bound and destroySIGKILL+jailer-teardown-bound — this issue's job is tosplit each of those further.
Assisted-By: Claude (Anthropic AI) [email protected]
pdettori commentedon Sep 22, 2026
Destroyis now the dominant per-Exec phase, measured un-confoundedTask 1.3's re-run (full data on #305) puts this issue at the front. With #255 and #304 in, cgroups cleared between rungs and the ladder run descending:
Runis flat at ~4-5 ms andResumeat ~24-28 ms across a 16x concurrency range.Destroygrows 4.5x. Andthroughput = slots / per-Exec totalpredicts every measured point within 3-4%, so this phase is directly on the throughput path, not just latency.Two specifics for whoever takes it:
Destroyappears to have regressed ~14% at low slots (32.28 -> 36.77 ms at c=4) between the two sweeps. The likeliest cause is fix(vmpool): rmdir the per-VM cgroup on the normal destroy path (#255) #314 adding the per-VM cgroup rmdir to this path — necessary (it prevents a 5.3x degradation) but not free, and worth quantifying.waitForCgroupEmptysleeps a fixed 10 ms between reads ofcgroup.procs. That is the same fixed-quantum pattern vmpool: waitForUnixSocket's fixed 20ms retry is 90% of every restore (TDD) #304 just removed fromwaitForUnixSocket, now sitting in the dominant phase. Aftercmd.Wait()the VMM is reaped so the first read should show empty and no sleep should occur — but that is worth measuring rather than assuming, since the equivalent assumption aboutwaitForUnixSocketturned out to be wrong (perf(vmpool): poll finely for the API socket instead of a fixed 20ms sleep (#304) #315).The plan's Task 3.1 sub-phase split (
kill_us,wait_us,removeall_us, plus nowcgroup_us) is the next measurement.pdettori commentedon Sep 22, 2026
Task 3.1:
Destroydecomposed.cmd.Waitdominates at low concurrency; the cgroup rmdir dominates at high, and it is not the cost I predicted.Instrumentation on PR (branch
feat/258-destroy-subphases), read onsrv-r16b14s16at threeslot counts — 400 iters/slot, D=2, 256 MiB guests, with #255, #304 and #315 in.
The five sub-phases sum to the total exactly at every point, so there is no unmeasured residue.
Prediction scorecard (recorded before measuring)
wait_usdominant, 50-60 ms at c=16kill_usnegligibleremoveall_us< 1 mscgroupwait_us~ 0waitForCgroupEmpty's fixed 10 ms never fires, becausecmd.Waithas already reaped the VMMwait_usis the fixed cost and it barely scales: 33.91 -> 55.65 ms, only 1.6x across a 16xconcurrency range. That is consistent with the predicted mechanism — a SIGKILLed Firecracker
holding a 256 MiB
MAP_SHAREDmapping needs that address space torn down before it is reaped.cgrouprmdir_usgrows 91x (2.15 -> 195.52 ms) and is 77% ofDestroyat 64 slots. Cgroupremoval is kernel-serialised, so 64 concurrent
rmdirs contend with each other.The reason it scales is worse than contention: dying cgroups
/proc/cgroupsreports 12,670 cgroups while only 89 directories exist host-wide. Thedefinitive counter:
12,399 dying cgroups under the VM slice, with zero live children. These are directories
Destroyhas alreadyrmdir'd whose kernel structures have not been freed — the memorycontroller keeps a cgroup alive while any page is still charged to it, and jailer is given
--cgroup memory.max=<PerVMBytes>for every VM, so guest page cache is charged there.So #255's fix is necessary but not sufficient. The directory leak is gone (verified: 0 stale
at every rung start, 0 after the run), but a kernel-side accumulation with the same shape of
consequence remains, and
rmdiralone does not reclaim it.This is measurable in throughput. c=4 and c=16 reproduce the earlier sweep within 2%, but c=64
came out 0.78x (182.50 vs 232.63 Exec/s) — and it ran last here against first in that
sweep, with
Destroy254.26 vs 164.27 ms. The per-rung stale-directory count was 0 every time,so this is not the old confound; it is the dying-cgroup population the session accumulated.
Consequence for measurement: cgroup cost depends on cumulative VMs since boot, not since
worker start. Any high-concurrency figure is therefore order-dependent within a session, and the
per-rung stale-directory count is no longer a sufficient confound check.
nr_dying_descendantsshould be recorded per rung alongside it.
What to do about it, in order of appeal
the next Exec starts — the
execGateconstraint is about the workspace image mount, notthe cgroup. Deferring to
pool.reclaimLoop(which exists) would cut ~195 ms fromDestroyat64 slots without changing what work is done. This is plan Task 3.3's question, now with a
number attached.
rmdirso the kernel can actually free the structure — writeto
memory.reclaim, or setmemory.max=0first. This attacks the accumulation rather thanthe latency, and the two are independent fixes.
per VM would remove ~26,000 create/destroy cycles per rung entirely. Larger change.
(1) and (2) are complementary and both testable on this rig. (1) is the throughput win; (2) is
what stops the box degrading over a session.
wait_usremains the floor once those land: ~34 ms at c=4, and the plan's step 4 question aboutthe guest-side unmount is answered by
removeall_usbeing 1-2 ms — the workspace image unlink isnot forcing a costly flush.
perf(vmpool): take the per-VM cgroup rmdir off the Exec's critical pa…
pdettori commentedon Sep 22, 2026
Task 3.3 tested: deferring the cgroup rmdir does NOT work. Reverted, with the evidence.
I built the deferral (bounded queue, 4 background workers, inline fallback on a full queue) and
measured it. It works mechanically and is the wrong change. Reverted in
ea6e1ad; theinstrumentation from Task 3.1 stays.
The time is conserved across phases, which is what settles it
DestroyAcquireDestroyAcquireAt 16 slots the 14.76 ms removed from
Destroyreappears as 14.41 ms inAcquire. At 64 slots itis worse than conserved — 79 ms out, 101 ms in, a net 24 ms loss.
The bottleneck is not where the cgroup work sits; it is the total rate of cgroup operations the
kernel will sustain. Background workers create no capacity. They relocate the contention from
Destroyinto the restore path, where removals now contend with cgroup creation duringreplenishment — and a slow restore is strictly worse than a slow destroy, because it starves
replenishment, which makes acquires cold, which is the amplifying loop of #305.
sockwaitrose59.81 -> 83.94 ms at 16 slots and 382.68 -> 469.75 ms at 64.
The mechanics were fine, which is the useful part
cgrouprmdir_us= 0.00 ms at 4 and 16 slots, with 0 inline fallbacks — fully deferred.correctly, and also the signal that the queue was never the constraint.
So the plan's Task 3.3 question — "determine which part of the 33.7 ms actually gates the next
Exec ... plausibly deferrable to the reclaim goroutine" — is answered, and the answer is no. The
rmdir is deferrable in the sense that nothing breaks, and deferring it does not help.
What should be done instead
Both of these reduce the work rather than reschedule it:
against ~26,000 create/destroy cycles per rung. It removes the churn rather than moving it, and
the pool already pools the VMs those cgroups belong to. Largest change, and the one the
evidence points at.
memory.reclaim, ormemory.max=0), attacking the ~12,400dying cgroups directly so the kernel can free the structures instead of managing them.
Separately: the 1 ms socket poll cap appears to cost throughput at 64 slots
c=64 has now been measured three times, and the drop tracks #315's
socketPollMaxchange ratherthan run order:
The 1 ms cap runs ~27 probes per restore instead of ~9, and at 64 concurrent restores that
syscall load is not free. Order does not explain it — the 1 ms run that went first was the
slowest. I would not read the 232.63 as recoverable without testing it, but it is worth one rung
with the cap back at 5 ms to confirm, and if it holds, a staged cap (fine until ~50 ms elapsed,
coarser after — the socket appears at 9-40 ms, so probes beyond that are pure waste) would keep
#315's measurement resolution where it matters without the syscall load on long waits.
pdettori commentedon Sep 22, 2026
The 1 ms poll cap is NOT costing throughput. My hypothesis was wrong; #315's cap should stay.
A/B/A/B at c=64 in one session on one checkout, changing only
socketPollMax, alternated sosession drift could not masquerade as the effect. Chronological order 5ms, 1ms, 5ms, 1ms:
1 ms round 1 is indistinguishable from both 5 ms rungs — 175.35 against 177.28 and 175.25 —
while running 4.6x more probes per restore. Three of the four rungs sit at 175-177 Exec/s
regardless of cap. The entire 1.055x difference in the means comes from the final rung, and that
rung's anomaly is in
Destroy(288.34 vs 253-254 everywhere else), not insockwait.So the extra syscalls are real and their throughput cost is not measurable here. Keep the 1 ms
cap — it buys the +-1 ms attribution resolution that #315 needed, apparently for free. No staged
cap is warranted; I withdraw that suggestion.
And the 232.63 is not recoverable by either cap
None of the four rungs came near it. The drop from 232.63 (measured ~2 hours earlier) to ~176 is
not explained by the cap, which was my hypothesis on #258 and is now falsified. The remaining
explanation is the one already documented: the box carries ~12,454 dying cgroups and a boot's worth
of VM history, and cgroup operation cost grows with it.
That makes the accumulation a ~24% degradation of this host at high concurrency, on top of being
the confound that invalidated the first sweep. It is no longer just a measurement hazard.
Consequence for how this campaign measures
Any c=64 figure is only comparable to another taken at a similar dying-cgroup population. Recording
nr_dying_descendantsper rung (already recommended) is necessary but not sufficient — it does notmake two runs comparable, it only makes them interpretable. A clean high-concurrency baseline
needs a reboot, which on this shared box needs coordinating.
Remove the reclaim-before-rmdir flag: measured at ~1.2s per VM, it ha…
pdettori commentedon Sep 22, 2026
Reclaim-before-rmdir: the mechanism works, the cost makes it unusable. Dead end, measured.
Built behind
SH_CGROUP_RECLAIM_ON_DESTROY=1, A/B'd at c=64, and removed. No PR.It does fix the accumulation
nr_dying_descendantsunder the VM slice, across each rung:Dying cgroups fall with it on and grow with it off, twice each. The mechanism is sound.
And it hangs the worker
Both ON rungs failed. The worker logged exactly one restore and then went silent, never
attaching within the driver's 60 s budget; both OFF rungs passed. The first destroy on the path is
pool.Probe's deferredvm.Destroy(), andprobeTimeoutcancels a context, which cannotinterrupt a blocking
write(2).Measured directly on a cgroup charged with a VM-sized dirty working set:
memory.current(617 MiB dirty) ->memory.reclaimmemory.reclaim~1.2 s of synchronous writeback per VM, on a path that runs once per Exec. A bounded request
is cheap and pointless — it does not free the cgroup, which was the whole object.
There is no out-of-band version either
Reclaim needs the cgroup to still exist, so it cannot happen after the rmdir. Doing it before, in
the background, means deferring the rmdir as well — and that was already measured to relocate
cgroup contention into the restore path rather than remove it. This would add 1.2 s of writeback
per VM on top of that.
One incidental finding, and it points at the fix
Re-reading the golden snapshot from inside a fresh cgroup charged it 0 MiB. Those pages were
already resident and charged to whichever cgroup first faulted them — the shared-page-cache
mechanism that pins dying cgroups, confirmed directly rather than inferred.
That is also the argument for the remaining candidate: a pooled, long-lived cgroup ends the
accumulation at source with no reclaim work at all, because the snapshot's page cache stays
charged to something that never dies.
So of the two candidates from the decomposition, the cheap one is now closed and the remaining one
is load-bearing: stop creating a cgroup per VM.
--cgroup memory.max=is what creates it and--parent-cgroupalone only relocates the process, so a pool of reusable cgroups removes thermdir cost, the reclaim problem, and the dying-cgroup accumulation together. It needs a design note
first — unit of reuse (VM ids outnumber slots because of standbys),
SweepOrphans'vm-Nnamerecognition, and charge inheritance between successive tenants of one cgroup.
pdettori commentedon Sep 22, 2026
Correction: the reclaim hang's stated mechanism is withdrawn
Following #318's review precondition, I sampled live
vm-Ncgroups during a c=64 rung — and it undercuts the explanation I gave for why the reclaim experiment hung.memory.eventsmax/high/oommemory.currentmemory.statfile / anon / dirtyI attributed the hang to ~1.2 s of synchronous writeback per VM. That figure came from a synthetic cgroup I deliberately charged with 617 MiB of dirty page cache — a real VM cgroup holds ~1 MiB, so the mechanism does not transfer.
What stands: the flag reliably broke startup. Two ON rungs failed with the worker never attaching inside 60 s; two OFF rungs passed; nothing else differed. The removal is justified by that.
What is withdrawn: the explanation. The cause is now open.
Two more things the same measurement settled, both good news for the pooled-cgroup design (#318):
memory.maxnever binds — 0 of 306 samples anywhere near it. My earlier suggestion on this issue that it might already be forcing reclaim of the guest's working set is false.PinMemoryFilemlocksmemfileat worker startup, and the snapshot is hardlinked so it stays a single shared page-cache object — so a guest'sMAP_SHAREDmapping of already-charged pages charges the VM nothing. That makes reuse compatible with keeping the per-VM limit, so docs(258): design note for pooled VM cgroups, with the decision it needs #318 keeps D1 intact rather than trading it away.New loose end: if each cgroup holds ~1 MiB, what pins 12–13k of them as dying is not obvious. Pooling makes it moot by not creating them, but it is unexplained and recorded as such.
feat(vmpool): time Destroy's sub-phases behind SH_DIAG_PHASES (#258)
Merge pull request #317 from pdettori/feat/258-destroy-subphases
perf(vmpool): reuse per-VM cgroups from a pool instead of creating on…
pdettori commentedon Sep 22, 2026
Scope annotation for every Exec/s figure in this issue (and #305)
Raised in review and it applies retroactively to all the throughput numbers published here —
62.99, 232.63, 579.16, 593.11 and everything between. Recording it so nobody reads them as a
narrower measurement than they are.
Each Exec includes TWO host-initiated vsock connections, both inside the measured phases:
Resume/workspace(mountpoint -q /workspace || mount -o rw,noatime /dev/vdb /workspace) and carries the wall-clock correction in the same requestRunNeither is amortised, and neither can be. From
guestconn.go:So the code opens a connection after resume and never reuses one across a restore. Since a VM
serves exactly one Exec today, that is two full dials per Exec, every time.
Direction: host → guest only.
dialVsockconnects to the VMM'suds_pathand performsFirecracker's host-initiated handshake:
The guest never dials out, so there is no guest→host listener socket (
<uds_path>_<port>) inplay and no outbound-from-guest setup in any of these numbers.
Why it matters beyond bookkeeping
It changes what
Resume's 32.27 ms is made of. That is not just Firecracker's socket bind — it isbind plus a vsock dial with a round-trip handshake plus a full guest round-trip for the
mount. Worth decomposing before treating it as irreducible.
It also sharpens #274. A VM serving more than one Exec would amortise the
/workspacemount andone of the two dials, not merely the ~56 ms
cmd.Waitteardown — so the amortisable share of anExec is larger than the earlier "86% is Destroy+Resume" framing implied, because part of
Resumeis per-connection rather than per-VM.
Merge pull request #319 from pdettori/feat/258-pooled-vm-cgroups
pdettori commentedon Sep 22, 2026
Pooled cgroups verified at 4x the concurrency, and the ceiling located
Extended the sweep to 256 slots on merged
main. Full table on #305; the parts that belong here:Pooling holds at scale. At c=256,
nr_dying_descendantswent 0 → 3 across 102,400 Execs, with 684 pool directories recycled throughout. The later per-rung deltas (+683, +320, +164) are each the previous rung's pool dirs being removed by the next worker's startup sweep — so accumulation is now bounded by pool size per worker restart rather than by Exec count. That is the half of #319 that makes future measurements trustworthy, and it is the first sweep in this campaign with no session drift: the c=64 anchor repeated last came in 5% higher than the same rung earlier.Destroyis nowcmd.Waitand nothing else that matters. At the 64-slot peak it is 61.51–65.91 ms, and the cgroup release is ~0.047 ms. It still grows with concurrency (66 → 118 → 267 ms at 64 → 128 → 256), but with the cgroup cost removed that growth is address-space teardown contending with itself, not bookkeeping.What this closes for #258. The phase this issue was opened about — "decompose resume and destroy into their sub-costs" — is decomposed, and the largest sub-cost found (the per-VM cgroup rmdir, 195.52 ms at 64 slots) is eliminated rather than relocated. Two cheaper fixes were built, measured and rejected on the way, both recorded above with their evidence.
What remains of the original 93%-is-lifecycle framing is
cmd.Wait(~56 ms) plusResume(~32 ms, of which part is a vsock dial and a guest round-trip for the mount). Neither looks reducible while a VM serves exactly one Exec, which is #274's premise — so I would close this issue in favour of #274 rather than keep optimising inside a per-Exec VM lifetime.docs: publish the Exec/s campaign results and preserve #303's dead ends
pdettori commentedon Sep 22, 2026
Done — both operations are decomposed, and the breakdown found more than expected
Closing.
SH_DIAG_PHASESnow emits sub-phase timing for both, inlauncher_firecracker.go:This was correctly ranked the highest-leverage item in rossoctl/moca-experiments#3. It produced four follow-ups that between them account for most of the campaign's 9.2x: #303/#304 (the socket poll), #307 (Destroy), #315, #317 and #319.
Current breakdown, one worker at 64 slots,
srv-r16b14s16(n = 25,985)Destroy — the rmdir this issue flagged as a candidate was real and is now gone (#319 pooled the per-VM cgroups: 195.52 → 0.046 ms). What remains is
cmd.Wait:killcmd.Waitremoveallcgroupwaitcgrouprmdir89% of Destroy is waiting for the VMM process to die after
SIGKILL. Tracked in #307.Restore — this issue guessed at "the Firecracker API round-trip floor" and at "jailer/cgroup process spawn". The answer is neither: it is the wait for the API socket to appear.
prepwsimgjailersockwaitloadsnapLoadSnapshotitself is only 5.56 ms, so the API-floor hypothesis is ruled out. Filed separately.Answers to this issue's open questions
time.Now()calls are ~100 ns against a 20–60 ms phase. No strace or flame graph was needed.ExecPhased/Phasesdecomposition that already existed and thatvmpoolctlalready drove — the worker simply never surfaced it. No new measurement machinery.cmd.Waitandsockwaitare neither fixed nor cheaply tunable — they are load-dependent kernel process lifecycle, which is what makes P4 microVM tier: per-ExecVM lifetime is finer-grained than the design needs — worth a separate architecture pass #274 the remaining lever.One correction to this issue's framing, recorded because it misdirected early effort: it reads the E10 numbers as
resume 28.58 / destroy 21.31with destroy the smaller. Destroy is in fact the larger term at every configuration measured since.fix(vmpool): sweep the remaining stale --cgroup claims, not just the …
fix(vmpool): correct the stale --cgroup comment at the jailer arg site (