HomeAbout UsContact Us

Fixing Yocto Bitbake Out-of-Memory Build Failures

By Jithin Tom
November 30, 2026
10 min read
Fixing Yocto Bitbake Out-of-Memory Build Failures

Table Of Contents

01
The Problem: SIGKILL, Exit Code 137, and Task Exit Code 1
02
Root Cause Analysis: Why Yocto Builds Exhaust Memory
03
Immediate Fixes: Reduce Parallelism
04
Structural Fix: Swap Space
05
Advanced: BitBake PSI Pressure Monitoring
06
Debugging Workflow: From Failure to Fix
07
CI-Specific Strategies
08
Long-Term Guardrails
09
Related Reading
10
References
11
Summary
12
Frequently Asked Questions

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.

The Problem: SIGKILL, Exit Code 137, and Task Exit Code 1

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:

  1. Child compiler/linker killed inside 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'.
  2. BitBake or CI container killed directly: On memory-capped CI runners (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) |
+------------------------------------------------------------------+

Root Cause Analysis: Why Yocto Builds Exhaust Memory

Four interacting factors drive Yocto memory spikes past host limits:

1. Multiplicative Default Parallelism

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 |
+------------------------------------------------------------------+

2. Memory-Hungry Recipes

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+ GBEmbedded Chromium/Blink C++ templates, unified builds, libQt*WebEngineCore.so link
chromium-x11 / chromium-wayland8-20+ GBHuge Chromium tree, parallel cc1plus/Clang jobs, massive final ELF link
webkitgtk6-14 GBLarge C++ template units, unified source bundles, JSC/WebCore linking
llvm / llvm-native / clang4-12 GBHeavy C++ AST/IR passes, llvm-tblgen, large shared library links, optional LTO
rust / Cargo recipes4-8+ GBParallel rustc LLVM codegen units, proc-macro crates, whole-crate LTO
firefox6-14 GBUnified C++ compilation, SpiderMonkey, Rust/Servo components, libxul.so link
nodejs / nodejs-native3-6 GBV8 C++ compilation and mksnapshot generation
mesa (with LLVM/Rusticl)2-5 GBGallium/LLVM shader compiler and Rust/C++ driver builds

3. Linker Memory Spikes

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 RAM
LDFLAGS:append:pn-qtwebengine = " -Wl,--no-keep-memory"

4. Debug Info Generation, Split Debug, and xz Compression

