Patchwork [22/22] ram: save live optimization

login
register
mail settings
Submitter Juan Quintela
Date July 13, 2012, 7:23 a.m.
Message ID <1342164224-32709-23-git-send-email-quintela@redhat.com>
Download mbox | patch
Permalink /patch/170816/
State New
Headers show

Comments

Juan Quintela - July 13, 2012, 7:23 a.m.
Optimize stage3 (complete), to use the page cached if it is there, but
not update the cache with new pages (they will never be reused).

Signed-off-by: Juan Quintela <quintela@redhat.com>
---
 arch_init.c |   14 ++++++++------
 1 file changed, 8 insertions(+), 6 deletions(-)

Patch

diff --git a/arch_init.c b/arch_init.c
index ab3fb2c..de2d801 100644
--- a/arch_init.c
+++ b/arch_init.c
@@ -276,7 +276,7 @@  static void save_block_hdr(QEMUFile *f, RAMBlock *block, ram_addr_t offset,

 static int save_xbzrle_page(QEMUFile *f, uint8_t *current_data,
                             ram_addr_t current_addr, RAMBlock *block,
-                            ram_addr_t offset, int cont)
+                            ram_addr_t offset, int cont, bool last_stage)
 {
     int encoded_len = 0, bytes_sent = -1, ret = -1;
     XBZRLEHeader hdr = {
@@ -341,7 +341,7 @@  static ram_addr_t last_offset;
  *           n: the amount of bytes written in other case
  */

-static int ram_save_block(QEMUFile *f)
+static int ram_save_block(QEMUFile *f, bool last_stage)
 {
     RAMBlock *block = last_block;
     ram_addr_t offset = last_offset;
@@ -372,8 +372,10 @@  static int ram_save_block(QEMUFile *f)
             } else if (migrate_use_xbzrle()) {
                 current_addr = block->offset + offset;
                 bytes_sent = save_xbzrle_page(f, p, current_addr, block,
-                                              offset, cont);
-                p = get_cached_data(XBZRLE.cache, current_addr);
+                                              offset, cont, last_stage);
+                if ((bytes_sent != -1) || !last_stage) {
+                    p = get_cached_data(XBZRLE.cache, current_addr);
+                }
             }

             /* either we didn't send yet (we may have had XBZRLE overflow) */
@@ -543,7 +545,7 @@  static int ram_save_iterate(QEMUFile *f, void *opaque)
     while ((ret = qemu_file_rate_limit(f)) == 0) {
         int bytes_sent;

-        bytes_sent = ram_save_block(f);
+        bytes_sent = ram_save_block(f, false);
         /* no more blocks to sent */
         if (bytes_sent < 0) {
             break;
@@ -605,7 +607,7 @@  static int ram_save_complete(QEMUFile *f, void *opaque)
     while (true) {
         int bytes_sent;

-        bytes_sent = ram_save_block(f);
+        bytes_sent = ram_save_block(f, true);
         /* no more blocks to sent */
         if (bytes_sent < 0) {
             break;