Skip to content

feat(vmpool): decompose Resume — 80% is the guest ext4 mount, and it will not yield a multiple (#307) - #337

Merged
pdettori merged 3 commits into
rossoctl:docs/307-deferred-reap-designfrom
pdettori:feat/307-resume-decomposition
Sep 24, 2026
Merged

pdettori merged 3 commits into
rossoctl:docs/307-deferred-reap-designfrom
pdettori:feat/307-resume-decomposition

Conversation

@pdettori

Copy link
Copy Markdown
Member

Summary

Decomposes Resume, the last opaque phase on the execGate-held critical path, and records
that it will not yield a multiple — so the search for a lever here can stop.

Stacked PR: based on docs/307-deferred-reap-design (#336). Merge #336 first; this PR
will be retargeted to main once it does. It depends on #336's --defer-reap-workers and
reaps_inline, so it cannot sit on main today.

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_us on the exec phase line and in
    vmpoolctl --json. resume_us is unchanged and still means the whole phase, which the three
    sum to — feat(vmpool): defer the VM reap off the execGate path — 1.70x gate-held, 1.12x end to end (#307) #336 kept total_us the same way, because 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), not a widened VM interface: the CHV
    launcher's Resume is a different shape (virtio-fs, no workspace mount) and would otherwise
    have to answer a question that does not apply to it. Without the seam a launcher reports
    zeros, distinguishable from "measured zero" because resume_us stays populated beside them.
  • Two tests, because the whole decomposition hangs off one type assertion. Dropping it leaves
    resume_us reporting while the sub-phases silently read zero, so
    TestExecPhasedReportsResumeSubPhases asserts on values, not field names — confirmed to
    fail when the assertion is removed.
  • The design note with the measurements.

Results

Descending ladder, deferred reap ON, 250 iters/slot, cheapest rung repeated last.
Anchor drift +0.07% on resume, +0.05% on mount (#336 measured 12.4% on one sweep,
which disqualified a whole column). p50 µs.

rung thru/s total resume vmresume vsockdial mount run
64 655.8 82180 35545 1192 (3.4%) 5770 (16.2%) 27630 (77.7%) 4542
32 646.6 45404 31135 563 (1.8%) 5423 (17.4%) 24602 (79.0%) 3811
16 433.0 35101 25327 412 (1.6%) 4446 (17.6%) 20271 (80.0%) 2927
8 240.6 31104 23871 361 (1.5%) 4159 (17.4%) 19225 (80.5%) 2762
8′ 237.8 31596 23896 367 4172 19251 2761

vmresume is sub-millisecond — the vcpu un-pause is not the cost. mount is 78–81% at
every rung.
Note Resume is 35.5 ms of 82.2 ms at 64 slots (43.3%), not the ~23 ms some
tables 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_recovery is set on a real
leftover image and a host loop-mount logs EXT4-fs: recovery complete. Worth knowing —
Filesystem state reads clean in both cases, because for a journaled ext4 the dirty bit
is the needs_recovery feature flag, not s_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 dumpe2fs probe per arm proving the arm
applied rather than silently failing:

arm (8 slots, 2000 iters) mount_us run_us thru/s fs left
A true 19261 2756 239.2 needs_recovery
C cd /; umount /workspace 18710 (−2.86%) 5052 (+83%) 228.7 (−4.38%) clean
A′ true (anchor) 19271 2758 240.0 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 mount there, 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 the
guest on a fixed ext4 path
.

Recommendation (nothing optimised in this PR)

  • Don't build the journal fix, or data=writeback / ^has_journal / geometry tuning — all
    capped by the 2.86% recovery share or the mount floor.
  • One cheap win, identified and deliberately 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 (~8% at 8 slots). It
    moves the mount-failure boundary from RefuseSpawn to an exit code, and at 64 slots the
    bound is the replenish rate (coldAcquireRateTrue 0.643), so it must be measured as
    throughput first.
  • A multiple here needs a substrate change, not a tweak: virtio-fs for the workspace, which
    the CHV launcher already uses.

Verification

make lint clean; go test ./... -count=1 green (9 packages, exit 0); instrument verified
before the ladder — at c=1/24 iters the three sub-phases sum to 22891 µs against resume_us
22916, 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

…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 mrsabath left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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) }()

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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:335 deliberately 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's resumePhaser comment argues zeros are unambiguous: a non-implementing launcher "reports zeros, which read as not decomposed rather than as measured zero because resume_us stays 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.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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()

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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]>
@pdettori
pdettori merged commit 0e930f1 into rossoctl:docs/307-deferred-reap-design Sep 24, 2026
1 check passed
@pdettori
pdettori deleted the feat/307-resume-decomposition branch September 24, 2026 01:39
@pdettori

Copy link
Copy Markdown
Member Author

This PR was merged to the wrong base — no code reached main, and nothing is lost

Recording what happened so the "merged" badge above is not misleading.

What happened. This PR targeted docs/307-deferred-reap-design, a branch I pushed to rossoctl purely so a stacked PR had something to target. That branch was never #336's head — #336's head is pdettori:docs/307-deferred-reap-design, in the fork. So merging this PR wrote into a mirror branch that could not propagate anywhere.

Blast radius: none.

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.

@pdettori

Copy link
Copy Markdown
Member Author

Replacement opened: #339, base main, same three commits (bda8cf0, 3081d31, 8b1527e) — mergeable: true, 8 files, nothing rebased.

#336 merged as 1bcc138, and because it merged with a merge commit its head 94bd034 is now an ancestor of main. This branch is parented on that head, so #339 shows exactly the three commits with no rebase and no conflicts, as expected.

Re-verified against merged main before opening, on a throwaway merge of the branch into 1bcc138: go build, go vet, go test ./... -count=1 green (9 packages), vmpool clean under -race, make lint clean. #336 touched pool.go and stats.go, so that check was to rule out a semantic conflict behind a clean textual merge; there was none.

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants