Watch
0
0
Fork
You've already forked hyperhive
0

hive-priv: no agent container swaps, budgeted or not

The container drop-in wrote MemorySwapMax=0 only next to a finite
MemoryMax=. A container with MemoryMax=infinity kept host swap, so a
container over its memory share paged out and every process that
touched a paged-out page slept in D, out of reach of a signal.

limits_dropin_body now writes MemorySwapMax=0 for every container. The
OOM killer inside the container's cgroup takes over: subagent runs
(+900) and bash tasks (+1000) die before the agent's own session
(-500), as before. Docs say so.
This commit is contained in:
maia 2026-11-27 03:40:04 +01:00
commit dfd4212e10
2 changed files with 26 additions and 31 deletions

View file

@ -491,12 +491,15 @@ changed cap reaches them at the next container start without a rebuild.
`hyperhive-memory-cap-check.service` logs a warning naming the path in the
container's journal. The container's `MemoryMax=` still applies.
A container with a finite `MemoryMax=` also gets, in the same drop-in,
`MemorySwapMax=0` and `MemoryHigh=` at 90% of the cap (bytes, rounded down).
A budgeted agent never swaps: paging it out to host swap would move the
pressure onto the host. Past 90% the kernel slows the container and reclaims
from it, and at 100% it kills. `MemoryMax=infinity` sets neither. Like the
rest of the drop-in, they reach a running agent at its next spawn or rebuild.
Every container also gets, in the same drop-in, `MemorySwapMax=0`, whatever
its `MemoryMax=`. No agent swaps: paging it out to host swap would move the
pressure onto the host, and every process that touches a paged-out page would
sleep in `D`, where a signal cannot reach it.
A container with a finite `MemoryMax=` also gets `MemoryHigh=` at 90% of the
cap (bytes, rounded down). Past 90% the kernel slows the container and
reclaims from it, and at 100% it kills. `MemoryMax=infinity` sets no
`MemoryHigh=`. Like the rest of the drop-in, they reach a running agent at its
next spawn or rebuild.
When the container reaches its cap, the kernel kills inside it, in this order:
@ -516,9 +519,8 @@ runs still get +900 and bash tasks +1000.
The container stays up through these kills. Each one counts in the
`hyperhive.container.memory.oom_kills` metric, shown as "OOM kills by agent"
on the health tab of the agents dashboard. `hyperhive.container.memory.swap.usage`
is the memory the container has swapped out: nonzero only for an agent with
no budget, or one whose container started before its drop-in carried
`MemorySwapMax=0`.
is the memory the container has swapped out: nonzero only for an agent whose
container started before its drop-in carried `MemorySwapMax=0`.
More than 3 kills of one agent in an hour raise the `hh-agent-oom-kills` alert.

View file

@ -235,9 +235,10 @@ const RESTART_SEC: u32 = 5;
/// the cap, where the kernel slows the container and reclaims from it. `None`
/// omits the line.
///
/// A finite `MemoryMax=` comes with `MemorySwapMax=0`: at the budget the
/// kernel kills inside the container instead of paging it out to host swap.
/// `MemoryMax=infinity` is no budget and leaves swap alone.
/// Every container gets `MemorySwapMax=0`, whatever its
/// `MemoryMax=`: past its share the kernel kills inside the container instead
/// of paging it out to host swap, where every process that touches a paged-out
/// page sleeps in `D` and a signal cannot reach it.
fn limits_dropin_body(
runtime_dir: &str,
rootfs_check: &str,
@ -253,11 +254,6 @@ fn limits_dropin_body(
let cpu_weight_line = cpu_weight.map_or_else(String::new, |w| format!("CPUWeight={w}\n"));
let io_weight_line = io_weight.map_or_else(String::new, |w| format!("IOWeight={w}\n"));
let high_line = memory_high.map_or_else(String::new, |b| format!("MemoryHigh={b}\n"));
let swap_line = if memory_max == "infinity" {
""
} else {
"MemorySwapMax=0\n"
};
format!(
"[Unit]\n\
ConditionPathIsDirectory={runtime_dir}\n\
@ -269,7 +265,7 @@ fn limits_dropin_body(
RestartSec={RESTART_SEC}\n\
MemoryMax={memory_max}\n\
{high_line}\
{swap_line}\
MemorySwapMax=0\n\
CPUQuota={cpu_quota}\n\
{cpu_weight_line}{io_weight_line}"
)
@ -994,28 +990,25 @@ mod tests {
}
}
/// A budgeted container gets no swap; an unbudgeted one keeps it. The
/// finite arm is the presence control for the infinity arm's absence.
/// No container swaps, budgeted or not: the cap sits right after the
/// memory lines, once. `infinity` is the
/// arm that used to keep swap.
#[test]
fn swap_is_off_exactly_when_the_memory_is_budgeted() {
for mem in ["4G", "512M", "50%", "8589934592"] {
fn swap_is_off_whatever_the_memory_budget() {
for mem in ["4G", "512M", "50%", "8589934592", "infinity"] {
let body = limits_dropin_body("/rt/x", CHECK, mem, "200%", None, None, None);
assert!(
body.contains(&format!("\nMemoryMax={mem}\nMemorySwapMax=0\n")),
"no swap line under a budget of {mem}: {body}"
body.contains(&format!(
"\nMemoryMax={mem}\nMemorySwapMax=0\nCPUQuota=200%\n"
)),
"no swap lines under a budget of {mem}: {body}"
);
assert_eq!(body.matches("MemorySwapMax=").count(), 1, "{body}");
}
let unbudgeted = limits_dropin_body("/rt/x", CHECK, "infinity", "200%", None, None, None);
assert!(
unbudgeted.contains("\nMemoryMax=infinity\n"),
"{unbudgeted}"
);
assert!(!unbudgeted.contains("MemorySwapMax"), "{unbudgeted}");
}
/// `MemoryHigh=` is the byte count the caller sends, between `MemoryMax=`
/// and the swap line, and absent when none is sent.
/// and the swap lines, and absent when none is sent.
#[test]
fn memory_high_is_rendered_only_when_sent() {
let with = limits_dropin_body(