Restrict the amount of CPU and memory resources that Chrome can consume.
*Tested on Ubuntu 16.04/Linux Mint 18.*
---
Install cgroups:
```
sudo apt install cgroup-bin
```
Set up a browser group in `/etc/cgconfig.conf` to limit the amount of resources Chrome can use:
```
group browsers {
perm {
task {
uid = jake;
gid = users;
}
admin {
uid = jake;
gid = users;
}
}
cpu {
# Allow chromium to use 2 CPU cores maximum (current machine has 4 cores).
# See: https://access.redhat.com/documentation/en-US/Red_Hat_Enterprise_Linux/6/html/Resource_Management_Guide/sect-cpu-Example_Usage.html
cpu.cfs_quota_us = 200000;
cpu.cfs_period_us = 100000;
}
memory {
# Allow chromium to use 6GB maximum (current machine has 16GB RAM)
memory.limit_in_bytes = "6G";
memory.soft_limit_in_bytes = "5G";
}
}
```
Then add a rule to `/etc/cgrules.conf` so that any new Chrome processes launched by my own user (`jake`) are added to the cgroup `browsers`:
```
# user:process subsystems group
jake:/usr/lib/chromium-browser/chromium-browser cpu,memory browsers
```
Since Ubuntu doesn't provide a systemd service to start cgroups, create your own in `/etc/systemd/system/cgroups.service`:
```
[Unit]
Description=Load cgroup configs
After=remote-fs.target
[Service]
Type=forking
ExecStartPre=/bin/echo "Processing /etc/cgconfig.conf..."
ExecStartPre=/usr/sbin/cgconfigparser -l /etc/cgconfig.conf
ExecStartPre=/bin/echo "Processing /etc/cgrules.conf..."
ExecStart=/usr/sbin/cgrulesengd --logfile=/var/log/cgrulesengd.log
Restart=on-failure
[Install]
WantedBy=multi-user.target
```
Finally, enable & start the service to load up your rules
```
sudo systemctl enable --now cgroups.service
```
---
#### References:
https://gist.github.com/juanje/9861623
https://wiki.archlinux.org/index.php/cgroups#Persistent_group_configuration
https://askubuntu.com/questions/836469/install-cgconfig-in-ubuntu-16-04
https://bugs.launchpad.net/fuel/+bug/1674633