Skip to content

feat(vmpool): decompose cmd.Wait, inventory the jail, and let vmpoolctl reach concurrency (#307) - #334

Merged
pdettori merged 2 commits into
rossoctl:mainfrom
pdettori:feat/307-destroy-instrumentation
Sep 23, 2026
Merged

pdettori merged 2 commits into
rossoctl:mainfrom
pdettori:feat/307-destroy-instrumentation

Conversation

@pdettori

Copy link
Copy Markdown
Member

Summary

Three instruments for #307, no behaviour change. Each exists because one of that issue's
premises could not be tested without it — and two of the three premises turned out to be
wrong, which is in the issue comment rather than here.

1. cmd.Wait is two waits, not one. os/exec's Wait calls Process.Wait() and only
then awaitGoroutines(), which drains the stdout/stderr copy goroutines that exist because
Restore passes io.Discard — not an *os.File — so writerDescriptor takes its pipe
branch and allocates two os.Pipe()s per VM. "89% of Destroy is cmd.Wait" was equally
consistent with the kernel being slow to reap and with this process being slow to schedule two
goroutines, and those have opposite fixes. drain_us separates them.

Measured: drain is 0.006–0.055 ms, 0.016–0.097% of Destroy. The goroutine hypothesis is
dead and cmd.Wait is the reap. Split only under SH_DIAG_PHASES, so the production path
keeps one Wait and its error semantics.

2. A jail inventory. "removeall unlinks six hardlinks" does not say what is freed. The
five golden-snapshot components and workspace.img have nlink > 1, so dropping the jail's
reference releases nothing — the snapshot directory and the run's WorkspaceDir still hold
those inodes. Only entries the jail owns do.

Measured, identical on every VM: 6 linked entries holding 3,136,449,916 bytes that are NOT
freed, and 3,676,687 bytes that are
— the jailer's exec-file copy, matching #332's 3.6 MiB.
That is the number the thin-provisioning question in #307 needed.

3. vmpoolctl --keys. The Firecracker launcher reports SerializesExecsPerRun, pool.go
gives each runPool an execGate of capacity 1, and ExecPhased holds it from a
successful acquire until the VM is destroyed — Destroy included. runExecMode passed one
key for every iteration, so --concurrency only changed how many goroutines queued at that
one gate.

That is what produced #307's original table: --concurrency=8 and --concurrency=16 both ran
one VM at a time, which is why Destroy read 33,752 µs and 33,694 µs and the issue concluded
teardown does not scale with load. With a key per slot the same driver shows it growing
monotonically, 19.28 ms at c=1 to 52.48 ms at c=64 (c=8 repeated last agrees to 0.6%).

--concurrency above --keys on that arm is refused, not clamped: a clamp would emit the
same unreadable record with a warning nobody reads. keys is recorded in the JSON for the same
reason — on this arm it, not concurrency, bounds how many VMs were ever alive at once.

--keys=1 is the default and is byte-identical to the previous behaviour, so every recorded
invocation in the notes still means what it said.

Note on the warmup default

With --keys>1 the derived default warmup is floored at one per key. The warmup loop
round-robins the keys, so a default of 5 against --keys=64 would leave 59 run pools cold and
charge their first restores to the measured window — the effect --warmup exists to exclude,
reintroduced in proportion to the variable a slot sweep sweeps. An explicit --warmup is left
alone, including an explicit 0.

Testing

  • make lint clean; go test -count=1 ./... green, 9/9 packages, exit 0.
  • Six new tests in cmd/vmpoolctl/keys_test.go pin the key, the refusal (scoped to the arm
    that has the constraint) and both warmup behaviours; drain_us added to the existing
    destroy phase-line assertion, which is there because aggregate tooling parses those names.
  • Cross-built GOOS=windows to exercise jail_inventory_other.go.
  • Verified on srv-r16b14s16 end to end: a short run first to confirm the instrument emits
    before spending a long one, then a descending ladder (c=64/32/16/8/8-repeat) with dying
    cgroups recorded per rung — flat at 54–55, so perf(vmpool): reuse per-VM cgroups from a pool instead of creating one per VM (#258) #319's pool is holding.
  • TestWaitForUnixSocketBackoffGrowsAndIsCapped flaked once in a full run and passed 5/5
    isolated; the diff has zero references to waitForUnixSocket.

Related

Findings are in a comment on #307. In short: the floor is KVM VM destruction blocking on
RCU/SRCU grace periods under kvm_vm_release, so the signal, the mapping and thin
provisioning are all answered as non-levers. Refs #274, #319, #332.

🤖 Generated with Claude Code

…olctl reach concurrency (rossoctl#307)

Three instruments, all needed before rossoctl#307's four questions can be answered with
numbers rather than with the premises in its body.

1. cmd.Wait is TWO waits. os/exec's Wait calls Process.Wait() and only then
   awaitGoroutines(), which drains the stdout/stderr copy goroutines that exist
   because Restore passes io.Discard -- not an *os.File -- so writerDescriptor
   takes its pipe branch. "89% of Destroy is cmd.Wait" was consistent with the
   kernel being slow to reap AND with this process being slow to schedule two
   goroutines, and those have opposite fixes. drain_us separates them. Split only
   under SH_DIAG_PHASES so the production path keeps one Wait and its error
   semantics.

   Measured: drain is 0.006-0.055 ms, 0.016-0.097% of Destroy. The goroutine
   hypothesis is dead, and cmd.Wait is the reap.

2. A jail inventory, because "removeall unlinks six hardlinks" does not say what
   is freed. Five golden-snapshot components and workspace.img have nlink > 1, so
   dropping the jail's reference releases nothing; only entries the jail owns do.
   Measured: 6 linked entries holding 3,136,449,916 bytes that are NOT freed, and
   3,676,687 bytes that are -- the jailer's exec-file copy. Identical every VM.

3. vmpoolctl --keys. The Firecracker launcher reports SerializesExecsPerRun, so a
   run's execGate admits one Exec at a time and --concurrency alone only queues
   goroutines at that gate. With one key, "c=8" and "c=16" both ran ONE VM at a
   time -- which is why rossoctl#307's original table found Destroy identical between them
   and concluded teardown does not scale with load. --keys gives the arm more than
   one gate; the combination is refused rather than clamped, since a clamp would
   emit the same unreadable record with a warning nobody reads.

   With it, the same driver shows Destroy's wait growing monotonically: 19.28 ms
   at c=1 to 52.48 ms at c=64 (c=8 repeated last agrees to 0.6%).

Assisted-By: Claude (Anthropic AI) <[email protected]>
Signed-off-by: Paolo Dettori <[email protected]>
pdettori added a commit to pdettori/moca that referenced this pull request Sep 23, 2026
…nism confirmed (rossoctl#307)

A/B on one binary, arms interleaved off/on/off/on, 1200 Execs each against ONE
workspace_key at c=64. One key is deliberate: the Firecracker launcher
SerializesExecsPerRun, so every goroutine queues at that key's single execGate and
throughput is exactly 1/(gate-held time) -- a direct measurement of the critical
section with nothing else in it.

21.29 -> 36.27 Exec/s, 1.704x. Reproducibility 0.5% off and 0.14% on, far inside
today's 8.2% session spread, so this is not drift.

The mechanism is confirmed term by term, which is what makes it more than a number.
Destroy falls 20.4 -> 1.49 ms, the barrier (independently measured at 1.41 ms
median) replacing the whole reap. Resume 23.00 -> 23.24 and Run 2.64 -> 2.64 do not
move, so nothing was traded. p95 nearly halves. Acquire stays at 0.00 ms, so no
cost reappeared where the cgroup-rmdir deferral's did. reaps_inline is 0, so the
reaper was never saturated and the arm was fully applied. Zero failures in 4800
Execs. Destroy reads 20.4 ms rather than 53 because one key serialises teardowns
too, so each sees c=1 conditions -- right on rossoctl#307's 19.28 ms wait at c=1.

What this does NOT establish is end-to-end throughput at 64 slots: with one key the
absolute figures (21 -> 36) are critical-section numbers, not the 577 Exec/s
production one. The production configuration needs a key per slot (rossoctl#334's --keys),
and there the ~872/s restore+destroy ceiling binds instead, so the prediction stays
800-870 Exec/s, at most 1.51x, with the residue in Acquire. A 1.70x critical-section
win against a 1.51x supply ceiling says supply, not the gate, binds next -- which is
where the ceiling ladder already pointed.

Assisted-By: Claude (Anthropic AI) <[email protected]>
Signed-off-by: Paolo Dettori <[email protected]>
pdettori added a commit to pdettori/moca that referenced this pull request Sep 23, 2026
…nism confirmed (rossoctl#307)

A/B on one binary, arms interleaved off/on/off/on, 1200 Execs each against ONE
workspace_key at c=64. One key is deliberate: the Firecracker launcher
SerializesExecsPerRun, so every goroutine queues at that key's single execGate and
throughput is exactly 1/(gate-held time) -- a direct measurement of the critical
section with nothing else in it.

21.29 -> 36.27 Exec/s, 1.704x. Reproducibility 0.5% off and 0.14% on, far inside
today's 8.2% session spread, so this is not drift.

The mechanism is confirmed term by term, which is what makes it more than a number.
Destroy falls 20.4 -> 1.49 ms, the barrier (independently measured at 1.41 ms
median) replacing the whole reap. Resume 23.00 -> 23.24 and Run 2.64 -> 2.64 do not
move, so nothing was traded. p95 nearly halves. Acquire stays at 0.00 ms, so no
cost reappeared where the cgroup-rmdir deferral's did. reaps_inline is 0, so the
reaper was never saturated and the arm was fully applied. Zero failures in 4800
Execs. Destroy reads 20.4 ms rather than 53 because one key serialises teardowns
too, so each sees c=1 conditions -- right on rossoctl#307's 19.28 ms wait at c=1.

What this does NOT establish is end-to-end throughput at 64 slots: with one key the
absolute figures (21 -> 36) are critical-section numbers, not the 577 Exec/s
production one. The production configuration needs a key per slot (rossoctl#334's --keys),
and there the ~872/s restore+destroy ceiling binds instead, so the prediction stays
800-870 Exec/s, at most 1.51x, with the residue in Acquire. A 1.70x critical-section
win against a 1.51x supply ceiling says supply, not the gate, binds next -- which is
where the ceiling ladder already pointed.

Assisted-By: Claude (Anthropic AI) <[email protected]>
Signed-off-by: Paolo Dettori <[email protected]>
pdettori added a commit to pdettori/moca that referenced this pull request Sep 23, 2026
…ves to replenishment (rossoctl#307)

The rung the single-key A/B could not answer. --concurrency=64 --keys=64 (rossoctl#334),
arms interleaved, 16,000 Execs per rung, 64,000 total, zero failures.

off mean 560.16 Exec/s, on mean 626.79 -- 1.119x, not the 1.4-1.5x the issue
expected. The off arm reproduces the campaign baseline exactly (576.68 against
577.55). Rep-to-rep spread is 6.1% off and 3.2% on, so the gain clears noise but
not by the margin 1.5x would have.

The mechanism worked and the bound moved, exactly as predicted. Destroy falls
56-60 ms to 4.4 ms; Resume and Run barely move; reaps_inline is 0 then 24 of 16,000,
so the arm was fully applied. And Acquire goes 0.00 to ~42 ms while
coldAcquireRateTrue goes 0.161 to 0.741 -- three of four acquires now pay a restore
inline. That is why 1.70x on the critical section becomes 1.12x end to end: the gate
stopped being the constraint and restore supply became it immediately. Cores-busy
rose 39% to 52.5%, the right direction but not saturation, so the pre-registered
"bound moved to CPU" criterion is only half met: it moved to REPLENISHMENT.

Why the 800-870 prediction was wrong: ~872 VM/s was the wrong ceiling to divide by.
The probe reached it with its OWN workers restoring. Production restores through
replenishOne, which is sequential per run by design, so 64 keys hold at most 64
restores in flight at the ~75 ms that rate costs -- and at a 0.74 cold rate most are
not background restores at all any more, they are inline inside the Exec, back on
the critical path the deferral just cleared. The achievable ceiling is ~630 and the
deferral has already reached it.

Verdict: keep it as a 1.12x. Real, above noise, mechanism proven, correctness on a
measured barrier, ~1.5 ms of gate time. But not the lever the issue expected, and
p95 gets WORSE (161 -> 204 ms) as a direct consequence of relocating the bound.

The next lever is now sharply identified and it is not this one: per-run
replenishment is sequential, and with a 1.7x faster consumer that is what binds.

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.

Three well-motivated instruments, and the production path is genuinely preserved. Approving.

Verification

I checked the mechanism claims against upstream source, and the os/exec claim against the actual Go runtime rather than from memory:

Claim Result
One runPool per distinct key, each execGate capacity 1 Confirmed — pool.go:501-505, make(chan struct{}, 1)
The gate is held through Destroy Confirmed — pool.go:292-305, acquired before defer destroy() registers, with a comment saying exactly why
Firecracker is the only arm reporting SerializesExecsPerRun() == true Confirmed — fc true; chv false (virtio-fs); fake false
Cmd.Wait is Process.Wait() then awaitGoroutines() Confirmed in Go 1.24.7 os/exec/exec.go
io.Discard is not an *os.File, so writerDescriptor takes the pipe branch Consistent with the stdlib source
--keys=1 is byte-identical to the previous behaviour Confirmed — execKey returns the bare key

The --keys finding is the substantive one, and it is a good catch: the old table really was running one VM at a time at every "concurrency" setting, so --concurrency=8 and --concurrency=16 reading 33,752 and 33,694 µs was the instrument reporting itself, not teardown failing to scale. Refusing rather than clamping is the right call for the stated reason — a warning nobody reads still leaves a record that parses cleanly and means the wrong thing.

Worth saying plainly: the most valuable part of this PR is that it reports two of #307's own premises as disproven. Instrumentation that comes back and says "the hypothesis was wrong" is harder to write than instrumentation that confirms, and it is what stops a thin-provisioning or goroutine-scheduling proposal from being built on a number nobody separated. Misurare prima di ottimizzare — and here measuring is what closed the question rather than opening it.

Findings

One comment-accuracy fix worth making and three nits, all inline. Nothing blocking, and nothing that changes a reported measurement.

Areas reviewed: Go (os/exec semantics, build-tag split, concurrency and gating), tests, CLI flag validation, cross-file consistency against pool.go and all three launchers
Commits: 1, signed off, conventional-commit prefix
CI status: 13/13 passing (lint, CodeQL, Trivy, shellcheck, hadolint, proto, microvm-gates, dependency-review, deploy-scripts, check)

// opposite fixes. Split only under diagnostics so the production path keeps the
// single Wait and its error semantics.
//
// The second call's Process.Wait() returns ErrProcessDone without a syscall

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 — the stated mechanism here is wrong, though the measurement it justifies is fine.

The comment says:

The second call's Process.Wait() returns ErrProcessDone without a syscall (os.Process remembers it was reaped), so phDrain is awaitGoroutines and not a second reap.

I ran it against Go 1.24.7:

1st Process.Wait(): state=signal: killed  err=<nil>
2nd cmd.Wait():     err=wait: no child processes
  errors.Is(err, os.ErrProcessDone) = false
  cmd.ProcessState = <nil>

The second call returns ECHILD, not ErrProcessDone. In os/pidfd_linux.go, pidfdWait hits statusDone and returns NewSyscallError("wait", syscall.ECHILD) with the explicit rationale "for consistency with what the wait syscall would return". pidWait returns a wait syscall error on the same path. ErrProcessDone is what Signal returns on a finished process, not what Wait returns on a second call.

The conclusion is unaffected. Cmd.Wait does not return early on that error — it assigns c.ProcessState, then calls awaitGoroutines(timer) regardless — so phDrain really is the drain, and "drain is 0.006–0.055 ms, 0.016–0.097% of Destroy" stands. The goroutine hypothesis is dead either way.

It is still worth fixing, because this comment is load-bearing: it is the reason a future reader believes phDrain is not a second reap. A reader who checks it against the stdlib finds it wrong and then has to re-derive whether the number means anything. The accurate version is slightly stronger, since it does not depend on a no-syscall claim:

// The second call's Process.Wait() fails fast with ECHILD (the process was
// already reaped above, so there is no child left to wait for) -- Cmd.Wait
// does not return early on that error, it falls through to awaitGoroutines.
// So phDrain is the goroutine drain, not a second reap.

One thing to state while here: this path leaves cmd.ProcessState nil, because Cmd.Wait assigns it from the failed second Process.Wait(). Harmless today — nothing downstream of Destroy reads it and both results are discarded with _ = — but it is the kind of invariant that holds until someone adds an exit-code check inside the diagnostic branch and cannot reproduce the nil on the production path.

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 4d70ac8 — and you were right on the nil ProcessState too, which I had not noticed.

I re-ran your check against go1.25.0, the toolchain these numbers were actually measured with, rather than taking the 1.24.7 result on trust:

1st Process.Wait(): state=signal: killed err=<nil>
2nd cmd.Wait():     err=wait: no child processes
  errors.Is(err, os.ErrProcessDone) = false
  errors.Is(err, syscall.ECHILD)    = true
  cmd.ProcessState = <nil>

Same on both, so it is not a version-specific detail. I took your wording and added the ProcessState invariant explicitly, since your framing of it is the useful part — it holds until someone adds an exit-code check inside the diagnostic branch and then cannot reproduce the nil on the production path.

Your point about why this is worth fixing is the one I want to acknowledge: the comment is load-bearing precisely because it is the reason a reader believes phDrain is not a second reap. A wrong justification for a right number is worse than no justification, because it costs the next reader the whole re-derivation. The corrected version also does not depend on the no-syscall claim, so it is less to get wrong later.

Comment thread remote-worker/cmd/vmpoolctl/main.go Outdated
res := runResult{
VMM: *vmm, Host: host, Key: *key, Command: command, Mode: *mode,
Iterations: *iterations, Concurrency: *concurrency,
Iterations: *iterations, Concurrency: *concurrency, Keys: *keys,

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 — Keys is recorded unconditionally, but only honoured in mode=exec.

The flag help says "mode=exec only", and both the warmup floor (line 172) and the round-robin are correctly gated on *mode == "exec". This assignment is not. So --keys=8 --mode=replenish emits "keys": 8 for a run that used exactly one key.

Given the field was added precisely so a record cannot be misread — and the doc comment on it cites #307's table as the worked example of that failure — a record that overstates keys in the non-exec modes is the same shape of problem in miniature. Either gate it:

if *mode == "exec" {
    res.Keys = *keys
}

or record 1 outside exec mode. Low stakes, since the sweeps that matter are all mode=exec.

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 4d70ac8, via a keysUsed(mode, keys) helper so the gating lives in one place next to the reason.

You have this exactly right, and the sting is that it is the same failure as the one the field was added to prevent — a record that parses cleanly and means something other than what it says. --keys=8 --mode=replenish claiming "keys": 8 for a run with one run pool is #307's table in miniature, which makes it a poor field to leave half-wired however low the stakes.

I recorded 1 rather than gating the assignment, because absent and wrong are different: a reader who sees "keys": 1 knows the run used one key, whereas a missing field invites the guess that the run predates the flag. Pinned both ways — keysUsed directly, and end to end through a mode=replenish record, since the unit test alone would not catch the wiring being dropped at the call site.

// warning nobody reads.
if *keys < *concurrency && *mode == "exec" && *vmm == "firecracker" {
return fmt.Errorf("--concurrency=%d needs --keys>=%d on the firecracker arm: it "+
"SerializesExecsPerRun, so %d key(s) admit at most %d Exec(s) at a time and the rest "+

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 — the refusal hardcodes the arm name that Launcher already reports.

*vmm == "firecracker" duplicates SerializesExecsPerRun(), which is the interface method that exists to answer exactly this. Today the two agree — I checked all three arms, and Firecracker is the only true — so this is not a live bug.

I can see why it is written this way: lc is not constructed until line ~177, well after this validation block, so asking the launcher would mean reordering construction before validation. That is a real constraint and probably not worth disturbing for this.

Two smaller things that would cost nothing:

  • The string is compared raw where vmpool.Firecracker exists as a VMMKind constant — launcher() itself uses string(vmpool.Firecracker). Using the constant here keeps the two in sync if the wire name ever changes.
  • A one-line note that this mirrors firecrackerLauncher.SerializesExecsPerRun would tell whoever adds a fourth serializing arm that this site needs updating too. As written, a new serializing launcher would silently accept --concurrency > --keys and produce precisely the unreadable record this flag was added to prevent.

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.

Both done in 4d70ac8: it now compares against string(vmpool.Firecracker), and carries a note that it mirrors firecrackerLauncher.SerializesExecsPerRun and must be updated if a second arm ever reports true.

Thank you for working out the constraint rather than just flagging the duplication — lc genuinely is not built until after this validation block, and I agree reordering construction ahead of flag validation to satisfy one check is the more fragile trade. I wrote that reasoning into the comment too, so the next person does not have to rediscover why the obvious fix was declined.

The failure mode you describe is the reason the note earns its place: a new serializing launcher would not error, it would accept --concurrency > --keys and emit precisely the unreadable record this refusal exists to prevent. Silent and plausible, like every other trap in this area.

return nil
}
nlink, blocks := statLinksAndBlocks(info)
s.blocks512 += blocks

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 — blocks512 spans both classes, so it cannot be read the way the rest of the struct can.

s.blocks512 += blocks accumulates for every file regardless of nlink, and it is then logged as a single figure alongside linked_bytes and owned_bytes. The whole point of jailStats is the freed/not-freed split — the doc comment says so directly ("linked counts dentry work and owned counts block work") — and this is the one field that mixes them.

That matters most for the use the comment in jail_inventory_unix.go claims for it: blocks are the allocated size, reported "because on a sparse or thin-provisioned image the two disagree, and that gap is exactly what a storage-layer proposal would be claiming to exploit". But the interesting gap is between ownedBytes and owned blocks — the bytes this unlink actually returns. A total that includes the 3.1 GB of hardlinked snapshot components buries that comparison, since the shared inodes dominate the sum.

Splitting it keeps every field readable on its own:

linkedBlocks512, ownedBlocks512 int64

The measured headline in the PR body (3,136,449,916 not freed vs 3,676,687 freed) comes from the *Bytes fields, so this does not affect the finding.

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 4d70ac8 — split into linkedBlocks512 and ownedBlocks512, and re-measured. You were right that the combined total was burying the comparison, and the split turns out to strengthen the Q4 conclusion rather than just tidy it:

linked_bytes=3136449916 linked_blocks512=1574088  owned_bytes=3676687 owned_blocks512=7192

So the jail's own data is 3,676,687 bytes apparent against 3,682,304 allocated — the jailer's exec-file copy is ~0% sparse. That is the number the sparse-image argument actually needed, and it says there is no thin-provisioning headroom at all on the one file whose blocks this unlink frees. Meanwhile the hardlinked set is heavily sparse (805,933,056 allocated of 3,136,449,916 apparent, mostly the 2 GiB workspace.img) — and none of it is freed here regardless.

The old combined blocks512=1581280 hid the 7192 completely, exactly as you said: the shared components dominate the sum by two orders of magnitude. A field that can only be read by subtracting two other fields is not a reported measurement.

Also added jail_inventory_test.go, which pins the freed/not-freed split directly against a real hardlink rather than inferring it from a Destroy — plus the missing-root case, since Destroy calls this for diagnostics and must not fail a teardown over a stat that did not land.

…unts (rossoctl#334 review)

Four review findings, none of which changes a reported measurement.

The comment on the diagnostic Wait split named the wrong error. It claimed the
second Process.Wait() returns ErrProcessDone "without a syscall"; it actually
fails with ECHILD, because the process was already reaped by the first call.
Verified against go1.25.0 -- the toolchain these numbers were measured with, not
just the 1.24.7 the review checked:

  2nd cmd.Wait(): err=wait: no child processes
    errors.Is(err, os.ErrProcessDone) = false
    errors.Is(err, syscall.ECHILD)    = true
    cmd.ProcessState = <nil>

The conclusion is unaffected -- Cmd.Wait does not return early on that error, it
assigns ProcessState and falls through to awaitGoroutines, so phDrain is still the
drain and "0.016-0.097% of Destroy" stands. Worth fixing anyway: this comment is
the reason a reader believes phDrain is not a second reap, and one who checks it
against the stdlib finds it wrong and has to re-derive the whole thing. The
accurate version is also stronger, since it does not rest on a no-syscall claim.
Records the nil ProcessState this branch leaves behind, which is harmless only
until someone adds an exit-code check inside it.

jailStats mixed its two classes in one field. blocks512 accumulated across linked
and owned alike, which is the one thing the struct exists to keep apart -- and it
defeated the reason allocated size is reported at all, since the gap worth reading
is between owned bytes and owned BLOCKS. Split into linkedBlocks512 and
ownedBlocks512, and the measurement is better for it: owned_bytes=3,676,687
against owned_blocks512=7192, i.e. 3,682,304 bytes allocated. The one file whose
blocks this unlink frees is ~0% sparse, so there is no thin-provisioning headroom
on it. The old combined 1,581,280 buried that 7192 under the hardlinked snapshot
components, which ARE sparse (805,933,056 allocated of 3,136,449,916) and are not
freed here regardless.

runResult recorded the --keys flag rather than the keys used. Only mode=exec
spreads across keys -- the warmup floor and the round-robin are both gated on it --
so --keys=8 --mode=replenish emitted "keys": 8 for a run with one run pool. That is
the same failure in miniature as the table this field was added to make
unreadable-proof, so keysUsed() reports what the mode actually used.

The refusal compared a raw "firecracker" against the VMMKind constant launcher()
already uses, and did not say that it mirrors SerializesExecsPerRun. A second
serializing arm would have silently accepted --concurrency > --keys and produced
exactly the record the refusal exists to prevent. Not asked of the launcher
directly because lc is built after flag validation, and reordering that for one
check is the more fragile trade -- noted in place instead.

Assisted-By: Claude (Anthropic AI) <[email protected]>
Signed-off-by: Paolo Dettori <[email protected]>
pdettori added a commit to pdettori/moca that referenced this pull request Sep 23, 2026
…nism confirmed (rossoctl#307)

A/B on one binary, arms interleaved off/on/off/on, 1200 Execs each against ONE
workspace_key at c=64. One key is deliberate: the Firecracker launcher
SerializesExecsPerRun, so every goroutine queues at that key's single execGate and
throughput is exactly 1/(gate-held time) -- a direct measurement of the critical
section with nothing else in it.

21.29 -> 36.27 Exec/s, 1.704x. Reproducibility 0.5% off and 0.14% on, far inside
today's 8.2% session spread, so this is not drift.

The mechanism is confirmed term by term, which is what makes it more than a number.
Destroy falls 20.4 -> 1.49 ms, the barrier (independently measured at 1.41 ms
median) replacing the whole reap. Resume 23.00 -> 23.24 and Run 2.64 -> 2.64 do not
move, so nothing was traded. p95 nearly halves. Acquire stays at 0.00 ms, so no
cost reappeared where the cgroup-rmdir deferral's did. reaps_inline is 0, so the
reaper was never saturated and the arm was fully applied. Zero failures in 4800
Execs. Destroy reads 20.4 ms rather than 53 because one key serialises teardowns
too, so each sees c=1 conditions -- right on rossoctl#307's 19.28 ms wait at c=1.

What this does NOT establish is end-to-end throughput at 64 slots: with one key the
absolute figures (21 -> 36) are critical-section numbers, not the 577 Exec/s
production one. The production configuration needs a key per slot (rossoctl#334's --keys),
and there the ~872/s restore+destroy ceiling binds instead, so the prediction stays
800-870 Exec/s, at most 1.51x, with the residue in Acquire. A 1.70x critical-section
win against a 1.51x supply ceiling says supply, not the gate, binds next -- which is
where the ceiling ladder already pointed.

Assisted-By: Claude (Anthropic AI) <[email protected]>
Signed-off-by: Paolo Dettori <[email protected]>
pdettori added a commit to pdettori/moca that referenced this pull request Sep 23, 2026
…ves to replenishment (rossoctl#307)

The rung the single-key A/B could not answer. --concurrency=64 --keys=64 (rossoctl#334),
arms interleaved, 16,000 Execs per rung, 64,000 total, zero failures.

off mean 560.16 Exec/s, on mean 626.79 -- 1.119x, not the 1.4-1.5x the issue
expected. The off arm reproduces the campaign baseline exactly (576.68 against
577.55). Rep-to-rep spread is 6.1% off and 3.2% on, so the gain clears noise but
not by the margin 1.5x would have.

The mechanism worked and the bound moved, exactly as predicted. Destroy falls
56-60 ms to 4.4 ms; Resume and Run barely move; reaps_inline is 0 then 24 of 16,000,
so the arm was fully applied. And Acquire goes 0.00 to ~42 ms while
coldAcquireRateTrue goes 0.161 to 0.741 -- three of four acquires now pay a restore
inline. That is why 1.70x on the critical section becomes 1.12x end to end: the gate
stopped being the constraint and restore supply became it immediately. Cores-busy
rose 39% to 52.5%, the right direction but not saturation, so the pre-registered
"bound moved to CPU" criterion is only half met: it moved to REPLENISHMENT.

Why the 800-870 prediction was wrong: ~872 VM/s was the wrong ceiling to divide by.
The probe reached it with its OWN workers restoring. Production restores through
replenishOne, which is sequential per run by design, so 64 keys hold at most 64
restores in flight at the ~75 ms that rate costs -- and at a 0.74 cold rate most are
not background restores at all any more, they are inline inside the Exec, back on
the critical path the deferral just cleared. The achievable ceiling is ~630 and the
deferral has already reached it.

Verdict: keep it as a 1.12x. Real, above noise, mechanism proven, correctness on a
measured barrier, ~1.5 ms of gate time. But not the lever the issue expected, and
p95 gets WORSE (161 -> 204 ms) as a direct consequence of relocating the bound.

The next lever is now sharply identified and it is not this one: per-run
replenishment is sequential, and with a 1.7x faster consumer that is what binds.

Assisted-By: Claude (Anthropic AI) <[email protected]>
Signed-off-by: Paolo Dettori <[email protected]>
@pdettori
pdettori merged commit ab8f2c8 into rossoctl:main Sep 23, 2026
13 checks passed
@pdettori
pdettori deleted the feat/307-destroy-instrumentation branch September 23, 2026 19:24
pdettori added a commit to pdettori/moca that referenced this pull request Sep 23, 2026
…nism confirmed (rossoctl#307)

A/B on one binary, arms interleaved off/on/off/on, 1200 Execs each against ONE
workspace_key at c=64. One key is deliberate: the Firecracker launcher
SerializesExecsPerRun, so every goroutine queues at that key's single execGate and
throughput is exactly 1/(gate-held time) -- a direct measurement of the critical
section with nothing else in it.

21.29 -> 36.27 Exec/s, 1.704x. Reproducibility 0.5% off and 0.14% on, far inside
today's 8.2% session spread, so this is not drift.

The mechanism is confirmed term by term, which is what makes it more than a number.
Destroy falls 20.4 -> 1.49 ms, the barrier (independently measured at 1.41 ms
median) replacing the whole reap. Resume 23.00 -> 23.24 and Run 2.64 -> 2.64 do not
move, so nothing was traded. p95 nearly halves. Acquire stays at 0.00 ms, so no
cost reappeared where the cgroup-rmdir deferral's did. reaps_inline is 0, so the
reaper was never saturated and the arm was fully applied. Zero failures in 4800
Execs. Destroy reads 20.4 ms rather than 53 because one key serialises teardowns
too, so each sees c=1 conditions -- right on rossoctl#307's 19.28 ms wait at c=1.

What this does NOT establish is end-to-end throughput at 64 slots: with one key the
absolute figures (21 -> 36) are critical-section numbers, not the 577 Exec/s
production one. The production configuration needs a key per slot (rossoctl#334's --keys),
and there the ~872/s restore+destroy ceiling binds instead, so the prediction stays
800-870 Exec/s, at most 1.51x, with the residue in Acquire. A 1.70x critical-section
win against a 1.51x supply ceiling says supply, not the gate, binds next -- which is
where the ceiling ladder already pointed.

Assisted-By: Claude (Anthropic AI) <[email protected]>
Signed-off-by: Paolo Dettori <[email protected]>
pdettori added a commit to pdettori/moca that referenced this pull request Sep 23, 2026
…ves to replenishment (rossoctl#307)

The rung the single-key A/B could not answer. --concurrency=64 --keys=64 (rossoctl#334),
arms interleaved, 16,000 Execs per rung, 64,000 total, zero failures.

off mean 560.16 Exec/s, on mean 626.79 -- 1.119x, not the 1.4-1.5x the issue
expected. The off arm reproduces the campaign baseline exactly (576.68 against
577.55). Rep-to-rep spread is 6.1% off and 3.2% on, so the gain clears noise but
not by the margin 1.5x would have.

The mechanism worked and the bound moved, exactly as predicted. Destroy falls
56-60 ms to 4.4 ms; Resume and Run barely move; reaps_inline is 0 then 24 of 16,000,
so the arm was fully applied. And Acquire goes 0.00 to ~42 ms while
coldAcquireRateTrue goes 0.161 to 0.741 -- three of four acquires now pay a restore
inline. That is why 1.70x on the critical section becomes 1.12x end to end: the gate
stopped being the constraint and restore supply became it immediately. Cores-busy
rose 39% to 52.5%, the right direction but not saturation, so the pre-registered
"bound moved to CPU" criterion is only half met: it moved to REPLENISHMENT.

Why the 800-870 prediction was wrong: ~872 VM/s was the wrong ceiling to divide by.
The probe reached it with its OWN workers restoring. Production restores through
replenishOne, which is sequential per run by design, so 64 keys hold at most 64
restores in flight at the ~75 ms that rate costs -- and at a 0.74 cold rate most are
not background restores at all any more, they are inline inside the Exec, back on
the critical path the deferral just cleared. The achievable ceiling is ~630 and the
deferral has already reached it.

Verdict: keep it as a 1.12x. Real, above noise, mechanism proven, correctness on a
measured barrier, ~1.5 ms of gate time. But not the lever the issue expected, and
p95 gets WORSE (161 -> 204 ms) as a direct consequence of relocating the bound.

The next lever is now sharply identified and it is not this one: per-run
replenishment is sequential, and with a 1.7x faster consumer that is what binds.

Assisted-By: Claude (Anthropic AI) <[email protected]>
Signed-off-by: Paolo Dettori <[email protected]>
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