Panu Matilainen a0095d
From 4c772fcf7114d6ce20800c12bc377b490d267548 Mon Sep 17 00:00:00 2001
Panu Matilainen a0095d
Message-Id: <4c772fcf7114d6ce20800c12bc377b490d267548.1566558648.git.pmatilai@redhat.com>
Panu Matilainen a0095d
In-Reply-To: <4d16d81a1af3e43b8392e7c335f616c9c0c6e41b.1566558648.git.pmatilai@redhat.com>
Panu Matilainen a0095d
References: <4d16d81a1af3e43b8392e7c335f616c9c0c6e41b.1566558648.git.pmatilai@redhat.com>
Panu Matilainen d678a6
From: Panu Matilainen <pmatilai@redhat.com>
Panu Matilainen d678a6
Date: Fri, 23 Aug 2019 11:17:21 +0300
Panu Matilainen d678a6
Subject: [PATCH 2/2] Cap number of threads on 32bit platforms, add a tunable
Panu Matilainen d678a6
 (RhBug:1729382)
Panu Matilainen d678a6
Panu Matilainen d678a6
On 32bit plaforms, address space is easily exhausted with multiple
Panu Matilainen d678a6
threads, causing arbitrary builds failure regressions (RhBug:1729382).
Panu Matilainen d678a6
Simply cap the number of threads to maximum of four on any 32bit
Panu Matilainen d678a6
platform to play it safe. It's still three more than we were able to
Panu Matilainen d678a6
use on older releases...
Panu Matilainen d678a6
Panu Matilainen d678a6
In addition, introduce a separate tunable for tweaking the maximum
Panu Matilainen d678a6
number of threads just in case, defaulting to max CPUs available.
Panu Matilainen d678a6
---
Panu Matilainen d678a6
 build/parseSpec.c | 10 +++++++++-
Panu Matilainen d678a6
 platform.in       |  3 +++
Panu Matilainen d678a6
 2 files changed, 12 insertions(+), 1 deletion(-)
Panu Matilainen d678a6
Panu Matilainen d678a6
diff --git a/build/parseSpec.c b/build/parseSpec.c
Panu Matilainen a0095d
index 737a1233c..ab3ba9cae 100644
Panu Matilainen d678a6
--- a/build/parseSpec.c
Panu Matilainen d678a6
+++ b/build/parseSpec.c
Panu Matilainen a0095d
@@ -1035,7 +1035,15 @@ static rpmSpec parseSpec(const char *specFile, rpmSpecFlags flags,
Panu Matilainen d678a6
 
Panu Matilainen d678a6
 #ifdef ENABLE_OPENMP
Panu Matilainen d678a6
     /* Set number of OMP threads centrally */
Panu Matilainen d678a6
-    int ncpus = rpmExpandNumeric("%{?_smp_build_ncpus}");
Panu Matilainen d678a6
+    int ncpus = rpmExpandNumeric("%{?_smp_nthreads_max}");
Panu Matilainen d678a6
+#if __WORDSIZE == 32
Panu Matilainen d678a6
+    /* On 32bit platforms, address space shortage is an issue. Play safe. */
Panu Matilainen d678a6
+    if (ncpus <= 0 || ncpus > 4) {
Panu Matilainen d678a6
+	ncpus = 4;
Panu Matilainen d678a6
+	rpmlog(RPMLOG_DEBUG,
Panu Matilainen d678a6
+		"limiting number of threads to %d due to platform\n", ncpus);
Panu Matilainen d678a6
+    }
Panu Matilainen d678a6
+#endif
Panu Matilainen a0095d
     if (ncpus > 0)
Panu Matilainen a0095d
 	omp_set_num_threads(ncpus);
Panu Matilainen d678a6
 #endif
Panu Matilainen d678a6
diff --git a/platform.in b/platform.in
Panu Matilainen d678a6
index db6d2382f..c70f44193 100644
Panu Matilainen d678a6
--- a/platform.in
Panu Matilainen d678a6
+++ b/platform.in
Panu Matilainen d678a6
@@ -59,6 +59,9 @@
Panu Matilainen d678a6
 
Panu Matilainen d678a6
 %_smp_mflags -j%{_smp_build_ncpus}
Panu Matilainen d678a6
 
Panu Matilainen d678a6
+# Maximum number of CPU's to use for threads
Panu Matilainen d678a6
+%_smp_nthreads_max %{_smp_build_ncpus}
Panu Matilainen d678a6
+
Panu Matilainen d678a6
 #==============================================================================
Panu Matilainen d678a6
 # ---- Build policy macros.
Panu Matilainen d678a6
 #
Panu Matilainen d678a6
-- 
Panu Matilainen d678a6
2.21.0
Panu Matilainen d678a6