Make the build agent and buildkitd immune to the OOM killer#134
Open
robstolarz wants to merge 1 commit into
Open
Make the build agent and buildkitd immune to the OOM killer#134robstolarz wants to merge 1 commit into
robstolarz wants to merge 1 commit into
Conversation
Before launching buildkitd, set the agent's own oom_score_adj to -1000 so the kernel OOM killer never picks the agent or the buildkitd it spawns (which inherits the value across the fork) as its victim under memory pressure. When a RUN step exhausts memory, the kernel scores per process and reaps the single highest-scoring one. buildkitd is often the fattest process on the box (it holds the LLB graph and cache), so today it can be the victim and the whole build interaction hangs. Making the agent and buildkitd immune guarantees a parent survives to report the death; build steps are biased positive (buildkit's oomScoreAdj default), so they remain the preferred victim and the OOM lands on something we can afford to lose. The agent runs as root, so the negative adjustment is permitted. The write is best-effort — a non-Linux/dev environment without a writable /proc logs and continues rather than failing the task. DEP-5151 Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
jacobwgillespie
approved these changes
Jun 25, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Before launching buildkitd, the agent sets its own
oom_score_adjto-1000. buildkitd is spawned as a child and inherits the value, so both the agent and buildkitd become immune to the kernel OOM killer.Why
Part of DEP-5144 (survive RUN-step OOMs without killing the build interaction). The kernel scores per-process and reaps the single highest-scoring one. buildkitd is often the fattest process on the box (it holds the LLB graph + cache), so today an OOM can take down buildkitd itself and the build interaction hangs forever.
Making the agent + buildkitd immune guarantees a parent survives to report the death. Build steps are biased positive (buildkit's
oomScoreAdjdefault of +500), so they stay the preferred victim and the OOM lands on something we can afford to lose. Because runc sets each step's adj from the OCI spec, steps don't inherit the daemon's immunity.This stands alone, and composes with the buildkit-private change (depot/buildkit-private#57) that biases steps positive. Deploy ordering: roll the buildkit-private binary to builders before this, so steps are already being reset to +500 when the daemon goes immune.
The agent runs as root, so the negative adjustment is permitted. The write is best-effort — a non-Linux/dev environment without a writable
/proclogs and continues rather than failing the task.Test
pnpm type-checkclean.DEP-5151