[PATCH] Add virt-install option to auto choose cpuset value (NUMA)

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



The patch below adds an option to virt-install to auto choose
physical cpu pinning based on available memory on a NUMA machine.
Conceivably this could be expanded in the future to auto choose
by some other metric as well, but for now only a NUMA setup is
implemented.

Using --cpuset=auto will create a traditional cpuset argument
using all the cpus associated with the cell that best fits the
requested guest memory.

The only question I have for those interested: Is best fit an 
appropriate default choice? should there be a way to choose 
another scheme (i.e. worst fit)?

Thanks,
Cole

diff -r 465f440a8a42 virt-install
--- a/virt-install	Fri Mar 14 10:55:32 2008 -0400
+++ b/virt-install	Fri Mar 14 15:16:39 2008 -0400
@@ -400,7 +400,7 @@ def main():
 
     # set up cpuset
     if type == "xen":
-        cli.get_cpuset(options.cpuset, guest)
+        cli.get_cpuset(options.cpuset, guest.memory, guest, conn)
 
     # set up disks
     get_disks(options.diskfile, options.disksize, options.sparse, options.nodisks,
diff -r 465f440a8a42 virtinst/cli.py
--- a/virtinst/cli.py	Fri Mar 14 10:55:32 2008 -0400
+++ b/virtinst/cli.py	Fri Mar 14 15:16:39 2008 -0400
@@ -26,7 +26,7 @@ from optparse import OptionValueError
 
 import libvirt
 import util
-import Guest
+import Guest, CapabilitiesParser
 
 MIN_RAM = 64
 force = False
@@ -189,9 +189,38 @@ def get_vcpus(vcpus, check_cpu, guest, c
         except ValueError, e:
             print _("ERROR: "), e
 
-def get_cpuset(cpuset, guest):
-    if cpuset:
+def get_cpuset(cpuset, mem, guest, conn):
+    if cpuset != "auto":
         guest.cpuset = cpuset
+    else:
+        caps = CapabilitiesParser.parse(conn.getCapabilities())
+        cells = caps.host.topology.cells
+        if len(cells) <= 1:
+            logging.debug("Capabilities only show <= 1 cell. Not NUMA capable")
+            print >> sys.stderr, _("This system is not NUMA capable.")
+            sys.exit(1)
+
+        cell_mem = conn.getCellsFreeMemory(0, len(cells))
+        cell_id = -1
+        mem = mem * 1024 * 1024
+        for i in range(len(cells)):
+            if cell_mem[i] > mem and len(cells[i].cpus) != 0:
+                # Find smallest cell that fits
+                if cell_id < 0 or cell_mem[i] < cell_mem[cell_id]:
+                    cell_id = i;
+        if cell_id < 0:
+            print >> sys.stderr,\
+                     _("Could not find any usable NUMA cell/cpu combinations")
+            sys.exit(1)
+
+        # Build cpuset
+        cpustr = ""
+        for cpu in cells[cell_id].cpus:
+            if cpustr != "":
+                cpustr += ","
+            cpustr += str(cpu.id)
+        guest.cpuset = cpustr
+    return
 
 def get_network(mac, network, guest):
     if mac == "RANDOM":

_______________________________________________
et-mgmt-tools mailing list
et-mgmt-tools@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/et-mgmt-tools

[Index of Archives]     [Fedora Users]     [Fedora Legacy List]     [Fedora Maintainers]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]

  Powered by Linux