30. File-backed root overlays
30. Where a container's writes land: file-backed root overlays¶
Learning goal: which medium gVisor's root filesystem overlay uses today under the runner's containerd, on smaug and in the Mac runner's VM; whether a file-backed overlay keeps a container's writes on the host's disk and out of the job's memory; whether that file goes away with the run and leaves nothing the unprivileged warden must delete; and whether runsc can cap the file's size per container (design, 'Volumes and pads').
Method: spike/compose_pod/main.go overlay, through containerd's CRI
with handler runsc. One pod, one debian:trixie-slim container running as
uid 999 (as Postgres's image does), in which dd writes 2 GiB from
/dev/urandom (so neither compression nor sparse files hide the data)
through ExecSync, then sync. The probe reads the sandbox's cgroup
(memory.current, memory.peak, memory.stat, memory.events, found
through the sandbox process's /proc/PID/cgroup) and the free space of the
filesystem holding containerd's root, before and after the write and after
the pod is removed; as root in the VM it also lists files of 64 MiB or more
under containerd's root.
Hosts: smaug (Debian 13.8, containerd 1.7.24, gVisor release-20261116.0,
containerd's root on the ext4 root disk, 152 GB free; as the developer in
the socket's group, so without root) and the Mac runner's Lima VM (Debian 13
arm64, the same containerd and gVisor, containerd's root on the VM's ext4
root disk; as root). That VM is the runner's older VM made by install.sh
--vm, not the deploy/vmimage image with its XFS data disk; no image VM
was available.
Configured values were tried through a scratch containerd started in the
Mac VM for this experiment, with its own root, state directory and socket
and a loopback-only CNI network (pods used the host's network namespace),
and stopped and deleted afterwards. Its config is deploy/linux's plus
ConfigPath naming a runsc TOML. Neither the runner's containerd in the VM
nor smaug's was reconfigured: smaug needs a password for sudo, and the
Mac runner's VM is the runner's to configure.
No predictions were written down before the run.
A. Today: runsc's defaults¶
runsc flags on smaug: -overlay2 ... (default root:self), and
{mount}:{medium}[,size={size}] where size "overrides default overlay
upper layer size". runsc's state for the container confirms it in the VM:
the gofer runs with --gofer-mount-confs=lisafs:self,... for the root.
Results (2026-11-30):
| Write 2 GiB to | Host | Free space | Sandbox cgroup after the write | After the pod is removed |
|---|---|---|---|---|
/tmp/big |
smaug | unchanged | memory.current 2,074 MiB: shmem 2,048 MiB, anon 13 MiB |
free space unchanged, cgroup gone |
/tmp/big |
Mac VM | unchanged | 2,085 MiB: shmem 2,048, anon 21 |
the same |
/var/tmp/big |
smaug | −2,048 MiB | 2,101 MiB: file 2,023 (668 dirty), shmem 0, anon 14 (11 before) |
free space back to +0 MiB, cgroup gone |
/var/tmp/big |
Mac VM | −2,048 MiB | 2,139 MiB: file 2,048 (716 dirty), shmem 0, anon 23 (20 before) |
+0 MiB; the file below is gone |
In the VM, with the pod up, the 2 GiB was one file in the container's
snapshot, the upper directory of its root filesystem's overlayfs mount:
/var/lib/containerd/io.containerd.snapshotter.v1.overlayfs/snapshots/70/fs/.gvisor.filestore.<sandbox id>,
2,048 MiB on disk, owned by root, mode 0644. Inside the container, df /
reports a size of 8,796,093,022,208 MiB (8 EiB): no limit.
/tmp differs because gVisor mounts its own memory-backed tmpfs at /tmp
whenever the image's /tmp is empty and nothing is mounted there
(mountTmp in runsc/boot/vfs.go; Debian's /tmp is empty).
With the sandbox cgroup's memory.max set to 512 MiB (Mac VM, as root):
| Write 2 GiB to | Result |
|---|---|
/var/tmp/big |
completes in 6.5 s (4.8 s without the limit); memory.current 510 MiB, file 464 MiB, anon 23 MiB; memory.events: max 6108, oom 0, oom_kill 0; free space −2,048 MiB |
/tmp/big |
the sandbox is OOM-killed after about 390 MiB (oom_kill 1); ExecSync fails with urpc method "containerManager.WaitPID" failed: EOF |
B. Configured through containerd's ConfigPath¶
[plugins."io.containerd.grpc.v1.cri".containerd.runtimes.runsc.options]
with TypeUrl = "io.containerd.runsc.v1.options" and ConfigPath naming a
TOML whose [runsc_config] table holds overlay2 (gVisor's
g3doc/user_guide/containerd/configuration.md). The shim reads the file
each time it starts a pod; changing it needed no containerd restart. Each
row writes 2 GiB to /var/tmp as uid 999.
overlay2 |
Result |
|---|---|
root:self,size=1g |
df / in the container: 1,024 MiB; dd stops at 1,073,741,824 bytes; free space −1,071 MiB; the filestore file is 1,024 MiB; gone after removal |
root:dir=/var/tmp/exp30/overlay |
free space −2,048 MiB (statfs of that directory's filesystem); no file to be seen: runsc creates it there and unlinks it at once (createGoferFilestoreInDir), so only the sandbox's open descriptor keeps it; memory as in A; after removal, free space +0 MiB |
Per pod, through the annotation dev.gvisor.flag.overlay2, which runsc lets
a pod set without --allow-flag-override for the memory, self and
none media only (overrideAllowlist in runsc/config/flags.go):
| Annotation on the pod sandbox config | Result |
|---|---|
root:self,size=512m, runtime without pod_annotations |
ignored: containerd doesn't pass it on; 1 GiB written |
root:self,size=512m, runtime with pod_annotations = ["dev.gvisor.flag.overlay2"] |
dd: error writing '/var/tmp/big': No space left on device at 536,870,912 bytes; df / 512 MiB |
root:dir=/var/tmp/exp30/overlay, same runtime |
the pod doesn't start: Failed to apply OCI spec annotations to runsc config: error setting flag overlay2="root:dir=/var/tmp/exp30/overlay": ... overlay medium requires flag "allow-flag-override" to be enabled |
What we learned¶
- Root overlays are already file-backed on both hosts, by runsc's
default
root:self: a container's writes to its own filesystem land in.gvisor.filestore.<sandbox id>in the upper directory of its containerd snapshot, on the disk holding containerd's root, and runsc deletes the file when the container goes (containerd then removes the snapshot). /tmpis memory. gVisor puts a tmpfs at an empty/tmp, so 2 GiB written there is 2 GiB of the job's memory, and past the job's limit the sandbox is OOM-killed. The warden sets the job'sHOMEto/tmp, so caches written underHOMEland there too.- The file's page cache shows in
memory.currentandmemory.peak(2 GiB after a 2 GiB write) but isn't held against the limit: under a 512 MiBmemory.maxthe kernel reclaims it and the write completes with no OOM, whileanonandshmemstay within 3 MiB of where they began. So the job's limit is safe, but the memory the runner reports for a run includes page cache. - Teardown leaves nothing for the warden. In
selfmode the file is root's and runsc and containerd delete it; indirmode it is unlinked from the start. A container's own files, owned by uid 999, never exist on the host as files of their own: they are inside the filestore. (A path the image declares as aVOLUMEis different: experiment 29 found it is a host directory containerd makes and removes, with files owned by the container's uid.) - There is a per-container size cap:
size=inoverlay2, ending writes withENOSPC. Set in runsc's config it applies to every container's root of every pod; set by the pod's annotation (with the runtime'spod_annotationsletting it through) it applies to one pod, for theselfmedium only. Without it, a container's writes are bounded only by the free space of containerd's disk.
What it changes¶
- Linux runners pin
overlay2 = "root:self"in a runsc config (deploy/linux/allmyram-runsc.toml, installed as/etc/containerd/allmyram-runsc.toml), named byConfigPathin containerd's config. The name is allmyram's own:/etc/containerd/runsc.toml, the path gVisor's guide uses, may hold the owner's config. It is runsc's default, written down so that a gVisor upgrade can't change it unnoticed. The Mac VM image is unchanged for now, since changing it means building and pinning a new image; the next image build should pinoverlay2the same way, through/etc/containerd/allmyram-runsc.toml.selfrather thandir=: it is what the design describes, it needs no directory set up, and it can still be capped per pod by annotation, whichdir=can't. - For Gavin:
selfputs job data on the disk holding containerd's root (smaug's root filesystem; the VM's root disk, not its XFS data disk), while kata xtb5's free-space floor watches allmyram's data directory. So the floor does not bound overlay writes, and a job can fill the host's root filesystem. The choices in view: a cap withsize=(global inallmyram-runsc.toml, or per job through the annotation), orroot:dir=on the data directory, where the floor sees it. - For Gavin: a job's
/tmpand its defaultHOMEare memory. Mounting something at/tmpturns gVisor's tmpfs off (mountTmp); whether the warden should is open. - Not run: the configured values through the runner's own containerd on
smaug or in the VM (only through the scratch containerd), and anything
in the
deploy/vmimageVM (Garden Linux, containerd 2.3.7). For that image's containerd 2.x config, containerd 2.3.7's source decodes a runtime'soptionstable intoruntimeoptions.Options(GenerateRuntimeOptions), whose fields areTypeUrlandConfigPath; untested.