Fixes ram_allocation_ratio based over subscription
Fix for bug 1016273 Change-Id: I7f7b227e71e93b4bcded150791fb0b9e9df98e4c
This commit is contained in:
parent
3252371afc
commit
1b40708287
@ -62,7 +62,9 @@ code. For example class |RamFilter| has the next realization:
|
|||||||
instance_type = filter_properties.get('instance_type')
|
instance_type = filter_properties.get('instance_type')
|
||||||
requested_ram = instance_type['memory_mb']
|
requested_ram = instance_type['memory_mb']
|
||||||
free_ram_mb = host_state.free_ram_mb
|
free_ram_mb = host_state.free_ram_mb
|
||||||
return free_ram_mb * FLAGS.ram_allocation_ratio >= requested_ram
|
total_usable_ram_mb = host_state.total_usable_ram_mb
|
||||||
|
used_ram_mb = total_usable_ram_mb - free_ram_mb
|
||||||
|
return total_usable_ram_mb * FLAGS.ram_allocation_ratio - used_ram_mb >= requested_ram
|
||||||
|
|
||||||
Here `ram_allocation_ratio` means the virtual RAM to physical RAM allocation
|
Here `ram_allocation_ratio` means the virtual RAM to physical RAM allocation
|
||||||
ratio (it is 1.5 by default). Really, nice and simple.
|
ratio (it is 1.5 by default). Really, nice and simple.
|
||||||
|
@ -37,4 +37,7 @@ class RamFilter(filters.BaseHostFilter):
|
|||||||
instance_type = filter_properties.get('instance_type')
|
instance_type = filter_properties.get('instance_type')
|
||||||
requested_ram = instance_type['memory_mb']
|
requested_ram = instance_type['memory_mb']
|
||||||
free_ram_mb = host_state.free_ram_mb
|
free_ram_mb = host_state.free_ram_mb
|
||||||
return free_ram_mb * FLAGS.ram_allocation_ratio >= requested_ram
|
total_usable_ram_mb = host_state.total_usable_ram_mb
|
||||||
|
used_ram_mb = total_usable_ram_mb - free_ram_mb
|
||||||
|
return (total_usable_ram_mb * FLAGS.ram_allocation_ratio -
|
||||||
|
used_ram_mb >= requested_ram)
|
||||||
|
@ -124,7 +124,9 @@ class HostState(object):
|
|||||||
all_disk_mb -= FLAGS.reserved_host_disk_mb
|
all_disk_mb -= FLAGS.reserved_host_disk_mb
|
||||||
if FLAGS.reserved_host_memory_mb > 0:
|
if FLAGS.reserved_host_memory_mb > 0:
|
||||||
all_ram_mb -= FLAGS.reserved_host_memory_mb
|
all_ram_mb -= FLAGS.reserved_host_memory_mb
|
||||||
|
#NOTE(jogo) free_ram_mb can be negative
|
||||||
self.free_ram_mb = all_ram_mb
|
self.free_ram_mb = all_ram_mb
|
||||||
|
self.total_usable_ram_mb = all_ram_mb
|
||||||
self.free_disk_mb = all_disk_mb
|
self.free_disk_mb = all_disk_mb
|
||||||
self.vcpus_total = vcpus_total
|
self.vcpus_total = vcpus_total
|
||||||
|
|
||||||
|
@ -274,10 +274,22 @@ class HostFiltersTestCase(test.TestCase):
|
|||||||
capabilities = {'enabled': True}
|
capabilities = {'enabled': True}
|
||||||
service = {'disabled': False}
|
service = {'disabled': False}
|
||||||
host = fakes.FakeHostState('host1', 'compute',
|
host = fakes.FakeHostState('host1', 'compute',
|
||||||
{'free_ram_mb': 1023, 'capabilities': capabilities,
|
{'free_ram_mb': 1023, 'total_usable_ram_mb': 1024,
|
||||||
'service': service})
|
'capabilities': capabilities, 'service': service})
|
||||||
self.assertFalse(filt_cls.host_passes(host, filter_properties))
|
self.assertFalse(filt_cls.host_passes(host, filter_properties))
|
||||||
|
|
||||||
|
def test_ram_filter_oversubscribe(self):
|
||||||
|
self._stub_service_is_up(True)
|
||||||
|
filt_cls = self.class_map['RamFilter']()
|
||||||
|
self.flags(ram_allocation_ratio=2.0)
|
||||||
|
filter_properties = {'instance_type': {'memory_mb': 1024}}
|
||||||
|
capabilities = {'enabled': True}
|
||||||
|
service = {'disabled': False}
|
||||||
|
host = fakes.FakeHostState('host1', 'compute',
|
||||||
|
{'free_ram_mb': -1024, 'total_usable_ram_mb': 2048,
|
||||||
|
'capabilities': capabilities, 'service': service})
|
||||||
|
self.assertTrue(filt_cls.host_passes(host, filter_properties))
|
||||||
|
|
||||||
def test_compute_filter_fails_on_service_disabled(self):
|
def test_compute_filter_fails_on_service_disabled(self):
|
||||||
self._stub_service_is_up(True)
|
self._stub_service_is_up(True)
|
||||||
filt_cls = self.class_map['ComputeFilter']()
|
filt_cls = self.class_map['ComputeFilter']()
|
||||||
|
Loading…
Reference in New Issue
Block a user