summaryrefslogtreecommitdiff
path: root/jenkins-helpers.sh
diff options
context:
space:
mode:
Diffstat (limited to 'jenkins-helpers.sh')
-rw-r--r--jenkins-helpers.sh19
1 files changed, 18 insertions, 1 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