View previous topic :: View next topic |
Author |
Message |
pietinger Moderator

Joined: 17 Oct 2006 Posts: 5423 Location: Bavaria
|
Posted: Sat Feb 22, 2025 2:12 pm Post subject: emerge uses more CPU cores (threads) than permitted |
|
|
... and only at the start of the compilation phase.
I am posting here because I am not sure if this is a bug and needs a bug report. But I suspect a bug.
I usually do my word update at night (unattended) so I don't know when this behavior started. Today I could observe (with btop) that during today's word-update almost all packages after the configuration phase started the compilation phase immediately with 32 threads and after these were “processed”, portage “only” started the allowed 24 threads. My setting in make.conf is very simple:
Code: | RUSTFLAGS="${RUSTFLAGS} -C target-cpu=native"
MAKEOPTS="-j24 |
Some packages (e.g. qtwebengine) even had this behavior several times: sometimes 32 threads were started, then 24 and suddenly 32 again in the middle. Could this be due to a missing/incorrect setting? _________________ https://wiki.gentoo.org/wiki/User:Pietinger |
|
Back to top |
|
 |
Hu Administrator

Joined: 06 Mar 2007 Posts: 23129
|
Posted: Sat Feb 22, 2025 2:24 pm Post subject: |
|
|
I have seen reports like this before. It is unfortunate, but it is not a Portage bug. When you set MAKEOPTS, you tell GNU Make (and certain other build systems that, for compatibility, try to understand at least some GNU Make options) how many jobs it can start. Some build systems just guess on their own how many parallel jobs they should start. For example, dev-build/ninja states in its documentation:That page does indicate that explicitly passing -j overrides the default of guessing the number of allowed threads.
I seem to recall other build systems that were even less well behaved, but I cannot recall names now.
A full solution may require that emerge direct the kernel to limit the resources allowed to the individual packages, such as through cgroup settings. |
|
Back to top |
|
 |
pietinger Moderator

Joined: 17 Oct 2006 Posts: 5423 Location: Bavaria
|
Posted: Sat Feb 22, 2025 3:13 pm Post subject: |
|
|
Hu, thank you very much for your (detailed) answer. If I understand correctly, I only have two options: Either there is the possibility to give NINJA this parameter (for each run), or it is only possible via the cgroups? (otherwise I have to live with the behavior) _________________ https://wiki.gentoo.org/wiki/User:Pietinger |
|
Back to top |
|
 |
Hu Administrator

Joined: 06 Mar 2007 Posts: 23129
|
Posted: Sat Feb 22, 2025 4:52 pm Post subject: |
|
|
I thought most ebuilds that used non-GNU Make systems already handled this for you, when they can. Some build systems might not allow handling this (whereas Ninja allows you to set this right, but is greedy by default) and I don't know if Ninja is even involved in the packages you reported. I expect cgroups could enforce the limits you want, but I am not aware of any native Portage support for applying the requisite limits.
Can you capture a process tree of a misbehaving build, so we can determine what build system it uses and what, if any, options were passed that should have constrained it? |
|
Back to top |
|
 |
Zucca Moderator


Joined: 14 Jun 2007 Posts: 3956 Location: Rasi, Finland
|
Posted: Sat Feb 22, 2025 4:55 pm Post subject: |
|
|
As far as I know if the ebuild uses correct eclasses (and their functions) for building with ninja, the switches specified in MAKEOPTS should be automatically passed to ninja. I've observed this by looking at the command line arguments ninja gets.
But does ninja respect those in all cases...
I'll spin up a qtwebengine build... _________________ ..: Zucca :..
My gentoo installs: | init=/sbin/openrc-init
-systemd -logind -elogind seatd |
Quote: | I am NaN! I am a man! |
|
|
Back to top |
|
 |
sam_ Developer


Joined: 14 Aug 2020 Posts: 2173
|
Posted: Sat Feb 22, 2025 5:26 pm Post subject: |
|
|
Zucca wrote: | As far as I know if the ebuild uses correct eclasses (and their functions) for building with ninja, the switches specified in MAKEOPTS should be automatically passed to ninja. I've observed this by looking at the command line arguments ninja gets.
But does ninja respect those in all cases...
I'll spin up a qtwebengine build... |
Yep, you're right. But note that the ninja maintainers upstream refuse to add support for NINJAOPTS or similar, so if ninja is invoked by a tool down the line rather than directly in the ebuild or something we can control, it may not respect the desired job count. |
|
Back to top |
|
 |
