Linux – Cgroups with libvirt/kvm on Centos 6.5

centos6cgroupkvm-virtualizationlinux

I am trying to limit all the memory used by virtual machines to a particular value.

On Ubuntu servers, setting limit to "libvirt-qemu " solves the issue. But in the case of CentOS, it creates libvirt/qemu/virtual-machine-name
and it looks like it is not possible to set global memory limit for virtual machines; instead the only way is to change the memory of limit virtual machines created under the qemu directory.

Is it possible to set a global cgroup memory limit?

mount {
    cpuset  = /cgroup/cpuset;
    cpu     = /cgroup/cpu;
    cpuacct = /cgroup/cpuacct;
    memory  = /cgroup/memory;
    devices = /cgroup/devices;
    freezer = /cgroup/freezer;
    net_cls = /cgroup/net_cls;
    blkio   = /cgroup/blkio;
 }
group mynamekvm {
   perm {
            admin {
                    uid = root;
                    gid = root;
            }
            task {
#uid of qemu and gid of kvm 
                   uid = 107;
                    gid = 37;
            }
   }
   memory {
            memory.limit_in_bytes = 61G;
  }

}

I have this set in cgrules.conf

 qemu            memory          mynamekvm

and restarted cgconfig and libvirtd and restarted virtual machines,

but still

mynamekvm/memory.usage_in_bytes is 0

Any idea how to set limits in libvirt on centOS systems?

Best Answer

Configuration is little different from Ubuntu. You need to add CGROUP_DAEMON=sets:name in /etc/sysconfig/libvirtd.

in your case it is

CGROUP_DAEMON=memory:/mynamekvm

Restart all relavant services that is cgconfig,libvirt and guests. Also make sure selinux is configured properly or try disabling and then restart services.

Related Topic