From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1NenIJ-00019P-Vi for qemu-devel@nongnu.org; Tue, 09 Feb 2010 05:26:12 -0500 Received: from [199.232.76.173] (port=37941 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1NenIJ-00019G-Lw for qemu-devel@nongnu.org; Tue, 09 Feb 2010 05:26:11 -0500 Received: from Debian-exim by monty-python.gnu.org with spam-scanned (Exim 4.60) (envelope-from ) id 1NenIF-0001Yw-7o for qemu-devel@nongnu.org; Tue, 09 Feb 2010 05:26:11 -0500 Received: from mx1.redhat.com ([209.132.183.28]:22708) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1NenIE-0001Yp-Bi for qemu-devel@nongnu.org; Tue, 09 Feb 2010 05:26:07 -0500 Message-ID: <4B713839.30301@redhat.com> Date: Tue, 09 Feb 2010 12:26:01 +0200 From: Avi Kivity MIME-Version: 1.0 References: <4B6BF06D.1090909@lab.ntt.co.jp> <4B70065B.1010401@redhat.com> <4B7130E9.7060809@lab.ntt.co.jp> In-Reply-To: <4B7130E9.7060809@lab.ntt.co.jp> Content-Type: text/plain; charset=ISO-2022-JP Content-Transfer-Encoding: 7bit Subject: [Qemu-devel] Re: [PATCH] qemu-kvm: Speed up of the dirty-bitmap-traveling List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: OHMURA Kei Cc: mtosatti@redhat.com, qemu-devel@nongnu.org, kvm@vger.kernel.org On 02/09/2010 11:54 AM, OHMURA Kei wrote: > Thank you for your comments. We have implemented the code which applied your > comments. This is patch for qemu-kvm.c. > Please reuse the changelog when reposing a patch, this makes it easier for me to apply it. > @@ -2438,27 +2438,34 @@ static int kvm_get_dirty_pages_log_range(unsigned long start_addr, > unsigned long offset, > unsigned long mem_size) > { > - unsigned int i, j, n = 0; > + 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) + 7) / 8; > + 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++) { > - c = bitmap[i]; > - while (c > 0) { > - j = ffsl(c) - 1; > - c &= ~(1u << j); > - page_number = i * 8 + j; > - addr1 = page_number * TARGET_PAGE_SIZE; > - addr = offset + addr1; > - ram_addr = cpu_get_physical_page_desc(addr); > - cpu_physical_memory_set_dirty(ram_addr); > - n++; > + if (bitmap_ul[i] != 0) { > + start = i * TARGET_LONG_SIZE; > + end = (i + 1) * TARGET_LONG_SIZE; > Should be a host long size, not guest. This will fail when running a 32-bit qemu-system-x86_64 binary. > + 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); > + } > + } > Instead of using a nested loop if bitmap_ul[i] != 0, it is possible to use just a single loop (while (c > 0)), and process a long's worth of data. The only trickery is with big endian hosts, where the conversion from bit number to page number is a bit complicated. If we do this, we can convert the bitmap's type to unsigned long throughout, and avoid the casts. -- error compiling committee.c: too many arguments to function