In 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:

  1. Compile/link-time DWARF emission (DEBUG_LEVELFLAG / DEBUG_FLAGS): Dropping -g (or switching to line-tables-only -g1) reduces compiler and linker memory usage during do_compile.
  2. Packaging-time debug splitting (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.

Immediate Fixes: Reduce Parallelism

Global Limits in conf/local.conf

Add 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 N
PARALLEL_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.

Recipe-Specific Overrides (and a Common Pitfall)

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 RAM
PARALLEL_MAKE:pn-qtwebengine = "-j 1"
LDFLAGS:append:pn-qtwebengine = " -Wl,--no-keep-memory"
# LLVM / Clang: cap parallel jobs to 2
PARALLEL_MAKE:pn-llvm = "-j 2"
PARALLEL_MAKE:pn-llvm-native = "-j 2"
# Chromium: serialize compile and link
PARALLEL_MAKE:pn-chromium-x11 = "-j 1"
PARALLEL_MAKE:pn-chromium-wayland = "-j 1"
# Node.js native V8 snapshot build
PARALLEL_MAKE:pn-nodejs-native = "-j 2"
# Cargo / Rust recipes: Cargo uses -j or CARGO_BUILD_JOBS rather than PARALLEL_MAKE
CARGO_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.

How PARALLEL_MAKE Reaches cmake, meson, and ninja

Unlike 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.

Environment Variable Overrides (CI-Friendly)

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=4
export PARALLEL_MAKE="-j 4"
source oe-init-build-env build
bitbake core-image-minimal

Two strict rules govern environment overrides in BitBake:

  1. Passthrough allowlist: BitBake scrubs the host environment for reproducibility unless a variable name appears in 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.
  2. Weak assignment in 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.

Structural Fix: Swap Space

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.

Create a Swap File (Linux)

On ext4 or modern xfs filesystems:

# Create a 16 GB swap file (adjust size to available disk space)
sudo fallocate -l 16G /swapfile
sudo chmod 600 /swapfile
sudo mkswap /swapfile
sudo swapon /swapfile
# Persist across reboots
echo '/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+).

Swap Sizing Guidance

Physical RAMRecommended SwapNotes
8 GB16-24 GBRequired for any modern C++/Qt/LLVM build
16 GB16-32 GBAllows qtwebengine/chromium links to survive spikes
32 GB8-16 GBSafety buffer for concurrent links and cc1plus bursts
64 GB+4-8 GBOptional 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 |
+------------------------------------------------------------------+

Swappiness Tuning

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 reboots
echo 'vm.swappiness=10' | sudo tee /etc/sysctl.d/99-yocto-swap.conf
sudo sysctl --system

zswap vs zram: Compressed Swap Mechanics

Both 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-generator
sudo tee /etc/systemd/zram-generator.conf > /dev/null <<'EOF'
[zram0]
zram-size = ram * 0.5
compression-algorithm = zstd
swap-priority = 100
EOF
sudo systemctl daemon-reload
sudo systemctl start systemd-zram-setup@zram0.service
zramctl

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/compressor
echo 20 | sudo tee /sys/module/zswap/parameters/max_pool_percent
echo 1 | sudo tee /sys/module/zswap/parameters/enabled

Advanced: BitBake PSI Pressure Monitoring

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.

Configuration Variables in conf/local.conf

BitBake 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.0
BB_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.

How BitBake Evaluates PSI

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=0
full avg10=0.00 avg60=0.00 avg300=0.00 total=0
LineMeaningFields
someShare of time at least one task is stalled waiting for the resourceavg10, avg60, avg300 (%), total (cumulative microseconds)
fullShare 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:

  1. Reads field total= from line 1 (some) of /proc/pressure/{cpu,io,memory}.
  2. Computes (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).
  3. If any configured resource exceeds its 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.

Measuring and Tuning PSI Thresholds

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 build
pressure=$(head -1 /proc/pressure/memory | cut -d ' ' -f5 | cut -d '=' -f2)
while true; do
sleep 1
prev_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).

Limitations

  • Requires Linux 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).
  • System-wide /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.
  • Inter-task only: PSI throttling stops BitBake from launching new tasks, so it cannot reduce PARALLEL_MAKE jobs already running inside a single massive recipe such as qtwebengine. Always combine PSI limits with sane PARALLEL_MAKE overrides.

Debugging Workflow: From Failure to Fix

Step 1: Capture the Failure Context

# Check kernel ring buffer / systemd journal for OOM killer events
dmesg -T | grep -iE "oom|killed process" | tail -20
journalctl -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

Step 2: Profile Concurrency and Memory Hotspots

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 UI
bitbake -g -u taskexp <target>

Step 3: Profile the Specific Recipe

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.

Step 4: Apply Targeted Fix

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.

Step 5: Verify Fix with Forced Recompile and Full Image Build

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.

Step 6: Establish a Team Baseline

Record measured resource profiles once builds pass cleanly:

# Build Baseline (2026-11-30)
Host: 16 physical cores, 32 GB RAM, 16 GB swap
Image: core-image-minimal + qtwebengine
BB_NUMBER_THREADS: 6
PARALLEL_MAKE: -j 6 (qtwebengine: -j 1)
Peak task RSS: 14.2 GB
Peak swap used: 2.1 GB
Duration: 1h 42m
OOM events: 0

CI-Specific Strategies

GitLab CI

