forge
Explore
Log in

Don't you dare go Hollow

Cap every cargo-run test binary in a 10G systemd scope

Browse files at this commit

df0c158b2ae655c6b0aa0371fdc69db3b3b4548aAhmet Kaan GümüşParent: 463079b
  • feat
    • cap every cargo-run test binary in a 10G systemd scope
Show full message
feat(infra): cap every cargo-run test binary in a 10G systemd scope

Three kernel OOM kills in 48h came from test binaries launched outside the
omp-worker scope; a cap that lives in the launcher misses every other path.
The cargo target runner now wraps each test/bin in a transient user scope
(MemoryMax=10G, MemorySwapMax=2G), resolved via git rev-parse so every
worktree checkout carries it. EC_NOMEMGUARD=1 bypasses; fails open where
systemd is absent.
.cargo/config.tomladded+7 -0
@@ -0,0 +1,7 @@
1+[target.x86_64-unknown-linux-gnu]
2+# Wrap every test/bin run in scripts/memguard-runner.sh so a runaway
3+# allocation gets killed inside its own cgroup instead of OOM-killing the
4+# machine. Located via `git rev-parse --show-toplevel` from the invoker's cwd
5+# (cargo does not resolve runner paths relative to this file, and an absolute
6+# path would break other worktree checkouts of this repo).
7+runner = ["bash", "-c", "root=$(git rev-parse --show-toplevel) && exec \"$root/scripts/memguard-runner.sh\" \"$@\"", "--"]
scripts/memguard-runner.shadded+21 -0
@@ -0,0 +1,21 @@
1+#!/usr/bin/env bash
2+# Wraps a test/bin invocation in a transient user cgroup scope so a runaway
3+# allocation dies inside its own cgroup instead of triggering a machine-wide
4+# OOM kill. Used as the cargo target runner (see .cargo/config.toml) so every
5+# `cargo test`/`cargo run` invocation of this workspace is capped, from any
6+# checkout (main repo or worktree).
7+set -euo pipefail
8+
9+if [ "${EC_NOMEMGUARD:-0}" = "1" ]; then
10+ echo "memguard-runner: EC_NOMEMGUARD=1, running without memory cap" >&2
11+ exec "$@"
12+fi
13+
14+if ! systemd-run --user --scope --quiet -p MemoryMax=10G true >/dev/null 2>&1; then
15+ echo "memguard-runner: systemd-run --user --scope unavailable, running without memory cap" >&2
16+ exec "$@"
17+fi
18+
19+exec systemd-run --user --scope --quiet --same-dir \
20+ -p MemoryMax=10G -p MemorySwapMax=2G \
21+ -- "$@"