diff mbox

[RFC,v3,6/8] exec: add qemu_ram_unmap_hva() API for unmapping memory from HVA area

Message ID 1436348808-223033-7-git-send-email-imammedo@redhat.com
State New
Headers show

Commit Message

Igor Mammedov July 8, 2015, 9:46 a.m. UTC
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 <imammedo@redhat.com>
---
 exec.c                    | 11 +++++++++++
 include/exec/cpu-common.h |  1 +
 2 files changed, 12 insertions(+)
diff mbox

Patch

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);