# .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 ]; then
SUDO=""
[ "$(id -u)" -ne 0 ] && SUDO="sudo"
$SUDO fallocate -l 16G /swapfile
$SUDO chmod 600 /swapfile
$SUDO mkswap /swapfile
$SUDO swapon /swapfile
fi
build:
script:
- source oe-init-build-env build
- bitbake core-image-minimal

GitHub Actions

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 Build
on:
push:
branches: [main]
pull_request:
branches: [main]
jobs:
build:
runs-on: [self-hosted, linux, x64]
timeout-minutes: 240
steps:
- uses: actions/checkout@v4
- name: Configure swap
run: |
if ! swapon --show | grep -q '/swapfile'; then
sudo fallocate -l 16G /swapfile
sudo chmod 600 /swapfile
sudo mkswap /swapfile
sudo swapon /swapfile
fi
echo "vm.swappiness=10" | sudo tee /etc/sysctl.d/99-yocto.conf
sudo sysctl --system
- name: Install Yocto host dependencies
run: |
sudo apt-get update
sudo 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.conf
run: |
source oe-init-build-env build
cat >> 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 image
run: |
source oe-init-build-env build
bitbake core-image-minimal
- name: Upload image artifacts
uses: actions/upload-artifact@v4
with:
name: build-output
path: build/tmp/deploy/images/

