[pve-devel] [PATCH 3/3] livemigrate : activate xbzrle cache

Alexandre Derumier aderumier at odiso.com
Tue Aug 28 12:46:08 CEST 2012


This help migrate for vm with of lot of memory access (like database)

live migration tests working:

kvm 1.2 -> kvm 1.2  (xbzrle set on both side)
kvm 1.1 -> kvm 1.2 (xbzrle on target)
kvm 1.1 -> kvm 1.1 (xbzrle not set, qmp command try to set xbzrle but fail)

failing migration

kvm 1.2 -> kvm 1.1 fail, but this is expected.

I tested with a memory benchmark running on the vm with 4GB ram

without xbzrle : migration take 10min, with many network hang
with xbzrle : migration take 1min, no hang

I display xbzrle counters for debug purpose, we can remove them later

Signed-off-by: Alexandre Derumier <aderumier at odiso.com>
---
 PVE/QemuMigrate.pm |   22 ++++++++++++++++++++++
 PVE/QemuServer.pm  |    7 +++++++
 2 files changed, 29 insertions(+), 0 deletions(-)

diff --git a/PVE/QemuMigrate.pm b/PVE/QemuMigrate.pm
index 82eb61e..335bb32 100644
--- a/PVE/QemuMigrate.pm
+++ b/PVE/QemuMigrate.pm
@@ -325,6 +325,21 @@ sub phase2 {
     # start migration
 
     my $start = time();
+
+    my $capabilities = {};
+    $capabilities->{capability} =  "xbzrle";
+    $capabilities->{state} = JSON::true;
+
+    eval {
+	PVE::QemuServer::vm_mon_cmd_nocheck($vmid, "migrate-set-capabilities", capabilities => [$capabilities]);
+    };
+
+    #set cachesize 10% of the total memory
+    my $cachesize = int($conf->{memory}*1048576/10);
+    eval {
+	PVE::QemuServer::vm_mon_cmd_nocheck($vmid, "migrate-set-cache-size", value => $cachesize);
+    };
+
     eval {
         PVE::QemuServer::vm_mon_cmd_nocheck($vmid, "migrate", uri => "tcp:localhost:$lport");
     };
@@ -363,11 +378,18 @@ sub phase2 {
 		my $trans = $stat->{ram}->{transferred} || 0;
 		my $rem = $stat->{ram}->{remaining} || 0;
 		my $total = $stat->{ram}->{total} || 0;
+		my $xbzrlecachesize = $stat->{"xbzrle-cache"}->{"cache-size"} || 0;
+		my $xbzrlebytes = $stat->{"xbzrle-cache"}->{"bytes"} || 0;
+		my $xbzrlepages = $stat->{"xbzrle-cache"}->{"pages"} || 0;
+		my $xbzrlecachemiss = $stat->{"xbzrle-cache"}->{"cache-miss"} || 0;
+		my $xbzrleoverflow = $stat->{"xbzrle-cache"}->{"overflow"} || 0;
 		#reduce sleep if remainig memory if lower than the everage transfert 
 		$usleep = 300000 if $rem < $avglstat;
 
 		$self->log('info', "migration status: $stat->{status} (transferred ${trans}, " .
 			   "remaining ${rem}), total ${total})");
+
+		$self->log('info', "migration xbzrle cachesize: ${xbzrlecachesize} transferred ${xbzrlebytes} pages ${xbzrlepages} cachemiss ${xbzrlecachemiss} overflow ${xbzrleoverflow}");
 	    }
 
 	    $lstat = $stat->{ram}->{transferred};
diff --git a/PVE/QemuServer.pm b/PVE/QemuServer.pm
index 8731d99..2416bf0 100644
--- a/PVE/QemuServer.pm
+++ b/PVE/QemuServer.pm
@@ -2790,6 +2790,13 @@ sub vm_start {
 	    eval { vm_mon_cmd($vmid, "migrate_set_downtime", value => $migrate_downtime); };
 	}
 
+	if($migratedfrom) {
+	    my $capabilities = {};
+	    $capabilities->{capability} =  "xbzrle";
+	    $capabilities->{state} = JSON::true;
+	    eval { PVE::QemuServer::vm_mon_cmd_nocheck($vmid, "migrate-set-capabilities", capabilities => [$capabilities]); };
+	}
+
 	vm_balloonset($vmid, $conf->{balloon}) if $conf->{balloon};
 
     });
-- 
1.7.2.5




More information about the pve-devel mailing list