at the beginning of migration all pages are marked dirty and in the first round a bulk migration of all pages is performed.
currently all these pages are copied to the page cache regardless if there are frequently updated or not. this doesn't make sense since most of these pages are never transferred again. this patch changes the XBZRLE transfer to only be used after the bulk stage has been completed. that means a page is added to the page cache the second time it is transferred and XBZRLE can benefit from the third time of transfer. since the page cache is likely smaller than the number of pages its also likely that in the second round the page is missing in the cache due to collisions in the bulk phase. on the other hand a lot of unneccssary mallocs, memdups and frees are saved. Signed-off-by: Peter Lieven <p...@kamp.de> --- arch_init.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/arch_init.c b/arch_init.c index 8da868b..24241e0 100644 --- a/arch_init.c +++ b/arch_init.c @@ -347,6 +347,7 @@ static ram_addr_t last_offset; static unsigned long *migration_bitmap; static uint64_t migration_dirty_pages; static uint32_t last_version; +static bool ram_bulk_stage; static inline ram_addr_t migration_bitmap_find_and_reset_dirty(MemoryRegion *mr, @@ -451,6 +452,7 @@ static int ram_save_block(QEMUFile *f, bool last_stage) if (!block) { block = QTAILQ_FIRST(&ram_list.blocks); complete_round = true; + ram_bulk_stage = false; } } else { uint8_t *p; @@ -467,7 +469,7 @@ static int ram_save_block(QEMUFile *f, bool last_stage) RAM_SAVE_FLAG_COMPRESS); qemu_put_byte(f, *p); bytes_sent += 1; - } else if (migrate_use_xbzrle()) { + } else if (!ram_bulk_stage && migrate_use_xbzrle()) { current_addr = block->offset + offset; bytes_sent = save_xbzrle_page(f, p, current_addr, block, offset, cont, last_stage); @@ -554,6 +556,7 @@ static void reset_ram_globals(void) last_sent_block = NULL; last_offset = 0; last_version = ram_list.version; + ram_bulk_stage = true; } #define MAX_WAIT 50 /* ms, half buffered_file limit */ -- 1.7.9.5