Jenkins / Self-Hosted Runners

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.conf
vm.oom_kill_allocating_task = 0
vm.panic_on_oom = 0
vm.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 ]; then
sudo fallocate -l 32G /swapfile
sudo chmod 600 /swapfile
sudo mkswap /swapfile
sudo swapon /swapfile
fi
'''
}
}
stage('Build') {
steps {
sh '''
source oe-init-build-env build
bitbake core-image-minimal
'''
}
}
}
}

Docker-Based CI

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.04
RUN 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.

Build Caching for Faster CI (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 mirror
SSTATE_MIRRORS ?= "file://.* https://sstate.internal.example.com/PATH;downloadfilename=PATH"

Long-Term Guardrails

1. Commit Baseline Limits in 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 builds
PARALLEL_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"

2. Enable PSI Pressure Monitoring on Bare-Metal/VM Hosts

# 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"

3. Cap xz Compression Memory and Control Debug Info Overhead

Where 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 each
XZ_MEMLIMIT = "1024M"

4. Use rm_work and Linker Memory Controls

Enable 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.

5. Document Team Conventions

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=1
export PARALLEL_MAKE="-j 1"
bitbake <target>

6. Monitor Build Metrics in CI

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 kill
if dmesg -T 2>/dev/null | grep -qE "Out of memory: Killed process|oom-killer"; then
echo "::error::OOM kill detected during Yocto build"
exit 1
fi

References

  1. BitBake User Manual — Execution
  2. BitBake User Manual — Variables Glossary (BB_NUMBER_THREADS, PARALLEL_MAKE, BB_PRESSURE_MAX_*)
  3. Yocto Project Development Tasks Manual — Limiting the Host Resources Usage
  4. Yocto Project Development Tasks Manual — Speeding Up a Build
  5. Yocto Project Reference Manual — System Requirements
  6. Yocto Project Reference Manual — Variables Glossary
  7. Linux Kernel Documentation — PSI (Pressure Stall Information)
  8. Linux Kernel Documentation — Sysctl VM Parameters (vm.swappiness, vm.oom_kill_allocating_task)
  9. Linux Kernel Documentation — zswap
  10. Docker Documentation — Resource Constraints (--memory, --memory-swap)
  11. Randy MacLeod — “Making bitbake PSI-chic: regulating builds using /proc/pressure” (YouTube)
  12. Stack Overflow — “Out of memory building Yocto with 32G of RAM”

Summary

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:

  1. Immediate: Bound global 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.
  2. Structural: Provision 8-32 GB of swap (or zswap backed by disk swap) with tuned vm.swappiness on workstations and CI VMs.
  3. Automated: Enable 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.
  4. Operational: Use ?= in conf/local.conf for CI overrides, cap XZ_MEMLIMIT, share SSTATE_MIRRORS, and monitor buildstats peak RSS and kernel OOM logs in CI.

Frequently Asked Questions

What does exit code 137 mean in a Yocto build?

Exit code 137 equals 128 + 9, meaning a process was terminated by SIGKILL (signal 9) -- on Linux, almost always by the kernel or container cgroup OOM killer. When the OOM killer terminates a compiler or linker child process such as cc1plus or ld inside do_compile, make or ninja aborts and BitBake reports task exit code 1, whereas a container or CI runner hitting its cgroup memory ceiling kills the top-level job with exit code 137. Check dmesg -T or journalctl -k for 'Out of memory: Killed process' entries.

Which Bitbake variables control memory usage during builds?

The primary static controls are BB_NUMBER_THREADS (global concurrent BitBake tasks), PARALLEL_MAKE (per-recipe compilation parallelism across make, cmake, meson, and ninja-wrapped recipes such as qtwebengine), PARALLEL_MAKEINST (do_install parallelism), and XZ_MEMLIMIT (default 50% RAM cap for xz packaging/image compression). For dynamic throttling based on Linux PSI, BitBake 2.2+ (backported to Kirkstone) provides BB_PRESSURE_MAX_MEMORY, BB_PRESSURE_MAX_CPU, and BB_PRESSURE_MAX_IO. Set them in conf/local.conf, using ?= if CI environment overrides must take effect.

How do I limit memory for a specific memory-hungry recipe like qtwebengine?

Use PARALLEL_MAKE:pn-qtwebengine = "-j 1" in conf/local.conf (along with DEBUG_LEVELFLAG:pn-qtwebengine = "" on Yocto 5.1+ or stripping -g/-g1 from DEBUG_FLAGS on Yocto 5.0 Scarthgap and earlier if full DWARF symbols are not needed, and LDFLAGS:append:pn-qtwebengine = " -Wl,--no-keep-memory" for GNU ld.bfd). Note that BB_NUMBER_THREADS is a global RunQueue setting and ignores :pn-<recipe> overrides, so pair per-recipe PARALLEL_MAKE overrides with a sensible global BB_NUMBER_THREADS cap or BB_PRESSURE_MAX_MEMORY.

Can swap space help prevent Yocto OOM kills?

Yes. Adding disk swap (8-32 GB depending on physical RAM and target recipes) gives the Linux page-reclaim subsystem backing storage to page out cold anonymous pages instead of triggering OOM kills during transient link or compile spikes. Create a swap file with fallocate (on ext4/xfs; use chattr +C or btrfs filesystem mkswapfile on Btrfs), mkswap, and swapon, and optionally pair it with zswap or zram.

What is BB_PRESSURE_MAX_MEMORY and how does it work?

Introduced in BitBake 2.2 (Yocto 4.1 Langdale, and backported to Yocto 4.0 Kirkstone), BB_PRESSURE_MAX_MEMORY reads the cumulative 'total' stall time from /proc/pressure/memory (Linux kernel 4.20+ PSI) and computes its rate of change in microseconds per second over 1-second intervals. Accepting values from 1.0 to 1000000.0 (for example, "15000" for 15 ms/s of memory stall), it prevents BitBake's RunQueue from launching new tasks while at least one task remains active until pressure drops below the threshold.

Tags

yoctobitbakebuildrootembedded-linuxoomci-cd

Share


Previous Article
Fixing I2C Stuck Bus: SDA/SCL Recovery in Multi-Device Sys
Jithin Tom

Jithin Tom

A Closer Look at C/C++, RTOS, and Embedded Systems

Related Posts

Fixing Buildroot Kernel Panic: VFS Unable to Mount Root FS
Fixing Buildroot Kernel Panic: VFS Unable to Mount Root FS
November 26, 2026
7 min
© 2026, All Rights Reserved.
Powered By Netlyft

Quick Links

Advertise with usAbout UsContact Us

Social Media