I am trying to limit the amount of CPU any application on my Fedora 41 workstation can use. In particular web browsers like firefox when launching or starting new tabs max out all cores and cause other apps, browsers to freeze.
I have an 8 core i5 laptop.
I tried to use cpulimit but it just does not work…
so launching firefox from the command prompt using: cpulimit -l 400 -i firefox
… does not work. Firefox uses all 8 cores to start and during this time other browsers freeze.
Is there a different way to limit cpu for an application? Even better is there a global Fedora workstation setting that I can set to limit any application to no more than a % of cores?
You could try messing with the niceness of the process, see if that helps.
nice -n 19 firefox
Essentially makes the process less demanding when competing for CPU resources. 19 being the most nice (least demanding) and -20 being the least nice (most demanding)
I am watching the system via System Monitor - history. It shows: CPU%, memory, network, IO read/write B/s and GPU %. The only metric that I can clearly see maxing out is the CPU% at 800% as soon as I launch firefox.
I tried top and it is a bit overwhelming as both chrome and firefox run multiple processes. Interestingly cpulimit uses almost 100% of a single core to run.
Changing the command to cpulimit -l 200 -i firefox seems to lower the time the computer spends at 800% but there is still impact to the other browser and top shows firefox using more than 200% cpu frequently.
I also tried nice -n 19 firefox and it did not help.
The other browser is running a video and during this time the GPU is close to 90%. However that stat does not seem to change when firefox is launched. I am not sure this stat is valid though as I have the laptop feed an external graphics card which is connected to 3 monitors.
Well … good news is that the multi-threading is working (%800 CPU utilization on an 8 CPU computer == all CPUs running at %100 … so at least that’s working / reacting correctly )
Makes me wonder if you are running a slow clock frequency …
which laptop do have?
(also, install btop … sudo dnf install btop … and let’s see what that says…)
It is a Lenovo ThinkPad X1 Yoga Gen 5… which btop claims is running an i5-10210U processor. Looking that up on the intel website it says that it has 4 cores and 8 threads. So perhaps one source of trouble is that I am not sure what the cpulimit -l 200 parameter does… is that 2 cores or 2 threads?
According to btop (which by the way is great!) the frequency ranges from 400MHz to 1.6 GHz. Its close to 600MHz and stays there when I run firefox while chrome is playing a video. That seems low but I am not sure how to change that.
Other than that… btop shows the same stats as system monitor… all CPUs/threads are maxed out when firefox is launched and everything else is ok.
Ok … cpulimit -l 200 means "limit the amount of cpu that the following exec gets to %200 … so basically give this process only 2 threads worth of cpu …
… according to the specs, that CPU is capable of doing 4.2GHz clock frequency in turbo-boost … so … it seams you aren’t getting the full capabilities if you are only getting to 1.6GHz under high demand …
I have so far used: top, btop, radeontop, powertop, cpupower, cpulimit, nice, turbostat, system monitor and yes > /dev/null.
Observing top with 1 shows almost 90% user load followed by system. IOWAIT is not a factor.
Here is what I observer:
When I run the test with no external monitor connections the CPU % rises along with the CPU clock and everything works fine…
When I run the test with only one external monitor connected via HDMI the CPU % rises along with the CPU clock and everything works fine…
When I run the test with 3 external monitors connected via laptop → usbc → external GPU → dp *3 → monitor *3 the CPU clock falls as the CPU load increases… in fact when the CPU load reaches 100% the clock never rises above 600MHz and browser videos freeze.
Closing the laptop screen helps but only in reducing the time the CPU spends at 100%… not the CPU frequency fall.
I am starting to think it is a power issue since this happens, not when the browsers are playing videos, but when firefox loads ‘Fedora Start | The Fedora Project’ (what’s in that page???) and the disk drive spins… but the disk io is low so that is not it… and both the external GPU and the laptop are independently connected to power… so that is not it either.
Or a combination of a power issue with something in the video pipeline limiting the CPU speed.
Don’t know about anyone else but I’m getting a faint whiff of “insufficient power from the power supply”, as Tom alludes to in this post.
Would powertop be of use in this scenario (I’m on a desktop with 800 watts at my disposal so I’ve never even considered measuring power draw. I seems concievable to me though that running all that output might well drop the supply to the processor so that it doesn’t boost to anything more than 600 Mhz.
Ok, so, let’s see if I am understanding this correctly:
The only time that you experience performance degradation (your#3) is when you use 3 monitors connected via laptop → usbc → external GPU → dp *3?
If this is the case, then your bottle-neck is the bandwidth of the USB connection + the external GPU … I am assuming that the “External GPU” is actually just a 3 usb-c → 3 port docking station kind of device, Not an actual accelerated GPU like an Nvidia …
What is happening is a block on I/O to the display/video output. Since the I/O is slow through the UCB-C then the main CPU is just backed up waiting. The rest of the system appears to freeze because the output to the USB-C → monitors is all buffered up on the computer side.
So, here are a couple of questions and some information to help you understand
look at the specs for that USB-C-> 3 port device … is it USB-C 3.2 Gen2 ? bandwidth is around 20Gbps
or is it Thunderbolt 3/4— 40Gbps
Now Display Port is between 21.6Gbps (DP 1.2) and 77.4Gbps (DP 2.0) … so, just for the sake of example:
3 x 1920x1080p monitors connected to 3 independent displayPort 2.0 could potentially/theoretically handle the combined bandwidth demand of 240Gbps … BUT …
If you connect that to a channel (USB-C 3.2 Gen 2) … the MAXIMUM bandwidth drops to 20Gbps == a whole lot of volume trying to go through a small straw to an ocean …
The only ways you will get better performance in your current setup would be:
drop the resolution — ugly
drop the color depth — ugly
use the laptop screen and connect 1 external monitor to the HDMI port and 1 to the DP port on your USB-C device ---- IF you want 3 monitors and better performance (would still bottle-neck due to the speed of USB-C Gen < 4 but would not be as bad as current)
reduce your screens to just the laptop monitor and an 1 HDMI connected monitor connected directly to your laptop
You also have 2 x thunderbolt ports on that laptop (per the specs) so you could also get 2 x thunderbolt → dp/hdmi and connect things like this:
a) 1 monitor to HDMI on laptop
b) 1 monitor to each of the Thunderbolt → DP/HDMI
#5 would give you the BEST performance with the same number of monitors/displays you currently have attached
Nope … its an actual external GPU (AMD Radeon RX 6800 XT) in its own enclosure and power supply.
The 3 screens are: 2560x1440, 3840x2160, 2560x1440 all at 60Hz.
I mostly use the 3 screens for IDEs + consoles + web reading and maybe 1 video playing… and it mostly works perfectly. At the moment: screen 1 has youtube video, screen 2 has a Netflix movie playing and screen 3 has all of my btop, top and system monitoring tools… and its all working.
Its only when I fire up Firefox and open that Fedora tab that the CPU freaks out and everything freezes for a bit.
Tomorrow I am going to do one more test where I just use the one HDMI connected monitor and I will take a look at the System Monitor - GPU usage… and see if its a lot lower. I still do think its a power issue on the laptop. As in you can have high power to two of: CPU, GPU, disk but not all 3.
However since it mostly works for my typical use case I am just going to live with it and maybe in the future I will switch to a tower workstation with an 800W power supply like Steve.
Ok, then that enclosure is most likely ThunderBolt 3/4 → PCIexpress → GPU → 3xDP …
Just for the sake of seeing what happens … next time you launch FF, right click and use “Launch using Discrete Graphics Card”
… also, not likely a Power supply issue … if it was, you would have way more serious side effects than just a stall/freeze under high demand … the machine would just plain crash
An 8 core processor should definitely be beefy enough to open a web browser and not have other applications freeze. I also have problems with loading the Fedora start page at times – the Mozilla home screen or a blank tab start are no problem at all.
I have a Ryzen 7 2700U, which is a 4 core processor with two threads each core. There were never any problems as in the past I usually used a blank tab and just recently in the past few months decided to keep the Fedora start page. So I think there is probably something about that page which could be optimized.
It sounds like you are well on your way to figuring it out but just wanted to add something that first came to mind reading your original post – you can limit the CPU count in Firefox itself.
“Adjusting these settings can be done in Preferences or by changing the dom.ipc.processCount value to 1-8 and browser.preferences.defaultPerformanceSettings.enabled to false manually in about:config.”
I guess Firefox allows to set how many concurrent processes it uses. It is not directly related to the CPU, in fact the default setting is 8 processes regardless, I am typing on a dual core Celeron CPU.
Another thing is Firefox uses lots of CPU when it starts because it pre-loads all the pages set in the “matrix” of the “first page”. If it is just an empty page it should use way less CPU (and network).