Problem :
When leaving several tabs open in Google Chrome for hours/days, I notice that some pages end up using huge amounts of RAM, to the point where the whole OS (XP) becomes unresponsive due to paging. When I’m lucky, I can finally bookmark the list of open URLs, close Chrome, and start again; When I’m not, I simply must kill Chrome and hope I can recover the list of open URLs.
- Why is that? Memory leaks in plug-ins?
- Is there a way to configure Chrome so that a single tab/page won’t use more than a set amount of RAM?
Thank you.
Solution :
I think you should just opt for buying as much RAM as your OS can handle. You should not limit Chrome’s RAM usage because it will just ruin your surfing experience on the Web. Assuming that you use your computer for surfing the Internet most of the time, you should let Chrome get all the resources it needs in order to deliver the performance that you want for you to “enjoy” running those tabs at the same time.
I don’t think there is a way to limit every individual tab’s RAM usage but you can limit Chrome’s usage altogether. Look here:
https://stackoverflow.com/questions/192876/set-windows-process-or-user-memory-limit
I would rather not do that, if I were you, if I want smooth web surfing.
-
I wrote a Python 2.5 program which kills chrome’s renderers when they use over a set amount of memory. I run this program under
watch
. (note that it uses the psutil module which isn’t included with Python.)import sys, os, psutil if len(sys.argv) == 2: try: limit = int(sys.argv[1]) except: limit = 200 # default 200MB else: limit = 200 uid = os.getuid() for p in psutil.get_process_list(): try: if (p.name == 'chrome' and any('type=renderer' in part for part in p.cmdline) and p.uid == uid): m = p.get_memory_info() #print p.pid,m, m.rss / 1024 / 1024, m.vms / 1024 / 1024 if (m.rss / 1024 / 1024) > limit: # kill if rss is greater than limit print 'Killed', p.pid p.kill() except psutil.error.NoSuchProcess: pass except psutil.error.AccessDenied: pass
-
I rely on Session Buddy to recover the open tabs when chrome fails to restore them.
The only thing I’ve seen to date that can do this is to run chrome inside a container and limit the containers ram.
However this has some major caveats,
-
Running chrome is complicated by the dockerize setup and launch sequence
-
for one, Chrome already uses kernel containers to sandbox its threads; so you have to run the container with a kind of root privilege that allows that to work. This can be circumvented, and the linked container model does so. (it does practically everything it needs to)
-
You will almost certainly loose gpu acceleration
-
getting audio to work is complicated, but handled in the linked container model.
-
Whatever else you expect to go wrong when you void your warranty, Chrome violently dislikes being told not to use more ram, and will act up and tantrum accordingly.
But it ultimately does work.
I am more interested in applying these ram limits to Electron Shell apps which don’t have prebuilt docker images to rangle them for you.
Off topic but I want to note that Firefox is very well behaved on limited hardware, but I don’t consider that a real answer.
It isn’t necessarily plugin. Note that webpages are no longer static. Some webpages just have a non-trivial amount of async activity going on. Add on the activity from the plug-ins and you got some unknowns.
The best remedy I have found is to kill the webpage and reload it. AFAIK, there is no way to limit the amount of RAM a webpage uses.