Rust "ran out of memory" during LTO codegen in CI
Link-time optimization (especially fat LTO) merges every crate into one module for the optimizer, multiplying peak memory. On a memory-tight runner LLVM aborts with an out-of-memory error during codegen.
What this error means
The build fails late, during the final codegen/link, with LLVM ERROR: out of memory or an OOM kill of the codegen process. It appears with lto = "fat" or lto = true release profiles.
cargo
LLVM ERROR: out of memory
Allocation failed
error: could not compile `app` (bin "app")
# during the LTO codegen phase of a --release buildCommon causes
Fat LTO holds the whole program in memory
lto = "fat" (or true) merges all crates into one LLVM module, so peak memory scales with total program size and overruns the runner.
High codegen parallelism during LTO
Multiple parallel codegen threads each consume memory, compounding the LTO peak.
How to fix it
Use thin LTO or disable it for CI
Thin LTO keeps modules separate, drastically lowering peak memory.
Cargo.toml
# Cargo.toml
[profile.release]
lto = "thin" # or lto = false for CI builds
codegen-units = 16Build on a larger-memory runner
.github/workflows/ci.yml
runs-on: latchkey-largeHow to prevent it
- Prefer
lto = "thin"over fat LTO in CI. - Reserve fat LTO for release artifacts built on high-memory hosts.
- On self-healing managed runners (Latchkey), an OOM during LTO codegen is auto-retried with larger RAM and the registry is cached, so a memory spike does not break the build.
Related guides
Rust "rustc interrupted by SIGKILL" (OOM) in CIFix rust "error: rustc interrupted by signal 9 (SIGKILL)" in CI -- the OOM killer terminated rustc because th…
Rust Compile OOM / SIGKILL (Exit 137) in CIFix Rust compilation killed by OOM in CI - rustc SIGKILLed with exit 137 or "signal: 9". Lower codegen-units,…
Rust Linker OOM with High codegen-units in CIFix Rust build memory blowups from high codegen-units and debug info in CI - the linker peaks on memory. Lowe…