[pve-devel] [PATCH 1/2] add numa options v3

Alexandre Derumier aderumier at odiso.com
Wed Dec 3 16:23:47 CET 2014


This enable numa support inside the guest, and share the memory and cores across the sockets numa nodes.

numa: 0|1

example:
-------
sockets:2
cores:2
memory:4096
numa: 1

qemu command line
-----------------
-object memory-backend-ram,size=2048,id=ram-node0
-numa node,nodeid=0,cpus=0-1,memdev=ram-node0
-object memory-backend-ram,size=2048,id=ram-node1
-numa node,nodeid=1,cpus=2-3,memdev=ram-node1

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

diff --git a/PVE/QemuServer.pm b/PVE/QemuServer.pm
index 75ddcdd..94fd523 100644
--- a/PVE/QemuServer.pm
+++ b/PVE/QemuServer.pm
@@ -306,6 +306,12 @@ EODESC
 	minimum => 1,
 	default => 1,
     },
+    numa => {
+	optional => 1,
+	type => 'boolean',
+	description => "Enable/disable Numa.",
+	default => 0,
+    },
     maxcpus => {
 	optional => 1,
 	type => 'integer',
@@ -2686,8 +2692,29 @@ 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";
+
+	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;
+
+	    push @$cmd, '-object', "memory-backend-ram,size=$numa_memory,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 +2825,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