From patchwork Wed Jan 17 06:31:58 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Wang, Wei W" X-Patchwork-Id: 10168595 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id E252A60386 for ; Wed, 17 Jan 2018 06:51:44 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id CD92627D0E for ; Wed, 17 Jan 2018 06:51:44 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id C002727F85; Wed, 17 Jan 2018 06:51:44 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 1C12927D0E for ; Wed, 17 Jan 2018 06:51:43 +0000 (UTC) Received: from localhost ([::1]:41948 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ebhZW-0005zf-RS for patchwork-qemu-devel@patchwork.kernel.org; Wed, 17 Jan 2018 01:51:42 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:54618) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ebhYB-00053Y-8r for qemu-devel@nongnu.org; Wed, 17 Jan 2018 01:50:20 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ebhY9-0003pg-W7 for qemu-devel@nongnu.org; Wed, 17 Jan 2018 01:50:19 -0500 Received: from mga11.intel.com ([192.55.52.93]:59302) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1ebhY9-0003no-LR for qemu-devel@nongnu.org; Wed, 17 Jan 2018 01:50:17 -0500 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga006.fm.intel.com ([10.253.24.20]) by fmsmga102.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 16 Jan 2018 22:50:16 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.46,371,1511856000"; d="scan'208";a="196306519" Received: from devel-ww.sh.intel.com ([10.239.48.110]) by fmsmga006.fm.intel.com with ESMTP; 16 Jan 2018 22:50:14 -0800 From: Wei Wang To: qemu-devel@nongnu.org, virtio-dev@lists.oasis-open.org, mst@redhat.com, quintela@redhat.com, dgilbert@redhat.com Date: Wed, 17 Jan 2018 14:31:58 +0800 Message-Id: <1516170720-4948-3-git-send-email-wei.w.wang@intel.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1516170720-4948-1-git-send-email-wei.w.wang@intel.com> References: <1516170720-4948-1-git-send-email-wei.w.wang@intel.com> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 192.55.52.93 Subject: [Qemu-devel] [PATCH v1 2/4] migration: call balloon to clear bits of free pages from dirty bitmap X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: yang.zhang.wz@gmail.com, quan.xu0@gmail.com, liliang.opensource@gmail.com, wei.w.wang@intel.com, pbonzini@redhat.com, nilal@redhat.com Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP When migration starts, call the related balloon functions to clear the bits of guest free pages from the dirty bitmap. The dirty bitmap should be ready to use when sending pages to the destination, so stop the guest from reporting free pages before sending pages. Signed-off-by: Wei Wang CC: Michael S. Tsirkin --- migration/ram.c | 28 ++++++++++++++++++++++++---- 1 file changed, 24 insertions(+), 4 deletions(-) diff --git a/migration/ram.c b/migration/ram.c index d6f462c..9b8d102 100644 --- a/migration/ram.c +++ b/migration/ram.c @@ -49,6 +49,7 @@ #include "qemu/rcu_queue.h" #include "migration/colo.h" #include "migration/block.h" +#include "sysemu/balloon.h" /***********************************************************/ /* ram save/restore */ @@ -206,6 +207,10 @@ struct RAMState { uint32_t last_version; /* We are in the first round */ bool ram_bulk_stage; + /* The feature, skipping the transfer of free pages, is supported */ + bool free_page_support; + /* Skip the transfer of free pages in the bulk stage */ + bool free_page_done; /* How many times we have dirty too many pages */ int dirty_rate_high_cnt; /* these variables are used for bitmap sync */ @@ -773,7 +778,7 @@ unsigned long migration_bitmap_find_dirty(RAMState *rs, RAMBlock *rb, unsigned long *bitmap = rb->bmap; unsigned long next; - if (rs->ram_bulk_stage && start > 0) { + if (rs->ram_bulk_stage && start > 0 && !rs->free_page_support) { next = start + 1; } else { next = find_next_bit(bitmap, size, start); @@ -1653,6 +1658,8 @@ static void ram_state_reset(RAMState *rs) rs->last_page = 0; rs->last_version = ram_list.version; rs->ram_bulk_stage = true; + rs->free_page_support = balloon_free_page_support(); + rs->free_page_done = false; } #define MAX_WAIT 50 /* ms, half buffered_file limit */ @@ -2135,7 +2142,7 @@ static int ram_state_init(RAMState **rsp) return 0; } -static void ram_list_init_bitmaps(void) +static void ram_list_init_bitmaps(RAMState *rs) { RAMBlock *block; unsigned long pages; @@ -2145,7 +2152,11 @@ static void ram_list_init_bitmaps(void) QLIST_FOREACH_RCU(block, &ram_list.blocks, next) { pages = block->max_length >> TARGET_PAGE_BITS; block->bmap = bitmap_new(pages); - bitmap_set(block->bmap, 0, pages); + if (rs->free_page_support) { + bitmap_set(block->bmap, 1, pages); + } else { + bitmap_set(block->bmap, 0, pages); + } if (migrate_postcopy_ram()) { block->unsentmap = bitmap_new(pages); bitmap_set(block->unsentmap, 0, pages); @@ -2161,8 +2172,11 @@ static void ram_init_bitmaps(RAMState *rs) qemu_mutex_lock_ramlist(); rcu_read_lock(); - ram_list_init_bitmaps(); + ram_list_init_bitmaps(rs); memory_global_dirty_log_start(); + if (rs->free_page_support) { + balloon_free_page_start(); + } migration_bitmap_sync(rs); rcu_read_unlock(); @@ -2275,6 +2289,12 @@ static int ram_save_iterate(QEMUFile *f, void *opaque) ram_control_before_iterate(f, RAM_CONTROL_ROUND); + /* Before sending the pages, stop the guest from reporting free pages. */ + if (rs->free_page_support && !rs->free_page_done) { + balloon_free_page_stop(); + rs->free_page_done = true; + } + t0 = qemu_clock_get_ns(QEMU_CLOCK_REALTIME); i = 0; while ((ret = qemu_file_rate_limit(f)) == 0) {