Last active
November 29, 2022 21:18
-
-
Save fernandoalmeida/d5b21553bd5b5ab0c21dc371d1dababd to your computer and use it in GitHub Desktop.
How to limit cpu/memory usage of applications using cgroups on Debian Jessie
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
################################################## | |
$ sudo apt-get install cgroup-tools | |
################################################## | |
# /etc/default/grub | |
GRUB_CMDLINE_LINUX_DEFAULT="quiet cgroup_enable=memory swapaccount=1" | |
################################################## | |
$ sudo update-grub | |
################################################## | |
# /etc/cgconfig.conf | |
group app/browser { | |
cpu { | |
cpu.shares = 300; | |
} | |
memory { | |
memory.limit_in_bytes = 1000000000; | |
} | |
} | |
group app/util { | |
cpu { | |
cpu.shares = 100; | |
} | |
memory { | |
memory.limit_in_bytes = 256000000; | |
} | |
} | |
################################################## | |
# /etc/cgrules.conf | |
*:firefox cpu,memory app/browser/ | |
*:iceweasel cpu,memory app/browser/ | |
*:conkeror cpu,memory app/browser/ | |
*:rocketchat cpu,memory app/util/ | |
*:dropbox cpu,memory app/util/ | |
################################################## | |
# /etc/rc.local | |
cgconfigparser -l /etc/cgconfig.conf | |
cgrulesengd | |
################################################## | |
# check cgroups | |
$ cat /proc/`pidof iceweasel`/cgroup | grep app | |
5:memory:/app/browser | |
2:cpu,cpuacct:/app/browser | |
$ cat /proc/`pidof dropbox`/cgroup | grep app | |
5:memory:/app/util | |
2:cpu,cpuacct:/app/util | |
################################################## | |
# check memory usage | |
$ smem -P dropbox | |
PID User Command Swap USS PSS RSS | |
1955 fernando /home/fernando/.dropbox-dis 0 191800 192388 201124 | |
$ smem -P iceweasel | |
PID User Command Swap USS PSS RSS | |
2409 fernando /usr/bin/iceweasel -app /us 0 577580 582096 605088 | |
################################################## |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment