From patchwork Wed May 18 11:28:20 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jitendra Kolhe X-Patchwork-Id: 9117991 Return-Path: X-Original-To: patchwork-qemu-devel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id E3770BF29F for ; Wed, 18 May 2016 11:25:49 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 3F27F2021F for ; Wed, 18 May 2016 11:25:49 +0000 (UTC) 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.kernel.org (Postfix) with ESMTPS id 6728620212 for ; Wed, 18 May 2016 11:25:48 +0000 (UTC) Received: from localhost ([::1]:44351 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1b2zbn-0003xM-KG for patchwork-qemu-devel@patchwork.kernel.org; Wed, 18 May 2016 07:25:47 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:47902) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1b2zbY-0003wa-Oi for qemu-devel@nongnu.org; Wed, 18 May 2016 07:25:33 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1b2zbU-0000Be-HP for qemu-devel@nongnu.org; Wed, 18 May 2016 07:25:31 -0400 Received: from g9t5009.houston.hp.com ([15.240.92.67]:35919) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1b2zbU-0000Aj-8w for qemu-devel@nongnu.org; Wed, 18 May 2016 07:25:28 -0400 Received: from hpvmrhel1.in.rdlabs.hpecorp.net (unknown [15.213.178.32]) by g9t5009.houston.hp.com (Postfix) with ESMTP id AF87A4F; Wed, 18 May 2016 11:25:13 +0000 (UTC) From: Jitendra Kolhe To: qemu-devel@nongnu.org Date: Wed, 18 May 2016 16:58:20 +0530 Message-Id: <1463570900-30866-1-git-send-email-jitendra.kolhe@hpe.com> X-Mailer: git-send-email 1.8.3.1 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 15.240.92.67 Subject: [Qemu-devel] [PATCH v3 4/4] migration: skip scanning and migrating ram pages released by virtio-balloon driver. 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: renganathan.meenakshisundaram@hpe.com, JBottomley@Odin.com, ehabkost@redhat.com, crosthwaite.peter@gmail.com, simhan@hpe.com, quintela@redhat.com, armbru@redhat.com, lcapitulino@redhat.com, jitendra.kolhe@hpe.com, borntraeger@de.ibm.com, mst@redhat.com, mohan_parthasarathy@hpe.com, stefanha@redhat.com, den@openvz.org, amit.shah@redhat.com, pbonzini@redhat.com, dgilbert@redhat.com, rth@twiddle.net Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP During live migration, byte offset within memory region of the start of a dirty page is checked against the balloon bitmap, if the bit is set in the balloon bitmap, the corresponding ram page will be excluded from scanning and sending header information during migration. In case TARGET_PAGE_BITS > VIRTIO_BALLOON_PFN_SHIFT, the bitmap test function will return true if all sub-pages of size (1UL << VIRTIO_BALLOON_PFN_SHIFT) within dirty page are ballooned out. The test against bitmap gets disabled in case balloon bitmap status is set to disable during migration setup. Signed-off-by: Jitendra Kolhe --- balloon.c | 34 ++++++++++++++++++++++++++++++++++ include/sysemu/balloon.h | 1 + migration/ram.c | 6 +++++- 3 files changed, 40 insertions(+), 1 deletion(-) diff --git a/balloon.c b/balloon.c index 494b8aa..baa7e5a 100644 --- a/balloon.c +++ b/balloon.c @@ -274,3 +274,37 @@ void qemu_balloon_bitmap_reset(bool source) } balloon_bitmap_state = BALLOON_BITMAP_INIT; } + +int qemu_balloon_bitmap_test(RAMBlock *rb, ram_addr_t addr) +{ + ram_addr_t base; + unsigned long nr = 0; + int i = 0, count = 0, loop = 0; + int ret = 0; + + if (balloon_bitmap_state != BALLOON_BITMAP_ENABLE) { + return 0; + } + + base = rb->offset >> balloon_bitmap_pfn_shift; + nr = base + (addr >> balloon_bitmap_pfn_shift); + + qemu_mutex_lock_balloon_bitmap(); + if (TARGET_PAGE_BITS <= balloon_bitmap_pfn_shift) { + ret = (test_bit(nr, bmap)) ? 1 : 0; + } else { + loop = (1UL << (TARGET_PAGE_BITS - balloon_bitmap_pfn_shift)); + for (i = 0; i < loop; i++) { + if (test_bit((nr + i), bmap)) { + count++; + } + } + /* addr is alligned to TARGET_PAGE_SIZE, return true only if all + * sub-pages (1 << balloon_bitmap_pfn_shift or 4K) are ballooned out. + */ + ret = (count == loop) ? 1 : 0; + } + qemu_mutex_unlock_balloon_bitmap(); + + return ret; +} diff --git a/include/sysemu/balloon.h b/include/sysemu/balloon.h index 9a9bed9..941982e 100644 --- a/include/sysemu/balloon.h +++ b/include/sysemu/balloon.h @@ -34,5 +34,6 @@ void qemu_balloon_bitmap_extend(RAMBlock *new_block, ram_addr_t old, ram_addr_t new); void qemu_balloon_bitmap_setup(void); void qemu_balloon_bitmap_reset(bool source); +int qemu_balloon_bitmap_test(RAMBlock *rb, ram_addr_t addr); #endif diff --git a/migration/ram.c b/migration/ram.c index a4c3582..a5802d9 100644 --- a/migration/ram.c +++ b/migration/ram.c @@ -704,6 +704,10 @@ static int save_zero_page(QEMUFile *f, RAMBlock *block, ram_addr_t offset, { int pages = -1; + if (qemu_balloon_bitmap_test(block, offset) == 1) { + return 0; /* pages */ + } + if (is_zero_range(p, TARGET_PAGE_SIZE)) { acct_info.dup_pages++; *bytes_transferred += save_page_header(f, block, @@ -770,7 +774,7 @@ static int ram_save_page(QEMUFile *f, PageSearchStatus *pss, } } else { pages = save_zero_page(f, block, offset, p, bytes_transferred); - if (pages > 0) { + if (pages >= 0) { /* Must let xbzrle know, otherwise a previous (now 0'd) cached * page would be stale */