cloudstack icon indicating copy to clipboard operation
cloudstack copied to clipboard

cputune shares in domain xml set without CPU cap enabled

Open DennisKonrad opened this issue 6 years ago • 14 comments

ISSUE TYPE
  • Bug Report
COMPONENT NAME

KVM Domain XML LibvirtComputingResource

CLOUDSTACK VERSION

current master

CONFIGURATION

We see VMs with an compute offering that has CPU cap disabled that have CPU shares set in their domain XML.

Also we see that VMs that use very similar offerings that have "offer HA" enabled, do not have set cpu shares in their XML.

SUMMARY

cputune parameter should not be enabled when cpu cap is disabled for a vm.

STEPS TO REPRODUCE

Create offering with "offer HA" disabled and check domain XML file of an VM created with it. cputune and shares are set.

Create offering with "offer HA" enabled and check domain XML file of an VM created with it. cputune and shares are set.

EXPECTED RESULTS

When cpu cap is disabled there should be no cputune with shares in the domain xml.

DennisKonrad avatar Mar 02 '20 12:03 DennisKonrad

@ustcweizhou @wido Did you maybe encounter an issue like this before?

We saw a lot of CPU steal on VMs and investigated the issue. The culprit is the cputune parameter described above that lead to the stealtime. After using a offering with "offer HA" the cputune is gone and the cpusteal also.

DennisKonrad avatar Mar 02 '20 12:03 DennisKonrad

@DennisKonrad I have tested the offerings with HA and offering without HA, there is no difference with the vm xml definitions (cputune is defined with both offerings).

weizhouapache avatar Mar 02 '20 13:03 weizhouapache

@weizhouapache That's really weird...

Okay, do you think this should be like this? In my opinion cputune should not be set when cpu cap is disabled. Also it causes huge issues for us when VMs are maxing out on CPU usage. Steal time goes up to 50% with cputune shares

DennisKonrad avatar Mar 02 '20 13:03 DennisKonrad

@weizhouapache Or maybe do you know a way to not have this cputune set at all? Looking at the code it is my understanding that it should not be set when limit_cpu is false

DennisKonrad avatar Mar 02 '20 13:03 DennisKonrad

@weizhouapache I checked with virsh schedinfo [instance-name] what cpu_shares are really set (and double checked through looking into /sys/fs/cgroup/cpu/... ) and most of the VMs just have the default value of 1024.

Most of the values CS generates are way lower and probaly therefor discarded?! Just a few really get the value specified in the domain xml. Is this the same with your VMs?

DennisKonrad avatar Mar 02 '20 15:03 DennisKonrad

schedinfo

@DennisKonrad cpu_shares in "virsh schedinfo " = virsh dumpxml | grep shares = cpu cores * cpu speed / cpu.overprovisioning.factor

weizhouapache avatar Mar 02 '20 19:03 weizhouapache

2 Cores * 1000 MHz / 10 = 200

In reality theres 66 set. Did I get you right on the calculation? @weizhouapache

EDIT I found why the shares are not set correctly anymore. In our last update the qemu.conf got replaced and there were no controllers configured. After repairing that the values match beween XML, schedinfo and cgroup.

Click to expand!
<domain type='kvm' id='148'>
...
  <currentMemory unit='KiB'>4194304</currentMemory>
  <vcpu placement='static'>2</vcpu>
  <cputune>
    <shares>66</shares>
  </cputune>

Schedinfo is already wrong:

Scheduler      : posix
cpu_shares     : 1024
vcpu_period    : 100000
vcpu_quota     : -1
...

Cgroup (or CFS) shares are set falsely set also (as one would expect):

# cat cpu.shares
1024
# pwd
/sys/fs/cgroup/cpu/machine.slice/machine-qemu\x2d148\x2di\x2d331\x2d2003\x2dVM.scope

DennisKonrad avatar Mar 03 '20 10:03 DennisKonrad

After all the share values are correctly set through libvirt/qemu the steal issue is gone. Also as there is a default value of shares set anyway it makes absolutely sense to set it regardless of the cpu cap setting.

DennisKonrad avatar Mar 05 '20 09:03 DennisKonrad

After all the share values are correctly set through libvirt/qemu the steal issue is gone. Also as there is a default value of shares set anyway it makes absolutely sense to set it regardless of the cpu cap setting.

good to know.

weizhouapache avatar Mar 05 '20 09:03 weizhouapache

2 Cores * 1000 MHz / 10 = 200

In reality theres 66 set. Did I get you right on the calculation? @weizhouapache

EDIT I found why the shares are not set correctly anymore. In our last update the qemu.conf got replaced and there were no controllers configured. After repairing that the values match beween XML, schedinfo and cgroup.

Click to expand!

<domain type='kvm' id='148'>
...
  <currentMemory unit='KiB'>4194304</currentMemory>
  <vcpu placement='static'>2</vcpu>
  <cputune>
    <shares>66</shares>
  </cputune>

Schedinfo is already wrong:

Scheduler      : posix
cpu_shares     : 1024
vcpu_period    : 100000
vcpu_quota     : -1
...

Cgroup (or CFS) shares are set falsely set also (as one would expect):

# cat cpu.shares
1024
# pwd
/sys/fs/cgroup/cpu/machine.slice/machine-qemu\x2d148\x2di\x2d331\x2d2003\x2dVM.scope

@DennisKonrad could you give more details why controller is not configured and how you fixed it ?

weizhouapache avatar Mar 05 '20 09:03 weizhouapache

@weizhouapache The why is due to our way of provisioning the hosts. It does not seem CS related. Could be more documented maybe.

To solve the issue we just configured the cpu controllers in the qemu.conf on the hosts. There's already an example in the config file that you can adapt to your needs:

cgroup_controllers = [ "cpu", "devices", "memory", "blkio", "cpuset", "cpuacct" ]

To allow for the shares to be passed through corretly we needed to activate at least cpu and cpuacct.

DennisKonrad avatar Mar 06 '20 08:03 DennisKonrad

@DennisKonrad thanks for your info !

it is strange we do not configure cgroup in qemu.conf, but cpu_shares looks correctly. I use ubuntu 18.04

weizhouapache avatar Mar 06 '20 09:03 weizhouapache

@weizhouapache Maybe it's not the OS but qemu or libvirt version. It looks like it's "right" way to configure it. But it could also be this worked some time before so we didn't notice. And after some update it stopped to write the shares to cgroup. Only speculation though

DennisKonrad avatar Mar 06 '20 09:03 DennisKonrad

@weizhouapache We are very likely affected by this: https://bugzilla.redhat.com/show_bug.cgi?id=1789824

DennisKonrad avatar Mar 06 '20 09:03 DennisKonrad