From patchwork Mon Feb 8 10:22:32 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: OHMURA Kei X-Patchwork-Id: 77698 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 o18ANgdf020084 for ; Mon, 8 Feb 2010 10:23:42 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754592Ab0BHKXk (ORCPT ); Mon, 8 Feb 2010 05:23:40 -0500 Received: from tama50.ecl.ntt.co.jp ([129.60.39.147]:38689 "EHLO tama50.ecl.ntt.co.jp" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752100Ab0BHKXj (ORCPT ); Mon, 8 Feb 2010 05:23:39 -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 o18ANEks015283; Mon, 8 Feb 2010 19:23:14 +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 AE4F85E64; Mon, 8 Feb 2010 19:23:14 +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 A605C5C66; Mon, 8 Feb 2010 19:23:14 +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 o18ANEBd001714; Mon, 8 Feb 2010 19:23:14 +0900 (JST) Received: from localhost by mailsv02.y.ecl.ntt.co.jp (8.14.3/Lab-1.7) with ESMTP id o18ANDYo000460; Mon, 8 Feb 2010 19:23:13 +0900 (JST) Message-ID: <4B6FE5E8.3070003@lab.ntt.co.jp> Date: Mon, 08 Feb 2010 19:22:32 +0900 From: OHMURA Kei User-Agent: Thunderbird 2.0.0.23 (Windows/20090812) MIME-Version: 1.0 To: kvm@vger.kernel.org, qemu-devel@nongnu.org CC: avi@redhat.com, Jan Kiszka , anthony@codemonkey.ws, ohmura.kei@lab.ntt.co.jp Subject: [PATCH 3/3] qemu-kvm: Change the methods of get dirty pages. 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]); Mon, 08 Feb 2010 10:23:42 +0000 (UTC) diff --git a/vl.c b/vl.c index 4ef6a78..0835da6 100644 --- a/vl.c +++ b/vl.c @@ -2798,7 +2798,7 @@ static int ram_save_block(QEMUFile *f) static ram_addr_t current_addr = 0; ram_addr_t saved_addr = current_addr; ram_addr_t addr = 0; - int found = 0; + int i, found = 0, skip = 0; while (addr < last_ram_offset) { if (kvm_enabled() && current_addr == 0) { @@ -2810,28 +2810,37 @@ static int ram_save_block(QEMUFile *f) return 0; } } - if (cpu_physical_memory_get_dirty(current_addr, MIGRATION_DIRTY_FLAG)) { + if ((found = cpu_physical_memory_get_dirty_range(current_addr, + last_ram_offset, MIGRATION_DIRTY_FLAG))) { uint8_t *p; - cpu_physical_memory_reset_dirty(current_addr, - current_addr + TARGET_PAGE_SIZE, - MIGRATION_DIRTY_FLAG); + for (i = 0; i < found; i++) { + ram_addr_t page_addr = current_addr + (i * TARGET_PAGE_SIZE); + cpu_physical_memory_reset_dirty(page_addr, + page_addr + TARGET_PAGE_SIZE, + MIGRATION_DIRTY_FLAG); - p = qemu_get_ram_ptr(current_addr); + p = qemu_get_ram_ptr(page_addr); - if (is_dup_page(p, *p)) { - qemu_put_be64(f, current_addr | RAM_SAVE_FLAG_COMPRESS); - qemu_put_byte(f, *p); - } else { - qemu_put_be64(f, current_addr | RAM_SAVE_FLAG_PAGE); - qemu_put_buffer(f, p, TARGET_PAGE_SIZE); + if (is_dup_page(p, *p)) { + qemu_put_be64(f, (page_addr) | + RAM_SAVE_FLAG_COMPRESS); + qemu_put_byte(f, *p); + } else { + qemu_put_be64(f, (page_addr) | + RAM_SAVE_FLAG_PAGE); + qemu_put_buffer(f, p, TARGET_PAGE_SIZE); + } } - found = 1; break; } - addr += TARGET_PAGE_SIZE; - current_addr = (saved_addr + addr) % last_ram_offset; + while ((skip = cpu_physical_memory_get_non_dirty_range(current_addr, + last_ram_offset, MIGRATION_DIRTY_FLAG)) != 0) { + addr += TARGET_PAGE_SIZE * skip; + current_addr = (saved_addr + addr) % last_ram_offset; + if (addr >= last_ram_offset) break; + } } return found; @@ -2841,12 +2850,22 @@ static uint64_t bytes_transferred; static ram_addr_t ram_save_remaining(void) { - ram_addr_t addr; + ram_addr_t addr = 0; ram_addr_t count = 0; + int found = 0, skip = 0; - for (addr = 0; addr < last_ram_offset; addr += TARGET_PAGE_SIZE) { - if (cpu_physical_memory_get_dirty(addr, MIGRATION_DIRTY_FLAG)) - count++; + while (addr < last_ram_offset) { + if ((found = cpu_physical_memory_get_dirty_range(addr, + last_ram_offset, MIGRATION_DIRTY_FLAG))) { + count += found; + addr += TARGET_PAGE_SIZE * found; + } else { + while ((skip = cpu_physical_memory_get_non_dirty_range(addr, + last_ram_offset, MIGRATION_DIRTY_FLAG)) != 0) { + addr += TARGET_PAGE_SIZE * skip; + if (addr >= last_ram_offset) break; + } + } } return count;