Prefer non-PCI host nodes for non-PCI instances

When trying to fit an instance's topology to a host's, various
permutations of the host are attempted in the hope of finding one that
can be used. Modify this iteration to try use cells without a PCI
device attached first when we don't require PCI devices.

Change-Id: I8be6bf8c437fc801499b213c2e884defb7900b17
Implements: blueprint reserve-numa-with-pci
This commit is contained in:
Stephen Finucane 2016-09-29 17:44:29 +01:00
parent ec74cc688e
commit 0f6ab0dd7a
2 changed files with 39 additions and 1 deletions

View File

@ -13,6 +13,7 @@
# under the License.
import collections
import copy
import mock
from oslo_serialization import jsonutils
@ -25,6 +26,7 @@ from nova.objects import base as base_obj
from nova.objects import fields
from nova.pci import stats
from nova import test
from nova.tests.unit import fake_pci_device_pools as fake_pci
from nova.tests import uuidsentinel as uuids
from nova.virt import hardware as hw
@ -1782,6 +1784,33 @@ class VirtNUMAHostTopologyTestCase(test.NoDBTestCase):
pci_stats=pci_stats)
self.assertIsNone(fitted_instance1)
def test_get_fitting_pci_avoided(self):
def _create_pci_stats(node):
test_dict = copy.copy(fake_pci.fake_pool_dict)
test_dict['numa_node'] = node
return stats.PciDeviceStats(
[objects.PciDevicePool.from_dict(test_dict)])
# the PCI device is found on host cell 1
pci_stats = _create_pci_stats(1)
# ...threfore an instance without a PCI device should get host cell 2
instance_topology = hw.numa_fit_instance_to_host(
self.host, self.instance1, pci_stats=pci_stats)
self.assertIsInstance(instance_topology, objects.InstanceNUMATopology)
# TODO(sfinucan): We should be comparing this against the HOST cell
self.assertEqual(2, instance_topology.cells[0].id)
# the PCI device is now found on host cell 2
pci_stats = _create_pci_stats(2)
# ...threfore an instance without a PCI device should get host cell 1
instance_topology = hw.numa_fit_instance_to_host(
self.host, self.instance1, pci_stats=pci_stats)
self.assertIsInstance(instance_topology, objects.InstanceNUMATopology)
self.assertEqual(1, instance_topology.cells[0].id)
class NumberOfSerialPortsTest(test.NoDBTestCase):
def test_flavor(self):

View File

@ -1479,10 +1479,19 @@ def numa_fit_instance_to_host(
if 'emulator_threads_policy' in instance_topology:
emulator_threads_policy = instance_topology.emulator_threads_policy
host_cells = host_topology.cells
# If PCI device(s) are not required, prefer host cells that don't have
# devices attached. Presence of a given numa_node in a PCI pool is
# indicative of a PCI device being associated with that node
if not pci_requests and pci_stats:
host_cells = sorted(host_cells, key=lambda cell: cell.id in [
pool['numa_node'] for pool in pci_stats.pools])
# TODO(ndipanov): We may want to sort permutations differently
# depending on whether we want packing/spreading over NUMA nodes
for host_cell_perm in itertools.permutations(
host_topology.cells, len(instance_topology)):
host_cells, len(instance_topology)):
cells = []
for host_cell, instance_cell in zip(
host_cell_perm, instance_topology.cells):