diff --git a/exec.c b/exec.c index 49344577ea54e4d274fda16cb7dfdc805bdc2e00..aec65c506372a70f6ec3e3c18e147ab8e9b73d52 100644 --- a/exec.c +++ b/exec.c @@ -1156,21 +1156,17 @@ void qemu_ram_free(ram_addr_t addr) munmap(block->host, block->length); close(block->fd); } else { - qemu_vfree(block->host); + qemu_anon_ram_free(block->host, block->length); } #else abort(); #endif } else { -#if defined(TARGET_S390X) && defined(CONFIG_KVM) - munmap(block->host, block->length); -#else if (xen_enabled()) { xen_invalidate_map_cache_entry(block->host); } else { - qemu_vfree(block->host); + qemu_anon_ram_free(block->host, block->length); } -#endif } g_free(block); break; diff --git a/include/qemu/osdep.h b/include/qemu/osdep.h index 06c358846e77e2d538461a612f59360e3ac5e2c7..57d7b1fb4d028d4073391e3c49c14e3721cfbdfe 100644 --- a/include/qemu/osdep.h +++ b/include/qemu/osdep.h @@ -98,6 +98,7 @@ int qemu_daemon(int nochdir, int noclose); void *qemu_memalign(size_t alignment, size_t size); void *qemu_anon_ram_alloc(size_t size); void qemu_vfree(void *ptr); +void qemu_anon_ram_free(void *ptr, size_t size); #define QEMU_MADV_INVALID -1 diff --git a/trace-events b/trace-events index f1a8c3a2a14497a9eca571472bbc9a506f1f80b7..c03b9cb2cd2b6dbb8d47f22a7d09b68b19d3f997 100644 --- a/trace-events +++ b/trace-events @@ -34,6 +34,7 @@ g_free(void *ptr) "ptr %p" qemu_memalign(size_t alignment, size_t size, void *ptr) "alignment %zu size %zu ptr %p" qemu_anon_ram_alloc(size_t size, void *ptr) "size %zu ptr %p" qemu_vfree(void *ptr) "ptr %p" +qemu_anon_ram_free(void *ptr, size_t size) "size %zu ptr %p" # hw/virtio.c virtqueue_fill(void *vq, const void *elem, unsigned int len, unsigned int idx) "vq %p elem %p len %u idx %u" diff --git a/util/oslib-posix.c b/util/oslib-posix.c index 6acbbef971e540164fe9b21cb19c0ba861375fc1..631a1dea333a811fc3533c75560d8cd3a29cda56 100644 --- a/util/oslib-posix.c +++ b/util/oslib-posix.c @@ -135,6 +135,14 @@ void qemu_vfree(void *ptr) free(ptr); } +void qemu_anon_ram_free(void *ptr, size_t size) +{ + trace_qemu_anon_ram_free(ptr, size); + if (ptr) { + munmap(ptr, size); + } +} + void qemu_set_block(int fd) { int f; diff --git a/util/oslib-win32.c b/util/oslib-win32.c index 5b1fc20cc630d85e60dc12fce41022a034e6a537..df2ecbdffb6c33b07b882eb35735b4bbb7fbdfb2 100644 --- a/util/oslib-win32.c +++ b/util/oslib-win32.c @@ -76,6 +76,14 @@ void qemu_vfree(void *ptr) } } +void qemu_anon_ram_free(void *ptr, size_t size) +{ + trace_qemu_anon_ram_free(ptr, size); + if (ptr) { + VirtualFree(ptr, 0, MEM_RELEASE); + } +} + /* FIXME: add proper locking */ struct tm *gmtime_r(const time_t *timep, struct tm *result) {