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:
parent
8bd33a3482
commit
dfd4212e10
1 changed files with 26 additions and 31 deletions
|
|
@ -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(
|
||||
|
|
|
|||
Loading…
Reference in a new issue