Fixes ram_allocation_ratio based over subscription

Fix for bug 1016273

Change-Id: I7f7b227e71e93b4bcded150791fb0b9e9df98e4c
(cherry picked from commit 1b40708287)
This commit is contained in:
Joe Gordon 2012-06-21 16:41:17 -07:00 committed by Vishvananda Ishaya
parent 17c78ebca1
commit 5d8431b765
4 changed files with 23 additions and 4 deletions

View File

@ -58,7 +58,9 @@ code. For example class |RamFilter| has the next realization:
instance_type = filter_properties.get('instance_type')
requested_ram = instance_type['memory_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
ratio (it is 1.5 by default). Really, nice and simple.

View File

@ -37,4 +37,7 @@ class RamFilter(filters.BaseHostFilter):
instance_type = filter_properties.get('instance_type')
requested_ram = instance_type['memory_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)

View File

@ -124,7 +124,9 @@ class HostState(object):
all_disk_mb -= FLAGS.reserved_host_disk_mb
if FLAGS.reserved_host_memory_mb > 0:
all_ram_mb -= FLAGS.reserved_host_memory_mb
#NOTE(jogo) free_ram_mb can be negative
self.free_ram_mb = all_ram_mb
self.total_usable_ram_mb = all_ram_mb
self.free_disk_mb = all_disk_mb
self.vcpus_total = vcpus_total

View File

@ -182,10 +182,22 @@ class HostFiltersTestCase(test.TestCase):
capabilities = {'enabled': True}
service = {'disabled': False}
host = fakes.FakeHostState('host1', 'compute',
{'free_ram_mb': 1023, 'capabilities': capabilities,
'service': service})
{'free_ram_mb': 1023, 'total_usable_ram_mb': 1024,
'capabilities': capabilities, 'service': service})
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):
self._stub_service_is_up(True)
filt_cls = self.class_map['ComputeFilter']()