File 2681-erlc-Limit-the-number-of-schedulers-if-applicable.patch of Package erlang

From 1d3cdf05589a70f1baec323c42e57e864ed44c4c Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?John=20H=C3=B6gberg?= <john@erlang.org>
Date: Mon, 9 Mar 2020 10:48:10 +0100
Subject: [PATCH] erlc: Limit the number of schedulers if applicable

This fixes ERL-1186 and similar issues, where the system ran out of
threads because the emulators spawned by `erlc` used the default
number of schedulers even though all compilers except HiPE are
single-threaded and don't need that many.
---
 erts/etc/common/erlc.c | 18 ++++++++++++++++++
 1 file changed, 18 insertions(+)

diff --git a/erts/etc/common/erlc.c b/erts/etc/common/erlc.c
index e515a435c7..1dfcaaf0cd 100644
--- a/erts/etc/common/erlc.c
+++ b/erts/etc/common/erlc.c
@@ -176,6 +176,7 @@ int wmain(int argc, wchar_t **wcargv)
 int main(int argc, char** argv)
 {
 #endif
+    int single_scheduler;
     int eargv_size;
     int eargc_base;		/* How many arguments in the base of eargv. */
     char* emulator;
@@ -246,6 +247,8 @@ int main(int argc, char** argv)
      * Parse all command line switches.
      */
 
+    single_scheduler = 1;
+
     while (argc > 1) {
 
 	/*
@@ -254,6 +257,11 @@ int main(int argc, char** argv)
 
 	switch (argv[1][0]) {
 	case '+':
+            if (strcmp(argv[1], "+native") == 0) {
+                /* HiPE makes good use of multiple schedulers, so we'll let it
+                 * use the default number. */
+                single_scheduler = 0;
+            }
 	    PUSH(argv[1]);
 	    break;
 	case '-':
@@ -306,6 +314,16 @@ int main(int argc, char** argv)
 	argc--, argv++;
     }
 
+    /* The compile server benefits from multiple schedulers. */
+    single_scheduler = single_scheduler && !use_server;
+
+    if (single_scheduler) {
+        /* Limit ourselves to a single scheduler to save memory and avoid
+         * starving the system of threads when used in parallel builds (e.g.
+         * make -j64 on a 64-core system). */
+        UNSHIFT("+S1");
+    }
+
     /*
      * Move up the commands for invoking the emulator and adjust eargv
      * accordingly.
-- 
2.16.4

openSUSE Build Service is sponsored by