forge
Explore
Log in

Don't you dare go Hollow

A builtin job without `memory` gets the runner's memory budget as its cgroup limit, as docs/ci.md says, instead of limits.memory (4g), which OOM-killed rustc in cargo test

Browse files at this commit

bdd842ca6c9a6d4884fbdfff5e011f5f9c1dd218Ahmet Kaan Gümüş and Claude Opus 5.5Parent: 8176fe1
All checks have passed
Show checks
  • fix
    • a builtin job without `memory` gets the runner's memory budget as its cgroup limit, as docs/ci.md says, instead of limits.memory (4g), which OOM-killed rustc in cargo test
Show full message
🐛 fix: a builtin job without `memory` gets the runner's memory budget as its cgroup limit, as docs/ci.md says, instead of limits.memory (4g), which OOM-killed rustc in cargo test
crates/forge-runner/src/config.rsmodified+21 -0
@@ -98,6 +98,21 @@ impl Limits {
98 limits98 limits
99 }99 }
100 100
101+ /// [`Limits::for_job`] for the builtin executor, where every job sits in the runner's box: a
102+ /// job without `memory` may use the whole budget (docs/ci.md, Memory), never less than the
103+ /// default reservation. The box and the pressure controller keep jobs together inside it.
104+ pub fn for_builtin_job(&self, declared: Option<u64>, budget: Option<u64>) -> Limits {
105+ match (declared, budget) {
106+ (None, Some(budget)) => {
107+ let reserve = forge_ci::size::parse_size(&self.reserve_memory).unwrap_or(0);
108+ let mut limits = self.clone();
109+ limits.memory = budget.max(reserve).max(1).to_string();
110+ limits
111+ }
112+ _ => self.for_job(declared),
113+ }
114+ }
115+
101 /// The cgroup `memory.max` of a job in bytes, see [`Limits::for_job`]. `None` when116 /// The cgroup `memory.max` of a job in bytes, see [`Limits::for_job`]. `None` when
102 /// `limits.memory` does not parse, which the sandbox reports itself.117 /// `limits.memory` does not parse, which the sandbox reports itself.
103 pub fn job_memory_limit(&self, declared: Option<u64>) -> Option<u64> {118 pub fn job_memory_limit(&self, declared: Option<u64>) -> Option<u64> {
@@ -670,6 +685,12 @@ mod tests {
670 };685 };
671 assert_eq!(bad.job_memory_limit(None), None);686 assert_eq!(bad.job_memory_limit(None), None);
672 assert_eq!(bad.for_job(None).memory, "lots");687 assert_eq!(bad.for_job(None).memory, "lots");
688+ // Builtin: no `memory` means the whole budget; a declared one keeps its slack.
689+ assert_eq!(limits.for_builtin_job(None, Some(6 * gib)).memory, (6 * gib).to_string());
690+ assert_eq!(
691+ limits.for_builtin_job(Some(gib), Some(6 * gib)).memory,
692+ limits.for_job(Some(gib)).memory
693+ );
673 }694 }
674 695
675 #[test]696 #[test]
crates/forge-runner/src/executor.rsmodified+8 -2
@@ -57,6 +57,9 @@ pub struct ExecRequest<'a> {
57 /// Where the executor leaves OOM kills it saw in the job's cgroup. Executors that cannot see57 /// Where the executor leaves OOM kills it saw in the job's cgroup. Executors that cannot see
58 /// them leave it alone.58 /// them leave it alone.
59 pub oom: OomSink,59 pub oom: OomSink,
60+ /// The runner's memory budget now. The builtin executor gives a job without `memory` this as
61+ /// its cgroup limit; `None` keeps the configured `limits.memory`.
62+ pub memory_budget: Option<u64>,
60 }63 }
61 64
62 /// The executor's answer. The runner adds timeouts and artifact results on top of it.65 /// The executor's answer. The runner adds timeouts and artifact results on top of it.
@@ -641,14 +644,16 @@ impl<I: ImageSource> BuiltinExecutor<I> {
641 logs,644 logs,
642 cancel,645 cancel,
643 oom: oom_sink,646 oom: oom_sink,
647+ memory_budget,
644 } = req;648 } = req;
649+ let limits = self.limits.for_builtin_job(job.memory_bytes, memory_budget);
645 if let Err(e) = validate_job_id(&job.job_id) {650 if let Err(e) = validate_job_id(&job.job_id) {
646 return error_result(e.to_string());651 return error_result(e.to_string());
647 }652 }
648 if let Err(e) = check_image(&job.image) {653 if let Err(e) = check_image(&job.image) {
649 return error_result(e.to_string());654 return error_result(e.to_string());
650 }655 }
651- let env = match job_env_with_defaults(job, &self.limits.for_job(job.memory_bytes)) {656+ let env = match job_env_with_defaults(job, &limits) {
652 Ok(env) => env,657 Ok(env) => env,
653 Err(e) => return error_result(e.to_string()),658 Err(e) => return error_result(e.to_string()),
654 };659 };
@@ -680,7 +685,7 @@ impl<I: ImageSource> BuiltinExecutor<I> {
680 env,685 env,
681 run: job.run.clone(),686 run: job.run.clone(),
682 network: job.network,687 network: job.network,
683- limits: self.limits.for_job(job.memory_bytes),688+ limits,
684 idmap: self.idmap.clone(),689 idmap: self.idmap.clone(),
685 };690 };
686 // The request holds the secrets. It goes to the helper's stdin and nowhere else.691 // The request holds the secrets. It goes to the helper's stdin and nowhere else.
@@ -996,6 +1001,7 @@ mod tests {
996 logs: tx,1001 logs: tx,
997 cancel: CancellationToken::new(),1002 cancel: CancellationToken::new(),
998 oom: OomSink::default(),1003 oom: OomSink::default(),
1004+ memory_budget: None,
999 })1005 })
1000 .await;1006 .await;
1001 assert_eq!(result.outcome, Outcome::Success, "{result:?}");1007 assert_eq!(result.outcome, Outcome::Success, "{result:?}");
crates/forge-runner/src/runner.rsmodified+1 -0
@@ -407,6 +407,7 @@ impl Runner {
407 logs: tx.clone(),407 logs: tx.clone(),
408 cancel: job_cancel.clone(),408 cancel: job_cancel.clone(),
409 oom: oom.clone(),409 oom: oom.clone(),
410+ memory_budget: Some(self.memory.budget()),
410 })411 })
411 .await;412 .await;
412 workspace_dir = Some(dir);413 workspace_dir = Some(dir);
crates/forge-runner/tests/integration/builtin.rsmodified+1 -0
@@ -105,6 +105,7 @@ async fn run_job(
105 logs: tx,105 logs: tx,
106 cancel,106 cancel,
107 oom: forge_runner::oom::OomSink::default(),107 oom: forge_runner::oom::OomSink::default(),
108+ memory_budget: None,
108 })109 })
109 .await;110 .await;
110 let logs = collector.await.expect("log collector");111 let logs = collector.await.expect("log collector");