From 16183205fe12998a9227a4bb5f3e524a06a7f268 Mon Sep 17 00:00:00 2001 From: Zack Cerza Date: Fri, 29 Aug 2025 11:38:40 -0600 Subject: [PATCH] make-debs.sh: Avoid OOM errors during build This uses the logic from: https://github.com/ceph/ceph-build/blob/f074f1ce7fc05a5ac69e06fa9fa7ae45858b0110/scripts/build_utils.sh#L1411-L1435 Signed-off-by: Zack Cerza CEPH-BUILD-JOB: ceph-dev-pipeline ARCHS: x86_64 DISTROS: jammy noble FLAVORS: default --- make-debs.sh | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/make-debs.sh b/make-debs.sh index 7eaaccdb3dc..93f5e1120c8 100755 --- a/make-debs.sh +++ b/make-debs.sh @@ -80,14 +80,22 @@ fi # b) do not sign the packages # c) use half of the available processors # -: ${NPROC:=$(($(nproc) / 2))} -if test $NPROC -gt 1 ; then - j=-j${NPROC} +: ${NPROC:=$(nproc)} +RAM_MB=$(vmstat --stats --unit m | grep 'total memory' | awk '{print $1}') +if test "$NPROC" -gt 50; then + MAX_JOBS=$((${RAM_MB} / 4000)) +else + MAX_JOBS=$((${RAM_MB} / 3000)) +fi +if test "$NPROC" -gt "$MAX_JOBS"; then + JOBS_FLAG="-j${MAX_JOBS}" +else + JOBS_FLAG="-j${NPROC}" fi if [ "$SCCACHE" != "true" ] ; then PATH=/usr/lib/ccache:$PATH fi -PATH=$PATH dpkg-buildpackage $j -uc -us +PATH=$PATH dpkg-buildpackage $JOBS_FLAG -uc -us cd ../.. mkdir -p $VERSION_CODENAME/conf cat > $VERSION_CODENAME/conf/distributions <