From 328dfa12d0e165c8b6b861d9746cc87d71f7600704daeeade021262f2107dc11 Mon Sep 17 00:00:00 2001 From: Callum Farmer Date: Fri, 10 Jan 2025 10:42:45 +0000 Subject: [PATCH] - Also set _smp_build_ncpus to fix usage with meson macro and maybe others OBS-URL: https://build.opensuse.org/package/show/network:chromium/memory-constraints?expand=0&rev=22 --- .gitattributes | 23 ++++++++++++++++++ .gitignore | 1 + memory-constraints.changes | 44 ++++++++++++++++++++++++++++++++++ memory-constraints.macros | 28 ++++++++++++++++++++++ memory-constraints.spec | 49 ++++++++++++++++++++++++++++++++++++++ 5 files changed, 145 insertions(+) create mode 100644 .gitattributes create mode 100644 .gitignore create mode 100644 memory-constraints.changes create mode 100644 memory-constraints.macros create mode 100644 memory-constraints.spec diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..9b03811 --- /dev/null +++ b/.gitattributes @@ -0,0 +1,23 @@ +## Default LFS +*.7z filter=lfs diff=lfs merge=lfs -text +*.bsp filter=lfs diff=lfs merge=lfs -text +*.bz2 filter=lfs diff=lfs merge=lfs -text +*.gem filter=lfs diff=lfs merge=lfs -text +*.gz filter=lfs diff=lfs merge=lfs -text +*.jar filter=lfs diff=lfs merge=lfs -text +*.lz filter=lfs diff=lfs merge=lfs -text +*.lzma filter=lfs diff=lfs merge=lfs -text +*.obscpio filter=lfs diff=lfs merge=lfs -text +*.oxt filter=lfs diff=lfs merge=lfs -text +*.pdf filter=lfs diff=lfs merge=lfs -text +*.png filter=lfs diff=lfs merge=lfs -text +*.rpm filter=lfs diff=lfs merge=lfs -text +*.tbz filter=lfs diff=lfs merge=lfs -text +*.tbz2 filter=lfs diff=lfs merge=lfs -text +*.tgz filter=lfs diff=lfs merge=lfs -text +*.ttf filter=lfs diff=lfs merge=lfs -text +*.txz filter=lfs diff=lfs merge=lfs -text +*.whl filter=lfs diff=lfs merge=lfs -text +*.xz filter=lfs diff=lfs merge=lfs -text +*.zip filter=lfs diff=lfs merge=lfs -text +*.zst filter=lfs diff=lfs merge=lfs -text diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..57affb6 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +.osc diff --git a/memory-constraints.changes b/memory-constraints.changes new file mode 100644 index 0000000..9df30c7 --- /dev/null +++ b/memory-constraints.changes @@ -0,0 +1,44 @@ +------------------------------------------------------------------- +Thu Jan 9 11:29:51 UTC 2025 - Guillaume GARDET + +- Also set _smp_build_ncpus to fix usage with meson macro and + maybe others + +------------------------------------------------------------------- +Tue Jun 29 14:50:50 UTC 2021 - Andreas Schneider + +- Fix Requires for awk to work also on Fedora + +------------------------------------------------------------------- +Mon May 4 14:47:13 UTC 2020 - Dominique Leuenberger + +- Use the correct macro %_rpmmacrodir in the %files section. + +------------------------------------------------------------------- +Sat Jun 15 14:34:00 UTC 2019 - Stefan BrĂ¼ns + +- Take SwapTotal into account, MemTotal only reflects physical memory. Some + workers have a considerable amount of swap. + +------------------------------------------------------------------- +Sat Apr 7 14:57:25 UTC 2018 - tchvatal@suse.com + +- Fix the macros to define default value if _threads are not defined + to fallback to amount of CPUs + +------------------------------------------------------------------- +Fri Apr 6 13:41:22 UTC 2018 - tchvatal@suse.com + +- Use install instead of mkdir and cp + +------------------------------------------------------------------- +Fri Apr 6 13:00:10 UTC 2018 - tchvatal@suse.com + +- Update description to contain less typos + +------------------------------------------------------------------- +Fri Apr 6 10:56:54 UTC 2018 - tchvatal@suse.com + +- Initial package to ensure restrictions on jobs when building + huge packages + diff --git a/memory-constraints.macros b/memory-constraints.macros new file mode 100644 index 0000000..54385c7 --- /dev/null +++ b/memory-constraints.macros @@ -0,0 +1,28 @@ +# +# Macros for memory constraints on buildjobs. +# If you happen to have HUGE packages sometimes you need to do +# crazy magic in order to make sure it is most of the time building +# rather than just giving you OOM +# + +# m: memory limit in MBs per core; default is 1000 +%limit_build(m:) \ + _threads="`/usr/bin/getconf _NPROCESSORS_ONLN`" \ + _core_memory="%{-m:%{-m*}}%{!-m:1000}" \ + echo "Available memory:" \ + cat /proc/meminfo \ + echo "System limits:" \ + ulimit -a \ + echo "System jobs: $_threads" \ + if test "$_threads" -gt 1 ; then \ + mem_per_process="$_core_memory" \ + max_physmem=$(awk '/MemTotal/ { print $2 }' /proc/meminfo) \ + max_swapmem=$(awk '/SwapTotal/ { print $2 }' /proc/meminfo) \ + max_jobs="$((($max_physmem + $max_swapmem) / ($mem_per_process * 1000)))" \ + test "$_threads" -gt "$max_jobs" && _threads="$max_jobs" && echo "Warning: Reducing number of jobs to $max_jobs because of memory limits" \ + test "$_threads" -le 0 && _threads=1 && echo "Warning: Do not use the parallel build at all because of memory limits" \ + fi \ + %global jobs $([[ -n $_threads ]] && echo $_threads || echo "`/usr/bin/getconf _NPROCESSORS_ONLN`") \ + %global _smp_mflags $([[ -n $_threads ]] && echo "-j$_threads" || echo "-j`/usr/bin/getconf _NPROCESSORS_ONLN`") \ + %global _smp_build_ncpus $([[ -n $_threads ]] && echo "$_threads" || echo "`/usr/bin/getconf _NPROCESSORS_ONLN`") \ + %{nil} diff --git a/memory-constraints.spec b/memory-constraints.spec new file mode 100644 index 0000000..83f82e5 --- /dev/null +++ b/memory-constraints.spec @@ -0,0 +1,49 @@ +# +# spec file for package memory-constraints +# +# Copyright (c) 2021 SUSE LLC +# +# All modifications and additions to the file contributed by third parties +# remain the property of their copyright owners, unless otherwise agreed +# upon. The license for this file, and modifications and additions to the +# file, is the same license as for the pristine package itself (unless the +# license for the pristine package is not an Open Source License, in which +# case the license is the MIT License). An "Open Source License" is a +# license that conforms to the Open Source Definition (Version 1.9) +# published by the Open Source Initiative. + +# Please submit bugfixes or comments via https://bugs.opensuse.org/ +# + + +Name: memory-constraints +Version: 20180406 +Release: 0 +Summary: Macros to limit resources allocation when building +License: MIT +Group: Development/Tools/Building +URL: https://www.opensuse.org/ +Source0: %{name}.macros +BuildRequires: coreutils +BuildRequires: rpm +Requires: /usr/bin/awk +Requires: coreutils +BuildArch: noarch + +%description +Macros to limit various resources when building huge packages to +ensure we can produce results rather than OOM reports. + +%prep +: + +%build +: + +%install +install -D -m 644 %{SOURCE0} %{buildroot}/%{_rpmmacrodir}/macros.%{name} + +%files +%{_rpmmacrodir}/macros.%{name} + +%changelog