diff options
author | Maxim Kuvyrkov <maxim.kuvyrkov@linaro.org> | 2021-07-19 13:03:02 +0000 |
---|---|---|
committer | Maxim Kuvyrkov <maxim.kuvyrkov@linaro.org> | 2021-07-26 10:12:26 +0000 |
commit | 268e16e2ba1eaef8e211d6a0728c92f8cbde14c0 (patch) | |
tree | 0107e824671646d8e1b49629ea6133e906a5b182 | |
parent | 3922f589ab98b50295674d01287ed7fc693bbb47 (diff) |
start-container-docker.sh: Use at most half of RAM on normal builders
This reverts commit 73ab5ac992942292817b1441472d325ed4c553be.
Change-Id: Ia4148af0ac04a5f75b63d5c5af5a334939a39a03
-rw-r--r-- | jenkins-helpers.sh | 19 | ||||
-rwxr-xr-x | start-container-docker.sh | 10 | ||||
-rwxr-xr-x | start-container-qemu.sh | 3 |
3 files changed, 26 insertions, 6 deletions
diff --git a/jenkins-helpers.sh b/jenkins-helpers.sh index 62cc9e0a..7feb3edf 100644 --- a/jenkins-helpers.sh +++ b/jenkins-helpers.sh @@ -694,16 +694,33 @@ print_cpu_shares () # Print memory allocation for $task and $weight. # $1: task # $2: weight +# $3: number of expected parallel processes +# $4: amount of system RAM in MB print_memory_limit () { ( set -euf -o pipefail local task="$1" local weight="$2" + local nproc="$3" + local memlimit="$4" local memory case "$task" in build) - memory="unlimited" + # 2GB per compilation core, with 4GB minimum and + # half of total system RAM maximum. + memory=$(( 2000 * $weight * $nproc )) + + memlimit=$(( $memlimit / 2 )) + if [ "$memlimit" -lt "4000" ]; then + # Don't limit memory on machines with less than 8GB RAM. + memory="unlimited" + else + # Use at most half of RAM + if [ "$memory" -gt "$memlimit" ]; then + memory="$memlimit" + fi + fi ;; test) # 0.75GB per session diff --git a/start-container-docker.sh b/start-container-docker.sh index 71dec51f..a1e30b51 100755 --- a/start-container-docker.sh +++ b/start-container-docker.sh @@ -246,13 +246,15 @@ SECURITY="${SECURITY} --security-opt seccomp:unconfined" # Reserve resources according to weight and task nproc=$($SSH $session_host nproc --all) +memlimit=$($SSH $session_host free -m | awk '/^Mem/ { print $2 }') + pids=$(print_pids_limit "$task" "$weight") cpus=$(print_cpu_shares "$task" "$weight") +memory=$(print_memory_limit "$task" "$weight" "$nproc" "$memlimit") -memory=$(print_memory_limit "$task" "$weight") -memory_opt="--memory=${memory}M" -if [ x"$memory" = x"unlimited" ]; then - memory_opt="" +memory_opt="" +if [ x"$memory" != x"unlimited" ]; then + memory_opt="--memory=${memory}M" fi if [ x"${JOB_NAME:+set}" = x"set" ]; then diff --git a/start-container-qemu.sh b/start-container-qemu.sh index 6e01d9c1..235c4aea 100755 --- a/start-container-qemu.sh +++ b/start-container-qemu.sh @@ -97,7 +97,8 @@ fi # CPU is limited (on contention) by docker container. ncpus=$(container_exec nproc --all) -memory=$(print_memory_limit "$task" "$weight") +memlimit=$(container_exec free -m | awk '/^Mem/ { print $2 }') +memory=$(print_memory_limit "$task" "$weight" "$ncpus" "$memlimit") # Reduce memory limit for VM to leave something for QEMU itself. memory=$(($memory*2/3)) |