Gentoo Archives: gentoo-user

From: Laurence Perkins <lperkins@×××××××.net>
To: "gentoo-user@l.g.o" <gentoo-user@l.g.o>
Subject: RE: [gentoo-user] Jobs and load-average
Date: Thu, 16 Feb 2023 17:55:38
Message-Id: MW2PR07MB40588423AA621B798B70D8F2D2A09@MW2PR07MB4058.namprd07.prod.outlook.com
In Reply to: Re: [gentoo-user] Jobs and load-average by Rich Freeman
1 > -----Original Message-----
2 > From: Rich Freeman <rich0@g.o>
3 > Sent: Thursday, February 16, 2023 6:24 AM
4 > To: gentoo-user@l.g.o
5 > Subject: Re: [gentoo-user] Jobs and load-average
6 >
7 > On Thu, Feb 16, 2023 at 8:39 AM Peter Humphrey <peter@××××××××××××.uk> wrote:
8 > >
9 > > I've just looked at 'man make', from which it's clear that -j =
10 > > --jobs, and that both those and --load-average are passed to
11 > > /usr/bin/make, presumably untouched unless portage itself has
12 > > identically named variables. So I wonder how feasible it might be for
13 > > make to incorporate its own checks to ensure that the load average is
14 > > not exceeded. I am not a programmer (not for at least 35 years, anyway), so I have to leave any such suggestion to the experts.
15 > >
16 >
17 > Well, if we just want to have a fun discussion here are my thoughts.
18 > However, the complexity vs usefulness outside of Gentoo is such that I don't see it happening.
19 >
20 > For the most typical use case - a developer building the same thing over and over (which isn't Gentoo), then make could cache info on resources consumed, and use that to make more educated decisions about how many tasks to launch. That wouldn't help us at all, but it would help the typical make user. However, the typical make user can just tune things in other ways.
21 >
22 > It isn't going to be possible for make to estimate build complexity in any practical way. Halting problem aside maybe you could build in some smarts looking at the program being executed and its arguments, but it would be a big mess.
23 >
24 > Something make could do is tune the damping a bit. It could gradually increase the number of jobs it runs and watch the load average, and gradually scale it up appropriately, and gradually scale down if CPU is the issue, or rapidly scale down if swap is the issue. If swapping is detected it could even suspend most of the tasks it has spawned and then gradually continue them as other tasks finish to recover from this condition. However, this isn't going to work as well if portage is itself spawning parallel instances of make - they'd have to talk to each other or portage would somehow need to supervise things.
25 >
26 > A way of thinking about it is that when you have portage spawning multiple instances of make, that is a bit like adding gain to the --load-average MAKEOPTS. So each instance of make independently looks at load average and takes action. So you have an output (compilers that create load), then you sample that load with a time-weighted average, and then you apply gain to this average, and then use that as feedback. That's basically a recipe for out of control oscillation.
27 > You need to add damping and get rid of the gain.
28 >
29 > Disclaimer: I'm not an engineer and I suspect a real engineer would be able to add a bit more insight.
30 >
31 > Really though the issue is that this is the sort of thing that only impacts Gentoo and so nobody else is likely to solve this problem for us.
32 >
33 > --
34 > Rich
35
36 Expanding the capabilities of app-admin/cpulimit to tally up memory usage and suspend new compile jobs temporarily when it gets too high probably wouldn't be too horribly difficult...
37
38 LMP