Skip to contentSkip to conversation

migration: avoid divide by zero in xbzrle cache miss rate

PATCH Applied Michael Chapman 3 participants 4 messages Apr 15, 2015 – May 6, 2015

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 migration: avoid divide by zero in xbzrle cache miss rate

This bug manifested itself as a VM that could not be resumed by libvirt following a migration:

  # virsh resume example
  error: Failed to resume domain example
  error: internal error: cannot parse json {"return":
    {"xbzrle-cache":
      {..., "cache-miss-rate": -nan, ...},
      ...
    }
  }: lexical error: malformed number, a digit is required after the minus sign.

This patch also ensures xbzrle_cache_miss_prev and iterations_prev are cleared at the start of the migration.

---
 arch_init.c | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)
arch_init.c +5 -3
index 4c8fcee..ca45c7a 100644
@@ -520,12 +520,16 @@ static void migration_bitmap_sync_range(ram_addr_t start, ram_addr_t length)
 static int64_t start_time;
 static int64_t bytes_xfer_prev;
 static int64_t num_dirty_pages_period;
+static uint64_t xbzrle_cache_miss_prev;
+static uint64_t iterations_prev;
 
 static void migration_bitmap_sync_init(void)
 {
     start_time = 0;
     bytes_xfer_prev = 0;
     num_dirty_pages_period = 0;
+    xbzrle_cache_miss_prev = 0;
+    iterations_prev = 0;
 }
 
 /* Called with iothread lock held, to protect ram_list.dirty_memory[] */
@@ -536,8 +540,6 @@ static void migration_bitmap_sync(void)
     MigrationState *s = migrate_get_current();
     int64_t end_time;
     int64_t bytes_xfer_now;
-    static uint64_t xbzrle_cache_miss_prev;
-    static uint64_t iterations_prev;
 
     bitmap_sync_count++;
 
@@ -585,7 +587,7 @@ static void migration_bitmap_sync(void)
              mig_throttle_on = false;
         }
         if (migrate_use_xbzrle()) {
-            if (iterations_prev != 0) {
+            if (iterations_prev != acct_info.iterations) {
                 acct_info.xbzrle_cache_miss_rate =
                    (double)(acct_info.xbzrle_cache_miss -
                             xbzrle_cache_miss_prev) /
Signature · 1 line
2.1.0
Reviewed-by on v1 1/1
#1 lore raw
Quoted 12 lines · Michael Chapman

This bug manifested itself as a VM that could not be resumed by libvirt following a migration:

  # virsh resume example
  error: Failed to resume domain example
  error: internal error: cannot parse json {"return":
    {"xbzrle-cache":
      {..., "cache-miss-rate": -nan, ...},
      ...
    }
  }: lexical error: malformed number, a digit is required after the minus sign.
Quoted 4 lines

This patch also ensures xbzrle_cache_miss_prev and iterations_prev are cleared at the start of the migration.

Amit

#2 lore raw
In reply to Michael Chapman
Quoted 12 lines · Michael Chapman

This bug manifested itself as a VM that could not be resumed by libvirt following a migration:

  # virsh resume example
  error: Failed to resume domain example
  error: internal error: cannot parse json {"return":
    {"xbzrle-cache":
      {..., "cache-miss-rate": -nan, ...},
      ...
    }
  }: lexical error: malformed number, a digit is required after the minus sign.
Quoted 4 lines

This patch also ensures xbzrle_cache_miss_prev and iterations_prev are cleared at the start of the migration.

Added to queue for 2.4 & stable

Thanks

Quoted 43 lines
---
 arch_init.c | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)
arch_init.c +5 -3
index 4c8fcee..ca45c7a 100644
@@ -520,12 +520,16 @@ static void migration_bitmap_sync_range(ram_addr_t start, ram_addr_t length)
 static int64_t start_time;
 static int64_t bytes_xfer_prev;
 static int64_t num_dirty_pages_period;
+static uint64_t xbzrle_cache_miss_prev;
+static uint64_t iterations_prev;
 
 static void migration_bitmap_sync_init(void)
 {
     start_time = 0;
     bytes_xfer_prev = 0;
     num_dirty_pages_period = 0;
+    xbzrle_cache_miss_prev = 0;
+    iterations_prev = 0;
 }
 
 /* Called with iothread lock held, to protect ram_list.dirty_memory[] */
@@ -536,8 +540,6 @@ static void migration_bitmap_sync(void)
     MigrationState *s = migrate_get_current();
     int64_t end_time;
     int64_t bytes_xfer_now;
-    static uint64_t xbzrle_cache_miss_prev;
-    static uint64_t iterations_prev;
 
     bitmap_sync_count++;
 
@@ -585,7 +587,7 @@ static void migration_bitmap_sync(void)
              mig_throttle_on = false;
         }
         if (migrate_use_xbzrle()) {
-            if (iterations_prev != 0) {
+            if (iterations_prev != acct_info.iterations) {
                 acct_info.xbzrle_cache_miss_rate =
                    (double)(acct_info.xbzrle_cache_miss -
                             xbzrle_cache_miss_prev) /
#3 lore raw
In reply to Michael Chapman
Quoted 12 lines · Michael Chapman

This bug manifested itself as a VM that could not be resumed by libvirt following a migration:

  # virsh resume example
  error: Failed to resume domain example
  error: internal error: cannot parse json {"return":
    {"xbzrle-cache":
      {..., "cache-miss-rate": -nan, ...},
      ...
    }
  }: lexical error: malformed number, a digit is required after the minus sign.
Quoted 4 lines

This patch also ensures xbzrle_cache_miss_prev and iterations_prev are cleared at the start of the migration.

Applied, thanks.