Skip to content

Commit f51aec9

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

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

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

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2796,8 +2796,16 @@ public int calculateCpuShares(VirtualMachineTO vmTO) {
27962796

27972797
if (hostCpuMaxCapacity > 0) {
27982798
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));
2799+
2800+
/**
2801+
* Libvirt < 9.1.0 enforces the range [2, 262144] to both cgroupv1 and cgroupv2.
2802+
* Therefore, if the shares value is determined to be < 2, then raise it to 2 to fit into the constraint.
2803+
* See: https://github.com/libvirt/libvirt/commit/38af6497610075e5fe386734b87186731d4c17ac
2804+
*/
2805+
if (updatedCpuShares < 2) updatedCpuShares = 2;
2806+
2807+
LOGGER.debug(String.format("This host utilizes cgroupv2 (as the max shares value is [{}]), thus, the VM requested shares of [{}] will be converted to " +
2808+
"consider the host limits; the new CPU shares value is [{}].", hostCpuMaxCapacity, requestedCpuShares, updatedCpuShares));
28012809
return updatedCpuShares;
28022810
}
28032811
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)