(Updated) Chrome Browser Freezing Up Your Linux Box? Try This:

Being an absolutely avid GNU/Linux user, I am always very much enjoying my technological freedom!

In fact, switching to GNU/Linux is among the better choices I've ever made, career-wise and from the standpoint of weilding the cutting edge when it comes to Technology! Get Yours!

That said, I use two web browsers on my Linux machines: Google's Chrome and Mozilla's Firefox.

The thing with using Chrome on GNU/Linux, and it's good and a bad thing - is that the Adobe(tm) Flash plugin is integrated into the Chrome. So until all Flash content gives way to HTML5 content on the web, Chrome gives me the most functionality for the current Internet.

Google's Chrome is an awesome an powerful browser that's based on the Open Source Chromium project. This is an awesome project that helps to provide the most access to the web, from all sorts of devices and operating systems - it's cross-platform-compatible.

Google Chrome is awesome, but one thing I've noticed, is that since Chrome will launch extra processes as necessary to handle additional tabs in the browser, the browser can end up having a very large memory footprint on the machine. On several of my Linux boxes, this memory consumption by Chrome, seems to have caused an issue where the machine will actually lockup from being out of memory.

When the going gets tough, Linux is infinitely configurable! The user is in charge! So after looking around for a way to manage the issue where Chrome is eating up all of my system's memory and locking up the box, I found a blogpost entitled 'Automatically kill process using too much memory on Linux' by Jon Jensen on blog.endpoint.com - accessed 7/9/2016, that seems to have helped me solve my issue.

Mr. Jensen's blog post mentions a Perl script that is setup in a crontab to run every minute and kill off any process that uses too much memory. The script provides pretty much what I need to control my Chrome from running away with the memory on my system and locking up the machine.

After doing some testing, what I realized with the Chrome memory usage problem, is that due to the fact that many chrome processes are launched with the browser, we can't just watch for one process to eat up a large amount of memory and act accordingly. Instead, we need to look at the overall total usage of the several Chrome processes that will run to support multiple tabs in Chrome.

For instance, in a test, I have 7 tabs open in Chrome, and currently there are 10 chrome processes showing on my Linux machine:

Another thing I noticed is that with those 10 chrome processes, they are using over 2GB of the 8GB of RAM I have on my machine currently.

So here's the script I created to kill off some chrome processes when the overall memory usage from them is too large. This script is based on the example script from Mr. Jensen's blog post above. Note: The script example below will kill off chrome processes when total usage of system RAM by chrome is over 7.5GB, because I have 8GB of RAM installed. If your system has a different amount of RAM, adjust the value for $numMaxByteUsage accordingly. For example, if you have 2GB of RAM installed, I'd suggest setting something like this - $numMaxByteUsage = 1610612736 in the script below. Note, if the below is pasted into the terminal, it will create the script file named 'kill_chrome_tabs_when_ram_depleted.pl' in the home directory.

Note: You then can setup a crontab to run the script every minute. In this case, if you're browsing along and chrome starts eating up all your memory, the crontab+script will kill off any chrome processes after reaching the threshold noted in the script. See '$intRamUsed' setting, which is shown as byte-size.

To run the script, you may have to install the supporting Perl package to inspect system processes first (e.g., if you get error 'Can't locate Proc/ProcessTable.pm in @INC (you may need to install the Proc::ProcessTable module'):

Also, you'll want to add the script to run in a crontab every minute. Here's the example crontab entry for root(sudo crontab -e) in my case (sudo crontab -l):

To test, I opened up about 60 tabs in Chrome(see 1st pic below). I then ran the script above to output the total memory used by chrome. As you can see, the usage reached about 7.5GB of RAM, then the script executed a command to kill some chrome processes. This caused a few tabs to go "snap", but the rest of the browser tabs continued working(see 2nd pic below).

Lotsa tabs to use all my RAM!
Totalrss gets to around 7.5GB, then chrome processes start getting killed


Popular posts from this blog

How To Connect Ubuntu Linux to Cisco VPN with openconnect (anyconnect-capable alternative)

(updated) How To: Ubuntu 16.04 GNU / Linux - Netgear Wireless AC Adapter AC600 ( AC6100 ) Dual Band

How To Set Default Grub / kernel / boot option on Ubuntu GNU/Linux 14.04