Skip to content

microVM: two empty dirs leak per VM id, and a sudo-glob hazard when probing jail internals #255

Closed

Description

@pdettori

Two follow-ups observed while clearing the bare-metal box after the authoritative E10/E11
runs (PR #251). Neither affected a measurement, and neither is a data or process leak — both
are hygiene/guidance items deliberately left out of that PR because they were outside its
scope.

1. Two empty directories leak per VM id, unbounded across runs

firecrackerVM.Destroy removes the jail contents correctly, but one level too deep:

// launcher_firecracker.go:218
jailRoot := filepath.Join(l.opts.ChrootBase, filepath.Base(l.opts.FirecrackerBin), req.ID, "root")
// launcher_firecracker.go:692 (in Destroy)
if err := os.RemoveAll(v.jailRoot); err != nil { … }

jailRoot is <ChrootBase>/firecracker/<id>/root, so Destroy reclaims everything inside
but leaves the per-VM parent <ChrootBase>/firecracker/<id> behind as an empty directory.

Separately, the per-VM cgroup directory is created by jailer (via --cgroup) and is removed
only by SweepOrphans → removeCgroupDir. Nothing on the normal destroy path rmdirs it,
so a clean shutdown also leaves one empty cgroup dir per VM id.

Measured on metal after two E10 runs (ITERS=200) plus one 14-rung E11 sweep:

leftover count content size
/srv/jail/firecracker/vm-N/ 3007 0 of 3007 held any content ~12 MB of inode
/sys/fs/cgroup/microvm.slice/microvm-vms.slice/vm-N/ 3007 0 procs in all 3007 —

So the reclamation that matters works: no VM data, no processes, nothing to attribute to a
run. What accumulates is ~4 KB of inode per VM id, and VM ids are minted monotonically, so it
grows without bound across runs on a long-lived host.

The METAL-RUNBOOK.md §3a preflight already clears both, so the operational path is covered
and no run is at risk. Suggested fix: have Destroy remove the per-VM parent dir rather than
<id>/root, and rmdir the per-VM cgroup on the normal destroy path (keeping SweepOrphans
as the orphan backstop, not the only reaper). Note the cgroup half must stay rmdir, never
rm -rf — see the D5 note in cgroup.go:359.

2. Probing jail internals: expand globs inside the privileged shell

A verification hazard rather than a defect, worth a caution in §3a because that section is
where preflight checks get extended.

$ sudo ls -1d /srv/jail/firecracker/vm-*     ->  0 directories
$ sudo find /srv/jail -maxdepth 3 -name 'vm-*' | wc -l   ->  3007

The shell expands vm-* before sudo runs. jailer creates
/srv/jail/firecracker as drwx------ root, so an unprivileged shell matches nothing and
hands sudo ls the literal unexpanded pattern — which then reports an absence. Adding sudo
to the front of the command does not fix it, which is why it survives review. I briefly drew
the wrong conclusion ("0 of 3007 jail dirs hold content") from a probe that had enumerated
nothing at all; the corrected probe gave the same answer for a real reason.

The shipped commands are correct and need no change — I checked. §3a's
sudo rm -rf "$SH_WORKSPACE_ROOT"/* /srv/jail/firecracker works because /srv/workspaces is
drwxr-xr-x (verified empirically on the box: the glob expands, the decoy dir is removed),
and the jail path carries no wildcard. The hazard is confined to paths jailer creates at
mode 0700 — i.e. anything under /srv/jail/firecracker/<id>/.

Suggested fix: one caution in §3a — when probing jail internals, glob inside the privileged
shell (sudo bash -c '…') or let a privileged walker expand it (sudo find), and treat an
absence reported by an unprivileged glob as unproven. This is the same family as the existing
[ -S "$sock" ]-reads-absent and kill -0-reads-dead artifacts already documented on the
branch.


Context: both were found on 2026-09-15 while returning srv-r16b14s16 to a clean state after
the metal run. The box is left provisioned (toolchain + verified golden snapshot) so a rerun
is git fetch + reset rather than a rebuild.

Activity

  1. pdettori commented on Sep 17, 2026

    @pdettori
    MemberAuthor

    Epic: rossoctl/rossoctl#2546 (Stream 2 — microVM sandbox tier, via sub-epic rossoctl/serverless-harness#256)

    Status update (2026-09-17)

    Still open, no PR yet. Filed after #251 (P4 microVM sandbox
    tier) merged; no change since.

    Assisted-By: Claude (Anthropic AI) [email protected]

  2. pdettori commented on Sep 21, 2026

    @pdettori
    MemberAuthor

    Escalation: the leaked cgroup dirs are not hygiene — measured 5.3x throughput collapse

    This issue states that neither leak "affected a measurement" and that both are
    "hygiene/guidance items". The cgroup half of it is a progressive throughput defect, and it
    has now invalidated a measurement campaign (see #305).

    Measured causally

    Same host (srv-r16b14s16), same worker, same configuration throughout — one microVM worker,
    16 concurrency slots, 400 iters/slot, D=2, 256 MiB guests:

    run stale vm-* cgroups at start Exec/s restore sockwait mean
    ctl1 ~41,000 25.84 1007.98 ms
    ctl2 — identical config, directories removed 0 136.51 97.96 ms

    find /sys/fs/cgroup/microvm.slice -depth -type d -name 'vm-*' -delete and nothing else
    recovered 5.3x. Peak observed on the box was 47,940 stale directories.

    Mechanism

    Cgroup creation and destruction are serialised in the kernel, and cost grows with how many
    exist. A jailer-created cgroup that takes longer to set up delays the point at which
    Firecracker binds its API socket, so the cost lands in waitForUnixSocket — the restore
    sub-phase that is already 90% of a restore (#304). Restores are how the standby pool
    replenishes, so it becomes an aggregate throughput ceiling.

    The signature is distinctive and worth recording for whoever meets it next: throughput
    collapses while the host goes idle
    (88% idle at the worst point). Nothing is computing;
    everything is waiting on cgroup operations. A CPU-based diagnosis will look clean and find
    nothing.

    Why it is not confined to a test rig

    Destroy is the normal path, not an error path, so one cgroup leaks per Exec for the
    lifetime of the worker process
    . SweepOrphans only runs at startup, so a long-lived
    production worker degrades monotonically and is only repaired by a restart. At ~50,000 Execs the
    effect is already 5x. Nothing bounds it.

    Suggested change

    Have the normal destroy path rmdir the per-VM cgroup, reusing the existing
    removeCgroupDir that SweepOrphans already calls (D5's "rmdir, never rm -rf" applies — these
    are kernel-backed pseudo-files). The empty <ChrootBase>/firecracker/<id> parent dir from part 1
    of this issue is worth fixing in the same pass, though only the cgroup half has a measured
    throughput cost.

    I would also drop the "small / fold into whichever Phase 3 task is nearby" framing from the
    campaign plan: on this evidence it outranks the Destroy decomposition it was going to be
    folded into.

  3. pdettori commented on Sep 21, 2026

    @pdettori
    MemberAuthor

    Fixed in PR #314, verified on metal

    Following the escalation above, the cgroup half of this issue is fixed: Destroy now rmdirs the
    per-VM cgroup, reusing the same removeCgroupDir that SweepOrphans calls.

    Verified end to end on srv-r16b14s16 — one worker, 16 slots, 400 iters/slot (6,497 restores),
    identical configuration on every row:

    run stale dirs at start left behind Exec/s sockwait mean p50
    before ~41,000 +6,497 25.84 1008 ms 1058 ms
    before, clean start 0 +6,497 136.51 98 ms 81 ms
    after 0 0 182.79 34.40 ms 21.08 ms

    0 directories after 6,497 restores. And 1.34x even on a run that starts clean, because the
    leak degraded a run as it proceeded — that middle row had accumulated 6,497 of its own by the end.

    A side effect worth recording here: with the leak gone, sockwait p50 is 21.08 ms, i.e. back
    at the fixed 20 ms poll quantum. Most of what looked like "restores get slower under concurrency"
    was this leak, so #304 is now cleanly the next bottleneck instead of being tangled with it.

    Part 1 (the empty <ChrootBase>/firecracker/<id> parent dir) is deliberately left open — real, but
    ~4 KB of inode with no measured throughput cost. Worth keeping this issue open for it, or splitting
    it out.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions