From patchwork Mon Nov 2 07:37:00 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Li, Liang Z" X-Patchwork-Id: 538871 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 04372140D6A for ; Mon, 2 Nov 2015 18:42:54 +1100 (AEDT) Received: from localhost ([::1]:40467 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Zt9lT-0008J5-Qq for incoming@patchwork.ozlabs.org; Mon, 02 Nov 2015 02:42:51 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:33413) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Zt9l6-0007di-Ie for qemu-devel@nongnu.org; Mon, 02 Nov 2015 02:42:29 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Zt9l3-00014C-Bl for qemu-devel@nongnu.org; Mon, 02 Nov 2015 02:42:28 -0500 Received: from mga09.intel.com ([134.134.136.24]:10231) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Zt9l3-000148-6c for qemu-devel@nongnu.org; Mon, 02 Nov 2015 02:42:25 -0500 Received: from orsmga002.jf.intel.com ([10.7.209.21]) by orsmga102.jf.intel.com with ESMTP; 01 Nov 2015 23:42:26 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.20,233,1444719600"; d="scan'208";a="840418168" Received: from ll.sh.intel.com (HELO localhost) ([10.239.13.27]) by orsmga002.jf.intel.com with ESMTP; 01 Nov 2015 23:42:22 -0800 From: Liang Li To: qemu-devel@nongnu.org Date: Mon, 2 Nov 2015 15:37:00 +0800 Message-Id: <1446449823-25049-2-git-send-email-liang.z.li@intel.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1446449823-25049-1-git-send-email-liang.z.li@intel.com> References: <1446449823-25049-1-git-send-email-liang.z.li@intel.com> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 134.134.136.24 Cc: quintela@redhat.com, Liang Li , yong.y.wang@intel.com, stefanha@redhat.com, amit.shah@redhat.com, pbonzini@redhat.com Subject: [Qemu-devel] [v2 RESEND 1/4] migration: defer migration_end & blk_mig_cleanup X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Because of the patch 3ea3b7fa9af067982f34b of kvm, which introduces a lazy collapsing of small sptes into large sptes mechanism, now migration_end() is a time consuming operation because it calls memroy_global_dirty_log_stop(), which will trigger the dropping of small sptes operation and takes about dozens of milliseconds, so call migration_end() before all the vmsate data has already been transferred to the destination will prolong VM downtime. This operation should be deferred after all the data has been transferred to the destination. blk_mig_cleanup() can be deferred too. For a VM with 8G RAM, this patch can reduce the VM downtime about 30 ms. Signed-off-by: Liang Li Reviewed-by: Paolo Bonzini Reviewed-by: Juan Quintela --- migration/block.c | 1 - migration/migration.c | 13 ++++++------- migration/ram.c | 1 - 3 files changed, 6 insertions(+), 9 deletions(-) diff --git a/migration/block.c b/migration/block.c index f7bb1e0..8401597 100644 --- a/migration/block.c +++ b/migration/block.c @@ -750,7 +750,6 @@ static int block_save_complete(QEMUFile *f, void *opaque) qemu_put_be64(f, BLK_MIG_FLAG_EOS); - blk_mig_cleanup(); return 0; } diff --git a/migration/migration.c b/migration/migration.c index b092f38..d5a7304 100644 --- a/migration/migration.c +++ b/migration/migration.c @@ -613,12 +613,9 @@ static void migrate_fd_cleanup(void *opaque) assert(s->state != MIGRATION_STATUS_ACTIVE); - if (s->state != MIGRATION_STATUS_COMPLETED) { - qemu_savevm_state_cancel(); - if (s->state == MIGRATION_STATUS_CANCELLING) { - migrate_set_state(s, MIGRATION_STATUS_CANCELLING, - MIGRATION_STATUS_CANCELLED); - } + if (s->state == MIGRATION_STATUS_CANCELLING) { + migrate_set_state(s, MIGRATION_STATUS_CANCELLING, + MIGRATION_STATUS_CANCELLED); } notifier_list_notify(&migration_state_notifiers, s); @@ -1028,6 +1025,7 @@ static void *migration_thread(void *opaque) int64_t initial_bytes = 0; int64_t max_size = 0; int64_t start_time = initial_time; + int64_t end_time; bool old_vm_running = false; rcu_register_thread(); @@ -1089,10 +1087,11 @@ static void *migration_thread(void *opaque) /* If we enabled cpu throttling for auto-converge, turn it off. */ cpu_throttle_stop(); + end_time = qemu_clock_get_ms(QEMU_CLOCK_REALTIME); qemu_mutex_lock_iothread(); + qemu_savevm_state_cancel(); if (s->state == MIGRATION_STATUS_COMPLETED) { - int64_t end_time = qemu_clock_get_ms(QEMU_CLOCK_REALTIME); uint64_t transferred_bytes = qemu_ftell(s->file); s->total_time = end_time - s->total_time; s->downtime = end_time - start_time; diff --git a/migration/ram.c b/migration/ram.c index a25bcc7..25e9eeb 100644 --- a/migration/ram.c +++ b/migration/ram.c @@ -1344,7 +1344,6 @@ static int ram_save_complete(QEMUFile *f, void *opaque) rcu_read_unlock(); - migration_end(); qemu_put_be64(f, RAM_SAVE_FLAG_EOS); return 0;