it will allow to return atomically return RAMBlock's host address range into continuos HVA area so that no hole would appear in there.
also mark RAMBlock with RAM_PREALLOC flag so it won't be umapped as conventional memory by reclaim_ramblock()->qemu_anon_ram_free() Signed-off-by: Igor Mammedov <imamm...@redhat.com> --- exec.c | 11 +++++++++++ include/exec/cpu-common.h | 1 + 2 files changed, 12 insertions(+) diff --git a/exec.c b/exec.c index ebbcfe9..ec8f234 100644 --- a/exec.c +++ b/exec.c @@ -1346,11 +1346,22 @@ void *qemu_ram_reserve_hva(ram_addr_t length) MAP_NORESERVE | MAP_ANONYMOUS | MAP_PRIVATE, -1, 0); } +void qemu_ram_unmap_hva(ram_addr_t addr) +{ + RAMBlock *block = find_ram_block(addr); + + assert(block); + mmap(block->host, block->used_length, PROT_NONE, + MAP_FIXED | MAP_NORESERVE | MAP_ANONYMOUS | MAP_PRIVATE, -1, 0); +} + void qemu_ram_remap_hva(ram_addr_t addr, void *new_hva) { RAMBlock *block = find_ram_block(addr); assert(block); + assert(!(block->flags & RAM_PREALLOC)); + block->flags |= RAM_PREALLOC; block->host = mremap(block->host, block->used_length, block->used_length, MREMAP_MAYMOVE | MREMAP_FIXED, new_hva); diff --git a/include/exec/cpu-common.h b/include/exec/cpu-common.h index 301f50b..4da5cd7 100644 --- a/include/exec/cpu-common.h +++ b/include/exec/cpu-common.h @@ -64,6 +64,7 @@ typedef uint32_t CPUReadMemoryFunc(void *opaque, hwaddr addr); void qemu_ram_remap(ram_addr_t addr, ram_addr_t length); void *qemu_ram_reserve_hva(ram_addr_t length); void qemu_ram_remap_hva(ram_addr_t addr, void *new_hva); +void qemu_ram_unmap_hva(ram_addr_t addr); /* This should not be used by devices. */ MemoryRegion *qemu_ram_addr_from_host(void *ptr, ram_addr_t *ram_addr); void qemu_ram_set_idstr(ram_addr_t addr, const char *name, DeviceState *dev); -- 1.8.3.1