Zucca Moderator


Joined: 14 Jun 2007 Posts: 3956 Location: Rasi, Finland
|
Posted: Sat Feb 22, 2025 5:46 pm Post subject: |
|
|
Ok. First observations: Code: | d-mill /etc/portage # pgrep -a ninja
6301 ninja -v -j36 -l70
7420 /usr/bin/ninja -j36 -l70 -v -C /var/tmp/portage/dev-qt/qtwebengine-6.8.1-r1/work/qtwebengine-everywhere-src-6.8.1_build/src/core/RelWithDebInfo/x86_64 QtWebEngineCore | I have total available CPU threads of 72, so -j36 should yield to 50% CPU load.
At the start the CPU usage sometimes spiked at around 70%. But evetually settled pretty much spot on 50%, while occasionally spikes at around 70% but very shortly. The spiking may just be overhead caused by managing large number of threads.
graph from btop: | ┌─┐1cpu┌──┐menu┌┐preset *┌─────────────────────────────────────────────────────────────────────────────────────────┐21:41:28┌────────────
│
│ ▒▒
│ ░░ ░░ ░▒░ ▒█▒░██▒ ░░ ░░ ░█▒ ▒▒ ░░
│ ▒█▒▒ ▒█████░▒██████▒▒░██████░▒▒ ░▒██▒ ▒▒▒██░ ▒█░ ▒█▒ ░█▒
│ ▒▒░ ▒███▒█████████████████████████████▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒██████▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒██████▒▒▒▒▒▒▒▒▒▒▒██▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒████▒███▒███
│ ▒█▒ ▒██████████████████████████████████████████████████████████████████████████████████████████████████████████████████████
│ ▒█▒ ▒██████████████████████████████████████████████████████████████████████████████████████████████████████████████████████
│ ░███▒░░▒██████████████████████████████████████████████████████████████████████████████████████████████████████████████████████
│░░░░░░░░░░██████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████
│░░░░░░░░░░██████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████
│ ░███▒░░▒██████████████████████████████████████████████████████████████████████████████████████████████████████████████████████
│ ▒█▒ ▒██████████████████████████████████████████████████████████████████████████████████████████████████████████████████████
│ ▒█▒ ▒██████████████████████████████████████████████████████████████████████████████████████████████████████████████████████
│ ▒▒░ ▒███▒█████████████████████████████▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒██████▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒██████▒▒▒▒▒▒▒▒▒▒▒██▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒████▒███▒███
│ ▒█▒▒ ▒█████░▒██████▒▒░██████░▒▒ ░▒██▒ ▒▒▒██░ ▒█░ ▒█▒ ░█▒
│ ░░ ░░ ░▒░ ▒█▒░██▒ ░░ ░░ ░█▒ ▒▒ ░░
│ ▒▒
│ up 8d 22:44 | ... I hope the graph is readable.
But as sam_ said, some other packages using ninja may "run out of control". _________________ ..: Zucca :..
My gentoo installs: | init=/sbin/openrc-init
-systemd -logind -elogind seatd |
Quote: | I am NaN! I am a man! |
Last edited by Zucca on Sat Feb 22, 2025 11:17 pm; edited 1 time in total |
|
Back to top |
|
 |
keekkenen n00b

Joined: 05 Oct 2024 Posts: 37
|
Posted: Sat Feb 22, 2025 5:49 pm Post subject: |
|
|
By wiki, that means your system can use 48Gb RAM for tasks.
Try to use something like that
Code: | MAKEOPTS="-j24 --jobs 24 --load-average 24" |
_________________ 7950x3d / x670e MSI Tomagawk / Sapphire RX 7800XT 16Gb / G.Skill 64Gb 5600 / A-Data Legend 960 2Tb (x2), A-Data SX8200PNP 256Gb |
|
Back to top |
|
 |
logrusx Advocate


Joined: 22 Feb 2018 Posts: 2751
|
Posted: Sat Feb 22, 2025 6:06 pm Post subject: Re: emerge uses more CPU cores (threads) than permitted |
|
|
pietinger wrote: | ... and only at the start of the compilation phase.
I am posting here because I am not sure if this is a bug and needs a bug report. But I suspect a bug.
I usually do my word update at night (unattended) so I don't know when this behavior started. Today I could observe (with btop) that during today's word-update almost all packages after the configuration phase started the compilation phase immediately with 32 threads and after these were “processed”, portage “only” started the allowed 24 threads. |
How do you measure that?
Best Regards,
Georgi |
|
Back to top |
|
 |
