Gentoo Archives: gentoo-dev

From: Alexey Sokolov <alexey+gentoo@××××××××.org>
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 16:48:40
Message-Id: 584d516b-fd9a-0322-f4e5-7d97320a152f@asokolov.org
In Reply to: [gentoo-dev] [PATCH] check-reqs.eclass: clamp MAKEOPTS for memory/RAM usage by Sam James
1 I do sometimes run into OOM during emerge, but for a different reason:
2 when firefox and webengine are built in parallel. And I'm using tmpfs
3 for portage. These packages store lots of data in the build directory.
4 Decreasing -j of a single package may or may not help in this case.
5
6 The filled tmpfs issue becomes more severe if I have tests enabled,
7 because ctest has different behavior from make/ninja, and I use -j with
8 combination with -l: make and ninja run at least one job to ensure some
9 progress, while ctest does nothing when the load average is too high,
10 and while it's doing nothing, the portage cannot finish the build and
11 therefore cleanup the build dir from RAM.
12
13 Neither of these are exactly relevant to this patch, tbh.
14
15 04.01.2022 22:58, Sam James пишет:
16 > Crank down MAKEOPTS jobs if MAKEOPTS="-jN" is too high for the
17 > amount of RAM available (uses amount declared as needed
18 > in the ebuild). Typically should be ~2GB per job.
19 >
20 > Bug: https://bugs.gentoo.org/570534
21 > Signed-off-by: Sam James <sam@g.o>
22 > ---
23 > eclass/check-reqs.eclass | 42 +++++++++++++++++++++++++++++++++++++---
24 > 1 file changed, 39 insertions(+), 3 deletions(-)
25 >
26 > diff --git a/eclass/check-reqs.eclass b/eclass/check-reqs.eclass
27 > index 2130e2e349141..8c4adc8b4f121 100644
28 > --- a/eclass/check-reqs.eclass
29 > +++ b/eclass/check-reqs.eclass
30 > @@ -43,6 +43,8 @@ case ${EAPI} in
31 > *) die "${ECLASS}: EAPI=${EAPI:-0} is not supported" ;;
32 > esac
33 >
34 > +inherit multiprocessing
35 > +
36 > EXPORT_FUNCTIONS pkg_pretend pkg_setup
37 >
38 > if [[ ! ${_CHECK_REQS_ECLASS} ]]; then
39 > @@ -53,6 +55,13 @@ _CHECK_REQS_ECLASS=1
40 > # @DESCRIPTION:
41 > # How much RAM is needed? Eg.: CHECKREQS_MEMORY=15M
42 >
43 > +# @ECLASS-VARIABLE: CHECKREQS_MEMORY_MANGLE_JOBS
44 > +# @USER_VARIABLE
45 > +# @DESCRIPTION:
46 > +# Allow packages to reduce the number of multiprocessing (e.g. make, ninja) jobs
47 > +# to lower memory usage.
48 > +: ${CHECKREQS_MEMORY_MANGLE_JOBS=yes}
49 > +
50 > # @ECLASS-VARIABLE: CHECKREQS_DISK_BUILD
51 > # @DEFAULT_UNSET
52 > # @DESCRIPTION:
53 > @@ -346,9 +355,36 @@ _check-reqs_memory() {
54 > eend 0
55 > else
56 > eend 1
57 > - _check-reqs_unsatisfied \
58 > - ${size} \
59 > - "RAM"
60 > +
61 > + # Has the user allowed us to mangle their MAKEOPTS?
62 > + if [[ ${CHECKREQS_MEMORY_MANGLE_JOBS} == "yes" ]] ; then
63 > + local jobs=$(makeopts_jobs)
64 > +
65 > + local estimated_max_memory=$((${actual_memory}/$(_check-reqs_get_kibibytes 1G)))
66 > + if [[ $((jobs*2)) -gt ${estimated_max_memory} ]] ; then
67 > + # Number of jobs exceeds RAM/2GB, so clamp it.
68 > + local new_jobs=$(($(_check-reqs_get_number ${estimated_max_memory}G)*10/20))
69 > +
70 > + # This might _still_ be too big on small machines. Give up in such cases.
71 > + # (Users can still set the do nothing variable which is independent of this.)
72 > + if [[ $((new_jobs*2)) -gt ${estimated_max_memory} ]] ; then
73 > + _check-reqs_unsatisfied \
74 > + ${size} \
75 > + "RAM"
76 > + else
77 > + # The clamped jobs seem to be enough to satisfy the check-reqs requirement from the ebuild.
78 > + ewarn "Clamping MAKEOPTS jobs to -j${new_jobs} to reduce memory usage"
79 > + ewarn "Compiler jobs may use around ~2GB each: https://wiki.gentoo.org/wiki/MAKEOPTS"
80 > + ewarn "To disable this, set CHECKREQS_MEMORY_MANGLE_JOBS=no."
81 > +
82 > + MAKEOPTS+=" -j${new_jobs}"
83 > + fi
84 > + fi
85 > + else
86 > + _check-reqs_unsatisfied \
87 > + ${size} \
88 > + "RAM"
89 > + fi
90 > fi
91 > else
92 > eend 1
93
94
95 --
96 Best regards,
97 Alexey "DarthGandalf" Sokolov