9ae3a8
From 20a401a160bb959469e95cc809b53609eedccb40 Mon Sep 17 00:00:00 2001
9ae3a8
From: Dr. David Alan Gilbert (git) <dgilbert@redhat.com>
9ae3a8
Date: Thu, 8 May 2014 11:27:33 +0200
9ae3a8
Subject: [PATCH 08/31] Count used RAMBlock pages for migration_dirty_pages
9ae3a8
9ae3a8
RH-Author: Dr. David Alan Gilbert (git) <dgilbert@redhat.com>
9ae3a8
Message-id: <1399548453-9181-2-git-send-email-dgilbert@redhat.com>
9ae3a8
Patchwork-id: 58746
9ae3a8
O-Subject: [RHEL7.1/RHEL7.0.z qemu-kvm PATCH 1/1] Count used RAMBlock pages for migration_dirty_pages
9ae3a8
Bugzilla: 1074913
9ae3a8
RH-Acked-by: Juan Quintela <quintela@redhat.com>
9ae3a8
RH-Acked-by: Markus Armbruster <armbru@redhat.com>
9ae3a8
RH-Acked-by: Amit Shah <amit.shah@redhat.com>
9ae3a8
9ae3a8
From: "Dr. David Alan Gilbert" <dgilbert@redhat.com>
9ae3a8
9ae3a8
This is a fix for a bug* triggered by a migration after hot unplugging
9ae3a8
a few virtio-net NICs, that caused migration never to converge, because
9ae3a8
'migration_dirty_pages' is incorrectly initialised.
9ae3a8
9ae3a8
'migration_dirty_pages' is used as a tally of the number of outstanding
9ae3a8
dirty pages, to give the migration code an idea of how much more data
9ae3a8
will need to be transferred, and thus whether it can end the iterative
9ae3a8
phase.
9ae3a8
9ae3a8
It was initialised to the total size of the RAMBlock address space,
9ae3a8
however hotunplug can leave this space sparse, and hence
9ae3a8
migration_dirty_pages ended up too large.
9ae3a8
9ae3a8
Signed-off-by: Dr. David Alan Gilbert <dgilbert@redhat.com>
9ae3a8
9ae3a8
(* https://bugzilla.redhat.com/show_bug.cgi?id=1074913 )
9ae3a8
9ae3a8
Signed-off-by: Juan Quintela <quintela@redhat.com>
9ae3a8
(cherry picked from commit e30d1d8c7195848abb28a8c734a82b845b8b456a)
9ae3a8
---
9ae3a8
 arch_init.c | 21 +++++++++++++++++----
9ae3a8
 1 file changed, 17 insertions(+), 4 deletions(-)
9ae3a8
9ae3a8
Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
9ae3a8
---
9ae3a8
 arch_init.c |   21 +++++++++++++++++----
9ae3a8
 1 files changed, 17 insertions(+), 4 deletions(-)
9ae3a8
9ae3a8
diff --git a/arch_init.c b/arch_init.c
9ae3a8
index 22f7def..b88d686 100644
9ae3a8
--- a/arch_init.c
9ae3a8
+++ b/arch_init.c
9ae3a8
@@ -728,11 +728,8 @@ static void reset_ram_globals(void)
9ae3a8
 static int ram_save_setup(QEMUFile *f, void *opaque)
9ae3a8
 {
9ae3a8
     RAMBlock *block;
9ae3a8
-    int64_t ram_pages = last_ram_offset() >> TARGET_PAGE_BITS;
9ae3a8
+    int64_t ram_bitmap_pages; /* Size of bitmap in pages, including gaps */
9ae3a8
 
9ae3a8
-    migration_bitmap = bitmap_new(ram_pages);
9ae3a8
-    bitmap_set(migration_bitmap, 0, ram_pages);
9ae3a8
-    migration_dirty_pages = ram_pages;
9ae3a8
     mig_throttle_on = false;
9ae3a8
     dirty_rate_high_cnt = 0;
9ae3a8
 
9ae3a8
@@ -771,6 +768,22 @@ static int ram_save_setup(QEMUFile *f, void *opaque)
9ae3a8
     bytes_transferred = 0;
9ae3a8
     reset_ram_globals();
9ae3a8
 
9ae3a8
+    ram_bitmap_pages = last_ram_offset() >> TARGET_PAGE_BITS;
9ae3a8
+    migration_bitmap = bitmap_new(ram_bitmap_pages);
9ae3a8
+    bitmap_set(migration_bitmap, 0, ram_bitmap_pages);
9ae3a8
+
9ae3a8
+    /*
9ae3a8
+     * Count the total number of pages used by ram blocks not including any
9ae3a8
+     * gaps due to alignment or unplugs.
9ae3a8
+     */
9ae3a8
+    migration_dirty_pages = 0;
9ae3a8
+    QTAILQ_FOREACH(block, &ram_list.blocks, next) {
9ae3a8
+        uint64_t block_pages;
9ae3a8
+
9ae3a8
+        block_pages = block->length >> TARGET_PAGE_BITS;
9ae3a8
+        migration_dirty_pages += block_pages;
9ae3a8
+    }
9ae3a8
+
9ae3a8
     memory_global_dirty_log_start();
9ae3a8
     migration_bitmap_sync();
9ae3a8
     qemu_mutex_unlock_iothread();
9ae3a8
-- 
9ae3a8
1.7.1
9ae3a8