Getting better understanding of cpuunits in containers and VMs

dmshimself

New Member
Aug 15, 2020
5
0
1
65
This is for PVE Manager 6.2.11 running on a single test dual core box with 1 socket. I see that cpuunits can be applied to the cpu resources/hardware of both containers and kvm machines and I had hoped to use the information from the manual to give a low CPU priority to some containers which run low priority, background tasks, but without much success.

As a test I created a simple container running archlinux and a VM running W2012. There are apps installed so both the container and VM and will use all the CPU resources they can, given the chance. The container has 2 cpus allocated, unlimited with cpuunits as 10. The VM has the same, but cpuunits is 1000. Neither are memory or IO bound.

With both running, each gets a little under 50% of the CPU time which wasn't quite what I expected. I thought perhaps the VM would get 100 times the share of the CPU or at least a signifiacntly higher share than the container. Is there a way to do this sort of tailoring - to give the container a lower access to cpu resources so it gets 10% and the VM gets 90% when both are running the CPU flat out?

I can see that I can use a cpulimit to stop the container from getting more than say, half a core, but that would seem to mean when no other container/VM was running, it would only use quarter of the CPU resources available.

If the VM isn't running or doing a lot of IO, I'm happy for and would quite like the container to use more CPU resources.

Any thoughts appreciated :)
 

wolfgang

Proxmox Staff Member
Staff member
Oct 1, 2014
6,497
461
103
Hi,

cpuuinits are a priority system for all tasks at the host system.
But it no load is on the host there is no reason to restrict the task.

So if you have two guests with 2 cores and the host has 8 cores.
On the system is nothing less you will not see any restriction.
Because you are using a maximum of 4 cores out of 8 cores.
 

dmshimself

New Member
Aug 15, 2020
5
0
1
65
Thanks very much for that and I understand the limits you mentioned. In my sample case the host has 2 cores, the container has 2 cores with cpuunits 10 and the VM has 2 cores with cpuunits 1000. With container and VM running apps that use all the CPU resources available to the container/VM, the container and the VM both get about 50% of the host CPU, so about 100% together.

I had hoped with the cpuunits set to see the container getting (say) 10% of the host CPU time and the VM getting 90% as that seems to be the implied behaviour in the documentation.

Is there a way to achieve this 'unfair' sharing?
 

wolfgang

Proxmox Staff Member
Staff member
Oct 1, 2014
6,497
461
103
LXC and KVM in total have the same share for the fair scheduler.
Cgroups are hierarchical and Qemu and LXC guests have different parents.
This is the reason why it does not work here.

You could restrict LXC and KVM in total.
With 2 guests this would work.
 

dmshimself

New Member
Aug 15, 2020
5
0
1
65
LXC and KVM in total have the same share for the fair scheduler.
Cgroups are hierarchical and Qemu and LXC guests have different parents.
This is the reason why it does not work here.

You could restrict LXC and KVM in total.
With 2 guests this would work.

I'm not going mad then :) Thanks for guidance - do you know if there any guides on doing what you refer too, or is it time for me to hit the books?
 

wolfgang

Proxmox Staff Member
Staff member
Oct 1, 2014
6,497
461
103
do you know if there any guides on doing what you refer too, or is it time for me to hit the books?
It is never the wrong time to read well a book :)

I never did this before but you have to set the "cpu.shares" on these two paths

/sys/fs/cgroup/cpu,cpuacct/qemu.slice/cpu.share
/sys/fs/cgroup/cpu,cpuacct/lxc/cpu.share

As always sysfs are not persistent over boots.
 
  • Like
Reactions: avw

dmshimself

New Member
Aug 15, 2020
5
0
1
65
It is never the wrong time to read well a book :)

I never did this before but you have to set the "cpu.shares" on these two paths

/sys/fs/cgroup/cpu,cpuacct/qemu.slice/cpu.share
/sys/fs/cgroup/cpu,cpuacct/lxc/cpu.share

As always sysfs are not persistent over boots.

I shall have a go :)

Many thanks for your help - appreciated
 

About

The Proxmox community has been around for many years and offers help and support for Proxmox VE and Proxmox Mail Gateway. We think our community is one of the best thanks to people like you!

Get your subscription!

The Proxmox team works very hard to make sure you are running the best software and getting stable updates and security enhancements, as well as quick enterprise support. Tens of thousands of happy customers have a Proxmox subscription. Get your own in 60 seconds.

Buy now!