subagent and bash daemons: the runs' memory ceiling sits on their cgroup node, not on the unit
This commit is contained in:
parent
648076419f
commit
897f8af77d
2 changed files with 109 additions and 33 deletions
|
|
@ -458,8 +458,9 @@ in
|
|||
# actually chose and leaves the daemon serving, which is also what
|
||||
# lets it report the kill rather than vanish and be restarted.
|
||||
OOMPolicy = "continue";
|
||||
# `MemoryHigh=` is a drop-in from ./memory-cap.nix, sized at boot from
|
||||
# the container's cap.
|
||||
# The runs' memory ceiling is `HIVE_RUNS_MEMORY_HIGH`, a drop-in from
|
||||
# ./memory-cap.nix sized at boot from the container's cap. Not
|
||||
# `MemoryHigh=`: that would throttle the daemon with its runs.
|
||||
User = userName;
|
||||
Group = userName;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -19,15 +19,14 @@
|
|||
# it in login shells that no unit starts (`nixos-container root-login`).
|
||||
# `hive-agent` and `hive-subagent-daemon` spawn `claude` as a plain child,
|
||||
# which inherits it, so neither unit may set or unset it.
|
||||
# - `MemoryHigh=` on `hive-subagent-daemon` and on `hive-bash-daemon`, two
|
||||
# thirds of the cap each, as generator drop-ins. Each daemon's cgroup holds
|
||||
# its children (nested `claude` sessions, bash tasks), so a `cargo` or
|
||||
# `nix build` storm throttles itself there before the container's
|
||||
# `MemoryMax=`. `High`, not `Max`: past it the kernel reclaims hard and the
|
||||
# work slows down, so the last third stays free for the agent's own turn.
|
||||
#
|
||||
# Tested by `checks.script-test-agent-memory-cap` and
|
||||
# `checks.module-eval-agent-memory`.
|
||||
# - `HIVE_RUNS_MEMORY_HIGH`, two thirds of the cap, in `hive-subagent-daemon`'s
|
||||
# and `hive-bash-daemon`'s environment (generator drop-ins). Each daemon
|
||||
# writes it to `memory.high` of the cgroup node holding its runs
|
||||
# (`run_cgroup` in `hive-agent-sock`), so a `cargo` or `nix build` storm
|
||||
# throttles itself before the container's `MemoryMax=`. Not `MemoryHigh=` on
|
||||
# the unit, which would throttle the daemon beside its runs too. `High`, not
|
||||
# `Max`, so the last third stays free for the agent's own turn.
|
||||
# Tested by `checks.script-test-agent-memory-cap`, `checks.module-eval-agent-memory`.
|
||||
{ pkgs, ... }:
|
||||
let
|
||||
# Sets `bytes`. Exits for `infinity`, and runs `noCap` when there is no file
|
||||
|
|
@ -55,7 +54,7 @@ let
|
|||
for unit in hive-subagent-daemon hive-bash-daemon; do
|
||||
dir="$1/$unit.service.d"
|
||||
${pkgs.coreutils}/bin/mkdir -p "$dir"
|
||||
printf '[Service]\nMemoryHigh=%s\n' "$((bytes * 2 / 3))" > "$dir/50-memory-high.conf"
|
||||
printf '[Service]\nEnvironment=HIVE_RUNS_MEMORY_HIGH=%s\n' "$((bytes * 2 / 3))" > "$dir/50-runs-memory-high.conf"
|
||||
done
|
||||
'';
|
||||
|
||||
|
|
@ -69,7 +68,7 @@ let
|
|||
else
|
||||
why="is missing"
|
||||
fi
|
||||
echo "<4>/run/hive/memory-max-bytes $why: no BUN_JSC_forceRAMSize heap ceiling and no MemoryHigh= on hive-subagent-daemon or hive-bash-daemon; the host's MemoryMax= on the container still applies." >&2
|
||||
echo "<4>/run/hive/memory-max-bytes $why: no BUN_JSC_forceRAMSize heap ceiling and no memory ceiling on the subagent and bash daemons' runs; the host's MemoryMax= on the container still applies." >&2
|
||||
exit 0
|
||||
''}
|
||||
'';
|
||||
|
|
|
|||
Loading…
Reference in a new issue