From patchwork Wed May 18 11:22:12 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jitendra Kolhe X-Patchwork-Id: 623519 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 3r8sJg24Xlz9t5W for ; Wed, 18 May 2016 21:23:31 +1000 (AEST) Received: from localhost ([::1]:44340 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1b2zZY-0002ym-Fp for incoming@patchwork.ozlabs.org; Wed, 18 May 2016 07:23:28 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:46214) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1b2zVZ-0007gw-SS for qemu-devel@nongnu.org; Wed, 18 May 2016 07:19:23 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1b2zVV-0006vB-Lk for qemu-devel@nongnu.org; Wed, 18 May 2016 07:19:20 -0400 Received: from g1t5424.austin.hp.com ([15.216.225.54]:53070) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1b2zVV-0006uK-Cv for qemu-devel@nongnu.org; Wed, 18 May 2016 07:19:17 -0400 Received: from hpvmrhel1.in.rdlabs.hpecorp.net (unknown [15.213.178.32]) by g1t5424.austin.hp.com (Postfix) with ESMTP id 765BC59; Wed, 18 May 2016 11:19:06 +0000 (UTC) From: Jitendra Kolhe To: qemu-devel@nongnu.org Date: Wed, 18 May 2016 16:52:12 +0530 Message-Id: <1463570532-29862-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.216.225.54 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+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" 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 */