I am trying to use cgroup
(Control Group) to limit the memory usage of virtualbox, but it does not seem to work.
My machine is:
$ uname -a
Linux fc.bgi 2.6.40-4.fc15.i686 #1 SMP Fri Jul 29 18:54:39 UTC 2011 i686 i686 i386 GNU/Linux
I tried to get it to work like this:
-
Creating new cgroups under memory hierarchy:
$ cgcreate -g memory:vbox
-
Setting memory.limit_in_bytes for vbox:
$ cgset -r memory.limit_in_bytes=512M vbox
-
Grouping vbox running pid to vbox:
$ cgclassify -g memory:vbox 20015
Can someone explain why this is not working?
Best Answer
you could limt memory usege with /etc/security/limits.conf in this file you put :
domain type item value
where the
domain
is the@groupname
,type
ishard
orsoft
wherehard
is limt that cannot be exceeded under any circumstances.item
is the item field specifies what type of item is being limited. Examples include core (the size of core files), data (the size of a program’s data area), fsize (the size of files created by the user), nofile (the number of open data files), rss (the resident set size), stack (the stack size), cpu (the CPU time of a single process in minutes), nproc (the number of concurrent processes), maxlogins (the number of simultaneous logins), and priority (the process priority). The data, rss, and stack items all relate to memory consumed by a pro- gram. These and other measures of data capacity are measured in kilobytes.and
value
is relate to theitem
field that you have chose, for example if you have chosecpu
in theitem
field and put2
in thevalue
then in case thedomain
(you group of VirtualBox) is take more than2
of the cpu time it will be terminated.You can use
ulimit
too, but it restricted to the bash shell only.Hope this help you in you goal, although it isn't done with the method you asked.