Zucca Moderator


Joined: 14 Jun 2007 Posts: 3956 Location: Rasi, Finland
|
Posted: Sat Feb 22, 2025 6:14 pm Post subject: |
|
|
keekkenen,
Unless I'm totally lost, -j is shorthand for --jobs.
Anyway. My second test showed some interesting signs... Now with ninja -v -j72 -l68, the load has been staying at 68, except for the start (obviously). But at some points the load spiked up to 120. I compile everything in RAM, and it's far from exhausted. Not a single page of swap has been allocated. So it cannot be disk load. _________________ ..: Zucca :..
My gentoo installs: | init=/sbin/openrc-init
-systemd -logind -elogind seatd |
Quote: | I am NaN! I am a man! |
|
|
Back to top |
|
 |
logrusx Advocate


Joined: 22 Feb 2018 Posts: 2751
|
Posted: Sat Feb 22, 2025 6:22 pm Post subject: |
|
|
Zucca wrote: | My second test showed some interesting signs... Now with ninja -v -j72 -l68, the load has been staying at 68, except for the start (obviously). But at some points the load spiked up to 120. I compile everything in RAM, and it's far from exhausted. Not a single page of swap has been allocated. So it cannot be disk load. |
I this regard ninja should behave like make. And I think all build systems. It won't spawn a new job if the load is above the threshold, but nothing can guarantee the load will stay under the threshold. It can be below it when spawning one or more new jobs but it can increase during the life of the jobs and nothing can prevent or control that.
Best Regards,
Georgi |
|
Back to top |
|
 |
Zucca Moderator


Joined: 14 Jun 2007 Posts: 3956 Location: Rasi, Finland
|
Posted: Sat Feb 22, 2025 6:29 pm Post subject: |
|
|
Yes.
After the load spiked at 120, ninja stopped creating new threads until the load was again at 68.
So far no other load spike has happened.
I believe qtwebengine ebuild does respect MAKEOPTS quite well. At least ninja quickly reacts to change in load.
pietinger, did you observe load going up to 32 for how long?
Or was it only spiking sometimes for short durations, like what I've observed? _________________ ..: Zucca :..
My gentoo installs: | init=/sbin/openrc-init
-systemd -logind -elogind seatd |
Quote: | I am NaN! I am a man! |
|
|
Back to top |
|
 |
keekkenen n00b

Joined: 05 Oct 2024 Posts: 37
|
Posted: Sat Feb 22, 2025 6:33 pm Post subject: |
|
|
Zucca wrote: |
Unless I'm totally lost, -j is shorthand for --jobs. |
Yes, you are right, it's the same, but --load-average option gives us addition control to limit using threads. _________________ 7950x3d / x670e MSI Tomagawk / Sapphire RX 7800XT 16Gb / G.Skill 64Gb 5600 / A-Data Legend 960 2Tb (x2), A-Data SX8200PNP 256Gb |
|
Back to top |
|
 |
pietinger Moderator

Joined: 17 Oct 2006 Posts: 5423 Location: Bavaria
|
Posted: Sat Feb 22, 2025 8:10 pm Post subject: |
|
|
logrusx wrote: | How do you measure that? |
Zucca wrote: | pietinger, did you observe load going up to 32 for how long? |
I had a running "btop" (with 100ms) (together with output of emerge world) and have seen that immediatly AFTER the configuration phase there have been 32 threads for compiling ... then ... new threads have been added as soon as 9 thread have been finished ... so, after the initial 32 thread I had only the 24 threads ... and then after a while (in the middle?) ... I had 32 threads with the same behaviour: After 9 threads had finished new threads have been added ... to the limit of 24 (as said before this was not the case in every package; but some). _________________ https://wiki.gentoo.org/wiki/User:Pietinger |
|
Back to top |
|
 |
pietinger Moderator

Joined: 17 Oct 2006 Posts: 5423 Location: Bavaria
|
Posted: Sat Feb 22, 2025 8:11 pm Post subject: |
|
|
keekkenen wrote: |
By wiki, that means your system can use 48Gb RAM for tasks. |
Yes ... pls dont worry: I have 64 GB RAM. _________________ https://wiki.gentoo.org/wiki/User:Pietinger |
|
Back to top |
|
 |
