Skip to content
Latchkey

CMake parallel build OOM (compiler Killed, -j too high) in CI

The compiler process was killed by the OOM killer, not by a code error. A high -j parallelism spawned more compiler instances than the runner's RAM could hold, so the kernel killed one mid-compile.

What this error means

The build fails with "c++: fatal error: Killed signal terminated program cc1plus" or "internal compiler error: Killed", intermittently and often only under high parallelism.

cmake
c++: fatal error: Killed signal terminated program cc1plus
compilation terminated.
ninja: build stopped: subcommand failed.

Common causes

Too many parallel compile jobs for the RAM

A large -j (or the default = core count) runs many memory-hungry compilations at once, exceeding the runner memory.

A single heavy translation unit

A big template-heavy file needs a lot of memory to compile; under parallelism it tips the runner over its limit.

How to fix it

Cap the parallelism

Lower the number of parallel jobs so peak memory stays under the runner limit.

Terminal
cmake --build build --parallel 2

Reduce memory per compile or use a bigger runner

Split heavy headers or move to a higher-memory runner when the peak is unavoidable.

Terminal
# limit ninja jobs when memory is tight
cmake --build build -- -j2

How to prevent it

  • Set an explicit --parallel that fits the runner memory, not just the core count.
  • Watch peak RSS for template-heavy translation units.
  • Use a higher-memory runner for memory-bound builds.

Related guides

Tired of flaky CI? Latchkey auto-heals failed jobs and retries them for you. Start free →