I have an annoying problem with Ubuntu's resource management. Frequently it happens that some programs such as Google Chrome browser consume 100% CPU and most of my laptops memory.
I want to have a responsive OS all the time, it means that I want to be able to switch between programs and move my mouse on the screen or switch to a tty and give commands to the OS. Therefore I look for a way to configure the OS to reserve lets say 10% of system resources for itself. Currently Ubuntu does not behave this way, frequently chrome consumes all my CPU and memory and then the system becomes unresponsive, and of course I can't wait more that a minute or two so I have to long press power button.
Is there any way to make Ubuntu to be always responsive? At least to that extent that I can kill the resource hungry program? ( I know the kernel will eventually kill some programs to free some space but I want to force it to do it either faster or reserve more resources for itself)
Version: UBUNTU 14.04
~$ uname -a
Linux spielplatz 3.13.0-45-generic #74-Ubuntu SMP Tue Jan 13 19:36:28 UTC 2015 x86_64 x86_64 x86_64 GNU/Linux
CPU: Intel(R) Core(TM) i5-3210M CPU @ 2.50GHz
RAM: 8GB
Update (8 October 2017)
The best solution that I have found so far is using cgroups. There is a gist for that.
Best Answer
I've used
cpulimit
to "throttle" out-of-control CPU hungry programs before (Xfce4 Mailwatch Plugin gets hung up & grabs 100% CPU sometimes). cpulimit is a:It works by monitoring the target process, and sending "the SIGSTOP and SIGCONT signals to a process, both to verify that it can control it and to limit the average amount of CPU it consumes." See:
It should make the rest of your OS more responsive, but I've tried it on Firefox and it tends to render it much less responsive, so may not be the best answer for the Chrome browser. Searching for ways to speed up Chrome itself might be more fruitful.
If you just want a good way to see how much CPU & RAM is in use, and what processes are using them, I'd suggest a system monitoring program (like
top
,htop
, I prefer conky), then when you see something eating all your cpu or ram you can close/restart, etc.If you're interested in knowing what programs get scheduled to run first, look into scheduling priority & "niceness". Perhaps you could make Chrome act "nicer" without crippling it.
Here's a clip from
info coreutils 'nice invocation'
:And here are a few useful-looking links about scheduling
And muru's comment/post on Cgroups (on ArchWiki) looks good, about limiting ram, looks like it could limit CPU cores & "shares" too ("By default all groups have 1024 shares. A group with 100 shares will get a ~10% portion of the CPU time").
The first paragraph of the ArchWiki article also mentions this potentially useful option, though I think they're mainly for limiting users/groups, see:
man pam_limits
&man limits.conf