Gentoo Archives: gentoo-dev

From: Roy Bamford <neddyseagoon@g.o>
To: gentoo-dev@l.g.o
Subject: Re: [gentoo-dev] [PATCH] check-reqs.eclass: clamp MAKEOPTS for memory/RAM usage
Date: Wed, 05 Jan 2022 19:02:46
Message-Id: L4YFA6C3.PDXV2FSR.V4WJZVQC@UIO6EGY3.TE33RGIP.UZHHVIY5
In Reply to: [gentoo-dev] [PATCH] check-reqs.eclass: clamp MAKEOPTS for memory/RAM usage by Sam James
1 On 2022.01.04 22:58, Sam James wrote:
2 > Crank down MAKEOPTS jobs if MAKEOPTS="-jN" is too high for the
3 > amount of RAM available (uses amount declared as needed
4 > in the ebuild). Typically should be ~2GB per job.
5 >
6 > Bug: https://bugs.gentoo.org/570534
7 > Signed-off-by: Sam James <sam@g.o>
8 > ---
9 > eclass/check-reqs.eclass | 42 +++++++++++++++++++++++++++++++++++++---
10 > 1 file changed, 39 insertions(+), 3 deletions(-)
11 >
12 > diff --git a/eclass/check-reqs.eclass b/eclass/check-reqs.eclass
13 > index 2130e2e349141..8c4adc8b4f121 100644
14 > --- a/eclass/check-reqs.eclass
15 > +++ b/eclass/check-reqs.eclass
16 > @@ -43,6 +43,8 @@ case ${EAPI} in
17 > *) die "${ECLASS}: EAPI=${EAPI:-0} is not supported" ;;
18 > esac
19 >
20 > +inherit multiprocessing
21 > +
22 > EXPORT_FUNCTIONS pkg_pretend pkg_setup
23 >
24 > if [[ ! ${_CHECK_REQS_ECLASS} ]]; then
25 > @@ -53,6 +55,13 @@ _CHECK_REQS_ECLASS=1
26 > # @DESCRIPTION:
27 > # How much RAM is needed? Eg.: CHECKREQS_MEMORY=15M
28 >
29 > +# @ECLASS-VARIABLE: CHECKREQS_MEMORY_MANGLE_JOBS
30 > +# @USER_VARIABLE
31 > +# @DESCRIPTION:
32 > +# Allow packages to reduce the number of multiprocessing (e.g. make,
33 > ninja) jobs
34 > +# to lower memory usage.
35 > +: ${CHECKREQS_MEMORY_MANGLE_JOBS=yes}
36 > +
37 > # @ECLASS-VARIABLE: CHECKREQS_DISK_BUILD
38 > # @DEFAULT_UNSET
39 > # @DESCRIPTION:
40 > @@ -346,9 +355,36 @@ _check-reqs_memory() {
41 > eend 0
42 > else
43 > eend 1
44 > - _check-reqs_unsatisfied \
45 > - ${size} \
46 > - "RAM"
47 > +
48 > + # Has the user allowed us to mangle their
49 > MAKEOPTS?
50 > + if [[ ${CHECKREQS_MEMORY_MANGLE_JOBS} ==
51 > "yes" ]] ; then
52 > + local jobs=$(makeopts_jobs)
53 > +
54 > + local estimated_max_memory=$((${actual_memory}/$(_check-reqs_get_kibibytes
55 > 1G)))
56 > + if [[ $((jobs*2)) -gt ${estimated_max_memory}
57 > ]] ; then
58 > + # Number of jobs exceeds RAM/2GB,
59 > so clamp it.
60 > + local new_jobs=$(($(_check-reqs_get_number
61 > ${estimated_max_memory}G)*10/20))
62 > +
63 > + # This might _still_ be too big
64 > on small machines. Give up in such cases.
65 > + # (Users can still set the do
66 > nothing variable which is independent of this.)
67 > + if [[ $((new_jobs*2)) -gt ${estimated_max_memory}
68 > ]] ; then
69 > + _check-reqs_unsatisfied \
70 > + ${size} \
71 > + "RAM"
72 > + else
73 > + # The clamped jobs seem to be
74 > enough to satisfy the check-reqs requirement from the ebuild.
75 > + ewarn "Clamping MAKEOPTS jobs
76 > to -j${new_jobs} to reduce memory usage"
77 > + ewarn "Compiler jobs may use
78 > around ~2GB each: https://wiki.gentoo.org/wiki/MAKEOPTS"
79 > + ewarn "To disable this, set CHECKREQS_MEMORY_MANGLE_JOBS=no."
80 > +
81 > + MAKEOPTS+=" -j${new_jobs}"
82 > + fi
83 > + fi
84 > + else
85 > + _check-reqs_unsatisfied \
86 > + ${size} \
87 > + "RAM"
88 > + fi
89 > fi
90 > else
91 > eend 1
92 > --
93 > 2.34.1
94 >
95 >
96 >
97 >
98
99 Sam,
100
101 Do users with FEATURES=distcc still have to opt out of this
102 MAKEOPTS clamping?
103
104 --
105 Regards,
106
107 Roy Bamford
108 (Neddyseagoon) a member of
109 elections
110 gentoo-ops
111 forum-mods
112 arm64

Replies