Sophie

Sophie

distrib > Scientific%20Linux > 5x > x86_64 > by-pkgid > 3160499aacb81f6735941eb4c372d87a > files > 208

kvm-83-164.el5_5.30.src.rpm

From 739a9338774b11c41775f96090eb889d9fe66705 Mon Sep 17 00:00:00 2001
From: Glauber Costa <glommer@redhat.com>
Date: Tue, 2 Jun 2009 09:10:08 -0400
Subject: [PATCH 3/4] add non-arbitrary migration stop condition

Currently, we're entering migration's stage 3 when
a treshold of 10 pages remain to be transferred in the system.

This has hurt some users. However, any proposed threshold is
arbitrary by nature, and would only shift the annoyance.

The proposal of this patch is to define a max_downtime variable,
which represents the maximum downtime a migration user is willing
to suffer. Then, based on the bandwidth of last iteration, we
calculate how much data we can transfer in such a window of time.

Whenever we reach that value (or lower), we know is safe to enter
stage3.

This has largely improved the situation for me.
On localhost migrations, where one would expect things to go as
quickly as me running away from the duty of writting software for
windows, a kernel compile was enough to get the migration stuck.

It takes 20 ~ 30 iterations now.

Signed-off-by: Glauber Costa <glommer@redhat.com>
RH-Upstream-status: pending (qemu)
Message-Id: <1243948209-24257-2-git-send-email-glommer@redhat.com>
Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
Obsoletes: <1243925661-21880-2-git-send-email-glommer@redhat.com>
Acked-by: Dor Laor <dlaor@redhat.com>
Acked-by: Uri Lublin <uril@redhat.com>
Acked-by: "Michael S. Tsirkin" <mst@redhat.com>
Bugzilla: 504237
---
 qemu/migration.c |   11 +++++++++++
 qemu/migration.h |    2 ++
 qemu/vl.c        |   19 +++++++++++++++++--
 3 files changed, 30 insertions(+), 2 deletions(-)

diff --git a/qemu/migration.c b/qemu/migration.c
index 0c63463..a82cd61 100644
--- a/qemu/migration.c
+++ b/qemu/migration.c
@@ -108,6 +108,17 @@ void do_migrate_set_speed(const char *value)
     
 }
 
+/* amount of nanoseconds we are willing to wait for migration to be down.
+ * the choice of nanoseconds is because it is the maximum resolution that
+ * get_clock() can achieve. It is an internal measure. All user-visible
+ * units must be in seconds */
+static uint64_t max_downtime = 100000000;
+
+uint64_t migrate_max_downtime(void)
+{
+    return max_downtime;
+}
+
 void do_info_migrate(void)
 {
     MigrationState *s = current_migration;
diff --git a/qemu/migration.h b/qemu/migration.h
index 4d63a85..03a500b 100644
--- a/qemu/migration.h
+++ b/qemu/migration.h
@@ -55,6 +55,8 @@ void do_migrate_cancel(void);
 
 void do_migrate_set_speed(const char *value);
 
+uint64_t migrate_max_downtime(void);
+
 void do_info_migrate(void);
 
 int exec_start_incoming_migration(const char *host_port);
diff --git a/qemu/vl.c b/qemu/vl.c
index 626f4aa..89f260e 100644
--- a/qemu/vl.c
+++ b/qemu/vl.c
@@ -3299,7 +3299,6 @@ static int ram_save_block(QEMUFile *f)
     return found;
 }
 
-static ram_addr_t ram_save_threshold = 10;
 static uint64_t bytes_transferred = 0;
 
 static ram_addr_t ram_save_remaining(void)
@@ -3333,6 +3332,9 @@ uint64_t ram_bytes_total(void)
 static int ram_save_live(QEMUFile *f, int stage, void *opaque)
 {
     ram_addr_t addr;
+    uint64_t bytes_transferred_last;
+    double bwidth = 0;
+    uint64_t expected_time = 0;
 
     if (stage == 1) {
         /* Make sure all dirty bits are set */
@@ -3347,6 +3349,9 @@ static int ram_save_live(QEMUFile *f, int stage, void *opaque)
         qemu_put_be64(f, phys_ram_size | RAM_SAVE_FLAG_MEM_SIZE);
     }
 
+    bytes_transferred_last = bytes_transferred;
+    bwidth = get_clock();
+
     while (!qemu_file_rate_limit(f)) {
         int ret;
 
@@ -3356,6 +3361,14 @@ static int ram_save_live(QEMUFile *f, int stage, void *opaque)
             break;
     }
 
+    bwidth = get_clock() - bwidth;
+    bwidth = (bytes_transferred - bytes_transferred_last) / bwidth;
+
+    /* if we haven't transferred anything this round, force expected_time to a
+     * a very high value, but without crashing */
+    if (bwidth == 0)
+        bwidth = 0.000001;
+
     /* try transferring iterative blocks of memory */
 
     if (stage == 3) {
@@ -3374,7 +3387,9 @@ static int ram_save_live(QEMUFile *f, int stage, void *opaque)
 
     qemu_put_be64(f, RAM_SAVE_FLAG_EOS);
 
-    return (stage == 2) && (ram_save_remaining() < ram_save_threshold);
+    expected_time = ram_save_remaining() * TARGET_PAGE_SIZE / bwidth;
+
+    return (stage == 2) && (expected_time <= migrate_max_downtime());
 }
 
 static int ram_load_dead(QEMUFile *f, void *opaque)
-- 
1.6.3.rc4.29.g8146