From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1NUbOZ-0007Wj-32 for qemu-devel@nongnu.org; Tue, 12 Jan 2010 02:42:31 -0500 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1NUbOS-0007UD-KA for qemu-devel@nongnu.org; Tue, 12 Jan 2010 02:42:29 -0500 Received: from [199.232.76.173] (port=50248 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1NUbOQ-0007TU-3X for qemu-devel@nongnu.org; Tue, 12 Jan 2010 02:42:23 -0500 Received: from mtagate2.de.ibm.com ([195.212.17.162]:56093) by monty-python.gnu.org with esmtps (TLS-1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.60) (envelope-from ) id 1NUbOP-0005kE-Ch for qemu-devel@nongnu.org; Tue, 12 Jan 2010 02:42:21 -0500 Received: from d12nrmr1607.megacenter.de.ibm.com (d12nrmr1607.megacenter.de.ibm.com [9.149.167.49]) by mtagate2.de.ibm.com (8.13.1/8.13.1) with ESMTP id o0C7gGp7007171 for ; Tue, 12 Jan 2010 07:42:16 GMT Received: from d12av02.megacenter.de.ibm.com (d12av02.megacenter.de.ibm.com [9.149.165.228]) by d12nrmr1607.megacenter.de.ibm.com (8.13.8/8.13.8/NCO v10.0) with ESMTP id o0C7g9T91454134 for ; Tue, 12 Jan 2010 08:42:16 +0100 Received: from d12av02.megacenter.de.ibm.com (loopback [127.0.0.1]) by d12av02.megacenter.de.ibm.com (8.12.11.20060308/8.13.3) with ESMTP id o0C7g9Ch016631 for ; Tue, 12 Jan 2010 08:42:09 +0100 From: Liran Schour Date: Tue, 12 Jan 2010 10:27:13 +0200 Message-Id: <12632848353279-git-send-email-lirans@il.ibm.com> In-Reply-To: <12632848351489-git-send-email-lirans@il.ibm.com> References: <1263284833297-git-send-email-lirans@il.ibm.com> <12632848342235-git-send-email-lirans@il.ibm.com> <12632848343008-git-send-email-lirans@il.ibm.com> <12632848351489-git-send-email-lirans@il.ibm.com> Subject: [Qemu-devel] [PATCH 4/4] Try not to exceed max downtime on stage3 List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: Liran Schour Move to stage3 only when remaining work can be done below max downtime. To make sure the process will converge we will try only MAX_DIRTY_ITERATIONS. Signed-off-by: Liran Schour --- block-migration.c | 67 +++++++++++++++++++++++++++++++++++----------------- 1 files changed, 45 insertions(+), 22 deletions(-) diff --git a/block-migration.c b/block-migration.c index 90c84b1..9ae04c4 100644 --- a/block-migration.c +++ b/block-migration.c @@ -17,6 +17,7 @@ #include "qemu-queue.h" #include "monitor.h" #include "block-migration.h" +#include "migration.h" #include #define BLOCK_SIZE (BDRV_SECTORS_PER_DIRTY_CHUNK << BDRV_SECTOR_BITS) @@ -30,6 +31,7 @@ #define BLOCKS_READ_CHANGE 100 #define INITIAL_BLOCKS_READ 100 #define MAX_DIRTY_ITERATIONS 100 +#define DISK_RATE (30 << 20) //30 MB/sec //#define DEBUG_BLK_MIGRATION @@ -135,10 +137,11 @@ static void blk_mig_read_cb(void *opaque, int ret) blk->ret = ret; QSIMPLEQ_INSERT_TAIL(&block_mig_state.blk_list, blk, entry); - + block_mig_state.submitted--; block_mig_state.read_done++; assert(block_mig_state.submitted >= 0); + } static int mig_save_device_bulk(Monitor *mon, QEMUFile *f, @@ -225,7 +228,7 @@ static void init_blk_migration(Monitor *mon, QEMUFile *f) block_mig_state.prev_progress = -1; block_mig_state.bulk_completed = 0; block_mig_state.dirty_iterations = 0; - + for (bs = bdrv_first; bs != NULL; bs = bs->next) { if (bs->type == BDRV_TYPE_HD) { sectors = bdrv_getlength(bs) >> BDRV_SECTOR_BITS; @@ -405,15 +408,41 @@ static void flush_blks(QEMUFile* f) block_mig_state.transferred); } -static int is_stage2_completed(void) +static int64_t get_remaining_dirty(void) { + BlkMigDevState *bmds; + int64_t dirty = 0; + + QSIMPLEQ_FOREACH(bmds, &block_mig_state.bmds_list, entry) { + dirty += bdrv_get_dirty_count(bmds->bs); + } + + return dirty; +} - if (block_mig_state.submitted == 0 && - block_mig_state.bulk_completed == 1) { - return 1; - } else { - return 0; +static int is_stage2_completed(void) +{ + int64_t remaining_dirty; + + if (block_mig_state.bulk_completed == 1) { + if (block_mig_state.dirty_iterations++ > MAX_DIRTY_ITERATIONS) { + /* finish stage2 because we have too much dirty iterations */ + + return 1; + } + + remaining_dirty = get_remaining_dirty(); + + if ((remaining_dirty * BLOCK_SIZE) * 1000000000 / DISK_RATE <= + migrate_max_downtime()) { + /* finish stage2 because we think that we can finish remaing work + below max_downtime */ + + return 1; + } } + + return 0; } static void blk_mig_cleanup(Monitor *mon) @@ -438,9 +467,7 @@ static void blk_mig_cleanup(Monitor *mon) } static int block_save_live(Monitor *mon, QEMUFile *f, int stage, void *opaque) -{ - int dirty_iteration = 0; - +{ dprintf("Enter save live stage %d submitted %d transferred %d\n", stage, block_mig_state.submitted, block_mig_state.transferred); @@ -482,19 +509,12 @@ static int block_save_live(Monitor *mon, QEMUFile *f, int stage, void *opaque) /* finish saving bulk on all devices */ block_mig_state.bulk_completed = 1; } - } else if (block_mig_state.dirty_iterations < MAX_DIRTY_ITERATIONS) { - if (dirty_iteration == 0) { - /* increment dirty iteration only once per round */ - dirty_iteration = 1; - block_mig_state.dirty_iterations++; - } + } else { + if (blk_mig_save_dirty_block(mon, f, 1) == 0) { /* no more dirty blocks */ break; } - } else { - /* if we got here stop the loop */ - break; } } @@ -507,9 +527,12 @@ static int block_save_live(Monitor *mon, QEMUFile *f, int stage, void *opaque) } if (stage == 3) { - /* we now for sure that save bulk is completed */ - + /* we know for sure that save bulk is completed and + all async read completed */ + assert(block_mig_state.submitted == 0); + while(blk_mig_save_dirty_block(mon, f, 0) != 0); + blk_mig_cleanup(mon); /* report completion */ -- 1.5.2.4