From patchwork Mon May 24 03:59:50 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Cam Macdonell X-Patchwork-Id: 53365 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [199.232.76.165]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 906F8B7D20 for ; Mon, 24 May 2010 14:01:10 +1000 (EST) Received: from localhost ([127.0.0.1]:36715 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1OGOqg-0004Y7-J5 for incoming@patchwork.ozlabs.org; Mon, 24 May 2010 00:01:06 -0400 Received: from [140.186.70.92] (port=47739 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1OGOpr-0004Xq-GE for qemu-devel@nongnu.org; Mon, 24 May 2010 00:00:16 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.69) (envelope-from ) id 1OGOpp-0004SS-D7 for qemu-devel@nongnu.org; Mon, 24 May 2010 00:00:15 -0400 Received: from fleet.cs.ualberta.ca ([129.128.22.22]:49647) by eggs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1OGOpp-0004PB-5Z for qemu-devel@nongnu.org; Mon, 24 May 2010 00:00:13 -0400 Received: from localhost.localdomain (st-brides.cs.ualberta.ca [129.128.23.21]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by smtp-auth.cs.ualberta.ca (Postfix) with ESMTP id D7CDF28067; Sun, 23 May 2010 22:00:00 -0600 (MDT) From: Cam Macdonell To: kvm@vger.kernel.org Date: Sun, 23 May 2010 21:59:50 -0600 Message-Id: <1274673590-32288-2-git-send-email-cam@cs.ualberta.ca> X-Mailer: git-send-email 1.6.3.2.198.g6096d In-Reply-To: <1274673590-32288-1-git-send-email-cam@cs.ualberta.ca> References: <1274673590-32288-1-git-send-email-cam@cs.ualberta.ca> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6, seldom 2.4 (older, 4) Cc: Cam Macdonell , qemu-devel@nongnu.org Subject: [Qemu-devel] [PATCH RFC 2/2] Add support for marking memory to not be migrated X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Non-migrated memory is useful for devices that do not want to take memory region data with them on migration. As suggested by Avi, an alternative approach could add a "flags" parameter to cpu_register_physical_memory() rather than explicityly call cpu_mark_pages_no_migrate(). However, having a separate function doesn't require changes to existing call sites. Cam --- arch_init.c | 29 +++++++++++++++++------------ cpu-all.h | 2 ++ cpu-common.h | 2 ++ exec.c | 12 ++++++++++++ 4 files changed, 33 insertions(+), 12 deletions(-) diff --git a/arch_init.c b/arch_init.c index cfc03ea..c2fcad3 100644 --- a/arch_init.c +++ b/arch_init.c @@ -118,18 +118,22 @@ static int ram_save_block(QEMUFile *f) current_addr + TARGET_PAGE_SIZE, MIGRATION_DIRTY_FLAG); - p = qemu_get_ram_ptr(current_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 (!cpu_physical_memory_get_dirty(current_addr, + NO_MIGRATION_FLAG)) { + p = qemu_get_ram_ptr(current_addr); + printf("migrating: %ld\n", (long)current_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); + } - found = 1; - break; + found = 1; + break; + } } addr += TARGET_PAGE_SIZE; current_addr = (saved_addr + addr) % last_ram_offset; @@ -146,7 +150,8 @@ static ram_addr_t ram_save_remaining(void) ram_addr_t count = 0; for (addr = 0; addr < last_ram_offset; addr += TARGET_PAGE_SIZE) { - if (cpu_physical_memory_get_dirty(addr, MIGRATION_DIRTY_FLAG)) { + if (!cpu_physical_memory_get_dirty(addr, NO_MIGRATION_FLAG) && + cpu_physical_memory_get_dirty(addr, MIGRATION_DIRTY_FLAG)) { count++; } } diff --git a/cpu-all.h b/cpu-all.h index a4bb4fb..8e2e8c4 100644 --- a/cpu-all.h +++ b/cpu-all.h @@ -885,6 +885,8 @@ extern int mem_prealloc; #define CODE_DIRTY_FLAG 0x02 #define MIGRATION_DIRTY_FLAG 0x08 +#define NO_MIGRATION_FLAG 0x10 + #define DIRTY_ALL_FLAG (VGA_DIRTY_FLAG | CODE_DIRTY_FLAG | MIGRATION_DIRTY_FLAG) /* read dirty bit (return 0 or 1) */ diff --git a/cpu-common.h b/cpu-common.h index 4b0ba60..a1ebbbe 100644 --- a/cpu-common.h +++ b/cpu-common.h @@ -39,6 +39,8 @@ static inline void cpu_register_physical_memory(target_phys_addr_t start_addr, cpu_register_physical_memory_offset(start_addr, size, phys_offset, 0); } +void cpu_mark_pages_no_migrate(ram_addr_t start, uint64_t size); + ram_addr_t cpu_get_physical_page_desc(target_phys_addr_t addr); ram_addr_t qemu_ram_map(ram_addr_t size, void *host); ram_addr_t qemu_ram_alloc(ram_addr_t); diff --git a/exec.c b/exec.c index 07dc8b6..8c8053f 100644 --- a/exec.c +++ b/exec.c @@ -2781,6 +2781,18 @@ static void *file_ram_alloc(ram_addr_t memory, const char *path) } #endif +void cpu_mark_pages_no_migrate(ram_addr_t start, uint64_t length) +{ + int i, len; + uint8_t *p; + + len = length >> TARGET_PAGE_BITS; + p = phys_ram_flags + (start >> TARGET_PAGE_BITS); + for (i = 0; i < len; i++) { + p[i] |= NO_MIGRATION_FLAG; + } +} + ram_addr_t qemu_ram_map(ram_addr_t size, void *host) { RAMBlock *new_block;