On Mon, 9 Jun 2014 18:25:25 +0800 Hu Tao <hu...@cn.fujitsu.com> wrote:
> From: Paolo Bonzini <pbonz...@redhat.com> > > 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 <pbonz...@redhat.com> > Signed-off-by: Hu Tao <hu...@cn.fujitsu.com> > --- > 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