Restrict the number of jobs based on RAM

There have been builds failing recently because the number of jobs was
too high causing processes to be killed due to OOM.
Reuse the same mechanism available on flang in order to restrict the
number of jobs.
This commit is contained in:
Tulio Magno Quites Machado Filho 2023-10-05 12:05:44 -03:00
parent b952a4ffcc
commit 3e450e4b88
1 changed files with 41 additions and 0 deletions

View File

@ -23,6 +23,47 @@ Source2: release-keys.asc
Patch1: 0001-mlir-python-Reuse-the-library-directory.patch
%{lua:
-- Return the maximum number of parallel jobs a build can run based on the
-- amount of maximum memory used per process (per_proc_mem).
function print_max_procs(per_proc_mem)
local f = io.open("/proc/meminfo", "r")
local mem = 0
local nproc_str = nil
for line in f:lines() do
_, _, mem = string.find(line, "MemTotal:%s+(%d+)%s+kB")
if mem then
break
end
end
f:close()
local proc_handle = io.popen("nproc")
_, _, nproc_str = string.find(proc_handle:read("*a"), "(%d+)")
proc_handle:close()
local nproc = tonumber(nproc_str)
if nproc < 1 then
nproc = 1
end
local mem_mb = mem / 1024
local cpu = math.floor(mem_mb / per_proc_mem)
if cpu < 1 then
cpu = 1
end
if cpu > nproc then
cpu = nproc
end
print(cpu)
end
}
# The amount of RAM used per process has been set by trial and error.
# This number may increase/decrease from time to time and may require changes.
# We prefer to be on the safe side in order to avoid spurious errors.
%global _smp_mflags -j%{lua: print_max_procs(6144)}
# Support for i686 upstream is unclear with lots of tests failling.
ExcludeArch: i686