Skip to content

Commit

Permalink
fix: enforce the minimum cgroupv2 cpu shares to 2
Browse files Browse the repository at this point in the history
Co-authored-by: dahn <[email protected]>
  • Loading branch information
phsm and DaanHoogland committed Jan 20, 2025
1 parent a163831 commit f51aec9
Showing 1 changed file with 10 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2796,8 +2796,16 @@ public int calculateCpuShares(VirtualMachineTO vmTO) {

if (hostCpuMaxCapacity > 0) {
int updatedCpuShares = (int) Math.ceil((requestedCpuShares * CGROUP_V2_UPPER_LIMIT) / (double) hostCpuMaxCapacity);
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 " +
"consider the host limits; the new CPU shares value is [%s].", hostCpuMaxCapacity, requestedCpuShares, updatedCpuShares));

/**
* Libvirt < 9.1.0 enforces the range [2, 262144] to both cgroupv1 and cgroupv2.
* Therefore, if the shares value is determined to be < 2, then raise it to 2 to fit into the constraint.
* See: https://github.com/libvirt/libvirt/commit/38af6497610075e5fe386734b87186731d4c17ac
*/
if (updatedCpuShares < 2) updatedCpuShares = 2;

LOGGER.debug(String.format("This host utilizes cgroupv2 (as the max shares value is [{}]), thus, the VM requested shares of [{}] will be converted to " +
"consider the host limits; the new CPU shares value is [{}].", hostCpuMaxCapacity, requestedCpuShares, updatedCpuShares));
return updatedCpuShares;
}
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 " +
Expand Down

0 comments on commit f51aec9

Please sign in to comment.