phsm commented on code in PR #10221:
URL: https://github.com/apache/cloudstack/pull/10221#discussion_r1927025742


##########
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:
   I believe I have implemented it as you suggested.
   
   As for the "cgroup_v2" variable: I'm not quite sure how to properly place 
it, therefore I just relied on the existing condition `if (hostCpuMaxCapacity > 
0)`



-- 
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]

Reply via email to