Skip to content

Commit cd40e65

Browse files
authored
Merge pull request ceph#65313 from zmc/debs-nproc
make-debs.sh: Avoid OOM errors during build
2 parents 9c3d6e7 + 1618320 commit cd40e65

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

make-debs.sh

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -80,14 +80,22 @@ fi
8080
# b) do not sign the packages
8181
# c) use half of the available processors
8282
#
83-
: ${NPROC:=$(($(nproc) / 2))}
84-
if test $NPROC -gt 1 ; then
85-
j=-j${NPROC}
83+
: ${NPROC:=$(nproc)}
84+
RAM_MB=$(vmstat --stats --unit m | grep 'total memory' | awk '{print $1}')
85+
if test "$NPROC" -gt 50; then
86+
MAX_JOBS=$((${RAM_MB} / 4000))
87+
else
88+
MAX_JOBS=$((${RAM_MB} / 3000))
89+
fi
90+
if test "$NPROC" -gt "$MAX_JOBS"; then
91+
JOBS_FLAG="-j${MAX_JOBS}"
92+
else
93+
JOBS_FLAG="-j${NPROC}"
8694
fi
8795
if [ "$SCCACHE" != "true" ] ; then
8896
PATH=/usr/lib/ccache:$PATH
8997
fi
90-
PATH=$PATH dpkg-buildpackage $j -uc -us
98+
PATH=$PATH dpkg-buildpackage $JOBS_FLAG -uc -us
9199
cd ../..
92100
mkdir -p $VERSION_CODENAME/conf
93101
cat > $VERSION_CODENAME/conf/distributions <<EOF

0 commit comments

Comments
 (0)