pietinger Moderator

Joined: 17 Oct 2006 Posts: 5423 Location: Bavaria
|
Posted: Sat Feb 22, 2025 8:14 pm Post subject: |
|
|
keekkenen wrote: | [...] but --load-average option gives us addition control to limit using threads. |
AFAIK (but I can be wrong here) you will need load-average only if you use more than one installation jobs with EMERGE_DEFAULT_OPTS="--jobs X" (where X > 1) (which I dont use). _________________ https://wiki.gentoo.org/wiki/User:Pietinger |
|
Back to top |
|
 |
logrusx Advocate


Joined: 22 Feb 2018 Posts: 2751
|
Posted: Sat Feb 22, 2025 8:17 pm Post subject: |
|
|
pietinger wrote: | keekkenen wrote: |
By wiki, that means your system can use 48Gb RAM for tasks. |
Yes ... pls dont worry: I have 64 GB RAM. |
That's actually incorrect. It's the other way around. The recommendation is to adjust the number of threads to allow for 2GB of RAM per thread. Also this value is derived from practice, there's no regularity here.
Best Regards,
Georgi |
|
Back to top |
|
 |
sam_ Developer


Joined: 14 Aug 2020 Posts: 2173
|
Posted: Sat Feb 22, 2025 8:23 pm Post subject: |
|
|
pietinger wrote: | keekkenen wrote: | [...] but --load-average option gives us addition control to limit using threads. |
AFAIK (but I can be wrong here) you will need load-average only if you use more than one installation jobs with EMERGE_DEFAULT_OPTS="--jobs X" (where X > 1) (which I dont use). |
To be clear, both make and Portage accept both --jobs and --load-average. make for individual compile jobs, Portage for package builds/installation. --load-average has value and a different meaning accordingly for both MAKEOPTS and EMERGE_DEFAULT_OPTS. There is value in setting it for MAKEOPTS even if you do not set any EMERGE_DEFAULT_OPTS.
Portage defaults to -j$(nproc) -l$(nproc) for MAKEOPTS. |
|
Back to top |
|
 |
pietinger Moderator

Joined: 17 Oct 2006 Posts: 5423 Location: Bavaria
|
Posted: Sat Feb 22, 2025 9:07 pm Post subject: |
|
|
Hu wrote: | Can you capture a process tree of a misbehaving build, so we can determine what build system it uses and what, if any, options were passed that should have constrained it? |
Was not easy to catch it ... (I changed MAKEOPTS to 1) ... and so far I can see it is NOT ninja ... it was node.js ?! _________________ https://wiki.gentoo.org/wiki/User:Pietinger |
|
Back to top |
|
 |
keekkenen n00b

Joined: 05 Oct 2024 Posts: 37
|
Posted: Sat Feb 22, 2025 11:21 pm Post subject: |
|
|
sam_ wrote: |
Portage defaults to -j$(nproc) -l$(nproc) for MAKEOPTS. |
But, what's default ?
I tried to use
Code: | MAKEOPTS="--jobs 28" |
only and
shown me
Code: | 7678 ninja -v -j28 -l0 -C out/Release chrome chromedriver chrome_sandbox |
maybe value -l0 is equivalent -l32 (total CPUs count in my case) _________________ 7950x3d / x670e MSI Tomagawk / Sapphire RX 7800XT 16Gb / G.Skill 64Gb 5600 / A-Data Legend 960 2Tb (x2), A-Data SX8200PNP 256Gb |
|
Back to top |
|
 |
sam_ Developer


Joined: 14 Aug 2020 Posts: 2173
|
Posted: Sun Feb 23, 2025 12:30 am Post subject: |
|
|
I'm not sure what you mean. Portage defaults to that in GNUMAKEFLAGS (IIRC) if MAKEOPTS, GNUMAKEFLAGS, and MAKEOPTS aren't set (it's just a fail-safe default if the user specifies nothing at all in make.conf). |
|
Back to top |
|
 |
logrusx Advocate


Joined: 22 Feb 2018 Posts: 2751
|
Posted: Sun Feb 23, 2025 7:01 am Post subject: |
|
|
[quote="pietinger"] Hu wrote: | ... it was node.js ?! |
Yes, nodejs can be used to build stuff. Well you name the package already?
Best Regards,
Georgi |
|
Back to top |
|
 |
|