Watch
0
0
Fork
You've already forked hyperhive
0

memory-cap: give claude a heap ceiling of at most 3 GiB instead of 75% of the container cap

This commit is contained in:
damocles 2026-11-27 17:08:19 +01:00 • committed by mara
commit 82710f4fa8
3 changed files with 17 additions and 8 deletions

View file

@ -480,7 +480,7 @@ the last drop-in because it can't read the swarm caps file,
the file carries that drop-in's `MemoryMax=`.
At boot the container derives two values from a byte count:
`BUN_JSC_forceRAMSize` (75%, claude-code's heap ceiling) and
`BUN_JSC_forceRAMSize` (75%, but at most 3 GiB: claude-code's heap ceiling; it's a per-process hint while the agent's claude and every subagent's share one cap, so a share that grows with the cap would let a few processes together pass it) and
`HIVE_RUNS_MEMORY_HIGH` in `hive-subagent-daemon`'s and `hive-bash-daemon`'s
environment (two thirds each). Each daemon writes it to `memory.high` of the
cgroup node its runs live in, so a build storm throttles before the

View file

@ -10,10 +10,11 @@
# or malformed file sets neither too, and `hyperhive-memory-cap-check` logs a
# warning at boot:
#
# - `BUN_JSC_forceRAMSize`, 75% of the cap. Bun/JavaScriptCore, the runtime
# under claude-code, sizes its heap ceiling off `/proc/meminfo`, which under
# nspawn is the host's RAM, so without it the heap grows well past the real
# wall before GC kicks in hard and choom sessions hang. An environment
# - `BUN_JSC_forceRAMSize`, 75% of the cap, at most 3 GiB. Bun/JavaScriptCore,
# the runtime under claude-code, sizes its heap ceiling off `/proc/meminfo`,
# which under nspawn is the host's RAM, so without it the heap grows well past
# the real wall before GC kicks in hard and choom sessions hang. It is per
# process while the cap is shared, hence the fixed top. An environment
# generator hands it to every unit of the container's systemd, `machinectl
# shell` sessions (`hivectl choom`) included; `/etc/set-environment` exports
# it in login shells that no unit starts (`nixos-container root-login`).
@ -42,9 +43,14 @@ let
esac
'';
# What one claude process is told it may grow its heap toward, at most.
heapCeilingBytes = 3 * 1024 * 1024 * 1024;
envGenerator = pkgs.writeShellScript "hyperhive-memory-cap-env" ''
${readCap "exit 0"}
printf 'BUN_JSC_forceRAMSize=%s\n' "$((bytes * 75 / 100))"
heap=$((bytes * 75 / 100))
[ "$heap" -gt ${toString heapCeilingBytes} ] && heap=${toString heapCeilingBytes}
printf 'BUN_JSC_forceRAMSize=%s\n' "$heap"
'';
# `$1` is the generator's normal-priority output dir. A drop-in there merges

View file

@ -85,10 +85,13 @@ check() {
}
printf '8589934592\n' >"$cap"
check "an 8G cap" 6442450944 5726623061
check "an 8G cap keeps the heap at the 3 GiB ceiling, not 75%" 3221225472 5726623061
printf '2147483648\n' >"$cap"
check "a 2G cap is below the ceiling and keeps 75%" 1610612736 1431655765
printf '4294967296' >"$cap"
check "a line without a newline is kept" 3221225472 2863311530
check "a line without a newline is kept (75% is exactly the ceiling)" 3221225472 2863311530
printf '4294967296\nLD_PRELOAD=/x\n' >"$cap"
check "only the first line is read" 3221225472 2863311530