Respect allocation ratio on container update

Closes-Bug: #1931712
Change-Id: Ia5431c2d54ab293a502db2457cd9fe29b6fcfd07
This commit is contained in:
Hongbin Lu 2021-07-01 20:32:22 +08:00
parent 1f10576673
commit abd1e5c9f3
2 changed files with 16 additions and 2 deletions

View File

@ -900,8 +900,12 @@ class Manager(periodic_task.PeriodicTasks):
rt = self._get_resource_tracker()
# TODO(hongbin): limits should be populated by scheduler
# FIXME(hongbin): rt.compute_node could be None
limits = {'cpu': rt.compute_node.cpus,
'memory': rt.compute_node.mem_total}
cpu_limit = (rt.compute_node.cpus *
self.driver.get_cpu_allocation_ratio())
memory_limit = (rt.compute_node.mem_total *
self.driver.get_ram_allocation_ratio())
limits = {'cpu': cpu_limit,
'memory': memory_limit}
if container.cpu_policy == 'dedicated':
limits['cpuset'] = self._get_cpuset_limits(rt.compute_node,
container)

View File

@ -104,6 +104,8 @@ class BaseDriver(object):
for driver_name in CONF.volume.driver_list:
driver = vol_driver.driver(driver_name)
self.volume_drivers[driver_name] = driver
self.cpu_allocation_ratio = CONF.compute.cpu_allocation_ratio
self.ram_allocation_ratio = CONF.compute.ram_allocation_ratio
def get_host_numa_topology(self):
numa_topo_obj = objects.NUMATopology()
@ -228,6 +230,8 @@ class BaseDriver(object):
# otherwise.
inv = provider_tree.data(nodename).inventory
ratios = self._get_allocation_ratios(inv)
self.cpu_allocation_ratio = ratios[orc.VCPU]
self.ram_allocation_ratio = ratios[orc.MEMORY_MB]
result = {
orc.VCPU: {
'total': vcpus,
@ -275,6 +279,12 @@ class BaseDriver(object):
# so that spawn() or other methods can access it thru a getter
self.provider_tree = copy.deepcopy(provider_tree)
def get_cpu_allocation_ratio(self):
return self.cpu_allocation_ratio
def get_ram_allocation_ratio(self):
return self.ram_allocation_ratio
@staticmethod
def _get_allocation_ratios(inventory):
"""Get the cpu/ram/disk allocation ratios for the given inventory.