Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Cinder has calculations in the capacity filter and the Capacity weigher for determining how much free space there is.
https://github.com/openstack/cinder/blob/master/cinder/scheduler/filters/capacity_filter.py#L108-L159
and
https://github.com/openstack/cinder/blob/master/cinder/scheduler/weights/capacity.py#L118-L125
These 2 mechanisms turn up to having different values.
Take my pool stats of
Total Capacity 156871
Allocated Capacity 144553
Free Capacity 104897
Provisioning Type thin
Max Overcommit 1
Reserved 20 %
Using the math in the capacity filter. Notice we are applying the reserved to the free space.
free = free_space - math.floor(total * reserved)
free = 104897 - (156871 * .2)
free = 104897 - 31374
free = 73523
Then apply the final calculation here:
https://github.com/openstack/cinder/blob/master/cinder/scheduler/filters/capacity_filter.py#L156-L157
adjusted_free_virtual = (free * backend_state.max_over_subscription_ratio)
adjusted_free_virtual = (73523 * 1)
adjusted_free_virtual = 73523
Now using the CapacityWeigher algorightm here:
https://github.com/openstack/cinder/blob/master/cinder/utils.py#L739-L742
free = (total * max_over_subscription_ratio - provisioned_capacity - math.floor(total * reserved))
free = (156871 * 1 - 144553 - (156871 * .2)
free = 156871 - 144553 - 31374
free = -19056
@hemna
Copy link
Author

hemna commented Feb 22, 2022

thick vs. thin calculations

      Pool A
Total Capacity                     15360
Allocated Capacity                  5072
Free Capacity                      12333
Percent Free                      80.3 %
Virtual Free Space                  9261
Reserved                            20 %
Available until reserved            9261
Available until reserved %        75.1 %
Provisioning Type                  thick
Driver Version                3.4.2.99.3

thin

               POOL B
Total Capacity                    156871
Allocated Capacity                144553
Free Capacity                     104897
Percent Free                      66.9 %
Virtual Free Space              -19056.0
Reserved                            20 %
Available until reserved           73523
Available until reserved %        70.1 %
Current Overcommit                0.92 %
Max Overcommit                         1
Capacity Until Overcommit        12318.0
Provisioning Type                   thin
Driver Version                3.4.2.99.3

@hemna
Copy link
Author

hemna commented Feb 22, 2022

Using a max overcommit of 2 the numbers look different

Take my pool stats of
Total Capacity 156871
Allocated Capacity 144553
Free Capacity 104897
Provisioning Type thin
Max Overcommit 2
Reserved 20 %

Using the math in the capacity filter.
free = free_space - math.floor(total * reserved)
free = 104897 - (156871 * .2)
free = 104897 - 31374
free = 73523

adjusted_free_virtual = (free * backend_state.max_over_subscription_ratio)
adjusted_free_virtual = (73523 * 2)
adjusted_free_virtual = 147046

Reserve from raw total

  • reserved A (156781 * .2) = 31374
  • available total A = 125407 * 2 = 250814
  • available free A = (available total A - free) = 177291

OR

Reserve from max oversub total

max oversub total = 156871 * 2 = 313742

  • reserved B (313742 * .2) = 62748
    available total B = 250994
    available free B = (available total B - free) = 177471

virtual free in cinder utils

free = (total * max_oversub_ratio - provisioned - (total * reserved)
free = 156871 * 2 - 144553 - (156781 * .2)
free = 313742 - 144553 - 31374
free = 137815

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