Skip to content

Instantly share code, notes, and snippets.

@juanje
Last active November 30, 2023 19:29
Show Gist options
  • Save juanje/9861623 to your computer and use it in GitHub Desktop.
Save juanje/9861623 to your computer and use it in GitHub Desktop.
Limit Chrome from eating all the memory and CPU

I was tired of Chrome eating all my laptop resources so I decided to put some limit to it with cgroup.

As I was using Ubuntu 12.04 with support for cgroup, I installed the package cgroup-bin and add the following group to the file /etc/cgconfig.conf:

group browsers {
    cpu {
#       Set the relative share of CPU resources equal to 25%
        cpu.shares = "256";
    }
    memory {
#       Allocate at most 1 GB of memory to tasks
        memory.limit_in_bytes = "1G";
#       Apply a soft limit of 512 MB to tasks
        memory.soft_limit_in_bytes = "768M";
    }
}

Then I added one new rule to the file /etc/cgrules.conf to add any new Chrome process launched by my own user (jojeda) to the cgroup browsers:

# user:process                                          subsystems      group
jojeda:/usr/lib/chromium-browser/chromium-browser       cpu,memory      browsers

And then I restarted the cgconfig service:

$ sudo service cgconfig restart

Now all the new chromium process that I'll launch with my user jojeda will be under the cgroup browsers with its memory and cpu limits.

@juanje
Copy link
Author

juanje commented Jun 6, 2019

@kalimalrazif This is very old config and I don't even use it anymore, but I think is 1G for all the processes.
The config defined 1G for the group, so the 1G is to be shared by all processes fo the group. I think...

@kalimalrazif
Copy link

Ok all the processes then :-) thanks anyway for your answer :-)

@tobia
Copy link

tobia commented Mar 6, 2020

For those who want an up-to-date tutorial for Ubuntu, here is one https://www.paranoids.at/cgroup-ubuntu-18-04-howto/

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