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 `hyperhive-memory-cap-check.service` logs a warning naming the path in the
container's journal. The container's `MemoryMax=` still applies. container's journal. The container's `MemoryMax=` still applies.
A container with a finite `MemoryMax=` also gets, in the same drop-in, Every container also gets, in the same drop-in, `MemorySwapMax=0`, whatever
`MemorySwapMax=0` and `MemoryHigh=` at 90% of the cap (bytes, rounded down). its `MemoryMax=`. No agent swaps: paging it out to host swap would move the
A budgeted agent never swaps: paging it out to host swap would move the pressure onto the host, and every process that touches a paged-out page would
pressure onto the host. Past 90% the kernel slows the container and reclaims sleep in `D`, where a signal cannot reach it.
from it, and at 100% it kills. `MemoryMax=infinity` sets neither. Like the A container with a finite `MemoryMax=` also gets `MemoryHigh=` at 90% of the
rest of the drop-in, they reach a running agent at its next spawn or rebuild. 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: 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 The container stays up through these kills. Each one counts in the
`hyperhive.container.memory.oom_kills` metric, shown as "OOM kills by agent" `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` 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 is the memory the container has swapped out: nonzero only for an agent whose
no budget, or one whose container started before its drop-in carried container started before its drop-in carried `MemorySwapMax=0`.
`MemorySwapMax=0`.
More than 3 kills of one agent in an hour raise the `hh-agent-oom-kills` alert. 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` /// the cap, where the kernel slows the container and reclaims from it. `None`
/// omits the line. /// omits the line.
/// ///
/// A finite `MemoryMax=` comes with `MemorySwapMax=0`: at the budget the /// Every container gets `MemorySwapMax=0`, whatever its
/// kernel kills inside the container instead of paging it out to host swap. /// `MemoryMax=`: past its share the kernel kills inside the container instead
/// `MemoryMax=infinity` is no budget and leaves swap alone. /// 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( fn limits_dropin_body(
runtime_dir: &str, runtime_dir: &str,
rootfs_check: &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 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 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 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!( format!(
"[Unit]\n\ "[Unit]\n\
ConditionPathIsDirectory={runtime_dir}\n\ ConditionPathIsDirectory={runtime_dir}\n\
@ -269,7 +265,7 @@ fn limits_dropin_body(
RestartSec={RESTART_SEC}\n\ RestartSec={RESTART_SEC}\n\
MemoryMax={memory_max}\n\ MemoryMax={memory_max}\n\
{high_line}\ {high_line}\
{swap_line}\ MemorySwapMax=0\n\
CPUQuota={cpu_quota}\n\ CPUQuota={cpu_quota}\n\
{cpu_weight_line}{io_weight_line}" {cpu_weight_line}{io_weight_line}"
) )
@ -994,28 +990,25 @@ mod tests {
} }
} }
/// A budgeted container gets no swap; an unbudgeted one keeps it. The /// No container swaps, budgeted or not: the cap sits right after the
/// finite arm is the presence control for the infinity arm's absence. /// memory lines, once. `infinity` is the
/// arm that used to keep swap.
#[test] #[test]
fn swap_is_off_exactly_when_the_memory_is_budgeted() { fn swap_is_off_whatever_the_memory_budget() {
for mem in ["4G", "512M", "50%", "8589934592"] { for mem in ["4G", "512M", "50%", "8589934592", "infinity"] {
let body = limits_dropin_body("/rt/x", CHECK, mem, "200%", None, None, None); let body = limits_dropin_body("/rt/x", CHECK, mem, "200%", None, None, None);
assert!( assert!(
body.contains(&format!("\nMemoryMax={mem}\nMemorySwapMax=0\n")), body.contains(&format!(
"no swap line under a budget of {mem}: {body}" "\nMemoryMax={mem}\nMemorySwapMax=0\nCPUQuota=200%\n"
)),
"no swap lines under a budget of {mem}: {body}"
); );
assert_eq!(body.matches("MemorySwapMax=").count(), 1, "{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=` /// `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] #[test]
fn memory_high_is_rendered_only_when_sent() { fn memory_high_is_rendered_only_when_sent() {
let with = limits_dropin_body( let with = limits_dropin_body(