osdep: introduce qemu_anon_ram_free to free qemu_anon_ram_alloc-ed memory

We switched from qemu_memalign to mmap() but then we don't modify
qemu_vfree() to do a munmap() over free().  Which we cannot do
because qemu_vfree() frees memory allocated by qemu_{mem,block}align.

Introduce a new function that does the munmap(), luckily the size is
available in the RAMBlock.

Reported-by: Amos Kong <akong@redhat.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
Reviewed-by: Amos Kong <akong@redhat.com>
Message-id: 1368454796-14989-3-git-send-email-pbonzini@redhat.com
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
This commit is contained in:
Paolo Bonzini 2013-05-13 16:19:56 +02:00 committed by Anthony Liguori
parent 6eebf958ab
commit e7a09b92b7
5 changed files with 20 additions and 6 deletions

8
exec.c
View File

@ -1156,21 +1156,17 @@ void qemu_ram_free(ram_addr_t addr)
munmap(block->host, block->length); munmap(block->host, block->length);
close(block->fd); close(block->fd);
} else { } else {
qemu_vfree(block->host); qemu_anon_ram_free(block->host, block->length);
} }
#else #else
abort(); abort();
#endif #endif
} else { } else {
#if defined(TARGET_S390X) && defined(CONFIG_KVM)
munmap(block->host, block->length);
#else
if (xen_enabled()) { if (xen_enabled()) {
xen_invalidate_map_cache_entry(block->host); xen_invalidate_map_cache_entry(block->host);
} else { } else {
qemu_vfree(block->host); qemu_anon_ram_free(block->host, block->length);
} }
#endif
} }
g_free(block); g_free(block);
break; break;

View File

@ -98,6 +98,7 @@ int qemu_daemon(int nochdir, int noclose);
void *qemu_memalign(size_t alignment, size_t size); void *qemu_memalign(size_t alignment, size_t size);
void *qemu_anon_ram_alloc(size_t size); void *qemu_anon_ram_alloc(size_t size);
void qemu_vfree(void *ptr); void qemu_vfree(void *ptr);
void qemu_anon_ram_free(void *ptr, size_t size);
#define QEMU_MADV_INVALID -1 #define QEMU_MADV_INVALID -1

View File

@ -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_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_anon_ram_alloc(size_t size, void *ptr) "size %zu ptr %p"
qemu_vfree(void *ptr) "ptr %p" qemu_vfree(void *ptr) "ptr %p"
qemu_anon_ram_free(void *ptr, size_t size) "size %zu ptr %p"
# hw/virtio.c # hw/virtio.c
virtqueue_fill(void *vq, const void *elem, unsigned int len, unsigned int idx) "vq %p elem %p len %u idx %u" virtqueue_fill(void *vq, const void *elem, unsigned int len, unsigned int idx) "vq %p elem %p len %u idx %u"

View File

@ -135,6 +135,14 @@ void qemu_vfree(void *ptr)
free(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) void qemu_set_block(int fd)
{ {
int f; int f;

View File

@ -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 */ /* FIXME: add proper locking */
struct tm *gmtime_r(const time_t *timep, struct tm *result) struct tm *gmtime_r(const time_t *timep, struct tm *result)
{ {