I fed up Chrome eating all my memory so i put in a cage... the control groups way.
My kernel config diff:
diff -y ".config.cgroups" ".config" > diff_configcgroups_config1
http://pastebin.com/sAxdRNGa
the short version:
diff -y --suppress-common-lines ".config.cgroups" ".config" > diff_configcgroups_config2
http://pastebin.com/vAjeY8q1
Don't forget to enable control groups in openrc file:///etc/rc.conf:
Code: Select all
rc_controller_cgroups="YES"and:
Code: Select all
rc-update add cgred bootfile:///etc/cgroup/cgconfig.conf:
Code: Select all
#
# Copyright IBM Corporation. 2007
#
# Authors: Balbir Singh <balbir@linux.vnet.ibm.com>
# This program is free software; you can redistribute it and/or modify it
# under the terms of version 2.1 of the GNU Lesser General Public License
# as published by the Free Software Foundation.
#
# This program is distributed in the hope that it would be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
#
#group daemons/www {
# perm {
# task {
# uid = root;
# gid = webmaster;
# }
# admin {
# uid = root;
# gid = root;
# }
# }
# cpu {
# cpu.shares = 1000;
# }
#}
#
#group daemons/ftp {
# perm {
# task {
# uid = root;
# gid = ftpmaster;
# }
# admin {
# uid = root;
# gid = root;
# }
# }
# cpu {
# cpu.shares = 500;
# }
#}
#
# Prevent Chromium from taking all memory
group chromium {
perm {
admin {
uid = kollin;
}
task {
uid = kollin;
}
}
cpu {
# Set the relative share of CPU resources equal to 25%
cpu.shares = "256";
}
cpuset {
cpuset.mems="0";
cpuset.cpus="0-0";
}
memory {
# 1 GiB (1073741824 bytes) and total memory of 11G limit
memory.limit_in_bytes = 1G;
memory.memsw.limit_in_bytes = 11G;
memory.oom_control= 0;
}
}
mount {
cpuset = /cgroup/cpuset;
cpu = /cgroup/cpu;
cpuacct = /cgroup/cpuacct;
memory = /cgroup/memory;
devices = /cgroup/devices;
freezer = /cgroup/freezer;
#blkio = /cgroup/blkio;
"name=openrc" = /cgroup/blkio;
}memory.limit_in_bytes = 1G; - i'm limiting physical memory usage to 1G
memory.memsw.limit_in_bytes = 11G; all available memory for Chrome will be 11G physical+swap, then comes
memory.oom_control= 0; which will kill Chrome if exceeds the limit of 11G total
cpuset.cpus="0-0"; means that Chrome will be run only at core0 of my CPU.
cpu.shares = "256"; means that Chrome will not use more than 1/4 of CPU time compared to other processes
file:///etc/cgroup/cgrules.conf (here you decide what control groups will be available for Chrome)
Code: Select all
# /etc/cgrules.conf
#The format of this file is described in cgrules.conf(5)
#manual page.
#
# Example:
#<user> <controllers> <destination>
#@student cpu,memory usergroup/student/
#peter cpu test1/
#% memory test2/
kollin:/usr/bin/google-chrome-stable cpuset,cpu,memory chromium
kollin:/opt/google/chrome/google-chrome cpuset,cpu,memory chromium
kollin:/opt/google/chrome/chrome cpuset,cpu,memory chromium
#kollin:/usr/bin/google-chrome-stable cpuset,memory chromium
#kollin:/opt/google/chrome/google-chrome cpuset,memory chromium
#kollin:/opt/google/chrome/chrome cpuset,memory chromium
#kollin:/usr/bin/google-chrome-stable cpu,memory chromium
#kollin:/opt/google/chrome/google-chrome cpu,memory chromium
#kollin:/opt/google/chrome/chrome cpu,memory chromium
# End of file
Code: Select all
cgexec -g memory:/chromium --sticky /usr/bin/google-chrome-stable %UCode: Select all
cgexec -g memory,cpu:/chromium --sticky /usr/bin/google-chrome-stable %UCode: Select all
cgexec -g memory,cpu,cpuset:/chromium --sticky /usr/bin/google-chrome-stable %U--sticky makes it sure that no child process can escape out of the control group.
The bottom line:
It worked, but Chrome becomes unusable that way, it gets very slooooooowwwwwww and hogs the hard drive.
So, good bye Chrome welcome Firefox again!
