weizhouapache commented on code in PR #10221:
URL: https://github.com/apache/cloudstack/pull/10221#discussion_r1926809604
##########
plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/LibvirtComputingResource.java:
##########
@@ -2796,12 +2800,23 @@ 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));
- 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 " +
- "converted.", requestedCpuShares));
+
+ LOGGER.debug("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);
+ requestedCpuShares = updatedCpuShares;
+ } else {
+ LOGGER.debug("This host does not have a maximum CPU shares set;
therefore, this host utilizes cgroupv1 and the VM requested CPU shares [{}]
will not be " +
+ "converted.", requestedCpuShares);
+ }
+
+ /**
+ * Libvirt < 9.1.0 enforces the same value range to both cgroupv1 and
cgroupv2.
+ * Therefore, if the shares value is determined to be outside of
boundaries,
+ * then bring it to the minimum or maximum allowed value.
+ * See:
https://github.com/libvirt/libvirt/commit/38af6497610075e5fe386734b87186731d4c17ac
+ */
+ if (requestedCpuShares < LIBVIRT_CGROUPV1_CPU_SHARES_MIN)
requestedCpuShares = LIBVIRT_CGROUPV1_CPU_SHARES_MIN;
Review Comment:
@phsm
I checked libvirt code, it looks like the range for cgroup v1 and v2 are
different
for v1
```
#define VIR_CGROUP_CPU_SHARES_MIN 2LL
#define VIR_CGROUP_CPU_SHARES_MAX 262144LL
```
and for v2
```
#define VIR_CGROUPV2_WEIGHT_MIN 1LL
#define VIR_CGROUPV2_WEIGHT_MAX 10000LL
```
it would be better to define the constants and add checks for each cgroup
version.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]