Simplify NCPU computation and avoid fork bombs

Summary:public
Use getconf to compute NCPU as it is uniform across platforms.

Use result in several places to avoid fork bombs.  I routinely see
errors about fork running out of memory when building e.g. the clang
plugin.

Reviewed By: jvillard

Differential Revision: D3148970

fb-gh-sync-id: 6d071c9
fbshipit-source-id: 6d071c9
master
Josh Berdine 9 years ago committed by Facebook Github Bot 7
parent 44a6bf7128
commit ee206dbc12

@ -7,6 +7,8 @@
PLATFORM = $(shell uname)
NCPU = @NCPU@
ABSOLUTE_ROOT_DIR = $(shell cd $(ROOT_DIR) && pwd)
EXAMPLES_DIR = $(ABSOLUTE_ROOT_DIR)/examples

@ -29,8 +29,6 @@ TARGETS_TO_TEST += objc
endif
TARGETS_TO_TEST := $(shell echo $(TARGETS_TO_TEST))
NCPU = @NCPU@
all: $(INFER_ANALYZERS)
java: inferTraceBugs

@ -14,6 +14,7 @@ set -e
SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
INFER_ROOT="$SCRIPT_DIR/../"
PLATFORM="$(uname)"
NCPU="$(getconf _NPROCESSORS_ONLN 2>/dev/null || echo 1)"
function usage() {
echo "Usage: $0 [-y] [targets]"
@ -161,7 +162,7 @@ if [ "$BUILD_CLANG" = "yes" ] && ! facebook-clang-plugins/clang/setup.sh --only-
fi
fi
make -j $TARGETS || (
make -j $NCPU $TARGETS || (
echo
echo ' compilation failure; you can try running'
echo

@ -240,17 +240,11 @@ echo $buck_version > "$buckversion_file"
AC_MSG_RESULT([$buck_version])
AC_CHECK_TOOL([HAVE_NPROC], [nproc], [no])
AC_CHECK_TOOL([HAVE_SYSCTL], [sysctl], [no])
AC_CHECK_TOOL([GETCONF], [getconf], [no])
AC_MSG_CHECKING([the number of cpus the build host has])
if test "$HAVE_NPROC" != "no"; then
if test $(nproc); then
NCPU=$(nproc)
AC_MSG_RESULT([$NCPU])
fi
elif test $"HAVE_SYSCTL" != "no"; then
if test $(sysctl -n hw.ncpu); then
NCPU=$(sysctl -n hw.ncpu)
if test "$GETCONF" != "no"; then
if test $(getconf _NPROCESSORS_ONLN); then
NCPU=$(getconf _NPROCESSORS_ONLN)
AC_MSG_RESULT([$NCPU])
fi
else

@ -131,7 +131,7 @@ endif
DEPENDENCIES = IR backend checkers eradicate harness \
facebook/checkers facebook/checkers/graphql facebook/scripts $(EXTRA_DEPS)
OCAMLBUILD = ocamlbuild $(OCAMLBUILD_OPTIONS) -j 0 $(addprefix -I , $(DEPENDENCIES))
OCAMLBUILD = ocamlbuild $(OCAMLBUILD_OPTIONS) -j $(NCPU) $(addprefix -I , $(DEPENDENCIES))
.PHONY: all java clang llvm unit checkCopyright build_java build_clang build_llvm build_unit \
build_checkCopyright java_annotations clang_annotations llvm_annotations \

Loading…
Cancel
Save