Expand description
Whole-tree memory cap for a kernel: the kernel plus every process its cells spawn (tree-memory.ts).
Cgroup: the kernel starts inside a transient systemd user scope (systemd-run --user --scope -p MemoryMax=… -p MemorySwapMax=0), so the kernel’s memory controller enforces the cap; the host reads the scope’smemory.eventsto report an OOM kill clearly. Needs no root, only a user manager with the memory controller delegated (probed once per launcher program by starting a tiny scope and reading back itsmemory.max).Watchdog: the host sums the proportional anonymous and shared memory of the kernel’s descendant tree from /proc (Pss_Anon + Pss_Shmem + SwapPss; RssAnon + RssShmem + VmSwap where PSS is unavailable) and kills the tree when it is over the cap, polling every 500 ms, 250 ms above 40% of the cap and 100 ms above 70%.Off: no tree cap (the cap is 0, or not Linux).
RLIMIT_DATA per process stays in force in every mode.
Enums§
Functions§
- cgroup_
dir_ of - The cgroup v2 directory named by a
/proc/<pid>/cgrouptext. - cgroup_
oom_ kills cgroupOomKills: OOM kills recorded in a cgroup’smemory.events(0 without the line), or none when the cgroup is gone.- cgroup_
pids cgroupPids: pids listed in a cgroup’scgroup.procsand its child cgroups, or none when it is gone.- cgroup_
scope_ available cgroupScopeAvailable: whetherprogram(systemd-run) can start a transient user scope with a memory cap here. Probed once per program by starting a tiny scope and reading back itsmemory.max, which checks the launcher, the user manager and memory-controller delegation together.- cgroup_
scope_ command cgroupScopeCommand: the command prefix that starts the kernel inside a capped transient scope; the first item is the launcher (systemd-run), which execs the command after--itself.- is_
foreign_ scope - Whether
dirmay be treated as the kernel’s own scope: it is not this host process’s cgroup nor one of its ancestors. A kernel that was never moved into a scope of its own (a launcher that only execs, or the moment before systemd-run moves it) still sits in the host’s cgroup, and killing “every process in it” would kill the host and the terminal it runs in (on 2026-10-15 a test under a fake systemd-run killed the user’s Ghostty surface this way). - kernel_
tree_ memory_ limit kernelTreeMemoryLimit: the override, elseULTRON_RLM_MAX_TREE_MEMORY_MBwhen it is all digits, else twice the per-process limit; 0 disables. A value past 2^53 - 1 is an error, as in TypeScript.- private_
rss_ bytes processPrivateRssBytesof a/proc/<pid>/statustext: RssAnon + RssShmem + VmSwap.- process_
cgroup_ dir processCgroupDir: the cgroup v2 directory ofpid(from its0::line), or none.- process_
memory_ bytes processMemoryBytes: one process’s proportional memory in bytes; 0 when it is gone or a kernel thread.- proportional_
bytes processMemoryBytesof a/proc/<pid>/smaps_rolluptext: Pss_Anon + Pss_Shmem + SwapPss, where a page shared by N processes counts 1/N in each; none when the rollup has no Pss_Anon (before Linux 5.9: fall back to the status).- tree_
memory_ backend treeMemoryBackend:requested(ULTRON_RLM_TREE_MEMORY_BACKEND: auto|cgroup|watchdog|off) for a cap; “cgroup”, “auto” and anything unrecognized take a capped scope whencgroup_availablesays this system allows one, else the watchdog.- tree_
memory_ limit_ message treeMemoryLimitMessage: the error a kernel stopped by the tree cap reports.- tree_
memory_ usage treeMemoryUsage: memory ofrootand its live descendant tree, with the descendants seen.- watchdog_
poll_ ms watchdogPollMs: the watchdog’s next poll for a tree atbytesof acap_bytescap, faster near the cap.