Ray's Knowledge Base
Unlock

A spill file on tmpfs (/tmp, /dev/shm) counts against the cgroup and still gets the job OOM-killed

PitfallVerified 8 Oct 2026Holds project: dftracer-utils
Pitfall. The symptom, what causes it, and the fix that was run and seen to work.

Symptom#

The process was killed by the kernel (rc=137) under a cgroup limit although it held little memory. The kernel report in journalctl -k shows Memory cgroup out of memory: Killed process ... anon-rss:77300kB while the cgroup stats show file 849756160 and shmem 849756160.

Cause#

The spill directory was the system temp directory, which is tmpfs on that node (Arch Linux: /tmp is RAM). tmpfs pages are shmem, charged to the cgroup of the writer, and nothing can reclaim them without swap. Spilling to RAM only moves the bytes. No mount root was writable by a normal user, so mount discovery found nothing and the fallback was /tmp.

Fix#

Pick a disk-backed directory on purpose: DFTRACER_UTILS_SPILL_DIR, else a writable local-disk mount, else a per-user directory under /var/tmp or ~/.cache when filesystem_kind() is LOCAL, else /tmp with a warning when it is RAM-backed (spill_dir() in core/common). To measure, sample anon from the cgroup's memory.stat during the run: memory.peak includes page cache and sits at the limit.

Evidence#

Under systemd-run --user --scope -p MemoryMax=1G -p MemorySwapMax=0 the new binary was killed with shmem 849756160 on tmpfs, and finished with 222 MiB peak anon and oom_kill=0 after the fallback change.

Also found by searching

  • spill file gets the process OOM-killed under a cgroup limit
  • Memory cgroup out of memory shmem file pages with small anon rss
  • /tmp is tmpfs and counts against the memory limit
  • memory.peak equals the limit but the process is small