mailing-libvirt at posteo.de
2023-May-12 11:36 UTC
Question regaring correct usage of CPU shares
Hi there, I have a question regarding the shares option of the cputune section. I want to illustrate my question with the following example. Let's assume I have two virtual machines like the following on four dedicated core with two threads each: VM1: <cputune> <shares>512</shares> <vcpupin vcpu="0" cpuset="0"/> <vcpupin vcpu="1" cpuset="4"/> </cputune> VM2: cputune> <shares>512</shares> <vcpupin vcpu="0" cpuset="1"/> <vcpupin vcpu="1" cpuset="5"/> <vcpupin vcpu="2" cpuset="2"/> <vcpupin vcpu="3" cpuset="6"/> <vcpupin vcpu="4" cpuset="3"/> <vcpupin vcpu="5" cpuset="7"/> </cputune> Those two virtual machines I just mentioned won't interfere with one another since they are pinned to different cores. However I introduce another, third virtual machine, like this: VM3: <cputune> <shares>512</shares> <vcpupin vcpu="0" cpuset="0"/> <vcpupin vcpu="1" cpuset="4"/> <vcpupin vcpu="2" cpuset="1"/> <vcpupin vcpu="3" cpuset="5"/> <vcpupin vcpu="4" cpuset="2"/> <vcpupin vcpu="5" cpuset="6"/> <vcpupin vcpu="6" cpuset="3"/> <vcpupin vcpu="7" cpuset="7"/> </cputune> What I want is that VM1, VM2 and VM3 all receive half of the cores CPU time if congestion appears. My question is how the shares are calculated. Are they calculated on a per core basis? Meaning VM1 and VM3 use the first core so each will get half of the cores capacity when congestion appears, or are the shares calculated over all cores a virtual machine uses and I need to scale the amount of shares with increasing number of cores. What is the correct setting here so that all virtual machines in this example are guaranteed half of the capacity of each of their respective cores if congestion appears? Thank you.
On Fri, May 12, 2023 at 11:36:36AM +0000, mailing-libvirt at posteo.de wrote:>Hi there, >Hi, sorry for the late answer.>I have a question regarding the shares option of the cputune section. I >want to illustrate my question with the following example. Let's assume >I have two virtual machines like the following on four dedicated core >with two threads each: > >VM1: ><cputune> > <shares>512</shares> > <vcpupin vcpu="0" cpuset="0"/> > <vcpupin vcpu="1" cpuset="4"/> ></cputune> > >VM2: > cputune> > <shares>512</shares> > <vcpupin vcpu="0" cpuset="1"/> > <vcpupin vcpu="1" cpuset="5"/> > <vcpupin vcpu="2" cpuset="2"/> > <vcpupin vcpu="3" cpuset="6"/> > <vcpupin vcpu="4" cpuset="3"/> > <vcpupin vcpu="5" cpuset="7"/> ></cputune> > >Those two virtual machines I just mentioned won't interfere with one >another since they are pinned to different cores. However I introduce >another, third virtual machine, like this: > >VM3: ><cputune> > <shares>512</shares> > <vcpupin vcpu="0" cpuset="0"/> > <vcpupin vcpu="1" cpuset="4"/> > <vcpupin vcpu="2" cpuset="1"/> > <vcpupin vcpu="3" cpuset="5"/> > <vcpupin vcpu="4" cpuset="2"/> > <vcpupin vcpu="5" cpuset="6"/> > <vcpupin vcpu="6" cpuset="3"/> > <vcpupin vcpu="7" cpuset="7"/> ></cputune> > >What I want is that VM1, VM2 and VM3 all receive half of the cores CPU >time if congestion appears. My question is how the shares areThat is what should, theoretically, happen, yes. And it does not matter if the value is 512, 7 or 20000.>calculated. Are they calculated on a per core basis? Meaning VM1 andNo, they are set per-VM.>VM3 use the first core so each will get half of the cores capacity when >congestion appears, or are the shares calculated over all cores a >virtual machine uses and I need to scale the amount of shares with >increasing number of cores. What is the correct setting here so that >all virtual machines in this example are guaranteed half of the >capacity of each of their respective cores if congestion appears? >The above is okay from this point of view. But it depends on the rest of your system. What scheduler you have, what are the other processes running, etc. You can have a look at the settings in cgroups (in v1 this is cpu.shares, in v2 I think that's cpu.weight) and see how they are set. Hope that helps, Martin -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 833 bytes Desc: not available URL: <http://listman.redhat.com/archives/libvirt-users/attachments/20230526/cb3accf2/attachment.sig>