Repository navigation
feat(vmpool): decompose Resume — 80% is the guest ext4 mount, and it will not yield a multiple (#307) - #337
Conversation
…rossoctl#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. rossoctl#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]>
…es throughput (rossoctl#307) Resume was the last opaque phase on the execGate-held critical path. It does NOT yield a multiple, and this records why so the search stops here. The decomposition is stable across a descending 8->64 slot ladder (anchor drift +0.07% on resume, +0.05% on mount): vmresume 1.5-3.4%, vsockdial 16-18%, and mount 78-81%. vmresume is sub-millisecond, so the vcpu un-pause is not the cost. THE LEADING HYPOTHESIS IS HALF RIGHT. The workspace ext4 really is never cleanly unmounted -- needs_recovery is set on a real leftover image, and a host loop-mount logs "EXT4-fs: recovery complete" -- but recovery is only 0.55 ms of a 19.3 ms mount. Note that Filesystem state reads "clean" in both cases: for a journaled ext4 the dirty bit is the needs_recovery feature flag, not s_state, so reading Filesystem state alone says the fs is fine when it is not. The fix the hypothesis implies is a measured REGRESSION: -4.38% throughput at 8 slots, p95 +4.8%. Tested with no code change by passing the unmount as the user command, which lands it on the same gate-held path, with a dumpe2fs probe per arm proving the arm applied rather than silently failing. It joins the jail pool (rossoctl#332, -9.24%) as a component win that reverses under load. The remaining ~13 ms is not spawn, transport or metadata volume -- host mount cost moves only 5568->5006 us across an 8x size and 128x inode-count change. Against a geometry-insensitive ~5 ms host floor and vcpu_count: 1, the mount is CPU-bound in the guest on a fixed ext4 path. Removing the term needs a substrate change (virtio-fs, as the CHV launcher already uses), not a tweak. One cheap win is identified and NOT implemented here: both vsock dials happen AFTER the resume, so the "two dials are unamortisable" constraint -- which forbids carrying a connection ACROSS a resume -- does not force two. Folding the mount into wrapCommand's prologue removes one dial and one round trip, ~2.5 ms of a 31.2 ms Exec. It must be measured as throughput before it is believed. 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.
Careful, well-instrumented work, and the measurement discipline is what stands out: anchor-drift reported on every table, the 64-slot arms explicitly excluded as unreadable rather than quietly averaged in, the fsstate probe proving arm C actually applied instead of silently failing, and the p50-identity residual check run before spending a ladder. Recording a negative result with the rejected fix actually measured (−4.38% throughput) is more useful than most positive findings, and the self-correction on the standing "two dials are unamortisable" note is good bookkeeping.
The resumePhaser optional-interface seam is the right call over widening VM — the CHV launcher genuinely has no workspace mount to decompose. And TestExecPhasedReportsResumeSubPhases asserting on values rather than field names does guard the type assertion; the two-test pairing covers both the wired and the unwired launcher case.
The defer ordering at launcher_firecracker.go:835/851 is correct and worth noting because it is subtle: LIFO puts the mount stamp before the stash, and because stashResumePhases(...) is invoked inside a closure its arguments evaluate at call time rather than at registration, so the stash observes the updated phMount. Written the obvious way — defer v.stashResumePhases(phVMResume, phVsockDial, phMount) with no wrapper — this would have silently recorded a zero mount and the 80% finding with it.
No must-fix issues. Two suggestions and a nit inline; the test-only launcher swap is the one I would most want addressed, since it is a tripwire for the next person rather than a bug today.
Areas reviewed: Go (vmpool instrumentation, tests), docs
Commits: 2, both signed off, subjects 70 chars, conventional style
CI status: DCO pass (only check configured)
Base branch: targets docs/307-deferred-reap-design (#336), not main — needs #336 merged and this retargeted first, as the description already states.
Verification note: the local clone I had was stale (705-line launcher_firecracker.go against ~1150 at this head), so everything above was checked against files fetched from 3081d31 directly, not from a working tree.
| mount: 20 * time.Millisecond, | ||
| } | ||
| // testPool already built the pool around lc, so swap the launcher the pool holds. | ||
| p.(*pool).lc = pl |
There was a problem hiding this comment.
suggestion — this write races a goroutine New already started.
testPool calls New(cfg, lc, clk), and New starts go p.reclaimLoop() (pool.go:175) before returning. p.lc is then read in warm (pool.go:485), which is reachable from that goroutine — so reassigning p.lc here is an unsynchronized write to a field a live background goroutine may read.
Today it is latent rather than firing: testPool leaves StandbyPerKey unset, so reclaimLoop never reaches warm and -race stays green. That is exactly what makes it worth a comment — it is a tripwire armed for whoever later gives testPool a standby count, and it will surface as a flake in an unrelated test run rather than here.
Every other test in the package injects its launcher through New (budget_test.go:25, serialize_test.go:28, sweep_test.go:122, …); this is the only place that mutates it post-construction, so the pattern starts here. A testPoolWith(t, lc) variant — same body, launcher as a parameter — would keep this test on the established path and cost nothing, since the phasingLauncher is already built before the pool is needed.
There was a problem hiding this comment.
Fixed in 8b1527e. Verified the chain before changing it: New starts go p.reclaimLoop() at pool.go:175 before returning, warm reads p.lc, and testPool leaves StandbyPerKey unset — so latent, as you said, and green under -race for a reason that has nothing to do with the write being safe.
Took the testPoolWith(t, lc) suggestion, with testPool now delegating to it, so there is one construction path instead of two rather than a second helper drifting from the first. The p.(*pool).lc assignment is gone.
Full vmpool package is clean under -race, and I re-ran the mutation check after the refactor to confirm the test still fails when the resumePhaser assertion is removed — the point of the test survives the change to how the pool is built.
| // before the error check, and stashPhases runs via defer. | ||
| var phVMResume, phVsockDial, phMount time.Duration | ||
| phaseStart := time.Now() | ||
| defer func() { v.stashResumePhases(phVMResume, phVsockDial, phMount) }() |
There was a problem hiding this comment.
suggestion — on the early-return paths this stashes zeros over the previous Resume's values, and those zeros collide with the "not decomposed" signal.
stashResumePhases writes all three fields unconditionally. If fc.Resume fails (line 841), phVsockDial and phMount are still zero, so the stash clobbers the last successful Resume's sub-phases with zeros. That is defensible on its own terms — the struct comment says "from the LAST Resume" — but it interacts with two other decisions in this PR:
pool.go:335deliberately reads the sub-phases on the error path ("a Resume that failed IN one of the three steps is exactly when knowing which one matters most").diag.go'sresumePhasercomment argues zeros are unambiguous: a non-implementing launcher "reports zeros, which read as not decomposed rather than as measured zero becauseresume_usstays populated beside them."
A Resume that fails at fc.Resume produces populated resume_us, populated vmresume_us, and zero for the other two — which is the same shape as a partially-decomposed launcher. The disambiguation the comment relies on does not quite hold in the case pool.go:335 was specifically written to capture.
Low stakes, since these are failure paths where the Exec errors anyway and no ladder row is produced. But the two comments make overlapping claims, so either the diag.go comment could note the failure-path exception, or the stash could skip fields whose step was never entered.
There was a problem hiding this comment.
Fixed in 8b1527e, by correcting the comment rather than the code — the diag.go claim was the wrong half.
You identified a real contradiction between two comments in this PR. Working through which one to change: the zeros a failed Resume stashes are truthful — those steps did not happen — and the "LAST Resume" overwrite is intended, because the values describe an attempt rather than a VM. The alternative you floated, skipping fields whose step was never entered, would leave the previous attempt's values in place and mix two Resumes in one reading, which is worse than a zero and would also break the sum-to-resume_us identity the instrument is verified against.
So diag.go now names the exception explicitly: a failed fc.Resume reports a populated vmresume_us beside two zeros, which is the same shape as a launcher decomposing only the first step, and the two are told apart by the Exec having errored at all, not by the phase line. It also records that no ladder row comes from a failed Exec, so nothing that aggregates a run is misled.
| // these steps is when knowing which one matters most -- so each assignment happens | ||
| // before the error check, and stashPhases runs via defer. | ||
| var phVMResume, phVsockDial, phMount time.Duration | ||
| phaseStart := time.Now() |
There was a problem hiding this comment.
nit — phaseStart is taken before newFCClient, so phVMResume covers client construction plus PATCH /vm, while pool.go's field comment documents it as "PATCH /vm {state: Resumed} -- Firecracker un-pauses the vcpus" and the design note calls it the same.
newFCClient (fcapi.go:35) only allocates a struct and an http.Client with a custom DialContext — no connection, no syscall — so this is sub-microsecond against a 361 µs–1.2 ms measurement and changes none of the conclusions. Moving phaseStart := time.Now() below the newFCClient line would just make the stamp match its documented meaning exactly.
There was a problem hiding this comment.
Fixed in 8b1527e — phaseStart := time.Now() now sits below the newFCClient line, so vmresume_us is the PATCH alone as Phases.VMResume documents it.
Agreed on the magnitude: newFCClient only allocates a struct and an http.Client, so it is sub-microsecond against a 361 µs–1.2 ms measurement and no number in the ladder or the design note moves. Strictly, the committed measurements were taken with the old stamp; the difference is below the resolution of anything reported, so I have not re-run the ladder for it. Left a comment at the stamp saying why the clock starts where it does, so it does not drift back.
…g what zeros mean (rossoctl#337 review) Three review points, none of which changes a measurement. ROUTE THE TEST LAUNCHER THROUGH New. TestExecPhasedReportsResumeSubPhases assigned p.(*pool).lc after construction, and New starts `go p.reclaimLoop()` before it returns, so that was an unsynchronized write to a field warm reads from that goroutine. It stayed green under -race only because testPool leaves StandbyPerKey unset and the reclaim path therefore never reaches warm -- a tripwire armed for whoever gives that helper a standby count, which would then surface as a flake in an unrelated test. Every other test in the package injects through New; the new testPoolWith keeps this one on that path, and testPool now delegates to it so there is a single construction path rather than two. STOP OVERSTATING WHAT ZEROS MEAN. diag.go claimed zeros unambiguously read as "not decomposed", but a Resume that fails part-way stashes zeros for the steps it never entered -- so a failed fc.Resume reports a populated vmresume_us beside two zeros, the same shape as a launcher that decomposes only the first step. That is exactly the path pool.go deliberately reads. The zeros are truthful and the stash is intended, so the comment is what was wrong: it now names the exception, says the two cases are told apart by the Exec having errored rather than by the phase line, and notes that no ladder row comes from a failed Exec. phaseStart now starts below newFCClient, so vmresume_us is the PATCH alone as Phases.VMResume documents it. newFCClient only allocates, so this is a sub-microsecond correction against a 361 us measurement and no conclusion moves. Verified: full vmpool package clean under -race, `go test ./...` green (9 packages), and the mutation check re-run -- removing the resumePhaser assertion still fails TestExecPhasedReportsResumeSubPhases after the refactor. Assisted-By: Claude (Anthropic AI) <[email protected]> Signed-off-by: Paolo Dettori <[email protected]>
0e930f1
into
rossoctl:docs/307-deferred-reap-design
This PR was merged to the wrong base — no code reached
|
| state | affected | |
|---|---|---|
rossoctl/main |
ab8f2c8 |
No — no commit from this PR or #336 reached it |
#336 (head 94bd034, base main) |
open, mergeable: true |
No — untouched, all checks green |
| the mirror branch | held the merge at 0e930f1 |
Deleted — its only job was being this PR's base |
| this PR's 3 commits | bda8cf0, 3081d31, 8b1527e |
Safe on pdettori:feat/307-resume-decomposition |
Each commit was confirmed reachable from a surviving ref before the mirror was deleted.
What happens next. A merged PR cannot be reopened or retargeted, so this work returns as a new PR against main once #336 lands. Because the branch is parented on 94bd034 — which is #336's head — and this repo merges with merge commits, that PR will show exactly these 3 commits with no rebase and no conflicts. The new PR will link back here so @mrsabath's approving review and the three resolved threads stay findable.
Root cause, and the lesson. The mirror branch was my suggestion, and it carried exactly this failure mode: a branch on upstream whose name matches a PR head but whose contents are a copy, which then invites a merge into the copy. Basing on main with a "merge #336 first" note would have made the mistake impossible. That is what the replacement PR will do.
|
Replacement opened: #339, base #336 merged as Re-verified against merged The review here — the approval and the three resolved threads — is the record for that code; #339 links back to this PR rather than restating it. |
Summary
Decomposes
Resume, the last opaque phase on theexecGate-held critical path, and recordsthat it will not yield a multiple — so the search for a lever here can stop.
Every other opaque phase this campaign decomposed produced a multiple (#258 → #304, #307,
#315, #317, #319 — the 5.3x, the 3.25x, the 18%, #336's 1.7x). This one does not, because the
dominant term is single-threaded guest-kernel work on a code path we do not own.
Changes
vmresume_us/vsockdial_us/mount_uson the exec phase line and invmpoolctl --json.resume_usis unchanged and still means the whole phase, which the threesum to — feat(vmpool): defer the VM reap off the execGate path — 1.70x gate-held, 1.12x end to end (#307) #336 kept
total_usthe same way, because campaign tables compareresume_usacross runs and a silently redefined field reads as a missing phase rather than as an error.
resumePhaser), not a widenedVMinterface: the CHVlauncher's
Resumeis a different shape (virtio-fs, no workspace mount) and would otherwisehave to answer a question that does not apply to it. Without the seam a launcher reports
zeros, distinguishable from "measured zero" because
resume_usstays populated beside them.resume_usreporting while the sub-phases silently read zero, soTestExecPhasedReportsResumeSubPhasesasserts on values, not field names — confirmed tofail when the assertion is removed.
Results
Descending ladder, deferred reap ON, 250 iters/slot, cheapest rung repeated last.
Anchor drift +0.07% on
resume, +0.05% onmount(#336 measured 12.4% on one sweep,which disqualified a whole column). p50 µs.
vmresumevsockdialmountvmresumeis sub-millisecond — the vcpu un-pause is not the cost.mountis 78–81% atevery rung. Note
Resumeis 35.5 ms of 82.2 ms at 64 slots (43.3%), not the ~23 ms sometables carry for that rung; the ~23 ms is the ≤8-slot value, and the record those tables came
from (
i307-e2e1/s64-rep1-on.json,p50_resume_us=34287) agrees with this run.The journal hypothesis is half right, and its fix is a regression
The workspace ext4 really is never cleanly unmounted:
needs_recoveryis set on a realleftover image and a host loop-mount logs
EXT4-fs: recovery complete. Worth knowing —Filesystem statereadscleanin both cases, because for a journaled ext4 the dirty bitis the
needs_recoveryfeature flag, nots_state.But recovery is only 0.55 ms of a 19.3 ms mount, and removing it costs more than it saves.
Measured with no code change, by passing the unmount as the user command so it lands on the
same gate-held path a real fix would occupy, with a
dumpe2fsprobe per arm proving the armapplied rather than silently failing:
mount_usrun_ustrueneeds_recoverycd /; umount /workspacetrue(anchor)needs_recovery−4.38% throughput, p95 +4.8%. It joins the jail pool (#332, −9.24%) as a component win
that reverses under load. The 64-slot arms of that A/B are excluded as unreadable: the anchor
drifted −5.19% on
mountthere, which is the whole apparent effect.The remaining ~13 ms is not spawn (~1.3 ms/binary), transport (<2.76 ms) or metadata volume —
host mount cost moves only 5568→5006 µs across an 8x size and 128x inode-count change. Against
a geometry-insensitive ~5 ms host floor and
vcpu_count: 1, the mount is CPU-bound in theguest on a fixed ext4 path.
Recommendation (nothing optimised in this PR)
data=writeback/^has_journal/ geometry tuning — allcapped by the 2.86% recovery share or the mount floor.
after the resume, so the "two dials are unamortisable" constraint — which forbids carrying
a connection across a resume — does not force two. Folding the mount into
wrapCommand'sprologue removes one dial and one round trip, ~2.5 ms of a 31.2 ms Exec (~8% at 8 slots). It
moves the mount-failure boundary from
RefuseSpawnto an exit code, and at 64 slots thebound is the replenish rate (
coldAcquireRateTrue0.643), so it must be measured asthroughput first.
the CHV launcher already uses.
Verification
make lintclean;go test ./... -count=1green (9 packages, exit 0); instrument verifiedbefore the ladder — at c=1/24 iters the three sub-phases sum to 22891 µs against
resume_us22916, a +0.11% residual. Rig
srv-r16b14s16,SH_SUBSTRATE=metal, 72 cores, swap off,governor
performance, 0 orphans, dying cgroups flat 48→50 across the ladder.🤖 Generated with Claude Code