Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: enforce the minimum cgroup cpu shares value to 2 #10221

Open
wants to merge 2 commits into
base: 4.20
Choose a base branch
from

Conversation

phsm
Copy link
Contributor

@phsm phsm commented Jan 20, 2025

Description

This PR ensures that the cpu shares value is never < 2 to be compatible with Libvirt versions before 9.1.0.

It turned out that the older libvirt versions, such as Ubuntu 22.04 libvirt 8.0.0 has the hardcoded range of allowed cpu shares values for both cgroupv1 and cgroupv2, which is 2-262144.
This range enforcement was removed in Libvirt 9.1.0, see: libvirt/libvirt@38af649

If a host has lots of cores, and the huge CPU overprovisioning factor is set, then the computed shares value can become 1.
In such case, the following exception is generated on the Cloudstack Agent during provisioning:
org.libvirt.LibvirtException: unsupported configuration: Value of cputune 'shares' must be in range [2, 262144]

We noticed it when tried to restart a Shared network with cleanup.

Steps to reproduce:

  1. Get a KVM hypervisor host with lots of cores that has affected Libvirt version. Ubuntu 22.04 works.
  2. Make sure that cgroup v2 is enabled on the hypervisor: mount | grep -q cgroup2 && echo "yes, enabled" should echo the output.
  3. Set the overprovisioning ratio to some ridiculously high value, e.g. 1000
  4. Try to restart any network with cleanup. Since the virtual routers have tiny CPU specs (1 core, 500Mhz by default), it should trigger the bug.
  5. The com.cloud.exception.InsufficientServerCapacityException: No destination found for a deployment for VM instance will be generated on the management server.
  6. On the agent, you will see the following message in the log: org.libvirt.LibvirtException: unsupported configuration: Value of cputune 'shares' must be in range [2, 262144]

Types of changes

  • Breaking change (fix or feature that would cause existing functionality to change)
  • New feature (non-breaking change which adds functionality)
  • Bug fix (non-breaking change which fixes an issue)
  • Enhancement (improves an existing feature and functionality)
  • Cleanup (Code refactoring and cleanup, that may add test cases)
  • build/CI
  • test (unit or integration test code)

Feature/Enhancement Scale or Bug Severity

Feature/Enhancement Scale

  • Major
  • Minor

Bug Severity

  • BLOCKER
  • Critical
  • Major
  • Minor
  • Trivial

Screenshots (if appropriate):

How Has This Been Tested?

Tested on Ubuntu 22.04 with Libvirt 8.0.0.
After the patch was applied, the error was gone, and the virtual router appeared after the restart with the cpushares value 2.

How did you try to break this feature and the system with this change?

The only effective change that this change does, is excluding the return value "1". It is highly unlikely to break anything.

@phsm phsm force-pushed the 4.20-libvirt-cgroup-cpushares-bug branch from 85f0879 to c9ce12a Compare January 20, 2025 16:54
Copy link

codecov bot commented Jan 20, 2025

Codecov Report

Attention: Patch coverage is 66.66667% with 1 line in your changes missing coverage. Please review.

Project coverage is 16.13%. Comparing base (a163831) to head (691a0ff).

Files with missing lines Patch % Lines
...ervisor/kvm/resource/LibvirtComputingResource.java 66.66% 0 Missing and 1 partial ⚠️
Additional details and impacted files
@@             Coverage Diff              @@
##               4.20   #10221      +/-   ##
============================================
- Coverage     16.13%   16.13%   -0.01%     
+ Complexity    12967    12966       -1     
============================================
  Files          5639     5639              
  Lines        494264   494265       +1     
  Branches      59899    59900       +1     
============================================
- Hits          79760    79759       -1     
- Misses       405684   405685       +1     
- Partials       8820     8821       +1     
Flag Coverage Δ
uitests 4.02% <ø> (ø)
unittests 16.98% <66.66%> (-0.01%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@phsm phsm force-pushed the 4.20-libvirt-cgroup-cpushares-bug branch from 9e981b4 to f51aec9 Compare January 20, 2025 18:55
…/resource/LibvirtComputingResource.java

Co-authored-by: dahn <[email protected]>
@DaanHoogland DaanHoogland added this to the 4.20.1 milestone Jan 21, 2025
@DaanHoogland
Copy link
Contributor

@blueorangutan package

@blueorangutan
Copy link

@DaanHoogland a [SL] Jenkins job has been kicked to build packages. It will be bundled with KVM, XenServer and VMware SystemVM templates. I'll keep you posted as I make progress.

@blueorangutan
Copy link

Packaging result [SF]: ✔️ el8 ✔️ el9 ✔️ debian ✔️ suse15. SL-JID 12141

@DaanHoogland
Copy link
Contributor

@blueorangutan test

@blueorangutan
Copy link

@DaanHoogland a [SL] Trillian-Jenkins test job (ol8 mgmt + kvm-ol8) has been kicked to run smoke tests

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants