Skip to content

Commit 88de8f2

Browse files
committed
Fix OOM: Pass JOBS to ninja with memory-aware scaling
- Actually pass -j $JOBS to ninja (was being calculated but not used) - Default to 20 parallel jobs, scale down for smaller systems - ~6GB per compile job: 60GB RAM → 10 jobs, 128GB+ → 20 jobs
1 parent 219ef1e commit 88de8f2

File tree

1 file changed

+13
-3
lines changed

1 file changed

+13
-3
lines changed

scripts/build.sh

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,19 @@ HAF_BUILD=""
4141

4242
CMAKE_ARGS=()
4343

44+
# Calculate parallel jobs: default 20, scale down for systems with less RAM
4445
JOBS=$(nproc)
45-
JOBS=$(( JOBS > 10 ? 10 : JOBS ))
46-
echo "Build will use $JOBS concurrent jobs..."
46+
JOBS=$(( JOBS > 20 ? 20 : JOBS ))
47+
48+
# Memory-aware scaling: ~6GB per compile job
49+
AVAILABLE_MEM_GB=$(awk '/MemAvailable/ {printf "%d", $2/1024/1024}' /proc/meminfo 2>/dev/null || echo "128")
50+
MEM_BASED_JOBS=$(( AVAILABLE_MEM_GB / 6 ))
51+
MEM_BASED_JOBS=$(( MEM_BASED_JOBS < 1 ? 1 : MEM_BASED_JOBS ))
52+
if [[ $MEM_BASED_JOBS -lt $JOBS ]]; then
53+
JOBS=$MEM_BASED_JOBS
54+
fi
55+
56+
echo "Build will use $JOBS concurrent jobs (RAM: ${AVAILABLE_MEM_GB}GB)..."
4757

4858
add_cmake_arg () {
4959
CMAKE_ARGS+=("$1")
@@ -98,7 +108,7 @@ pushd "$abs_build_dir"
98108
echo "Building Hive!"
99109

100110
cmake -DCMAKE_BUILD_TYPE=Release -GNinja "${CMAKE_ARGS[@]}" "$abs_src_dir"
101-
ninja "$@"
111+
ninja -j "$JOBS" "$@"
102112

103113
if [[ "$CLEAN_AFTER_BUILD" == "true" ]]; then
104114
echo "Cleaning up after build..."

0 commit comments

Comments
 (0)