From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:40459) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Wtygn-00080A-FQ for qemu-devel@nongnu.org; Mon, 09 Jun 2014 08:28:42 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Wtygi-0001Jn-SG for qemu-devel@nongnu.org; Mon, 09 Jun 2014 08:28:37 -0400 Received: from mx1.redhat.com ([209.132.183.28]:27657) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Wtygi-0001JZ-Kt for qemu-devel@nongnu.org; Mon, 09 Jun 2014 08:28:32 -0400 Date: Mon, 9 Jun 2014 14:28:23 +0200 From: Igor Mammedov Message-ID: <20140609142823.5a822afa@thinkpad> In-Reply-To: References: MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Subject: Re: [Qemu-devel] [PATCH v4 20/29] hostmem: allow preallocation of any memory region List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Hu Tao Cc: Yasunori Goto , "Michael S. Tsirkin" , qemu-devel@nongnu.org, Eduardo Habkost , Paolo Bonzini On Mon, 9 Jun 2014 18:25:25 +0800 Hu Tao wrote: > From: Paolo Bonzini > > And allow preallocation of file-based memory even without -mem-prealloc. > Some care is necessary because -mem-prealloc does not allow disabling > preallocation for hostmem-file. maybe 'prealloc' property should belong to hostmem-file instead of the abstract hostmem. > > Signed-off-by: Paolo Bonzini > Signed-off-by: Hu Tao > --- > backends/hostmem-file.c | 3 +++ > backends/hostmem.c | 42 ++++++++++++++++++++++++++++++++++++++++++ > exec.c | 7 +++++++ > include/exec/memory.h | 10 ++++++++++ > include/exec/ram_addr.h | 1 + > include/sysemu/hostmem.h | 1 + > memory.c | 11 +++++++++++ > 7 files changed, 75 insertions(+) > [...] > @@ -165,6 +204,9 @@ host_memory_backend_memory_complete(UserCreatable *uc, Error **errp) > if (!backend->dump) { > qemu_madvise(ptr, sz, QEMU_MADV_DONTDUMP); > } > + if (backend->prealloc) { > + os_mem_prealloc(memory_region_get_fd(&backend->mr), ptr, sz); > + } could it be done inside of hostmem_file->alloc()? > } > } > > diff --git a/exec.c b/exec.c > index 739f0cf..520d673 100644 > --- a/exec.c > +++ b/exec.c > @@ -1432,6 +1432,13 @@ void qemu_ram_remap(ram_addr_t addr, ram_addr_t length) > } > #endif /* !_WIN32 */ > > +int qemu_get_ram_fd(ram_addr_t addr) > +{ > + RAMBlock *block = qemu_get_ram_block(addr); > + > + return block->fd; > +} > + > /* Return a host pointer to ram allocated with qemu_ram_alloc. > With the exception of the softmmu code in this file, this should > only be used for local memory (e.g. video ram) that the device owns, > diff --git a/include/exec/memory.h b/include/exec/memory.h > index 82d7781..36226f7 100644 > --- a/include/exec/memory.h > +++ b/include/exec/memory.h > @@ -534,6 +534,16 @@ bool memory_region_is_logging(MemoryRegion *mr); > bool memory_region_is_rom(MemoryRegion *mr); > > /** > + * memory_region_get_fd: Get a file descriptor backing a RAM memory region. > + * > + * Returns a file descriptor backing a file-based RAM memory region, > + * or -1 if the region is not a file-based RAM memory region. > + * > + * @mr: the RAM or alias memory region being queried. > + */ > +int memory_region_get_fd(MemoryRegion *mr); > + > +/** > * memory_region_get_ram_ptr: Get a pointer into a RAM memory region. > * > * Returns a host pointer to a RAM memory region (created with > diff --git a/include/exec/ram_addr.h b/include/exec/ram_addr.h > index f9518a6..d352f60 100644 > --- a/include/exec/ram_addr.h > +++ b/include/exec/ram_addr.h > @@ -27,6 +27,7 @@ ram_addr_t qemu_ram_alloc_from_file(ram_addr_t size, MemoryRegion *mr, > ram_addr_t qemu_ram_alloc_from_ptr(ram_addr_t size, void *host, > MemoryRegion *mr); > ram_addr_t qemu_ram_alloc(ram_addr_t size, MemoryRegion *mr); > +int qemu_get_ram_fd(ram_addr_t addr); > void *qemu_get_ram_ptr(ram_addr_t addr); > void qemu_ram_free(ram_addr_t addr); > void qemu_ram_free_from_ptr(ram_addr_t addr); > diff --git a/include/sysemu/hostmem.h b/include/sysemu/hostmem.h > index ede5ec9..4cae673 100644 > --- a/include/sysemu/hostmem.h > +++ b/include/sysemu/hostmem.h > @@ -53,6 +53,7 @@ struct HostMemoryBackend { > /* protected */ > uint64_t size; > bool merge, dump; > + bool prealloc, force_prealloc; > > MemoryRegion mr; > }; > diff --git a/memory.c b/memory.c > index 310729a..bcef72b 100644 > --- a/memory.c > +++ b/memory.c > @@ -1258,6 +1258,17 @@ void memory_region_reset_dirty(MemoryRegion *mr, hwaddr addr, > cpu_physical_memory_reset_dirty(mr->ram_addr + addr, size, client); > } > > +int memory_region_get_fd(MemoryRegion *mr) > +{ > + if (mr->alias) { > + return memory_region_get_fd(mr->alias); > + } > + > + assert(mr->terminates); > + > + return qemu_get_ram_fd(mr->ram_addr & TARGET_PAGE_MASK); > +} > + > void *memory_region_get_ram_ptr(MemoryRegion *mr) > { > if (mr->alias) { > -- > 1.9.3 > > -- Regards, Igor