23

My computer has only 4GB memory, and opening 8-12 random tabs on chrome or chromium often freezes my computer. Currently I'm using google-chrome-stable --process-per-site. This helps to some extent. Is there any way to run chrome or chromium in a single process? Could anyone give me some tips on how to control chrome's excessive memory usage?

7 Answers7

8

I am using cgroup this way:

sudo cgcreate -a $USER:$USER -t $USER:$USER -g memory:groupChromiumMemLimit
sudo cgset -r memory.limit_in_bytes=$((1024*1024*1024)) groupChromiumMemLimit
cgexec -g memory:groupChromiumMemLimit chromium-browser

The chromium itself may get somewhat slowed sometimes, as it seems to be swapping, but it will not make the whole system hang on swapping other applications, so just chromium/chrome will swap as soon it "reaches 1GB limit".

But... if you look at htop, you will see many chromium processes that sum the resident memory a bit beyond 1GB, I think I need more info on this.

havent tried yet memory.soft_limit_in_bytes to see if it helps in some way, as is suggested in the link provided by https://superuser.com/a/1168435/157532.

but overall, chromium is using much less RAM than it used to, and it is clearly being swapped a lot, so these cgroup commands are working despite of what I can see at htop, so cgroup seems to try to keep chromium using "not much more than 1GB" what is good enough.

8

There are a couple of other Chromium options you could use:

  1. Since Chromium 67 you may also want to disable Site Isolation to save another 9-11%, using flag chrome://flags/#site-isolation-trial-opt-out or --disable-site-isolation-trials command line option;

    Note: Since about July 2022 this option breaks all Cloudflare CAPTCHAs/​challenges!
    To workaround this issue you'll need to add a flag chrome://flags/#isolate-origins or --isolate-origins command line option as https://challenges.cloudflare.com.

    This appears to be a browser bug. Either that or Cloudflare is intentionally using Site Isolation / Spectre to detect browsers...

  2. You could explicitly limit the amount of renderer processes with --renderer-process-limit=2 command line option. This will put all of your extensions into a single process and ensure single process is used for all tabs as well. This didn't improve memory usage in my case, but I guess it depends on kind and amount of extensions you use, so it can be useful overall;

  3. Now if you really really want your Chrome-like to use less memory no matter what, you could enable low-end device mode. This will force your browser to think you're using some very poor Android device, so it will be clearing memory cache of inactive tabs and using 16-bit (65 536) colors for images. The option is --enable-low-end-device-mode.

    Since Chromium 108 a better setting is officially available at chrome://settings/performance called Memory Saver. If not there, this initially experimental feature can be enabled with flag chrome://flags/#high-efficiency-mode-available. Newer versions allow to abstractly adjust the unloading pace, while the flag allowed you to choose between 5s, 30s, 2m and 1h.

Finally, there is a --single-process option, but it's not officially supported, so it's not guaranteed to work, may still use more than a single process and may cause additional performance or stability issues. The use of more supported options above will give you a better balance between performance and memory usage.

Warning!
Most of these options will reduce the security of your browser! You use them at your own risk.


I was testing these options on Vivaldi 3.3 (Chrome 85) with 5 Super User tabs, 3 other tabs and 4 extensions. Here are the results I've got:

Default:                                            24 processes, ~920 MB
Default - Site Isolation:                           19 processes, ~835 MB,  -9%
Process per Site:                                   19 processes, ~770 MB, -16%
Process per Site - Site Isolation:                  13 processes, ~665 MB, -27%
Process per Site - Site Isolation + Renderer Limit: 10 processes, ~665 MB, -27%
4

There is a plugin you could use to write memory of unused open tabs to swap. It releases that ammount of memory, so CHrome/chromium shows less memory consumption.

Search for Tab-suspender on the webstore of plugins.

https://chrome.google.com/webstore/detail/tab-suspender/fiabciakcmgepblmdkmemdbbkilneeeh

2

I have the same issue, and I am not alone: Chrome/Chromium eats a lot of memory. Sometimes, this cause the system to freeze (in my case, Linux Mint 17).

solution 1

As a workaround I've started to use this Chrome-Extension: the-great-suspender

solution 2

