Fix macros.build-constraints' %limit_build
number of CPUs will never be set to less than 1 this now outputs build flag overrides to be used with %make_build etc. add documentation Signed-off-by: Michel Alexandre Salim <salimma@fedoraproject.org>
This commit is contained in:
parent
bc8fa85e90
commit
43dfe7d6f0
@ -1,10 +1,42 @@
|
|||||||
# Macros to constrain resource use during the build process
|
# Macros to constrain resource use during the build process
|
||||||
|
|
||||||
# m: memory limit in MBs per core; default is 1024
|
# outputs build flag overrides to be used in conjunction with
|
||||||
%limit_build(m:) \
|
# %%make_build, %%cmake_build etc.
|
||||||
_mem_per_process="%{-m:%{-m*}}%{!-m:1024}" \
|
#
|
||||||
_max_mem=$(awk '/MemTotal/ { print $2 }' /proc/meminfo) \
|
# if no override is needed, this macro outputs nothing
|
||||||
_max_jobs="$(($_max_mem / ($_mem_per_process * 1024)))" \
|
#
|
||||||
_cur_max_jobs="%{_smp_build_ncpus}" \
|
# - m memory limit in MBs per core; default is 1024
|
||||||
test "${_cur_max_jobs}" -gt "${_max_jobs}" && _cur_max_jobs="${_max_jobs}" && echo "Warning: Reducing build parallelism to -j${_max_jobs} because of memory limits" \
|
#
|
||||||
%global _smp_build_ncpus "${_cur_max_jobs}"
|
# Usage:
|
||||||
|
# e.g. %make_build %{limit_build -m 2048}
|
||||||
|
# => /usr/bin/make -O -j16 V=1 VERBOSE=1
|
||||||
|
# %make_build %{limit_build -m 40960}
|
||||||
|
# => /usr/bin/make -O -j16 V=1 VERBOSE=1 -j1
|
||||||
|
#
|
||||||
|
%limit_build(m:) %{lua:
|
||||||
|
local mem_per_process=rpm.expand("%{-m*}")
|
||||||
|
if mem_per_process == "" then
|
||||||
|
mem_per_process = 1024
|
||||||
|
else
|
||||||
|
mem_per_process = tonumber(mem_per_process)
|
||||||
|
end
|
||||||
|
local mem_total = 0
|
||||||
|
for line in io.lines('/proc/meminfo') do
|
||||||
|
if line:sub(1, 9) == "MemTotal:" then
|
||||||
|
local tokens = {}
|
||||||
|
for token in line:gmatch("%w+") do
|
||||||
|
tokens[#tokens + 1] = token
|
||||||
|
end
|
||||||
|
mem_total = tonumber(tokens[2])
|
||||||
|
break
|
||||||
|
end
|
||||||
|
end
|
||||||
|
local max_jobs = mem_total // (mem_per_process * 1024)
|
||||||
|
if max_jobs < 1 then
|
||||||
|
max_jobs = 1
|
||||||
|
end
|
||||||
|
cur_max_jobs=tonumber(rpm.expand("%{_smp_build_ncpus}"))
|
||||||
|
if cur_max_jobs > max_jobs then
|
||||||
|
print("-j" .. max_jobs)
|
||||||
|
end
|
||||||
|
}
|
||||||
|
@ -6,7 +6,7 @@
|
|||||||
|
|
||||||
Summary: Red Hat specific rpm configuration files
|
Summary: Red Hat specific rpm configuration files
|
||||||
Name: redhat-rpm-config
|
Name: redhat-rpm-config
|
||||||
Version: 194
|
Version: 195
|
||||||
Release: 1%{?dist}
|
Release: 1%{?dist}
|
||||||
# No version specified.
|
# No version specified.
|
||||||
License: GPL+
|
License: GPL+
|
||||||
@ -215,6 +215,12 @@ install -p -m 644 -t %{buildroot}%{_rpmluadir}/fedora/srpm forge.lua
|
|||||||
%{_rpmconfigdir}/macros.d/macros.kmp
|
%{_rpmconfigdir}/macros.d/macros.kmp
|
||||||
|
|
||||||
%changelog
|
%changelog
|
||||||
|
* Sun Aug 15 2021 Michel Alexandre Salim <salimma@fedoraproject.org> - 195-1
|
||||||
|
- Fix macros.build-constraints' %%limit_build
|
||||||
|
- number of CPUs will never be set to less than 1
|
||||||
|
- this now outputs build flag overrides to be used with %%make_build etc.
|
||||||
|
- add documentation
|
||||||
|
|
||||||
* Mon Aug 2 2021 Florian Weimer <fweimer@redhat.com> - 194-1
|
* Mon Aug 2 2021 Florian Weimer <fweimer@redhat.com> - 194-1
|
||||||
- Active GCC plugin during LTO linking
|
- Active GCC plugin during LTO linking
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user