From patchwork Thu Mar 25 06:08:29 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Cam Macdonell X-Patchwork-Id: 88157 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 o2P6CFAI008013 for ; Thu, 25 Mar 2010 06:12:15 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752725Ab0CYGMF (ORCPT ); Thu, 25 Mar 2010 02:12:05 -0400 Received: from fleet.cs.ualberta.ca ([129.128.22.22]:54437 "EHLO fleet.cs.ualberta.ca" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752741Ab0CYGME (ORCPT ); Thu, 25 Mar 2010 02:12:04 -0400 Received: from localhost.localdomain (botha10.cs.ualberta.ca [129.128.22.140]) (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 420F32801E; Thu, 25 Mar 2010 00:12:01 -0600 (MDT) From: Cam Macdonell To: kvm@vger.kernel.org Cc: qemu-devel@nongnu.org, Cam Macdonell Subject: [PATCH v3 1/2] Support adding a file to qemu's ram allocation Date: Thu, 25 Mar 2010 00:08:29 -0600 Message-Id: <1269497310-21858-2-git-send-email-cam@cs.ualberta.ca> X-Mailer: git-send-email 1.6.6.1 In-Reply-To: <1269497310-21858-1-git-send-email-cam@cs.ualberta.ca> References: <1269497310-21858-1-git-send-email-cam@cs.ualberta.ca> 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]); Thu, 25 Mar 2010 06:12:15 +0000 (UTC) diff --git a/cpu-common.h b/cpu-common.h index 6cae15b..dffe4e7 100644 --- a/cpu-common.h +++ b/cpu-common.h @@ -32,6 +32,7 @@ static inline void cpu_register_physical_memory(target_phys_addr_t start_addr, } ram_addr_t cpu_get_physical_page_desc(target_phys_addr_t addr); +ram_addr_t qemu_ram_mmap(int, ram_addr_t, int, int); ram_addr_t qemu_ram_alloc(ram_addr_t); void qemu_ram_free(ram_addr_t addr); /* This should only be used for ram local to a device. */ diff --git a/exec.c b/exec.c index 3b4426e..6f4e747 100644 --- a/exec.c +++ b/exec.c @@ -2727,6 +2727,39 @@ static void *file_ram_alloc(ram_addr_t memory, const char *path) } #endif +ram_addr_t qemu_ram_mmap(int fd, ram_addr_t size, int flags, int offset) +{ + RAMBlock *new_block; + + size = TARGET_PAGE_ALIGN(size); + new_block = qemu_malloc(sizeof(*new_block)); + + // map the file passed as a parameter to be this part of memory + new_block->host = mmap(0, size, PROT_READ|PROT_WRITE, flags, fd, offset); + +#ifdef MADV_MERGEABLE + madvise(new_block->host, size, MADV_MERGEABLE); +#endif + + new_block->offset = last_ram_offset; + new_block->length = size; + + new_block->next = ram_blocks; + ram_blocks = new_block; + + phys_ram_dirty = qemu_realloc(phys_ram_dirty, + (last_ram_offset + size) >> TARGET_PAGE_BITS); + memset(phys_ram_dirty + (last_ram_offset >> TARGET_PAGE_BITS), + 0xff, size >> TARGET_PAGE_BITS); + + last_ram_offset += size; + + if (kvm_enabled()) + kvm_setup_guest_memory(new_block->host, size); + + return new_block->offset; +} + ram_addr_t qemu_ram_alloc(ram_addr_t size) { RAMBlock *new_block;