Skip to content

Commit 08dfd7e

Browse files
phsmDaanHoogland
andcommitted
fix: enforce the minimum cgroupv2 cpu shares to 2
Co-authored-by: dahn <[email protected]>
1 parent a163831 commit 08dfd7e

File tree

1 file changed

+16
-2
lines changed

1 file changed

+16
-2
lines changed

plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/LibvirtComputingResource.java

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -320,6 +320,10 @@ public class LibvirtComputingResource extends ServerResourceBase implements Serv
320320
public static final String WINDOWS_GUEST_CONVERSION_SUPPORTED_CHECK_CMD = "rpm -qa | grep -i virtio-win";
321321
public static final String UBUNTU_WINDOWS_GUEST_CONVERSION_SUPPORTED_CHECK_CMD = "dpkg -l virtio-win";
322322
public static final String UBUNTU_NBDKIT_PKG_CHECK_CMD = "dpkg -l nbdkit";
323+
324+
// Libvirt < 9.1.0 cgroupv1 CPU shares values range
325+
public static final int LIBVIRT_CGROUPV1_CPU_SHARES_MIN = 2;
326+
public static final int LIBVIRT_CGROUPV1_CPU_SHARES_MAX = 262144;
323327

324328
private String modifyVlanPath;
325329
private String versionStringPath;
@@ -2796,8 +2800,18 @@ public int calculateCpuShares(VirtualMachineTO vmTO) {
27962800

27972801
if (hostCpuMaxCapacity > 0) {
27982802
int updatedCpuShares = (int) Math.ceil((requestedCpuShares * CGROUP_V2_UPPER_LIMIT) / (double) hostCpuMaxCapacity);
2799-
LOGGER.debug(String.format("This host utilizes cgroupv2 (as the max shares value is [%s]), thus, the VM requested shares of [%s] will be converted to " +
2800-
"consider the host limits; the new CPU shares value is [%s].", hostCpuMaxCapacity, requestedCpuShares, updatedCpuShares));
2803+
2804+
/**
2805+
* Libvirt < 9.1.0 enforces the same value range to both cgroupv1 and cgroupv2.
2806+
* Therefore, if the shares value is determined to be outside of boundaries,
2807+
* then bring it to the minimum or maximum allowed value.
2808+
* See: https://github.com/libvirt/libvirt/commit/38af6497610075e5fe386734b87186731d4c17ac
2809+
*/
2810+
if (updatedCpuShares < LIBVIRT_CGROUPV1_CPU_SHARES_MIN) updatedCpuShares = LIBVIRT_CGROUPV1_CPU_SHARES_MIN;
2811+
if (updatedCpuShares > LIBVIRT_CGROUPV1_CPU_SHARES_MAX) updatedCpuShares = LIBVIRT_CGROUPV1_CPU_SHARES_MAX;
2812+
2813+
LOGGER.debug("This host utilizes cgroupv2 (as the max shares value is [{}]), thus, the VM requested shares of [{}] will be converted to " +
2814+
"consider the host limits; the new CPU shares value is [{}].", hostCpuMaxCapacity, requestedCpuShares, updatedCpuShares);
28012815
return updatedCpuShares;
28022816
}
28032817
LOGGER.debug(String.format("This host does not have a maximum CPU shares set; therefore, this host utilizes cgroupv1 and the VM requested CPU shares [%s] will not be " +

0 commit comments

Comments
 (0)