VMmanager 5 KVM: Administrator guide
Do you make friends with the documentation?
Share your opinion and complete a small poll
Take a survey

Manage priorities of resource consumption using CGroups

CGroups is a feature that limits and isolates resources of a collection of processes.

It supports the following operations for the group of processes:

  • limit the RAM usage; 
  • set priorities for CPU usage and capacity of the I/O subsystem;
  • collect resource usage statistics; 
  • isolate namespaces; 
  • use management tools.

libvirt uses cgroups v1. With libvirt VMmanager uses two modules cgroups: cpu and  blkio that allow managing priorities of CPU usage and I/O subsystem capacity. 

For more information please refer to the article Virtualization management using libvirt.

The priorities are set in the fields CPU weight and I/O weight usage when you create a virtual machine. In cgroups of the cluster nodes, the corresponding directories with the specified parameters are created.

A virtual machine is allocated the CPU time according to its priorities from the total amount of priorities of virtual machines. I/O subsystem capacity is allocated in the same way. 

E.g., if three virtual machines are requesting CPU resources simultaneously:

  • VM1 with CPU weight 1000;
  • VM2 with CPU weight  2000;
  • VM3 with CPU weight 4000.

CPU time will be distributed between virtual machines in the following way:  

  • VM1: 1000/(1000+2000+4000)*100% = 14,3 %;
  • VM2: 2000/(1000+2000+4000)*100% = 28,6 %;
  • VM3: 4000/(1000+2000+4000)*100% = 57,1 %.

CPU weight is stored in the the file /sys/fs/cgroup/cpu/machine.slice/machine-qemu\x2dvm1.scope/cpu.shares.

blkio weight is stored in the file /sys/fs/cgroup/blkio/machine.slice/machine-qemu\x2dvm1.scope/blkio.weight.