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

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