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:

  1. Creating new cgroups under memory hierarchy:

    $ cgcreate -g memory:vbox
  2. Setting memory.limit_in_bytes for vbox:

    $ cgset -r memory.limit_in_bytes=512M vbox
  3. Grouping vbox running pid to vbox:

    $ cgclassify -g memory:vbox 20015

Can someone explain why this is not working?


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 is hard or soft where hard 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 the item field that you have chose, for example if you have chose cpu in the item field and put 2 in the value then in case the domain (you group of VirtualBox) is take more than 2 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.


I'm guessing there is something wrong with your /etc/cgconfig.conf file. This setup works for me:

[root@localhost cgroup]# cat /etc/cgconfig.conf
mount {
    memory  = /cgroup/memory;

[root@localhost cgroup]# service cgconfig start
Starting cgconfig service:                                 [  OK  ]
[root@localhost cgroup]# ls
[root@localhost cgroup]# ls memory/
cgroup.event_control  memory.limit_in_bytes        memory.memsw.max_usage_in_bytes  memory.soft_limit_in_bytes  memory.use_hierarchy
cgroup.procs          memory.max_usage_in_bytes    memory.memsw.usage_in_bytes      memory.stat                 notify_on_release
memory.failcnt        memory.memsw.failcnt         memory.move_charge_at_immigrate  memory.swappiness           release_agent
memory.force_empty    memory.memsw.limit_in_bytes  memory.oom_control               memory.usage_in_bytes       tasks
[root@localhost cgroup]# cgcreate -g memory:vbox
[root@localhost cgroup]# cgset -r memory.limit_in_bytes=512M vbox
[root@localhost cgroup]# cgclassify -g memory:vbox 11727
[root@localhost cgroup]# cat memory/vbox/tasks 

Though, rather than using the cgreate and cgset commands, I'd advise you to just create a /etc/cgconfig.conf file that would include these settings so that you don't have to repeat the process after every reboot. In your case, the file would look like this:

[root@localhost cgroup]# cat /etc/cgconfig.conf
mount {
    memory  = /cgroup/memory;

group vbox {
    memory {

Now, every time you start the cgconfig service, you'll have your vbox cgroup ready. All that's needed is to move the virtualbox's PID into the /cgroups/memory/vbox/tasks file using either cgclassify or just simply echo the number in that file.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy