Repository navigation
feat(vmpool): split the pre-socket window at the jailed execve (#328) - #332
Conversation
Correction: the jail pool is a ~9% throughput REGRESSION at the operating point. Converting to draft.The component result in the PR body is reproducible and I still believe it. It was the wrong thing to conclude from, and a throughput A/B says the opposite. Posting the correction prominently because the PR body currently reads as a win. Throughput A/BIdentical driver source built against each
The 64-slot reps do not overlap. At 8 slots the arms are indistinguishable. Mechanism: elided writes become real onesInstrumented at 64 slots,
~2.1× the disk writes, ~12% more CPU. It is correction 4 turned around. The jailer rewrites the 3.6 MiB exec copy every run either way, but:
Not creating a file you are about to delete is cheaper than reusing one. The pool's entire saving was keeping that file, so the saving and the cost are the same decision — and at a sustained ~550 restores/s the cost is bigger. Why the component measurement could not see itAvoided block allocation lands on the restore's own clock, which is why it measured cleanly and consistently at ~1.6 ms three independent ways. Writeback does not: asynchronous, done by kernel threads, charged to nobody's restore, visible only as a rate under sustained load. The instrument was right; the inference from it was wrong, and no additional care with the same instrument would have caught it. Second time in this issue a latency measurement pointed the wrong way — the first was #328's own No cheap fix
What I suggestLand the phase split (81639ea) and the design note; drop the pool. The split is independently correct, it is what localised the cost to the jailer, and it is what caught this — #328's option 2 gets stronger, not weaker. Bypassing the jailer removes the 3.6 MiB copy outright rather than relocating it, so it avoids both the allocation and the writeback. Pooling could only ever move that cost around, which is what it did. Happy to reshape this into a phase-split-only PR, or leave it as a draft for the record — say which you prefer. 🤖 Generated with Claude Code |
…ctl#328) The instrument, before the fix it exists to measure. The `jailer` phase timed time.Since AFTER cmd.Start() returned -- fork/exec RETURNING, 0.34-1.62 ms across a whole ladder -- so the jailer's 6-8 ms of chroot construction was accounted to sockwait instead. That mis-attribution is why the pre-socket wait read as "Firecracker is slow to bind" for two rounds of analysis, and it would equally obscure whether jail pooling worked. sockwait now splits into jailersetup_us and fcbind_us, and the old jailer_us is renamed spawn_us to say what it actually measures. sockwait_us is kept unchanged so rossoctl#328's tables and the campaign notes stay comparable against new runs. The boundary is /proc/<pid>/comm flipping to the jailed binary's name. The jailer execve's rather than forking, so cmd.Process.Pid names the Firecracker process too -- which makes the flip the execve ITSELF rather than a proxy for it. Both filesystem proxies rossoctl#328 suggested were measured and rejected: firecracker.pid appears 0.20 ms early because the jailer writes it just before the execve, and the jail directory appears at 1.55 ms of a 5.23 ms window. On srv-r16b14s16, n=8 cold, this puts jailer_setup at 93% of the pre-socket window and fc_bind at 0.37 ms -- corroborating rossoctl#328's 82-85% strace split by a different method. Two properties the tests pin, because a diagnostic that distorts what it measures is worse than none: - The observation is gated on phaseLog, so no restore pays a procfs read when diagnostics are off, and it self-disables after the flip rather than reading comm for all ~27 poll iterations of a sockwait. - It reuses waitForUnixSocket's loop instead of adding a second one. rossoctl#304's schedule is the resolution at which anything inside that wait can be measured, so two schedules would make the two halves accurate to different quanta and their sum no longer sockwait. Nothing here can fail a restore: an unobservable boundary reports -1 -- never a plausible 0 -- and the restore proceeds on sockwait alone. Refs rossoctl#328 Assisted-By: Claude (Anthropic AI) <[email protected]> Signed-off-by: Paolo Dettori <[email protected]>
…ossoctl#328) The investigation behind the phase split, kept so nobody re-runs it. The pool was designed, implemented and measured. It cuts restore latency by a reproducible ~1.6 ms -- three independent ways -- and loses ~9.24% throughput at the 64-slot operating point, because keeping the 3.6 MiB exec copy turns writes that base elides into real writeback: ~2.1x the disk writes and ~12% more host CPU. The saving and the cost are the same decision, since keeping that file was the entire saving. Also records four corrections to the premise in rossoctl#328's third comment, each measured with the previous VMM reaped and the socket deleted first: --id reuse fails outright unless root/dev/ is wiped (mknod EEXIST); the 2x figure was very likely timing that comment's own leftover socket; pre-creating the jail directory buys nothing, so the real baseline was not cold; and the jailer re-copies the binary every run regardless. The residue analysis is kept even though the code is not, because anyone retrying has to answer the same questions and two of the answers outlive the change: the jailer opens the exec path O_NOFOLLOW, so the symlink form of a root-write primitive is already refused, but a HARDLINK is not -- and the jail holds our own prep's hardlinks to the golden snapshot, so st_nlink == 1 is what stops a compromised VMM relinking that path onto memfile and having the next jailer run write Firecracker into the snapshot every VM restores from. The implementation is preserved on archive/328-jail-pool-regression rather than deleted, and this note says so, since the note's own instruction is not to re-investigate and the code is that evidence. rossoctl#328's option 2 gets stronger: bypassing the jailer removes the copy outright rather than relocating it, so it avoids both the allocation and the writeback. Refs rossoctl#328 Assisted-By: Claude (Anthropic AI) <[email protected]> Signed-off-by: Paolo Dettori <[email protected]>
63d295a to
44e4b50
Compare
|
Reshaped to the phase split only, and marked ready for review. Force-pushed, so the commits referenced above are no longer on this branch. The jail-pool implementation — Reviewable surface is now 2 commits / 4 files: |
esnible
left a comment
There was a problem hiding this comment.
Approving. Two nits below, neither blocking — both are cosmetic/defensive and neither changes a logged value.
I verified the central correctness claim against main: l.opts.FirecrackerBin is the --exec-file passed to the jailer (launcher_firecracker.go:403) and cmd = exec.Command(l.opts.JailerBin, ...) (:415) with a same-pid execve, so filepath.Base(FirecrackerBin) is exactly the comm value after the flip. The boundary detector reads the right name off the right pid.
Things this gets right that are easy to get wrong:
TASK_COMM_LENtruncation to 15 chars is handled and tested. Comparing against the untruncated basename would have silently never matched and reported-1forever — which would have read as "this platform has no procfs."- Unobserved reports
-1, not0, andlogRestorePhasesoverrides both fields before formatting, so the meaninglessphSock - 0the caller computes can never reach the log line. - Gated on
phaseLog != nilandcmd.Process != nil, so the production path constructs no boundary,observestays nil, andwaitForUnixSocketObservedis bit-for-bit the old loop. - One poll loop, not two. The reasoning in the comment is correct and non-obvious: two schedules would make the halves accurate to different quanta and their sum would no longer equal
sockwait. sockwait_uskept unchanged alongside the split, so #328's existing tables stay comparable.
Two notes, not blocking:
fc_bind right-censoring is disclosed, which I'd otherwise flag. Both signals share one 1 ms-capped poll, so when the flip and the bind land in the same iteration fc_bind reads ~0. The body and the code comments both say so and frame it as an upper bound on Firecracker's share — that's the honest framing. It does mean the headline "median fcbind_us is 46 µs" is a censored median, not Firecracker's actual bind time. Worth remembering before that number gets quoted as a measurement of Firecracker.
The design note is doing real work. §6 ("Dead ends, kept so they are not re-run") and §8's mechanism — base creates a fresh exec copy and Destroy unlinks it ~30 ms later, so dirty pages are dropped before writeback reaches them, while the pool keeps the file so the overwrite cannot be elided — are the kind of finding that otherwise gets rediscovered at full cost. The lesson that a component measurement is not a throughput claim, and that here the two have opposite signs, is the most transferable thing in the PR.
The st_nlink == 1 finding is the most durable item and outlives the rejected code: O_NOFOLLOW refuses the symlink form of a root-write primitive but not the hardlink form, and the jail legitimately holds our own prep's hardlinks to the golden snapshot. That check is documented but not shipped — it deserves its own tracking issue independent of this PR, since the residue analysis is the only place it currently lives.
Assisted-By: Claude Code
| // one costs a procfs read per poll iteration, so the production path must not pay it. | ||
| var boundary *fcExecBoundary | ||
| if phaseLog != nil && cmd.Process != nil { | ||
| boundary = newFCExecBoundary(cmd.Process.Pid, l.opts.FirecrackerBin, time.Now()) |
There was a problem hiding this comment.
nit: the boundary's start is a fresh time.Now() taken here, but phSpawn (line 431) was computed by subtraction from phaseStart. So jailerSetup/fcBind partition the interval beginning at this instant, while phSock partitions the interval beginning where phSpawn ended.
The gap is two branches and a struct alloc — nanoseconds, far below the 1 ms poll quantum — so it doesn't affect any conclusion in the PR. But the comment at the log site (line 464) claims the two halves "partition phSock exactly rather than approximately," and strictly they don't. Either derive the boundary start from the same instant phSpawn ends, or soften "exactly" to reflect the sub-quantum skew.
There was a problem hiding this comment.
Fixed in the code rather than in the comment. phSpawn and the boundary now share one clock reading:
spawnEnd := time.Now()
phSpawn = spawnEnd.Sub(phaseStart) - phPrep - phWsImg
...
boundary = newFCExecBoundary(cmd.Process.Pid, l.opts.FirecrackerBin, spawnEnd)Your diagnosis of where the skew went is exactly right, and it is worth stating because it is not symmetric: fcBind is computed as the remainder of phSock, so the gap was charged entirely to fcBind and none of it to jailerSetup. Sub-quantum, so no number in the PR moves — but it biased the one half that is already right-censored, which is the worse of the two places to put it.
The comment now says the halves partition phSock, without "exactly rather than approximately", since that phrasing was defending a property the code did not have.
| setup, seen := boundary.elapsed() | ||
| logRestorePhases(req.ID, restorePhases{ | ||
| prep: phPrep, wsimg: phWsImg, spawn: phSpawn, | ||
| jailerSetup: setup, fcBind: phSock - setup, boundaryObserved: seen, |
There was a problem hiding this comment.
nit: fcBind: phSock - setup is evaluated unconditionally, including when seen is false and setup is 0 — yielding a full-window value for fcBind that is then discarded.
This is correct as written: logRestorePhases overrides both jailersetup_us and fcbind_us with -1 when boundaryObserved is false, so the bogus value can't reach the log line, and TestRestorePhaseLineReportsAnUnobservedBoundaryAsMinusOne pins that. But the struct is momentarily self-inconsistent, and the guard lives one function away. Passing fcBind only when seen would make it correct at the point of construction rather than by downstream override.
There was a problem hiding this comment.
Fixed. The two halves are now set only when the boundary was observed, so the struct is consistent where it is built:
ph := restorePhases{prep: phPrep, wsimg: phWsImg, spawn: phSpawn,
sock: phSock, load: phLoad, total: time.Since(phaseStart)}
if setup, seen := boundary.elapsed(); seen {
ph.jailerSetup, ph.fcBind, ph.boundaryObserved = setup, phSock-setup, true
}
logRestorePhases(req.ID, ph)I kept the -1 override in logRestorePhases rather than replacing it. It is no longer load-bearing for this caller, but it is the invariant enforced at the formatting boundary for any future one, and it is what TestRestorePhaseLineReportsAnUnobservedBoundaryAsMinusOne pins — so removing it would delete the test's subject. The comment now says which of the two is the guarantee and which is defence in depth.
Worth noting the specific badness of the old value, since "bogus" undersells it: phSock - 0 is the entire pre-socket window attributed to Firecracker — i.e. precisely the wrong conclusion this PR exists to make impossible. It could not reach the log, but it was the wrong number sitting in the field.
…verride (rossoctl#332 review) Two review nits, both about the code being right only because something downstream rescued it. The boundary's window now opens at the SAME instant phSpawn ends. It took a second time.Now(), so the gap between the two -- two branches and a struct alloc -- was charged to fcBind, because fcBind is computed as the remainder of phSock. Nanoseconds against a 1 ms poll quantum, so no conclusion in the PR moves, but it made the comment's claim that the two halves partition phSock exactly untrue. One clock reading now ends phSpawn and opens the boundary, so the claim holds. jailerSetup and fcBind are set only when the boundary was actually observed. With an unobserved boundary the caller computed fcBind as phSock - 0 -- the whole window, attributed to Firecracker -- and only logRestorePhases' -1 override kept it out of the log. The struct is now consistent where it is constructed; the override stays as defence in depth for any future caller, and is still what TestRestorePhaseLineReportsAnUnobservedBoundaryAsMinusOne pins. Also labels fcbind_us's 46 us median as CENSORED at the point the note quotes it, not only in the limitations below it. Both signals are seen by one 1 ms-capped poll, so when they land in the same iteration it reads ~0 -- it is "at or below the poll resolution", not a measurement of Firecracker's bind time, and the note now points at the untraced 0.37 ms from section 2 for that instead. Refs rossoctl#328 Assisted-By: Claude (Anthropic AI) <[email protected]> Signed-off-by: Paolo Dettori <[email protected]>
|
Both nits fixed in
|
…es throughput (#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 (#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]>
…empty result Salvaged from the #331 handoff note, whose thesis #332 refuted. These four are recorded in neither #332's design note nor anywhere else on main, and they share a shape worth naming: the instrument reports something plausible, so a clean number is indistinguishable from a broken probe. - `RESULTS=` is the only name for a per-rung results dir. There is no SH_E11_RESULTS_DIR; an unrecognised name is silently ignored, every rung falls back to the default .results/, and the worker log is TRUNCATED per invocation. An eight-rung ladder can exit 0 everywhere and yield phase data for one rung. This cost a full ladder. - `sched_schedstats` is off on this host, so /proc/<pid>/sched carries no se.statistics.* fields. A probe reading wait_sum to detect CPU starvation measures nothing and reports nothing, which reads as "never starved". - Never time `sudo <thing>`: it is setuid doing PAM work and accounted for ~13 ms of a 16 ms reading. Also calibrate the harness, because each $(date +%s%N) is a fork+exec and puts the floor of a shell-timed measurement at ~2.4 ms — the same order as phases worth measuring. - A leftover socket reads as this run's socket coming up, because waitForUnixSocket dials. fcJailOccupied exists to refuse exactly this and its comment says so. The signature is repeated attempts agreeing far too closely: two runs within 17 us is a constant, not reproducibility. One measurement reported a 2x jail-reuse win on that basis; the real figure was -31%, and the change it motivated cost 9% throughput. Cross-references section 3a for the existing kill-by-cgroup-or-port guidance and adds that pgrep -f self-matches through its own ssh and sudo argv. Refs #328 #332 Assisted-By: Claude (Anthropic AI) <[email protected]> Signed-off-by: Paolo Dettori <[email protected]>
Splits the restore phase accounting so the pre-socket window says where its time goes, and records why pooling the jail — the fix #328 recommended — was investigated, measured and rejected.
The instrument
sockwaitwas one bucket holding two very different things. Thejailerphase timedtime.Sinceaftercmd.Start()returned — fork/exec returning, 0.34-1.62 ms across a whole ladder — so the jailer's 6-8 ms of chroot construction landed insockwaitinstead. That mis-attribution is why the wait read as "Firecracker is slow to bind" for two rounds of analysis.sockwait_usnow splits intojailersetup_us+fcbind_usjailer_usbecomesspawn_us, which is what it always measuredsockwait_usis kept unchanged, so vmpool: the pre-socket wait is 82-85% JAILER chroot construction, not Firecracker (which binds in ~1.5ms) #328's tables and the campaign notes stay comparableThe boundary is
/proc/<pid>/commflipping to the jailed binary's name. The jailerexecves rather than forking, socmd.Process.Pidnames the Firecracker process too — which makes the flip theexecveitself, not a proxy for it. Both filesystem proxies #328 suggested were measured and rejected:firecracker.pidappears 0.20 ms early (the jailer writes it just before theexecve), and the jail directory appears at 1.55 ms of a 5.23 ms window.Result: in-harness,
jailer_setupis 93.7% ofsockwaitandfcbind_us's median is 46 µs. That corroborates #328's 82-85% strace split by an independent method, and in the stronger direction — Firecracker is not the cost.It cannot distort or break what it measures
Three properties the tests pin, because a bad diagnostic is worse than none:
phaseLog, so no restore pays a procfs read when diagnostics are off — unlike the existing phase clocks, which are ~100 ns and unconditional.commfor all ~27 poll iterations of a sockwait.waitForUnixSocket's loop instead of adding a second one. vmpool: waitForUnixSocket's fixed 20ms retry is 90% of every restore (TDD) #304's schedule is the resolution at which anything inside that wait can be measured, so two schedules would make the halves accurate to different quanta and their sum no longersockwait.Nothing here can fail a restore: an unobservable boundary reports
-1— never a plausible0, which would aggregate as "the jailer took no time", the same wrong conclusion the old mis-attribution produced.fc_bindis right-censored and the note says so: both signals share one 1 ms-capped poll, so when they become visible in the same iteration it reads ~0. It is an upper bound on Firecracker's share and a lower bound onjailer_setup's.The design note, and why the pool was rejected
docs/notes/2026-09-22-328-jail-pool-design.mdis the record. Headlines:Four corrections to #328's premise, each measured with the previous VMM reaped and the socket deleted first:
--idreuse fails outright unlessroot/dev/is wiped (mknod /dev/net/tun: File exists).fcJailOccupiedexists to refuse.Restorealready did it, so the real baseline was not cold.Why it was rejected: latency −1.6 ms (reproducible three independent ways), throughput −9.24% at 64 slots (559.5/556.5/552.3 → 522.0/497.1/505.1 Exec/s, non-overlapping reps). Instrumented, the pool writes ~2.1× more to disk and burns ~12% more CPU: base creates a fresh exec copy and
Destroyunlinks it ~30 ms later, so most dirty pages are dropped before writeback reaches them, while the pool keeps the file and the overwrite cannot be elided. Keeping that file was the entire saving, so the saving and the cost are the same decision.The lesson worth keeping: avoided block allocation lands on the restore's own clock; writeback does not — it is asynchronous and only visible as a rate under load. A component measurement is not a throughput claim, and here the two have opposite signs.
Two security findings outlive the change, which is why the residue analysis is kept even though the code is not: the jailer opens the exec path
O_NOFOLLOW, so the symlink form of a root-write primitive is already refused (verified against an intact canary) — but a hardlink is not, and the jail holds our own prep's hardlinks to the golden snapshot, sost_nlink == 1is what would stop a compromised VMM relinking that path ontomemfileand having the next jailer run write Firecracker into the snapshot every VM restores from.#328's option 2 gets stronger. Bypassing the jailer removes the copy outright rather than relocating it, so it avoids both the allocation and the writeback.
Verification
go test -race ./...green,gofmtclean,go vetclean,make lintandmake typecheckgreen.TestWaitForUnixSocketBackoffGrowsAndIsCappedis load-sensitive (it counts probes in a 200 ms window); confirmed not a regression with 0 failures in 10 interleaved isolated runs and 3 full-suite runs on both this branch andmain.Rig left clean: 0 VMMs, 0 jail directories, 0 stray cgroups under the slice, governor
performanceand swap off as found.🤖 Generated with Claude Code