Skip to content

Commit

Permalink
Fixes ram_allocation_ratio based over subscription
Browse files Browse the repository at this point in the history
Fix for bug 1016273

Change-Id: I7f7b227e71e93b4bcded150791fb0b9e9df98e4c
(cherry picked from commit 1b40708)
  • Loading branch information
jogo authored and vishvananda committed Jun 25, 2012
1 parent 17c78eb commit 5d8431b
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 4 deletions.
4 changes: 3 additions & 1 deletion doc/source/devref/filter_scheduler.rst
Expand Up @@ -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.
Expand Down
5 changes: 4 additions & 1 deletion nova/scheduler/filters/ram_filter.py
Expand Up @@ -37,4 +37,7 @@ def host_passes(self, host_state, filter_properties):
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)
2 changes: 2 additions & 0 deletions nova/scheduler/host_manager.py
Expand Up @@ -124,7 +124,9 @@ def update_from_compute_node(self, compute):
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

Expand Down
16 changes: 14 additions & 2 deletions nova/tests/scheduler/test_host_filters.py
Expand Up @@ -182,10 +182,22 @@ def test_ram_filter_fails_on_memory(self):
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']()
Expand Down

0 comments on commit 5d8431b

Please sign in to comment.