From patchwork Tue Feb 9 09:55:40 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: OHMURA Kei X-Patchwork-Id: 77990 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by demeter.kernel.org (8.14.3/8.14.3) with ESMTP id o199u8TB009774 for ; Tue, 9 Feb 2010 09:56:08 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753393Ab0BIJ4G (ORCPT ); Tue, 9 Feb 2010 04:56:06 -0500 Received: from tama50.ecl.ntt.co.jp ([129.60.39.147]:53716 "EHLO tama50.ecl.ntt.co.jp" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752691Ab0BIJ4F (ORCPT ); Tue, 9 Feb 2010 04:56:05 -0500 Received: from mfs6.rdh.ecl.ntt.co.jp (mfs6.rdh.ecl.ntt.co.jp [129.60.39.149]) by tama50.ecl.ntt.co.jp (8.14.3/8.14.3) with ESMTP id o199teWI001365; Tue, 9 Feb 2010 18:55:40 +0900 (JST) Received: from mfs6.rdh.ecl.ntt.co.jp (localhost [127.0.0.1]) by mfs6.rdh.ecl.ntt.co.jp (Postfix) with ESMTP id F14B15E64; Tue, 9 Feb 2010 18:55:39 +0900 (JST) Received: from dmailsv1.y.ecl.ntt.co.jp (dmailsv1.y.ecl.ntt.co.jp [129.60.53.14]) by mfs6.rdh.ecl.ntt.co.jp (Postfix) with ESMTP id E6DD85C66; Tue, 9 Feb 2010 18:55:39 +0900 (JST) Received: from mailsv02.y.ecl.ntt.co.jp by dmailsv1.y.ecl.ntt.co.jp (8.14.3/dmailsv1-2.1) with ESMTP id o199tdVe023480; Tue, 9 Feb 2010 18:55:39 +0900 (JST) Received: from localhost by mailsv02.y.ecl.ntt.co.jp (8.14.3/Lab-1.7) with ESMTP id o199tdQ3011384; Tue, 9 Feb 2010 18:55:39 +0900 (JST) Message-ID: <4B71311C.8090108@lab.ntt.co.jp> Date: Tue, 09 Feb 2010 18:55:40 +0900 From: OHMURA Kei User-Agent: Thunderbird 2.0.0.23 (Windows/20090812) MIME-Version: 1.0 To: Jan Kiszka , "avi@redhat.com" CC: "kvm@vger.kernel.org" , "qemu-devel@nongnu.org" , mtosatti@redhat.com, ohmura.kei@lab.ntt.co.jp Subject: Re: [PATCH] qemu-kvm: Speed up of the dirty-bitmap-traveling References: <4B6BF06D.1090909@lab.ntt.co.jp> <4B6C0958.50704@siemens.com> <4B6FABCE.207@lab.ntt.co.jp> <4B6FF439.6030006@lab.ntt.co.jp> <4B6FF934.6010100@siemens.com> In-Reply-To: <4B6FF934.6010100@siemens.com> Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org X-Greylist: IP, sender and recipient auto-whitelisted, not delayed by milter-greylist-4.2.3 (demeter.kernel.org [140.211.167.41]); Tue, 09 Feb 2010 09:56:08 +0000 (UTC) diff --git a/kvm-all.c b/kvm-all.c index 6c0fd37..603307c 100644 --- a/kvm-all.c +++ b/kvm-all.c @@ -287,9 +287,43 @@ int kvm_set_migration_log(int enable) return 0; } -static int test_le_bit(unsigned long nr, unsigned char *addr) +/* get kvm's dirty pages bitmap and update qemu's */ +static int kvm_get_dirty_pages_log_range(unsigned long start_addr, + unsigned char *bitmap, + unsigned long offset, + unsigned long mem_size) { - return (addr[nr >> 3] >> (nr & 7)) & 1; + unsigned int i, j, k, start, end; + unsigned char c; + unsigned long page_number, addr, addr1; + ram_addr_t ram_addr; + unsigned int len = ((mem_size / TARGET_PAGE_SIZE) + TARGET_LONG_BITS - 1) / + TARGET_LONG_BITS; + unsigned long *bitmap_ul = (unsigned long *)bitmap; + + /* + * bitmap-traveling is faster than memory-traveling (for addr...) + * especially when most of the memory is not dirty. + */ + for (i = 0; i < len; i++) { + if (bitmap_ul[i] != 0) { + start = i * TARGET_LONG_SIZE; + end = (i + 1) * TARGET_LONG_SIZE; + for (j = start; j < end; j++) { + c = bitmap[j]; + while (c > 0) { + k = ffsl(c) - 1; + c &= ~(1u << k); + page_number = j * 8 + k; + addr1 = page_number * TARGET_PAGE_SIZE; + addr = offset + addr1; + ram_addr = cpu_get_physical_page_desc(addr); + cpu_physical_memory_set_dirty(ram_addr); + } + } + } + } + return 0; } /** @@ -305,8 +339,6 @@ int kvm_physical_sync_dirty_bitmap(target_phys_addr_t start_addr, { KVMState *s = kvm_state; unsigned long size, allocated_size = 0; - target_phys_addr_t phys_addr; - ram_addr_t addr; KVMDirtyLog d; KVMSlot *mem; int ret = 0; @@ -335,17 +367,9 @@ int kvm_physical_sync_dirty_bitmap(target_phys_addr_t start_addr, break; } - for (phys_addr = mem->start_addr, addr = mem->phys_offset; - phys_addr < mem->start_addr + mem->memory_size; - phys_addr += TARGET_PAGE_SIZE, addr += TARGET_PAGE_SIZE) { - unsigned char *bitmap = (unsigned char *)d.dirty_bitmap; - unsigned nr = (phys_addr - mem->start_addr) >> TARGET_PAGE_BITS; - - if (test_le_bit(nr, bitmap)) { - cpu_physical_memory_set_dirty(addr); - } - } - start_addr = phys_addr; + kvm_get_dirty_pages_log_range(mem->start_addr, d.dirty_bitmap, + mem->start_addr, mem->memory_size); + start_addr = mem->start_addr + mem->memory_size; } qemu_free(d.dirty_bitmap);