7. Limits
7. Limits¶
Result: works, once each job gets its own cgroup. Rootful containerd with gVisor enforces a memory limit and stops only the job that exceeds it, but only through containerd's CRI and only when the limit is on a cgroup the whole sandbox runs in. That is the kubelet's job in Kubernetes, so allmyram has to do it.
Setup (2026-11-22)¶
- Debian 13
containerd1.7.24 (it pulls inrunc1.1.15), gVisorrelease-20261116.0with itscontainerd-shim-runsc-v1,nerdctl2.4.2,crictlv1.37.0. Installed byspike/install_containerd.shandspike/install_cri.sh, run once by Gavin withsudo. - containerd's CRI plugin lists
runcandrunscas runtime handlers, as in gVisor's containerd quick start. Listing any runtime replaces containerd's built-in list, soruncmust be listed too, or the CRI plugin fails to load ("no corresponding runtime configured … fordefault_runtime_name = "runc""). My first script made that mistake. - A spike-only sudo rule lets
gavinrunnerdctl,ctrandcrictlwithout a password. Each of them is root-equivalent. spike/install_cgroup_parent.shcreates/sys/fs/cgroup/allmyramwith the cpu, memory and pids controllers enabled for its children, delegated togavin. Gone after a reboot.- Test:
spike/cri_memory_limit.py. A container with a 256 MiB limit and no swap writes 128 MiB (control) or 512 MiB, underrunscand underrunc(to show the test itself kills what it should). Three runs each.
Raw results¶
| Client | Runtime | Limit placed on | 128 MiB control | 512 MiB job |
|---|---|---|---|---|
| nerdctl | runsc | container | exit 120, no output | exit 137 |
| nerdctl | runc | container | exit 0, output | exit 137 |
| ctr | runsc | (no limit) | echo hi; exit 7 gives exit 128, no output |
— |
| crictl | runsc | container | exit 0, output | exit 0, "allocated 512 MiB" |
| crictl | runsc | container + CRI pod resources |
exit 0 | exit 0, "allocated 512 MiB" |
| crictl | runc | container | exit 0 | exit 137, OOMKilled |
| crictl | runsc | per-job cgroup as pod cgroup_parent |
exit 0, output, 0.49 s | exit 137, OOMKilled, 0.62 s |
| crictl | runc | per-job cgroup as pod cgroup_parent |
exit 0, 0.40 s | exit 137, OOMKilled, 0.52 s |
The CRI rows are identical across all three runs. The first pod per runtime takes about 3.5 s, and later ones about 0.5 s end to end (pod, container, exit, teardown).
Host cgroups while a 128 MiB job runs under runsc with the per-job cgroup:
| cgroup | memory.max |
memory.peak |
|---|---|---|
/allmyram/<job> (ours) |
256 MiB | 156.8 MB |
…/<pod sandbox> |
max |
156.7 MB |
…/<container> |
256 MiB | 0 |
Under runc the same job peaks at 138.7 MB.
What we learned¶
- nerdctl and ctr can't drive gVisor here. With gVisor's debug logs (via
a temporary wrapper around
runsc, since the shim only reads a runsc config file when the client passes runtime options, and neither client does), the job runs and exits with its real status inside the sandbox. Then containerd only starts it 5 s after the sandbox is ready, its output isn't connected, and the shim'srunsc waitfinds the sandbox already gone and reports 128, its internal-error code. gVisor's quick start namesctr, but on this containerd 1.7.24 it fails the same way. I didn't find the root cause; CRI made it moot. - CRI works. Exit codes, output and timing are all correct through
containerd's built-in CRI, the path Kubernetes uses and gVisor tests.
crictlneeds no Kubernetes. - Under gVisor, a container's own limit does nothing. The limit lands on
the container's cgroup, but gVisor runs the whole pod as one sandbox whose
processes live in the pod's cgroup, so that cgroup stays empty (peak 0).
CRI's pod-level
resourcesfield changes nothing either. gVisor's compatibility page says limits "are not enforced within the sandbox". - The fix is the kubelet's. A cgroup per job, carrying the limit,
passed as the pod's
cgroup_parent. Then the sandbox is inside it, and the 512 MiB job isOOMKilledwhile the control runs. - The limit counts gVisor's own memory. The same 128 MiB job peaks about
18 MB higher under gVisor than under
runc, so a job's limit has to allow for the sandbox. This also suggests experiment 5's ~410 MiB was mostly measurement (summedVmRSScounts shared pages more than once); that's an inference, not a measurement.
What it changes¶
- The runner drives containerd through CRI (its Go client in the product,
crictlin the spike), neverctrornerdctl. - A job is a CRI pod. The runner (or its root helper) creates a cgroup per
job with
memory.max,memory.swap.max, and latercpu.maxandpids.max, and passes it ascgroup_parent. The install step becomes: containerd, gVisor, the CRI runtime entries, and a systemd slice withDelegate=yesfor the job cgroups. - Limits must include the sandbox's overhead.
- Experiment 8's shared sandbox is a CRI pod with two containers. That is the path gVisor supports for multi-container sandboxes.