[pve-devel] [PATCH] add numa options v2

Alexandre Derumier aderumier at odiso.com
Tue Dec 2 18:08:24 CET 2014


This add numa topology support

numa: <on|default|preferred|bind|interleave>

on: only expose numa to guest
other values : bind memory to host numa nodes

example:
-------
sockets:4
cores:2
memory:4096
numa: bind

qemu command line for values != on
----------------------------------
-object memory-backend-ram,size=1024M,policy=bind,host-nodes=0,id=ram-node0
-numa node,nodeid=0,cpus=0-1,memdev=ram-node0

-object memory-backend-ram,size=1024M,policy=bind,host-nodes=1,id=ram-node2
-numa node,nodeid=1,cpus=2-3,memdev=ram-node

-object memory-backend-ram,size=1024M,policy=bind,host-nodes=2,id=ram-node3
-numa node,nodeid=2,cpus=4-5,memdev=ram-node

-object memory-backend-ram,size=1024M,policy=bind,host-nodes=3,id=ram-node4
-numa node,nodeid=3,cpus=6-7,memdev=ram-node

qemu command line for
values == on
or if host is not numa aware
or if hostdon't have enough nodes
----------------------------------
-numa node,nodeid=0,cpus=0-1
-numa node,nodeid=1,cpus=2-3
-numa node,nodeid=2,cpus=4-5
-numa node,nodeid=3,cpus=6-7

Signed-off-by: Alexandre Derumier <aderumier at odiso.com>
---
 PVE/QemuServer.pm |   40 ++++++++++++++++++++++++++++++++++++++--
 1 file changed, 38 insertions(+), 2 deletions(-)

diff --git a/PVE/QemuServer.pm b/PVE/QemuServer.pm
index 75ddcdd..d4e5cda 100644
--- a/PVE/QemuServer.pm
+++ b/PVE/QemuServer.pm
@@ -306,6 +306,12 @@ EODESC
 	minimum => 1,
 	default => 1,
     },
+    numa => {
+	optional => 1,
+	type => 'string',
+	enum => [qw(on default preferred bind interleave)],
+	description => "numa topology.",
+    },
     maxcpus => {
 	optional => 1,
 	type => 'integer',
@@ -2686,8 +2692,40 @@ sub config_to_command {
     # push @$cmd, '-cpu', "$cpu,enforce";
     push @$cmd, '-cpu', $cpu;
 
+    my $memory =  $conf->{memory} || $defaults->{memory};    
+    push @$cmd, '-m', $memory;
+
+    if($conf->{numa}){
+
+	my $numa_memory = ($memory / $sockets)."M";
+	my $hostnuma = 1;
+
+	#check if host have enough numa nodes
+	for (my $i = 0; $i < $sockets; $i++)  {
+	    $hostnuma = 0 if !(-d "/sys/devices/system/node/node$i/");
+	}
+
+	for (my $i = 0; $i < $sockets; $i++)  {
+
+	    my $cpustart = ($cores * $i);
+	    my $cpuend = ($cpustart + $cores - 1) if $cores && $cores > 1;
+	    my $cpus = $cpustart;
+	    $cpus .= "-$cpuend" if $cpuend;
+
+	    if($conf->{numa} eq 'on' || $hostnuma == 0){
+		push @$cmd, '-numa', "node,nodeid=$i,cpus=$cpus";
+	    }else{
+		push @$cmd, '-object', "memory-backend-ram,size=$numa_memory,policy=$conf->{numa},host-nodes=$i,id=ram-node$i";
+		push @$cmd, '-numa', "node,nodeid=$i,cpus=$cpus,memdev=ram-node$i";
+	    }
+
+	}
+    }
+
     push @$cmd, '-S' if $conf->{freeze};
 
+
+
     # set keyboard layout
     my $kb = $conf->{keyboard} || $defaults->{keyboard};
     push @$cmd, '-k', $kb if $kb;
@@ -2798,8 +2836,6 @@ sub config_to_command {
 	push @$devices, '-device', print_drivedevice_full($storecfg, $conf, $vmid, $drive, $bridges);
     });
 
-    push @$cmd, '-m', $conf->{memory} || $defaults->{memory};
-
     for (my $i = 0; $i < $MAX_NETS; $i++) {
          next if !$conf->{"net$i"};
          my $d = parse_net($conf->{"net$i"});
-- 
1.7.10.4




More information about the pve-devel mailing list