From patchwork Mon Oct 29 14:11:43 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Juan Quintela X-Patchwork-Id: 195021 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 29D9B2C008B for ; Tue, 30 Oct 2012 02:02:05 +1100 (EST) Received: from localhost ([::1]:44506 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TSq6Z-0006h7-Nk for incoming@patchwork.ozlabs.org; Mon, 29 Oct 2012 10:14:15 -0400 Received: from eggs.gnu.org ([208.118.235.92]:39088) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TSq4t-0003LQ-Nz for qemu-devel@nongnu.org; Mon, 29 Oct 2012 10:12:37 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1TSq4p-0007OL-JC for qemu-devel@nongnu.org; Mon, 29 Oct 2012 10:12:31 -0400 Received: from mx1.redhat.com ([209.132.183.28]:4686) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TSq4p-0007O5-Az for qemu-devel@nongnu.org; Mon, 29 Oct 2012 10:12:27 -0400 Received: from int-mx09.intmail.prod.int.phx2.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id q9TECQXr013380 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Mon, 29 Oct 2012 10:12:26 -0400 Received: from trasno.mitica (ovpn-113-116.phx2.redhat.com [10.3.113.116]) by int-mx09.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id q9TEBikV011647; Mon, 29 Oct 2012 10:12:24 -0400 From: Juan Quintela To: qemu-devel@nongnu.org Date: Mon, 29 Oct 2012 15:11:43 +0100 Message-Id: <1351519903-26607-19-git-send-email-quintela@redhat.com> In-Reply-To: <1351519903-26607-1-git-send-email-quintela@redhat.com> References: <1351519903-26607-1-git-send-email-quintela@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.22 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 209.132.183.28 Cc: owasserm@redhat.com, mtosatti@redhat.com, avi@redhat.com, pbonzini@redhat.com Subject: [Qemu-devel] [PATCH 18/18] ram: optimize migration bitmap walking 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 Instead of testing each page individually, we search what is the next dirty page with a bitmap operation. We have to reorganize the code to move from a "for" loop, to a while(dirty) loop. Signed-off-by: Juan Quintela --- arch_init.c | 45 ++++++++++++++++++++++++++------------------- 1 file changed, 26 insertions(+), 19 deletions(-) diff --git a/arch_init.c b/arch_init.c index 79f466f..d760caa 100644 --- a/arch_init.c +++ b/arch_init.c @@ -338,18 +338,21 @@ static unsigned long *migration_bitmap; static uint64_t migration_dirty_pages; static uint32_t last_version; -static inline bool migration_bitmap_test_and_reset_dirty(MemoryRegion *mr, - ram_addr_t offset) +static inline +ram_addr_t migration_bitmap_find_and_reset_dirty(MemoryRegion *mr, + ram_addr_t start) { - bool ret; - int nr = (mr->ram_addr + offset) >> TARGET_PAGE_BITS; + unsigned long base = mr->ram_addr >> TARGET_PAGE_BITS; + unsigned long nr = base + (start >> TARGET_PAGE_BITS); + unsigned long size = base + (int128_get64(mr->size) >> TARGET_PAGE_BITS); - ret = test_and_clear_bit(nr, migration_bitmap); + unsigned long next = find_next_bit(migration_bitmap, size, nr); - if (ret) { + if (next < size) { + clear_bit(next, migration_bitmap); migration_dirty_pages--; } - return ret; + return (next - base) << TARGET_PAGE_BITS; } static inline bool migration_bitmap_set_dirty(MemoryRegion *mr, @@ -418,6 +421,7 @@ static int ram_save_block(QEMUFile *f, bool last_stage) { RAMBlock *block = last_block; ram_addr_t offset = last_offset; + bool complete_round = false; int bytes_sent = -1; MemoryRegion *mr; ram_addr_t current_addr; @@ -425,9 +429,21 @@ static int ram_save_block(QEMUFile *f, bool last_stage) if (!block) block = QLIST_FIRST(&ram_list.blocks); - do { + while (true) { mr = block->mr; - if (migration_bitmap_test_and_reset_dirty(mr, offset)) { + offset = migration_bitmap_find_and_reset_dirty(mr, offset); + if (complete_round && block == last_block && + offset >= last_offset) { + break; + } + if (offset >= block->length) { + offset = 0; + block = QLIST_NEXT(block, next); + if (!block) { + block = QLIST_FIRST(&ram_list.blocks); + complete_round = true; + } + } else { uint8_t *p; int cont = (block == last_block) ? RAM_SAVE_FLAG_CONTINUE : 0; @@ -460,16 +476,7 @@ static int ram_save_block(QEMUFile *f, bool last_stage) break; } } - - offset += TARGET_PAGE_SIZE; - if (offset >= block->length) { - offset = 0; - block = QLIST_NEXT(block, next); - if (!block) - block = QLIST_FIRST(&ram_list.blocks); - } - } while (block != last_block || offset != last_offset); - + } last_block = block; last_offset = offset;