Skip to content

Instantly share code, notes, and snippets.

@jayeye
Created March 11, 2018 23:50
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save jayeye/9d2962c7ab59b1782f8a274f050a9ee7 to your computer and use it in GitHub Desktop.
Save jayeye/9d2962c7ab59b1782f8a274f050a9ee7 to your computer and use it in GitHub Desktop.
Run chrome in its own memory-limited cgroup
Ugly hack to run chrome in a memory-limited cgroup so it does not kill your workstation
when it tries to consume all available memory.
Put this in /usr/local/bin/cchrome, add that to whatever menu system you are using.
You can verify it worked by running:
grep memory `ps ax | grep chrome | grep -v grep | awk '{printf "/proc/%s/cgroup\n", $1}'`
This has only been tested on kubuntu desktop. Obviously, if you have not enabled
passwordless-sudo for yourself, create and chmod the cgroup directory from some
startup script!
#!/bin/sh
sudo mkdir -p /sys/fs/cgroup/memory/chrome
sudo chmod -R a=rwX /sys/fs/cgroup/memory/chrome
echo 8G > /sys/fs/cgroup/memory/chrome/memory.limit_in_bytes
exec cgexec -g memory:chrome google-chrome
@arcivanov
Copy link

arcivanov commented Mar 12, 2018

Line 4 works without sudo and tee?

UPD: Nevermind, chmod. :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment