Browse documentation

Memory Caps on a Shared Linux Machine

How to start a heavy run on a machine that several people or agents share so that a runaway run is far less likely to reach the machine-wide OOM killer, and how to read a kernel OOM report.

Executive Summary

  • The engine's ceiling is not a process cap — the default ceiling bounds the GC heap and the native storage the engine charges, not the whole process
  • Cap every heavy run — a whole gate, build, full suite, test262 or benchmark run is one command inside a memory-capped systemd scope, checked before the work starts
  • Budget the caps together — each cap is per run, so the caps of the runs that can overlap must fit in the machine's memory
  • Probes — a limit probe passes the limit under test as --max-memory and runs in a capped scope
  • Read the constraint — CONSTRAINT_MEMCG in a kernel OOM report is a cap doing its job; CONSTRAINT_NONE is the machine-wide kill

Why an Operating-System Cap

Without --max-memory, GocciaRunner and GocciaTestRunner get a default ceiling: half of the memory available to the process (the smallest memory limit of its cgroup and of the cgroups above it, else physical memory), at most 8 GiB on a 64-bit build (Garbage Collector has the details). GocciaTest262Runner defaults to 2 GiB. The ceiling counts the GC heap and the native storage the engine charges against it, so a process can use more than it: resident memory reached about 1.7 times a --max-memory=256MiB ceiling in one string-keys probe. It does not cover builds, compilers or package managers at all, and 8 GiB per run is more than a machine can give a dozen runs at once. When the kernel runs out of memory on a shared machine, it ends whichever process its OOM score picks (mostly the one using the most memory), not the one that grew.

Starting a Run

  • Cap every heavy run. Start a whole gate, a build, the full test suite, a test262 run or a benchmark run as one command inside a memory-capped scope: systemd-run --user --scope -q -p MemoryMax=<size> -p MemorySwapMax=0 -- <command>, or the wrapper your machine's own instructions name for it. MemorySwapMax=0 keeps a run that outgrows its cap from spilling into swap instead of ending.
  • Check that the cap applies. MemoryMax is enforced only when the user's systemd manager has the memory controller delegated; otherwise systemd accepts the property and enforces nothing. Make the check part of the same command, so that it runs in the scope that runs the work and the work starts only when the scope's own limit is the number you asked for (<bytes> is the size in bytes, 3 GiB being 3221225472): systemd-run --user --scope -q -p MemoryMax=<size> -p MemorySwapMax=0 -- sh -c 'test "$(cat /sys/fs/cgroup$(cut -d: -f3 /proc/self/cgroup)/memory.max)" = <bytes> || exit 1; exec "$@"' sh <command>. scripts/depth-probe.ts makes the same check before it trusts a systemd cap.
  • Budget the caps together. A cap limits one run, not the machine. Three runs capped at 40% of memory can still use 120% of it when they overlap, and other work on the machine uses memory too. Pick a size from how many runs can overlap and what else runs there.
  • Probes. A probe that tests a limit runs in its own scope and passes the limit under test as --max-memory, so the engine's refusal, not the cap, ends it; a probe that reaches the cap instead is a finding, so record its program and the limit it passed. Depth and Fuzz Probe is the exception: it passes no --max-memory by default, runs each probe under its own cap and time limit, and expects a large exponential probe to end at that cap (its memory-cap outcome is not a failure).

Reading a Kernel OOM Report

journalctl -k reports each kill with its constraint:

ReportMeaning
oom-kill:constraint=CONSTRAINT_MEMCG with an oom_memcg= that names a *.scope cgroup, and Memory cgroup out of memoryThe cap did its job: only that scope's processes were at risk
oom-kill:constraint=CONSTRAINT_NONE and Out of memory: Killed processThe machine-wide kill that caps exist to prevent

In the report's oom-kill: line, oom_memcg= is the cgroup that hit its limit and task_memcg= is the victim's. When oom_memcg= names a shared parent, such as a slice, every scope under it was at risk, not only the victim's. The victim is the process the kernel's OOM score picks, usually the one using the most memory in the scope or on the machine, and not necessarily what grew. The report's task list (resident pages per process) and the scope's name help establish what ran.