Skip to content

Commit

Permalink
stdenv: reintroduce limiting by system load
Browse files Browse the repository at this point in the history
Commit c2b898d removed the mechanism; now it's replaced
by a different one with higher limit of $(nproc) * 2.

Unfortunately there's no good mechanism how to override it from outside
like `--cores` or `--max-jobs`, but at least the new limit should be
high enough to avoid the previous downsides.
  • Loading branch information
vcunat committed Sep 24, 2022
1 parent 77f081b commit cb1d8be
Show file tree
Hide file tree
Showing 15 changed files with 31 additions and 21 deletions.
2 changes: 1 addition & 1 deletion pkgs/applications/emulators/np2kai/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ stdenv.mkDerivation rec {

configurePhase = ''
export GIT_VERSION=${builtins.substring 0 7 src.rev}
buildFlags="$buildFlags ''${enableParallelBuilding:+-j$NIX_BUILD_CORES"
buildFlags="$buildFlags ''${enableParallelBuilding:+-j$NIX_BUILD_CORES -l$NIX_LOAD_LIMIT}"
'' + optionalString enableX11 ''
cd x11
substituteInPlace Makefile.am \
Expand Down
2 changes: 1 addition & 1 deletion pkgs/applications/networking/browsers/chromium/common.nix
Original file line number Diff line number Diff line change
Expand Up @@ -325,7 +325,7 @@ let

buildPhase = let
buildCommand = target: ''
ninja -C "${buildPath}" -j$NIX_BUILD_CORES "${target}"
ninja -C "${buildPath}" -j$NIX_BUILD_CORES -l$NIX_LOAD_LIMIT "${target}"
(
source chrome/installer/linux/common/installer.include
PACKAGE=$packageName
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ stdenv.mkDerivation (finalAttrs: {
'')

+ lib.optionalString withManual ''# Install man pages
make -j $NIX_BUILD_CORES PERL_PATH="${buildPackages.perl}/bin/perl" cmd-list.made install install-html \
make -j $NIX_BUILD_CORES -l $NIX_LOAD_LIMIT PERL_PATH="${buildPackages.perl}/bin/perl" cmd-list.made install install-html \
-C Documentation ''

+ (if guiSupport then ''
Expand Down
2 changes: 1 addition & 1 deletion pkgs/development/embedded/blackmagic/helper.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ out=${out:-/tmp}
################################################################################
export CFLAGS=$NIX_CFLAGS_COMPILE
export MAKEFLAGS="\
${enableParallelBuilding:+-j${NIX_BUILD_CORES}}"
${enableParallelBuilding:+-j${NIX_BUILD_CORES} -l${NIX_LOAD_LIMIT}}"

################################################################################
PRODUCTS="blackmagic.bin blackmagic.hex blackmagic_dfu.bin blackmagic_dfu.hex"
Expand Down
2 changes: 1 addition & 1 deletion pkgs/development/libraries/glibc/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ callPackage ./common.nix { inherit stdenv; } {

postInstall = (if stdenv.hostPlatform == stdenv.buildPlatform then ''
echo SUPPORTED-LOCALES=C.UTF-8/UTF-8 > ../glibc-2*/localedata/SUPPORTED
make -j''${NIX_BUILD_CORES:-1} localedata/install-locales
make -j''${NIX_BUILD_CORES:-1} -l''${NIX_LOAD_LIMIT:-1} localedata/install-locales
'' else lib.optionalString stdenv.buildPlatform.isLinux ''
# This is based on http://www.linuxfromscratch.org/lfs/view/development/chapter06/glibc.html
# Instead of using their patch to build a build-native localedef,
Expand Down
2 changes: 1 addition & 1 deletion pkgs/development/libraries/kerberos/krb5.nix
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ stdenv.mkDerivation rec {
buildPhase = lib.optionalString libOnly ''
runHook preBuild
MAKE="make -j $NIX_BUILD_CORES"
MAKE="make -j $NIX_BUILD_CORES -l $NIX_LOAD_LIMIT"
for folder in $libFolders; do
$MAKE -C $folder
done
Expand Down
2 changes: 1 addition & 1 deletion pkgs/development/python-modules/pybind11/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ buildPythonPackage rec {

postBuild = ''
# build tests
make -j $NIX_BUILD_CORES
make -j $NIX_BUILD_CORES -l $NIX_LOAD_LIMIT
'';

postInstall = ''
Expand Down
4 changes: 2 additions & 2 deletions pkgs/development/tools/build-managers/ninja/setup-hook.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ ninjaBuildPhase() {
fi

local flagsArray=(
-j$buildCores
-j$buildCores -l$NIX_LOAD_LIMIT
$ninjaFlags "${ninjaFlagsArray[@]}"
)

Expand Down Expand Up @@ -61,7 +61,7 @@ ninjaCheckPhase() {
fi

local flagsArray=(
-j$buildCores
-j$buildCores -l$NIX_LOAD_LIMIT
$ninjaFlags "${ninjaFlagsArray[@]}"
$checkTarget
)
Expand Down
2 changes: 1 addition & 1 deletion pkgs/games/uhexen2/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ stdenv.mkDerivation rec {
runHook preBuild
for makefile in "''${makeFiles[@]}"; do
local flagsArray=(
-j$NIX_BUILD_CORES
-j$NIX_BUILD_CORES -l$NIX_LOAD_LIMIT
SHELL=$SHELL
$makeFlags "''${makeFlagsArray[@]}"
$buildFlags "''${buildFlagsArray[@]}"
Expand Down
8 changes: 4 additions & 4 deletions pkgs/games/xonotic/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -83,14 +83,14 @@ let
'';

buildPhase = (lib.optionalString withDedicated ''
make -j $NIX_BUILD_CORES sv-${target}
make -j $NIX_BUILD_CORES -l $NIX_LOAD_LIMIT sv-${target}
'' + lib.optionalString withGLX ''
make -j $NIX_BUILD_CORES cl-${target}
make -j $NIX_BUILD_CORES -l $NIX_LOAD_LIMIT cl-${target}
'' + lib.optionalString withSDL ''
make -j $NIX_BUILD_CORES sdl-${target}
make -j $NIX_BUILD_CORES -l $NIX_LOAD_LIMIT sdl-${target}
'') + ''
pushd ../d0_blind_id
make -j $NIX_BUILD_CORES
make -j $NIX_BUILD_CORES -l $NIX_LOAD_LIMIT
popd
'';

Expand Down
2 changes: 1 addition & 1 deletion pkgs/os-specific/linux/trace-cmd/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ stdenv.mkDerivation rec {
# because the Makefile would not print warnings about too old
# libraries (see "warning:" in the Makefile)
postBuild = ''
make libs doc -j$NIX_BUILD_CORES
make libs doc -j$NIX_BUILD_CORES -l$NIX_LOAD_LIMIT
'';

installTargets = [
Expand Down
16 changes: 13 additions & 3 deletions pkgs/stdenv/generic/setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -673,6 +673,16 @@ if ((NIX_BUILD_CORES <= 0)); then
fi
export NIX_BUILD_CORES

# Determine limit for make's `-l` parameter and equivalents.
# Limiting by load allows to mix serial and very parallel builds
# on a single machine with many cores - without overloading too much.

if [[ -z "${NIX_LOAD_LIMIT:-}" ]]; then
guess=$(nproc 2>/dev/null || true)
((NIX_LOAD_LIMIT = guess <= 0 ? 1 : guess * 2))
fi
export NIX_LOAD_LIMIT


# Prevent SSL libraries from using certificates in /etc/ssl, unless set explicitly.
# Leave it in impure shells for convenience.
Expand Down Expand Up @@ -1100,7 +1110,7 @@ buildPhase() {
# Old bash empty array hack
# shellcheck disable=SC2086
local flagsArray=(
${enableParallelBuilding:+-j${NIX_BUILD_CORES}}
${enableParallelBuilding:+-j${NIX_BUILD_CORES} -l${NIX_LOAD_LIMIT}}
SHELL=$SHELL
$makeFlags "${makeFlagsArray[@]}"
$buildFlags "${buildFlagsArray[@]}"
Expand Down Expand Up @@ -1139,7 +1149,7 @@ checkPhase() {
# Old bash empty array hack
# shellcheck disable=SC2086
local flagsArray=(
${enableParallelChecking:+-j${NIX_BUILD_CORES}}
${enableParallelChecking:+-j${NIX_BUILD_CORES} -l${NIX_LOAD_LIMIT}}
SHELL=$SHELL
$makeFlags "${makeFlagsArray[@]}"
${checkFlags:-VERBOSE=y} "${checkFlagsArray[@]}"
Expand Down Expand Up @@ -1273,7 +1283,7 @@ installCheckPhase() {
# Old bash empty array hack
# shellcheck disable=SC2086
local flagsArray=(
${enableParallelChecking:+-j${NIX_BUILD_CORES}}
${enableParallelChecking:+-j${NIX_BUILD_CORES} -l${NIX_LOAD_LIMIT}}
SHELL=$SHELL
$makeFlags "${makeFlagsArray[@]}"
$installCheckFlags "${installCheckFlagsArray[@]}"
Expand Down
2 changes: 1 addition & 1 deletion pkgs/tools/admin/tigervnc/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ stdenv.mkDerivation rec {
--with-xkb-path=${xkeyboard_config}/share/X11/xkb \
--with-xkb-bin-directory=${xorg.xkbcomp}/bin \
--with-xkb-output=$out/share/X11/xkb/compiled
make TIGERVNC_SRC=$src TIGERVNC_BUILDDIR=`pwd`/../.. -j$NIX_BUILD_CORES
make TIGERVNC_SRC=$src TIGERVNC_BUILDDIR=`pwd`/../.. -j$NIX_BUILD_CORES -l$NIX_LOAD_LIMIT
popd
'' + lib.optionalString stdenv.isDarwin ''
make dmg
Expand Down
2 changes: 1 addition & 1 deletion pkgs/tools/security/tracee/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ buildGoModule rec {

buildPhase = ''
runHook preBuild
make $makeFlags ''${enableParallelBuilding:+-j$NIX_BUILD_CORES
make $makeFlags ''${enableParallelBuilding:+-j$NIX_BUILD_CORES -l$NIX_LOAD_LIMIT}
runHook postBuild
'';

Expand Down
2 changes: 1 addition & 1 deletion pkgs/tools/typesetting/tex/texlive/bin.nix
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ core-big = stdenv.mkDerivation { #TODO: upmendex
if [[ "$path" =~ "libs/pplib" ]]; then
# TODO: revert for texlive 2022
# ../../../texk/web2c/luatexdir/luamd5/md5lib.c:197:10: fatal error: 'utilsha.h' file not found
make ''${enableParallelBuilding:+-j''${NIX_BUILD_CORES}}
make ''${enableParallelBuilding:+-j''${NIX_BUILD_CORES} -l''${NIX_LOAD_LIMIT}}
fi
)
done
Expand Down

0 comments on commit cb1d8be

Please sign in to comment.