Watch
0
0
Fork
You've already forked hyperhive
0

bash tasks are the OOM killer's first victims: score 1000, subagent runs 900, MemoryHigh on the bash daemon

This commit is contained in:
maia 2026-11-18 20:27:14 +01:00 • committed by mara
commit 77f33a23d8

View file

@ -786,7 +786,7 @@ async fn exec_cmd(
.stdout(std::process::Stdio::from(stdout_file))
.stderr(std::process::Stdio::from(stderr_file));
let cgroup_procs = cgroup_procs.map(std::os::fd::AsRawFd::as_raw_fd);
// SAFETY: `setpgid`/`nice`/`write` are async-signal-safe and only touch
// SAFETY: `setpgid`/`nice`/`open`/`write` are async-signal-safe and only touch
// the calling (child) process before exec — no allocations, no locks.
// `setpgid(0, 0)` makes the child its own process-group leader so the
// whole subtree can be signalled as a group (`kill(-pgid, …)`).
@ -796,6 +796,9 @@ async fn exec_cmd(
cmd_builder.pre_exec(move || {
libc::setpgid(0, 0);
libc::nice(10);
// Before the cgroup, and a failure is not the task's: a container
// that denies the write still runs it, at the daemon's own score.
let _ = run_cgroup::set_oom_score_adj_in_pre_exec(run_cgroup::BASH_TASK_OOM_SCORE_ADJ);
if let Some(procs) = cgroup_procs {
run_cgroup::enter_in_pre_exec(procs)?;
}
@ -1241,6 +1244,18 @@ mod tests {
assert_eq!(out, "hi\n");
}
#[test]
fn a_task_and_what_it_forks_run_at_the_bash_task_score() {
let (outcome, out) = run_within(
"cat /proc/self/oom_score_adj; sh -c 'cat /proc/self/oom_score_adj'",
None,
Duration::from_secs(10),
)
.unwrap();
assert!(matches!(outcome, ExecOutcome::Exited(0)));
assert_eq!(out, "1000\n1000\n");
}
#[test]
fn a_backgrounded_child_does_not_hold_the_task_open() {
let (outcome, out) = run_within("sleep 30 & echo started", None, Duration::from_secs(5))