How Much RAM Does colcon build Need? Nav2 Built at 16, 8 and 4GB

한국어로 읽기

If colcon build freezes your laptop or dies with c++: fatal error: Killed signal terminated program cc1plus, the usual cause is RAM. So how much RAM do you actually need? Instead of guessing, I built a real workspace (Nav2, Jazzy branch, 45 packages) five times under different memory caps and measured it.

Short answer

  • With default settings (colcon build), the build failed at 4GB. The compiler was killed for running out of memory.
  • At 8GB it succeeded, but peak usage reached 7.8GiB of the 8GiB cap. There is almost no headroom.
  • A sequential build (--parallel-workers 1 + MAKEFLAGS=-j1) peaked at 2.7GiB and finished even at 4GB.
  • A real laptop also spends 3–4GB on the OS, browser and IDE. So 16GB is the comfortable line for default builds; on an 8GB laptop, use the sequential settings.

Test setup

A 4 vCPU, 16GB Linux server (AWS Lightsail). Each build ran in a Docker container with a memory cap and swap disabled (--memory-swap equal to --memory), so “success” means it fit in RAM. Image: ros:jazzy (digest 066420e07f60…); Nav2 jazzy branch at commit 645abd95. Peak memory was read from the container cgroup’s memory.peak.

Setting RAM cap Result Peak memory
Default (4 workers × make -j4) 16GiB Success (45/45) 8.1GiB
Default 8GiB Success (45/45) 7.8GiB
Default 4GiB Failed: cc1plus Killed, stopped after 8 packages 4.0GiB (cap)
Sequential (1 worker × make -j1) 16GiB Success (45/45) 2.7GiB
Sequential 4GiB Success (45/45) 2.7GiB

How to read these numbers

  • memory.peak includes page cache. The 8.1GiB at 16GB is partly cache used simply because there was room. At 8GB the build reached 7.8GiB without being killed because the kernel dropped cache to make space. So the memory a default build truly needs is somewhere between 4GiB and 8GiB.
  • Build times are not compared. The server ran out of CPU credits partway through and was throttled (about 60% steal), so default and sequential builds both took around two hours. On a machine running at full speed, a sequential build is several times slower than the default.
  • Core count matters. With default settings the number of concurrent compilers grows roughly with the square of the core count (workers × make -j). On an 8- or 16-core laptop, the same Nav2 default build uses more RAM.

If you have an 8GB laptop

My own laptop is a 2020 Intel 13-inch MacBook Pro (4 cores, 8GB RAM). Going by these measurements, a default build of a large workspace like Nav2 on a machine like that is likely to run short of memory once the OS takes its share (the measurements were made on the Linux server above; I did not build on this Mac). If you have to build on 8GB, run:

MAKEFLAGS="-j1" colcon build --parallel-workers 1

To make it a little faster, raise the number one step at a time (MAKEFLAGS="-j2" and so on) until you find the highest setting that doesn’t freeze. Why peak memory grows with the number of concurrent compilers is measured separately in colcon sequential build: MAKEFLAGS, memory and time.

If you are buying or upgrading RAM

  • New laptop: 16GB or more for ROS 2 development. With 8 or more cores, 32GB is more comfortable.
  • Upgrading your current laptop: if it has a RAM slot, moving to a 16GB module is the cheapest fix. Check whether it takes DDR4 or DDR5 SO-DIMM first; the two don’t fit each other’s slots. Laptops with soldered RAM (LPDDR, MacBooks) can’t be upgraded, so use the sequential settings.

Reproduce it

The measurement script (measure.sh) and the raw results from all five runs (results.tsv and per-setting build logs) are in the public experiment folder. On Linux with Docker, bash measure.sh runs the same sequence again.