
Yocto builds failing under memory exhaustion are a rite of passage for embedded Linux engineers. The build progresses smoothly for hours, then suddenly g++: fatal error: Killed signal terminated program cc1plus appears, ninja or make aborts, and the task fails. Checking dmesg confirms the culprit: Out of memory: Killed process ... (cc1plus).
This guide explains why BitBake builds exhaust host RAM, why SIGKILL surfaces as task exit code 1 or container exit code 137, which Yocto/BitBake knobs actually work (and which common myths fail silently), and how to configure local workstations and CI runners for reliable builds.
When a Linux process receives SIGKILL (signal 9), the shell and container runtimes encode its exit status as 128 + 9 = 137. In Yocto builds, OOM kills show up in two ways depending on which process hits the memory ceiling:
do_compile (most common on bare-metal/VM hosts): The kernel OOM killer terminates cc1plus or ld. The compiler driver reports Killed signal terminated program, ninja or make exits non-zero, and BitBake logs failed with exit code '1'.docker --memory or Kubernetes pods), hitting the cgroup memory limit kills the main build process or container entrypoint, terminating the CI step with exit code 137.| aarch64-poky-linux-g++: fatal error: Killed signal terminated program cc1plus| compilation terminated.| ninja: build stopped: subcommand failed.ERROR: Task (/path/to/qtwebengine_git.bb:do_compile) failed with exit code '1'
Inspect kernel logs with dmesg -T (or journalctl -k on systemd hosts without /var/log/kern.log) immediately after the failure:
[9723286.547942] cc1plus invoked oom-killer: gfp_mask=0x100cca(GFP_HIGHUSER_MOVABLE), order=0, oom_score_adj=0[9723286.548289] Out of memory: Killed process 3575699 (cc1plus) total-vm:2776588kB, anon-rss:2485028kB, file-rss:0kB, shmem-rss:0kB
The Linux kernel OOM killer evaluates oom_badness() (exposed per process via /proc/<pid>/oom_score), ranking candidates primarily by anonymous + file RSS, swap usage, and page-table memory relative to total system RAM + swap, adjusted by oom_score_adj. In Yocto builds, the highest-scoring processes are almost always cc1plus, rustc, or the ELF linker (ld / ld.lld) processing large C++ or Rust translation units.
Key insight: The OOM killer triggers because total committed/active memory demand exceeds physical RAM plus available swap (or a container cgroup limit). It is a host resource-sizing and concurrency-control issue, not a BitBake defect.
+------------------------------------------------------------------+| MEMORY PRESSURE TIMELINE || || Build Start Mid-Build OOM Event || [====] [==============] [XXXXXXXX] || RAM: 20% RAM: 85% RAM: 99%+ || Swap: 0% Swap: 40% Swap: 100% || || Physical RAM + swap exhausted -> kernel invokes OOM killer || Highest oom_score victim: usually cc1plus or ld || Result: cc1plus gets SIGKILL -> task fails (or CI exits 137) |+------------------------------------------------------------------+
Four interacting factors drive Yocto memory spikes past host limits:
In OpenEmbedded-Core (meta/conf/bitbake.conf), both task-level and compiler-level concurrency default to the host CPU affinity count via oe.utils.cpu_count() (which checks len(os.sched_getaffinity(0)), clamped between 1 and 64):
BB_NUMBER_THREADS ?= "${@oe.utils.cpu_count()}"PARALLEL_MAKE ?= "-j ${@oe.utils.cpu_count()}"
Notice that BB_NUMBER_THREADS and PARALLEL_MAKE operate at two independent levels and multiply:
BB_NUMBER_THREADS caps how many distinct BitBake tasks (across recipes) run simultaneously in the RunQueue.PARALLEL_MAKE caps how many parallel compile jobs (make, ninja via cmake/meson/qtwebengine) each recipe’s do_compile task can spawn.On a 32-vCPU workstation or shared build server, defaults allow up to 32 concurrent BitBake tasks, each allowed -j 32 compiler jobs — a theoretical ceiling of 32 * 32 = 1024 simultaneous compiler/linker processes. Even if only a single heavy C++ recipe reaches 32 parallel cc1plus jobs at 1.5-2.0 GB RSS each, memory demand jumps to 48-64 GB immediately. As noted in the Yocto Project Reference Manual, setting BB_NUMBER_THREADS = "1" alone does not prevent a single task from consuming all resources if PARALLEL_MAKE remains high, and on large multi-socket hosts BB_NUMBER_THREADS should generally be capped (the manual suggests not exceeding 20 without tuning).
+------------------------------------------------------------------+| PARALLELISM MULTIPLICATION || || BB_NUMBER_THREADS = 32 (concurrent BitBake tasks) || | || +-> Task A: qtwebengine -> PARALLEL_MAKE = "-j 32" || | +-> up to 32 x cc1plus / ld || +-> Task B: llvm -> PARALLEL_MAKE = "-j 32" || | +-> up to 32 x cc1plus / ld || +-> Task C: chromium-x11 -> PARALLEL_MAKE = "-j 32" || | +-> up to 32 x cc1plus / ld || ... || || Theoretical ceiling: 32 tasks * 32 jobs = 1024 processes || Even 32 heavy C++ units at 1.5-2.0 GB RSS = 48-64 GB RAM |+------------------------------------------------------------------+
Certain recipes dominate peak RSS because they combine deep C++/template metaprogramming, unified/jumbo translation units, embedded V8/LLVM/Chromium trees, or heavy Rust codegen. The table below lists typical peak per-task RSS ranges observed on x86_64 hosts under moderate parallelism:
Recipe (PN) | Typical Peak Footprint (RSS) | Primary Memory Driver |
|---|---|---|
qtwebengine (meta-qt5 / meta-qt6) | 8-20+ GB | Embedded Chromium/Blink C++ templates, unified builds, libQt*WebEngineCore.so link |
chromium-x11 / chromium-wayland | 8-20+ GB | Huge Chromium tree, parallel cc1plus/Clang jobs, massive final ELF link |
webkitgtk | 6-14 GB | Large C++ template units, unified source bundles, JSC/WebCore linking |
llvm / llvm-native / clang | 4-12 GB | Heavy C++ AST/IR passes, llvm-tblgen, large shared library links, optional LTO |
rust / Cargo recipes | 4-8+ GB | Parallel rustc LLVM codegen units, proc-macro crates, whole-crate LTO |
firefox | 6-14 GB | Unified C++ compilation, SpiderMonkey, Rust/Servo components, libxul.so link |
nodejs / nodejs-native | 3-6 GB | V8 C++ compilation and mksnapshot generation |
mesa (with LLVM/Rusticl) | 2-5 GB | Gallium/LLVM shader compiler and Rust/C++ driver builds |
Unlike per-translation-unit compilation, linking a massive shared library such as libQt6WebEngineCore.so or libxul.so happens at the end of do_compile (before do_install and do_package) and requires loading symbol tables, relocations, and debug sections from hundreds of megabytes of object files simultaneously.
By default, Yocto uses GNU Binutils ld.bfd, which caches all input file symbol tables in RAM (--keep-memory) and runs single-threaded (unlike ld.lld, ld.gold, or mold, GNU ld.bfd does not distribute full ELF linking across --threads). A single ld.bfd invocation linking Chromium/WebEngine with full DWARF debug info can spike to 4-8+ GB RSS on its own. If BB_NUMBER_THREADS allows two or three heavy recipes to hit their link phase at the same time, memory exhausts within seconds.
For ld.bfd, passing --no-keep-memory trades extra disk I/O for substantially lower linker RSS:
# Force GNU ld.bfd to discard cached symbol tables instead of holding them in RAMLDFLAGS:append:pn-qtwebengine = " -Wl,--no-keep-memory"
xz CompressionIn meta/conf/bitbake.conf, OpenEmbedded enables debug symbols by default inside FULL_OPTIMIZATION: Yocto 5.1 (Styhead) and newer isolate the level flag in DEBUG_LEVELFLAG ?= "-g", while Yocto 5.0 (Scarthgap) and 4.0 (Kirkstone) include -g inside DEBUG_FLAGS ?= "-g -feliminate-unused-debug-types ${DEBUG_PREFIX_MAP}". (Layers also tune this per recipe: meta-qt6’s qtwebengine.inc downgrades -g to line-tables-only -g1 to curb binary size and relocation overflows, whereas meta-qt5 sets CONFIG+=force_debug_info.) Generating full DWARF sections substantially inflates .o file size and increases both cc1plus and ld RAM usage during do_compile.
Two separate mechanisms control debug data across tasks:
DEBUG_LEVELFLAG / DEBUG_FLAGS): Dropping -g (or switching to line-tables-only -g1) reduces compiler and linker memory usage during do_compile.INHIBIT_PACKAGE_DEBUG_SPLIT): During do_package, oe.package.process_split_and_strip_files() in meta/lib/oe/package.py spawns parallel workers (splitdebuginfo) running objcopy --only-keep-debug and debugedit to extract .debug files into -dbg packages. Setting INHIBIT_PACKAGE_DEBUG_SPLIT = "1" skips that do_package split step (saving peak memory and time during do_package), but does not stop cc1plus or ld from generating DWARF during do_compile. Note also that as long as INHIBIT_PACKAGE_STRIP is not set to "1" (default), binaries are still stripped when packaged, so you simply omit -dbg packages; setting both INHIBIT_PACKAGE_DEBUG_SPLIT = "1" and INHIBIT_PACKAGE_STRIP = "1" leaves unstripped debug binaries in the target rootfs.Additionally, bitbake.conf sets XZ_MEMLIMIT ?= "50%" and XZ_THREADS ?= "${@oe.utils.cpu_count(at_least=2)}" for xz compression during packaging and rootfs image creation (do_package_write_* / do_image_*). Because xz computes percentages against host physical RAM rather than container cgroup limits (on older xz releases) and multiple packaging tasks can run concurrently, XZ_MEMLIMIT can trigger OOM kills during packaging on constrained VMs or containers.
conf/local.confAdd explicit task and make limits to build/conf/local.conf. Use ?= (weak default assignment) if you want CI environment variables to override them:
# Limit concurrent BitBake tasks globally (default: host CPU count)BB_NUMBER_THREADS ?= "8"# Limit parallel jobs per recipe (make, cmake, meson, ninja-wrapped recipes)PARALLEL_MAKE ?= "-j 8"# Optional: Throttle GNU make / ninja job spawning when host load average exceeds NPARALLEL_MAKE:append = " -l 8"
The -l (load-average limit) flag instructs GNU make and ninja not to start additional jobs while host load average exceeds the threshold, smoothing ramp-up bursts. Note a subtle OpenEmbedded detail: oe.utils.parallel_make() (used by cmake.bbclass to set CMAKE_BUILD_PARALLEL_LEVEL) extracts only the integer after -j and discards -l, whereas GNU make, meson.bbclass, and NINJAFLAGS forward the full PARALLEL_MAKE string including -l.
Choosing initial values: Check your host’s physical cores rather than hyper-threaded logical CPUs, and budget roughly 2 GB of RAM per parallel heavy C++ job:
# Count physical CPU cores across all sockets (excluding SMT/Hyper-Threading siblings)lscpu -p=CORE | grep -v '^#' | sort -u | wc -l
For example, on a 16-core machine with 32 GB RAM, start with BB_NUMBER_THREADS ?= "6" and PARALLEL_MAKE ?= "-j 6" (or 8/8 with swap). On a 16 GB laptop, start with 4 and 4.
A widespread misconception in Yocto snippets is putting :pn-<recipe> on BB_NUMBER_THREADS:
# WRONG: BitBake's RunQueue reads BB_NUMBER_THREADS globally from cfgData;# recipe-specific :pn- overrides on BB_NUMBER_THREADS are silently ignored.# BB_NUMBER_THREADS:pn-qtwebengine = "1"
Because BB_NUMBER_THREADS is read once globally by BitBake’s RunQueue (self.cfgData.getVar("BB_NUMBER_THREADS") in lib/bb/runqueue.py), :pn-<recipe> overrides on BB_NUMBER_THREADS have no effect.
By contrast, PARALLEL_MAKE, PARALLEL_MAKEINST, LDFLAGS, DEBUG_LEVELFLAG (>= 5.1), DEBUG_FLAGS (<= 5.0), and INHIBIT_PACKAGE_DEBUG_SPLIT are evaluated in each recipe’s datastore and support :pn-<recipe> overrides cleanly:
# QtWebEngine: serialize compilation and linking, and reduce linker RAMPARALLEL_MAKE:pn-qtwebengine = "-j 1"LDFLAGS:append:pn-qtwebengine = " -Wl,--no-keep-memory"# LLVM / Clang: cap parallel jobs to 2PARALLEL_MAKE:pn-llvm = "-j 2"PARALLEL_MAKE:pn-llvm-native = "-j 2"# Chromium: serialize compile and linkPARALLEL_MAKE:pn-chromium-x11 = "-j 1"PARALLEL_MAKE:pn-chromium-wayland = "-j 1"# Node.js native V8 snapshot buildPARALLEL_MAKE:pn-nodejs-native = "-j 2"# Cargo / Rust recipes: Cargo uses -j or CARGO_BUILD_JOBS rather than PARALLEL_MAKECARGO_BUILD_FLAGS:append:pn-my-rust-app = " -j 2"
Note on Rust/Cargo: OpenEmbedded-Core’s cargo.bbclass passes ${CARGO_BUILD_FLAGS} directly to cargo build (and there is no RUST_CODEGEN_UNITS BitBake variable). Reducing Cargo’s -j (or exporting CARGO_BUILD_JOBS) caps concurrent rustc invocations. Avoid forcing -C codegen-units=1 when trying to fix OOMs — fewer codegen units force LLVM to optimize larger chunks per rustc process, which typically increases peak per-process RSS.
PARALLEL_MAKE Reaches cmake, meson, and ninjaUnlike GNU Make, ninja ignores MAKEFLAGS completely. Fortunately, OpenEmbedded-Core and Qt layers wire PARALLEL_MAKE into ninja-based builds automatically:
cmake.bbclass (which defaults to OECMAKE_GENERATOR ?= "Ninja"): Parses PARALLEL_MAKE with oe.utils.parallel_make() and exports CMAKE_BUILD_PARALLEL_LEVEL for do_compile and do_install.meson.bbclass: Runs ninja --verbose ${PARALLEL_MAKE} ${MESON_TARGET} directly inside meson_do_compile().meta-qt5 / meta-qt6 (qtwebengine_git.bb): Explicitly sets export NINJAFLAGS = "${PARALLEL_MAKE}" so Chromium’s nested ninja invocation obeys PARALLEL_MAKE:pn-qtwebengine.Only if a custom third-party recipe invokes ninja manually in do_compile without inheriting cmake/meson or exporting NINJAFLAGS do you need a .bbappend to pass ${PARALLEL_MAKE} (or ${@oe.utils.parallel_make_argument(d, '-j %d')}) to ninja directly.
In CI pipelines, you can inject BB_NUMBER_THREADS and PARALLEL_MAKE from the shell environment without editing tracked config files:
export BB_NUMBER_THREADS=4export PARALLEL_MAKE="-j 4"source oe-init-build-env buildbitbake core-image-minimal
Two strict rules govern environment overrides in BitBake:
BB_ENV_PASSTHROUGH_ADDITIONS (since Yocto 4.0 Kirkstone / BitBake 2.0; earlier releases used BB_ENV_EXTRAWHITE). Running source oe-init-build-env (scripts/oe-buildenv-internal) automatically adds BB_NUMBER_THREADS and PARALLEL_MAKE to BB_ENV_PASSTHROUGH_ADDITIONS. Variables not in that list (such as BB_PRESSURE_MAX_MEMORY) are ignored from the shell unless you append them to BB_ENV_PASSTHROUGH_ADDITIONS.local.conf: Environment variables take precedence only if conf/local.conf uses ?= (for example, BB_NUMBER_THREADS ?= "8"). A hard assignment (BB_NUMBER_THREADS = "8") in local.conf is evaluated after environment import and overwrites the shell value.When physical RAM is tight (16-32 GB workstations, VMs, or CI runners), swap gives the Linux virtual memory manager backing storage to page out cold anonymous memory rather than invoking the OOM killer during transient link or compile spikes.
On ext4 or modern xfs filesystems:
# Create a 16 GB swap file (adjust size to available disk space)sudo fallocate -l 16G /swapfilesudo chmod 600 /swapfilesudo mkswap /swapfilesudo swapon /swapfile# Persist across rebootsecho '/swapfile none swap sw 0 0' | sudo tee -a /etc/fstab
On Btrfs, standard fallocate swapfiles fail swapon unless Copy-on-Write (CoW) is disabled on the file (truncate -s 0 /swapfile && chattr +C /swapfile && fallocate -l 16G /swapfile) or you use sudo btrfs filesystem mkswapfile --size 16G /swapfile (btrfs-progs 6.1+).
| Physical RAM | Recommended Swap | Notes |
|---|---|---|
| 8 GB | 16-24 GB | Required for any modern C++/Qt/LLVM build |
| 16 GB | 16-32 GB | Allows qtwebengine/chromium links to survive spikes |
| 32 GB | 8-16 GB | Safety buffer for concurrent links and cc1plus bursts |
| 64 GB+ | 4-8 GB | Optional headroom; mostly avoids sudden OOM edge cases |
Trade-off: Disk swap is orders of magnitude slower than RAM. Heavy swapping slows compilation noticeably, but builds complete cleanly instead of crashing after two hours.
+------------------------------------------------------------------+| SWAP EFFECT ON BUILD OUTCOME || || NO SWAP (16 GB RAM, unthrottled 32-core build): || [BUILD]=======> [OOM KILL] [FAIL] || Result: Killed mid-compile (exit 137 / task exit 1) || || WITH 16 GB SWAP (16 GB RAM, unthrottled 32-core build): || [BUILD]===============> [SWAP ACTIVE]=========> [OK] || Result: Heavy paging slows build, but link/compile completes || || WITH SWAP + BOUNDED PARALLELISM (BB=4, PARALLEL="-j 4"): || [BUILD]===============================> [OK] || Result: Fits comfortably in RAM with minimal swap thrashing |+------------------------------------------------------------------+
The kernel’s vm.swappiness sysctl (0-200 since Linux 5.8; default 60) tunes the relative preference for reclaiming anonymous memory (to swap) versus dropping file-backed page cache. For builds backed by disk/SSD swap, a moderate-to-low value such as 10 or 20 avoids prematurely paging out active compiler working sets while still allowing swap under memory pressure:
# Temporary (until reboot)sudo sysctl -w vm.swappiness=10# Persistent across rebootsecho 'vm.swappiness=10' | sudo tee /etc/sysctl.d/99-yocto-swap.confsudo sysctl --system
zswap vs zram: Compressed Swap MechanicsBoth zswap and zram compress swap pages in RAM (compiler ASTs and linker buffers typically compress 2:1 to 3:1 with zstd or lz4), but they work differently:
zswap (compressed cache in front of disk swap): Requires an active disk swap file or partition as backing store. Before writing a page to disk swap, zswap compresses and holds it in a bounded RAM pool (max_pool_percent of physical RAM, default 20), evicting LRU pages to disk only when the pool fills.zram (compressed RAM block device): Creates an in-RAM compressed swap device without requiring disk I/O, but its compressed pool consumes physical RAM. On a 16 GB host compiling QtWebEngine, zram alone cannot hold a 20 GB uncompressed spike without also keeping a lower-priority disk swap file as overflow.To configure zram on modern Ubuntu/Debian (22.04 / 24.04), install systemd-zram-generator (or zram-tools) rather than legacy zram-config, and verify with zramctl:
sudo apt-get install -y systemd-zram-generatorsudo tee /etc/systemd/zram-generator.conf > /dev/null <<'EOF'[zram0]zram-size = ram * 0.5compression-algorithm = zstdswap-priority = 100EOFsudo systemctl daemon-reloadsudo systemctl start systemd-zram-setup@zram0.servicezramctl
Or enable kernel zswap alongside a disk swap file (requires CONFIG_ZSWAP=y and zstd crypto support in the host kernel):
echo zstd | sudo tee /sys/module/zswap/parameters/compressorecho 20 | sudo tee /sys/module/zswap/parameters/max_pool_percentecho 1 | sudo tee /sys/module/zswap/parameters/enabled
Modern BitBake versions support dynamic throttling using Linux kernel Pressure Stall Information (PSI). Support was integrated in Yocto 4.1 Langdale / BitBake 2.2 (2022) and backported to Yocto 4.0 Kirkstone point releases.
conf/local.confBitBake exposes three PSI limit variables (all measured in the same units):
# Throttle launching new tasks when PSI 'some' total stall delta exceeds threshold (us/s)# Valid range: 1.0 to 1000000.0BB_PRESSURE_MAX_MEMORY = "15000"BB_PRESSURE_MAX_CPU = "15000"BB_PRESSURE_MAX_IO = "15000"
Critical unit and range check: Unlike static RAM limits, BB_PRESSURE_MAX_MEMORY is not in megabytes, and BB_PRESSURE_MAX_CPU is not a 0.0-1.0 CPU utilization fraction. In BitBake’s lib/bb/runqueue.py, every BB_PRESSURE_MAX_* variable enforces lower_limit = 1.0 and upper_limit = 1000000.0. Setting BB_PRESSURE_MAX_CPU = "0.85" or BB_PRESSURE_MAX_MEMORY = "0" immediately aborts the build with bb.fatal("Invalid BB_PRESSURE_MAX_..."). Leave a variable unset (or empty "") to disable monitoring for that resource.
Kernel PSI files (/proc/pressure/cpu, /proc/pressure/memory, /proc/pressure/io, available on Linux 4.20+ with CONFIG_PSI=y) report two stall classes (cpu sets full to zero at the system level for compatibility):
some avg10=0.00 avg60=0.00 avg300=0.00 total=0full avg10=0.00 avg60=0.00 avg300=0.00 total=0
| Line | Meaning | Fields |
|---|---|---|
some | Share of time at least one task is stalled waiting for the resource | avg10, avg60, avg300 (%), total (cumulative microseconds) |
full | Share of time all non-idle tasks are stalled simultaneously (thrashing) | avg10, avg60, avg300 (%), total (cumulative microseconds) |
Inside RunQueueExecute.exceeds_max_pressure() (lib/bb/runqueue.py), BitBake:
total= from line 1 (some) of /proc/pressure/{cpu,io,memory}.(curr_total - prev_total) / tdiff over a fixed 1-second accumulation window (psi_accumulation_interval = 1.0 s), yielding stall microseconds per second (us/s) — for example, 15000 equals 15 ms of stall per second (1.5% partial stall rate).BB_PRESSURE_MAX_* limit and at least one task is already running, BitBake holds off starting new tasks until the 1-second stall rate drops below the limit.When PSI is unavailable on an older host kernel, BitBake falls back to BB_LOADFACTOR_MAX (for example, BB_LOADFACTOR_MAX = "1.5", which compares 1-minute load average divided by os.cpu_count()). Any BB_PRESSURE_MAX_* setting overrides BB_LOADFACTOR_MAX.
Because stall rates depend on host storage speed, RAM capacity, and swap responsiveness, tune thresholds empirically using the procedure from the Yocto Project Development Tasks Manual:
# Sample 1-second delta of /proc/pressure/memory 'total' (in us/s) while running a buildpressure=$(head -1 /proc/pressure/memory | cut -d ' ' -f5 | cut -d '=' -f2)while true; dosleep 1prev_pressure="$pressure"pressure=$(head -1 /proc/pressure/memory | cut -d ' ' -f5 | cut -d '=' -f2)echo $((pressure - prev_pressure))done
Once you pick a starting threshold (e.g., "15000"), verify throttling behavior live with RunQueue PSI logging:
bitbake virtual/kernel -c compile -f --verbose --log-domains BitBake.RunQueue.PSI
And watch Pressure status changed transitions in the cooker log:
tail -F tmp/log/cooker/<machine>/console-latest.log | grep "Pressure status changed"
If BitBake continuously prints Mem: True and throttles down to 1/N bitbake threads on tiny deltas, raise BB_PRESSURE_MAX_MEMORY. If memory stalls climb near OOM before throttling triggers, lower the threshold (for instance, from 15000 down to 5000 or 2000).
4.20+ with CONFIG_PSI=y: Some distro kernels or lightweight VMs omit PSI or return EOPNOTSUPP on read (in which case BitBake logs a note and disables pressure checking)./proc/pressure/* inside containers: BitBake reads /proc/pressure/* directly rather than cgroup2’s memory.pressure. Inside a memory-capped container (such as docker run --memory=16g on a 128 GB host), host /proc/pressure/memory can stay near zero even right before the container hits its cgroup OOM ceiling.PARALLEL_MAKE jobs already running inside a single massive recipe such as qtwebengine. Always combine PSI limits with sane PARALLEL_MAKE overrides.# Check kernel ring buffer / systemd journal for OOM killer eventsdmesg -T | grep -iE "oom|killed process" | tail -20journalctl -k --no-pager | grep -iE "oom|killed process" | tail -20
BitBake’s console error and tmp/log/cooker/<machine>/console-latest.log already identify the exact failing recipe .bb path, task name, and log.do_compile location:
grep -E "ERROR: Task|Logfile of failure" tmp/log/cooker/*/console-latest.log | tail -10
Inspect live compiler/linker memory usage during a suspect build with pidstat (sysstat package):
pidstat -r -C "cc1plus|ld|lld|rustc" 2
For post-mortem per-task peak memory across an entire image build, inspect Yocto’s buildstats data (enabled by default in local.conf.sample via USER_CLASSES ?= "buildstats"): each task file under tmp/buildstats/ records Child rusage ru_maxrss (in KB on Linux). To inspect task dependencies that run concurrently alongside a memory-hungry recipe on a headless SSH server or CI environment, use the ncurses task explorer (or GTK taskexp locally):
# Terminal UI (works over SSH without X11/GTK)bitbake -g -u taskexp_ncurses <target># Desktop GTK UIbitbake -g -u taskexp <target>
Remember that bitbake -c clean <recipe> && bitbake <recipe> often restores from sstate-cache without re-running do_compile. Force execution of do_compile (or use cleansstate) when benchmarking peak RSS:
/usr/bin/time -v bitbake -c compile -f <recipe>
Look for Maximum resident set size (kbytes) in /usr/bin/time -v output and verify task boundaries in tmp/work/*/<recipe>/*/temp/log.do_compile.
Add per-recipe limits in build/conf/local.conf (or a distro include file):
PARALLEL_MAKE:pn-<recipe> = "-j 1"LDFLAGS:append:pn-<recipe> = " -Wl,--no-keep-memory"# Optional if full DWARF symbols are not required for debugging this recipe:# Yocto 5.1+ (Styhead and newer):DEBUG_LEVELFLAG:pn-<recipe> = ""# Yocto 4.0 / 5.0 (Kirkstone / Scarthgap): omit -g/-g1 from optimization flags# FULL_OPTIMIZATION:pn-<recipe> = "-O2 -pipe ${DEBUG_PREFIX_MAP}"INHIBIT_PACKAGE_DEBUG_SPLIT:pn-<recipe> = "1"
If OOM occurs during multi-recipe concurrency rather than inside a single recipe, lower global BB_NUMBER_THREADS as well.
bitbake -c compile -f <recipe>bitbake <target>
Monitor free -h, vmstat 5, and dmesg -w during the rebuild to confirm swap pressure remains bounded and zero OOM kills occur.
Record measured resource profiles once builds pass cleanly:
# Build Baseline (2026-11-30)Host: 16 physical cores, 32 GB RAM, 16 GB swapImage: core-image-minimal + qtwebengineBB_NUMBER_THREADS: 6PARALLEL_MAKE: -j 6 (qtwebengine: -j 1)Peak task RSS: 14.2 GBPeak swap used: 2.1 GBDuration: 1h 42mOOM events: 0
# .gitlab-ci.yml (requires VM/privileged executor for host swap setup;# ensure conf/local.conf uses ?= for BB_NUMBER_THREADS and PARALLEL_MAKE)variables:BB_NUMBER_THREADS: "4"PARALLEL_MAKE: "-j 4"before_script:- |if [ ! -f /swapfile ]; thenSUDO=""[ "$(id -u)" -ne 0 ] && SUDO="sudo"$SUDO fallocate -l 16G /swapfile$SUDO chmod 600 /swapfile$SUDO mkswap /swapfile$SUDO swapon /swapfilefibuild:script:- source oe-init-build-env build- bitbake core-image-minimal
Standard public GitHub-hosted ubuntu-latest (ubuntu-24.04) runners provide 4 vCPUs, 16 GB RAM, and 14 GB free SSD space (meaning real Yocto image builds typically run on larger/self-hosted runners with 100+ GB storage, or aggressively reclaim runner disk space first). Ensure required Yocto host packages from the Yocto Project Reference Manual are installed and PSI thresholds use valid us/s integers:
name: Yocto Buildon:push:branches: [main]pull_request:branches: [main]jobs:build:runs-on: [self-hosted, linux, x64]timeout-minutes: 240steps:- uses: actions/checkout@v4- name: Configure swaprun: |if ! swapon --show | grep -q '/swapfile'; thensudo fallocate -l 16G /swapfilesudo chmod 600 /swapfilesudo mkswap /swapfilesudo swapon /swapfilefiecho "vm.swappiness=10" | sudo tee /etc/sysctl.d/99-yocto.confsudo sysctl --system- name: Install Yocto host dependenciesrun: |sudo apt-get updatesudo apt-get install -y build-essential chrpath cpio debianutils \diffstat file gawk gcc git iputils-ping libacl1 libcrypt-dev \locales python3 python3-git python3-jinja2 python3-pexpect \python3-pip python3-subunit socat texinfo unzip wget xz-utils zstd- name: Configure local.confrun: |source oe-init-build-env buildcat >> conf/local.conf <<'EOF'BB_NUMBER_THREADS ?= "4"PARALLEL_MAKE ?= "-j 4"BB_PRESSURE_MAX_MEMORY = "15000"BB_PRESSURE_MAX_CPU = "15000"EOF- name: Build imagerun: |source oe-init-build-env buildbitbake core-image-minimal- name: Upload image artifactsuses: actions/upload-artifact@v4with:name: build-outputpath: build/tmp/deploy/images/
Configure persistent kernel VM tuning once on dedicated build agents. Keep vm.oom_kill_allocating_task = 0 (the default) so that if an OOM ever occurs, the kernel uses oom_badness() to target the runaway memory consumer rather than arbitrarily killing whichever process happened to request the last page:
# /etc/sysctl.d/99-yocto-oom.confvm.oom_kill_allocating_task = 0vm.panic_on_oom = 0vm.swappiness = 10
Apply with sudo sysctl --system, and run the pipeline with bounded parallelism:
pipeline {agent { label 'yocto-build' }environment {BB_NUMBER_THREADS = '8'PARALLEL_MAKE = '-j 8'}stages {stage('Setup') {steps {sh '''if [ ! -f /swapfile ]; thensudo fallocate -l 32G /swapfilesudo chmod 600 /swapfilesudo mkswap /swapfilesudo swapon /swapfilefi'''}}stage('Build') {steps {sh '''source oe-init-build-env buildbitbake core-image-minimal'''}}}}
Docker containers share the host kernel’s swap subsystem automatically unless constrained by container cgroup limits. Do not attempt swapon or modprobe zram inside an unprivileged build container; instead, configure swap on the Docker host and set cgroup limits properly:
# Dockerfile for Yocto build container (Ubuntu 24.04)FROM ubuntu:24.04RUN apt-get update && apt-get install -y --no-install-recommends \build-essential chrpath cpio debianutils diffstat file gawk gcc git \iputils-ping libacl1 libcrypt-dev locales python3 python3-git \python3-jinja2 python3-pexpect python3-pip python3-subunit socat \texinfo unzip wget xz-utils zstd && \locale-gen en_US.UTF-8 && \rm -rf /var/lib/apt/lists/*
In Docker’s --memory and --memory-swap flags, --memory-swap specifies total combined RAM + swap (not swap alone), and requires --memory to be set:
# Allows 16 GB physical RAM + 16 GB host swap = 32 GB total cgroup limit# (requires at least 16 GB swap configured on the Docker host)docker run --rm --memory=16g --memory-swap=32g yocto-build
Remember that /proc/pressure/memory inside a container reflects host-wide pressure rather than the container’s cgroup memory ceiling. On memory-capped containers, rely on explicit BB_NUMBER_THREADS, PARALLEL_MAKE, and a fixed megabyte XZ_MEMLIMIT (such as XZ_MEMLIMIT = "1024M" rather than a percentage of host RAM) instead of BB_PRESSURE_MAX_MEMORY.
SSTATE_MIRRORS)Sharing sstate-cache and downloads eliminates repeated builds of LLVM, Node.js, or QtWebEngine across CI runs. Because Yocto sstate-cache trees routinely grow to tens of gigabytes (exceeding GitHub Actions’ 10 GB per-repository cache limit), production CI pipelines usually serve a shared SSTATE_MIRRORS over HTTP/HTTPS or NFS rather than uploading sstate-cache through artifact caches:
# Point CI runners to a shared sstate mirrorSSTATE_MIRRORS ?= "file://.* https://sstate.internal.example.com/PATH;downloadfilename=PATH"
conf/local.conf (or Distro Config)Use ?= for global defaults so CI environment variables can apply stricter limits, and put :pn-<recipe> overrides only on variables evaluated per recipe:
# Conservative defaults (overrideable via environment variables)BB_NUMBER_THREADS ?= "8"PARALLEL_MAKE ?= "-j 8 -l ${@oe.utils.cpu_count()}"# Recipe-specific overrides for known memory-intensive buildsPARALLEL_MAKE:pn-qtwebengine = "-j 1"LDFLAGS:append:pn-qtwebengine = " -Wl,--no-keep-memory"PARALLEL_MAKE:pn-llvm = "-j 2"PARALLEL_MAKE:pn-llvm-native = "-j 2"PARALLEL_MAKE:pn-nodejs-native = "-j 2"PARALLEL_MAKE:pn-chromium-x11 = "-j 1"PARALLEL_MAKE:pn-chromium-wayland = "-j 1"PARALLEL_MAKE:pn-firefox = "-j 1"PARALLEL_MAKE:pn-webkitgtk = "-j 1"
# Requires BitBake 2.2+ (Langdale / Kirkstone backports) and Linux 4.20+ PSI# Units: cumulative 'total' stall delta in microseconds/second (1.0 - 1000000.0)BB_PRESSURE_MAX_MEMORY = "15000"BB_PRESSURE_MAX_CPU = "15000"BB_PRESSURE_MAX_IO = "15000"
xz Compression Memory and Control Debug Info OverheadWhere full DWARF debug packages are unnecessary on large browser/compiler recipes, reduce compile-time debug generation (DEBUG_LEVELFLAG on Yocto >= 5.1, or FULL_OPTIMIZATION / DEBUG_FLAGS on <= 5.0) and skip do_package splitting with INHIBIT_PACKAGE_DEBUG_SPLIT. Also tighten XZ_MEMLIMIT with an explicit byte/megabyte cap so concurrent packaging or image compression tasks inside VMs or containers cannot claim 50% of host RAM apiece:
# Reduce compile/link DWARF memory on massive C++ recipes (Yocto 5.1+)DEBUG_LEVELFLAG:pn-qtwebengine = ""# For Yocto 4.0/5.0 (Kirkstone/Scarthgap), use FULL_OPTIMIZATION or DEBUG_FLAGS:# FULL_OPTIMIZATION:pn-qtwebengine = "-O2 -pipe ${DEBUG_PREFIX_MAP}"INHIBIT_PACKAGE_DEBUG_SPLIT:pn-qtwebengine = "1"INHIBIT_PACKAGE_DEBUG_SPLIT:pn-chromium-x11 = "1"INHIBIT_PACKAGE_DEBUG_SPLIT:pn-webkitgtk = "1"# Prevent concurrent xz packaging/image tasks from claiming 50% host RAM eachXZ_MEMLIMIT = "1024M"
rm_work and Linker Memory ControlsEnable rm_work in local.conf to clean intermediate build artifacts as recipes finish (INHERIT += "rm_work"), keeping disk cache pressure low on CI nodes, and pair ld.bfd recipes with -Wl,--no-keep-memory (or switch high-memory builds to ld.lld via meta-clang where supported). Note that BitBake pressure throttling never aborts an active task — it only delays starting new tasks while at least one task is running — so critical deployment/signing tasks always run to completion once started.
Create docs/yocto-build-tuning.md for your repository so every engineer and CI template uses consistent defaults:
# Yocto Build Tuning Guidelines## Local Workstations- 16 GB RAM laptop: BB_NUMBER_THREADS = "4", PARALLEL_MAKE = "-j 4"- 32 GB RAM desktop: BB_NUMBER_THREADS = "8", PARALLEL_MAKE = "-j 8"- 64 GB+ RAM workstation: BB_NUMBER_THREADS = "16", PARALLEL_MAKE = "-j 12"## CI Runners- 16 GB RAM runner: BB_NUMBER_THREADS=4, PARALLEL_MAKE="-j 4" + 16 GB swap- 32 GB RAM runner: BB_NUMBER_THREADS=8, PARALLEL_MAKE="-j 8" + 16 GB swap## Adding Memory-Intensive Recipes- If a recipe triggers OOM: add PARALLEL_MAKE:pn-<recipe> = "-j 1"- Profile with: /usr/bin/time -v bitbake -c compile -f <recipe>- Verify under watch: dmesg -T | grep -iE "oom|killed process"
For an emergency single-threaded override on a local machine (remembering that BB_PRESSURE_MAX_MEMORY = "0" triggers bb.fatal, so comment it out or set it to "" in conf/local.conf):
export BB_NUMBER_THREADS=1export PARALLEL_MAKE="-j 1"bitbake <target>
Track peak ru_maxrss from tmp/buildstats/, total build duration, swap usage (free -h), and post-build kernel OOM checks (note dmesg inside restricted hosts/containers may require CAP_SYSLOG or host-level log access):
#!/bin/bash# check-oom.sh -- fail CI step if host kernel logged an OOM killif dmesg -T 2>/dev/null | grep -qE "Out of memory: Killed process|oom-killer"; thenecho "::error::OOM kill detected during Yocto build"exit 1fi
BB_NUMBER_THREADS, PARALLEL_MAKE, BB_PRESSURE_MAX_*)vm.swappiness, vm.oom_kill_allocating_task)--memory, --memory-swap)Yocto BitBake OOM failures occur when unconstrained task-level and compiler-level parallelism (BB_NUMBER_THREADS * PARALLEL_MAKE), linker caching (ld.bfd), and debug/compression settings overwhelm host RAM and swap. To eliminate them reliably:
BB_NUMBER_THREADS ?= ... and PARALLEL_MAKE ?= ..., and apply PARALLEL_MAKE:pn-<recipe> (plus -Wl,--no-keep-memory for ld.bfd) to qtwebengine, llvm, chromium-x11 / chromium-wayland, webkitgtk, and nodejs-native — remembering that BB_NUMBER_THREADS ignores :pn- overrides.zswap backed by disk swap) with tuned vm.swappiness on workstations and CI VMs.BB_PRESSURE_MAX_MEMORY, BB_PRESSURE_MAX_CPU, and BB_PRESSURE_MAX_IO (in us/s over 1-second PSI intervals, range 1.0 to 1000000.0) on Linux 4.20+ bare-metal/VM hosts.?= in conf/local.conf for CI overrides, cap XZ_MEMLIMIT, share SSTATE_MIRRORS, and monitor buildstats peak RSS and kernel OOM logs in CI.Quick Links
Legal Stuff





