From bd4da136badb38590a2cb92606e7296207368b65 Mon Sep 17 00:00:00 2001 From: Kefu Chai Date: Wed, 17 Feb 2021 11:47:44 +0800 Subject: [PATCH] ceph.spec.in: use RPM_BUILD_NCPUS for number of jobs this env variable is defined by /usr/lib/rpm/macros. let's used it instead of inventing our own version. Signed-off-by: Kefu Chai --- ceph.spec.in | 43 +++++++++++++++++++++---------------------- 1 file changed, 21 insertions(+), 22 deletions(-) diff --git a/ceph.spec.in b/ceph.spec.in index 949ccae7caf..da419f4c490 100644 --- a/ceph.spec.in +++ b/ceph.spec.in @@ -109,6 +109,27 @@ %global _source_payload w7T%{_smp_build_ncpus}.xzdio %global _binary_payload w7T%{_smp_build_ncpus}.xzdio +# Parallel build settings ... +CEPH_SMP_NCPUS=$(RPM_BUILD_NCPUS) +%if 0%{?__isa_bits} == 32 +# 32-bit builds can use 3G memory max, which is not enough even for -j2 +CEPH_SMP_NCPUS="1" +%endif +# do not eat all memory +echo "Available memory:" +free -h +echo "System limits:" +ulimit -a +if test -n "$CEPH_SMP_NCPUS" -a "$CEPH_SMP_NCPUS" -gt 1 ; then + mem_per_process=2500 + max_mem=$(LANG=C free -m | sed -n "s|^Mem: *\([0-9]*\).*$|\1|p") + max_jobs="$(($max_mem / $mem_per_process))" + test "$CEPH_SMP_NCPUS" -gt "$max_jobs" && CEPH_SMP_NCPUS="$max_jobs" && echo "Warning: Reducing build parallelism to -j$max_jobs because of memory limits" + test "$CEPH_SMP_NCPUS" -le 0 && CEPH_SMP_NCPUS="1" && echo "Warning: Not using parallel build at all because of memory limits" +fi +export CEPH_SMP_NCPUS +export CEPH_MFLAGS_JOBS="-j$CEPH_SMP_NCPUS" + ################################################################################# # main package definition ################################################################################# @@ -1189,28 +1210,6 @@ export LDFLAGS="$RPM_LD_FLAGS" export CXXFLAGS=$(echo $RPM_OPT_FLAGS | sed -e 's/-Wp,-D_FORTIFY_SOURCE=2//g') %endif -# Parallel build settings ... -CEPH_MFLAGS_JOBS="%{?_smp_mflags}" -CEPH_SMP_NCPUS=$(echo "$CEPH_MFLAGS_JOBS" | sed 's/-j//') -%if 0%{?__isa_bits} == 32 -# 32-bit builds can use 3G memory max, which is not enough even for -j2 -CEPH_SMP_NCPUS="1" -%endif -# do not eat all memory -echo "Available memory:" -free -h -echo "System limits:" -ulimit -a -if test -n "$CEPH_SMP_NCPUS" -a "$CEPH_SMP_NCPUS" -gt 1 ; then - mem_per_process=2500 - max_mem=$(LANG=C free -m | sed -n "s|^Mem: *\([0-9]*\).*$|\1|p") - max_jobs="$(($max_mem / $mem_per_process))" - test "$CEPH_SMP_NCPUS" -gt "$max_jobs" && CEPH_SMP_NCPUS="$max_jobs" && echo "Warning: Reducing build parallelism to -j$max_jobs because of memory limits" - test "$CEPH_SMP_NCPUS" -le 0 && CEPH_SMP_NCPUS="1" && echo "Warning: Not using parallel build at all because of memory limits" -fi -export CEPH_SMP_NCPUS -export CEPH_MFLAGS_JOBS="-j$CEPH_SMP_NCPUS" - env | sort mkdir build -- 2.47.3