But there are several other solutions, for example linux cgroup (https://gist.github.com/juanje/9861623)

other solutions

I have attached my other solutions to my first answer to similar question.

Anyway: Chrome is a good (probably best) web-browser, and sites today have high requirements (a lot of JS, canvas, SVG, embed video, web-sockets..). Trying to cut some of functionality - is not a good idea. The only one problem I am trying to solve (at least for me): nobody wants to sit near frozen system.

mksm
  • 208
1

As an extreme example, I'm using Chromium just for Gmail (in app mode) with some Chrome extensions for Gmail. To reduce the memory footprint, I've set the --single-process mode, which makes sense in cases like this.

I don't use Chromium for anything else, but if it isn't your case you would like to change the User Data Directory for the app mode window, so that it and the regular browser windows run on separated processes with only the app window in single process mode. These are the relevant lines of my Gmail.desktop file:

Exec=/usr/bin/chromium-browser --single-process --class=gmail --user-data-dir=.config/gmail --app=https://mail.google.com/mail
StartupWMClass=gmail
leogama
  • 623
1

Warning regarding the --enable-low-end-device-mode flag for Chrome:

This flag will cause chrome to use less RAM but also cause chrome to use SWAP a LOT. You're trading ram usage for disk i/o.

I was testing the flag on a mid-tier 12GB ram laptop to attempt solving sluggishness issue (tab hoarder). Whilst the system as a whole felt more responsive - there were significant consequences that made this sub-optimal:

  • (large) Chrome tabs would crash out-of-memory. Refresh would usually solve it but interrupt work flow.
  • Extreme swappiness. High disk i/o. Impacts other disk activities.

I was hoping the flag would have other consequences (maybe it does?) such as lower background cpu usage, etc. but the memory/swappiness alone was enough to disable the flag.

Back to square one.

oeb201
  • 11
0

Also if you have auto-update disabled, now may be the most appropriate time to finally update your browser. In 2020 – early 2021 Microsoft and Google were working on optimization of Chromium memory usage and since Chromium 89 they became available to everyone:

In Chrome M89, we’re seeing significant memory savings on Windows – up to 22% in the browser process, 8% in the renderer, and 3% in the GPU. Even more than that, we’ve improved browser responsiveness by up to 9%. [...]

In addition to improving how we allocate memory, Chrome is now smarter about using (and discarding) memory. Chrome now reclaims up to 100MiB per tab, which is more than 20% on some popular sites, by discarding memory that the foreground tab is not actively using, such as big images you’ve scrolled off screen.

Note that unlike Edge's, Chromium's solution is built-in and will work on all OSes it can run on.

Or you may even switch to another browser, like Vivaldi. It's based on Chromium, has lazy tab loading, easy unloading of back­ground tabs, ad blocker and lots of other useful features built-in.


I was testing memory usage by different Chromium versions on Windows 7 SP1 with 7 modern heavy sites and 3 extensions. Here are the results I've got:

                                        Vivaldi 3.3 /    Vivaldi 3.7 /     Vivaldi 5.6 /
                                         Chrome 85        Chrome 89         Chrome 108
By mode (total):
  Default:                              18 processes     21 processes      20 processes
                                          ~1855 MB      ~1715 MB,  -7%    ~1930 MB,  +4%
  Default - Site Isolation:             16 processes     18 processes      17 processes
                                          ~1780 MB      ~1705 MB,  -4%    ~1930 MB,  +8%
  Process per Site:                     16 processes     18 processes      17 processes
                                          ~1705 MB      ~1620 MB,  -5%    ~1850 MB,  +8%
  Process per Site - Site Isolation:    12 processes     14 processes      13 processes
                                          ~1555 MB      ~1530 MB,  -1%    ~1690 MB,  +8%
  Process per Site - Site Isolation      9 processes     11 processes      11 processes
                   + Renderer Limit:      ~1550 MB      ~1530 MB,  -1%    ~1685 MB,  +8%
By type (private set @ default mode):
  Browser process (Vivaldi-specific?):     ~130 MB       ~160 MB, +23%     ~160 MB, +23%
  GPU process:                             ~120 MB       ~115 MB,  -4%     ~190 MB, +58%
  Renderer processes:                     ~1345 MB      ~1170 MB, -13%    ~1045 MB, -22%
    GMail (mentioned in comments):         ~195 MB       ~175 MB, -10%     ~110 MB, -43%

Overall Chromium 89+ is more dynamic in using renderer processes, so it's hard to tell an exact consumption. These results were recorded after a minute since all the sites had been fully loaded.

Indeed, in Chromium 89 total memory usage decreased by ~7% (~140 MB) @ default mode, with almost no decrease in least-isolated modes. However, with later updates Chromium effectively lost all of its advances showing increase by ~8% across most tested modes (at least on Windows 7), even with further optimizations of renderer processes!...