View previous topic :: View next topic |
Author |
Message |
Kollin Veteran
Joined: 25 Feb 2006 Posts: 1139 Location: Sofia/Bulgaria
|
Posted: Sun Feb 15, 2015 1:20 pm Post subject: Google-chrome & control groups |
|
|
I'm going to forget what i did learn about the control groups so I'm posting it here. Use it at your own risk!
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: | rc_controller_cgroups="YES" |
You should install dev-libs/libcgroup also.
and: Code: | rc-update add cgred boot |
control group configs in /etc/cgroup/
file:///etc/cgroup/cgconfig.conf:
Code: | #
# 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;
} |
blkio is commented out because it refused to mount.
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: | # /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
|
How to start Chrome in a cage:
Code: | cgexec -g memory:/chromium --sticky /usr/bin/google-chrome-stable %U |
or
Code: | cgexec -g memory,cpu:/chromium --sticky /usr/bin/google-chrome-stable %U |
or
Code: | cgexec -g memory,cpu,cpuset:/chromium --sticky /usr/bin/google-chrome-stable %U |
depending on the cgroup you want it to be started in: memory cgroup only, memory+cpu, or memmory+cpu+cpuset
--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! _________________ "Dear Enemy: may the Lord hate you and all your kind, may you be turned orange in hue, and may your head fall off at an awkward moment."
"Linux is like a wigwam - no windows, no gates, apache inside..." |
|
Back to top |
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|