#2805·ninja

nested cgroup2 cpu.max are not correctly read

Author: nkltzCreated Jun 29, 2026Updated Jun 29, 2026

Currently ninja only reads CPU quota from cpu.max if it is present within the most nested cgroup folder (specified in /proc/self/cgroup);

But when there is no cpu.max at that level because the cgroup does not have a CPU controller, or when it reads max 100000 but a parent reads 400000 100000, the parent takes precedence and ninja does not identify it.

The most precise quota we can get is the lowest value from any parent with a cpu.max.

Issues arise when building in containers, where each container gets 1/4 of the machine's RAM and 1/4 of the machine's cores; kubernetes creates nested cgroups, ninja miscomputes parallelism and containers go OOM trying to launch 4x too many g++ instances.

Ninja 1.13.2 sees all 16 available cores, but cgroups will allow only 8; proposed change sees 8. Image