>From b6afd850a8edec1da7eafcbb4705ec752ad6021b Mon Sep 17 00:00:00 2001 From: Laszlo Ersek Date: Thu, 21 Apr 2016 22:50:40 +0200 Subject: [PATCH 1/3] util/mmap-alloc: take alignment in qemu_ram_munmap() This parameter will become necessary later in the series. At this point, it is not used for anything. The alignment passed to qemu_ram_munmap() must be identical to the alignment that was used earlier for allocating the area (with qemu_ram_mmap()) that is now being released. There are two callers: - qemu_anon_ram_free(): its peer is qemu_anon_ram_alloc(), which uses QEMU_VMALLOC_ALIGN as alignment, - reclaim_ramblock(), via qemu_ram_free() -> call_rcu(), when (block->fd>=0): in this case its peer is file_ram_alloc(), which uses qemu_fd_getpagesize() as alignment. Signed-off-by: Laszlo Ersek --- include/qemu/mmap-alloc.h | 2 +- exec.c | 3 ++- util/mmap-alloc.c | 2 +- util/oslib-posix.c | 2 +- 4 files changed, 5 insertions(+), 4 deletions(-) diff --git a/include/qemu/mmap-alloc.h b/include/qemu/mmap-alloc.h index 0899b2f01e97..47ce60e6623c 100644 --- a/include/qemu/mmap-alloc.h +++ b/include/qemu/mmap-alloc.h @@ -7,6 +7,6 @@ size_t qemu_fd_getpagesize(int fd); void *qemu_ram_mmap(int fd, size_t size, size_t align, bool shared); -void qemu_ram_munmap(void *ptr, size_t size); +void qemu_ram_munmap(void *ptr, size_t size, size_t align); #endif diff --git a/exec.c b/exec.c index c4f9036184d8..d043cc4e496e 100644 --- a/exec.c +++ b/exec.c @@ -1762,7 +1762,8 @@ static void reclaim_ramblock(RAMBlock *block) xen_invalidate_map_cache_entry(block->host); #ifndef _WIN32 } else if (block->fd >= 0) { - qemu_ram_munmap(block->host, block->max_length); + qemu_ram_munmap(block->host, block->max_length, + qemu_fd_getpagesize(block->fd)); close(block->fd); #endif } else { diff --git a/util/mmap-alloc.c b/util/mmap-alloc.c index 0b4cc7f7f117..63bb1e215c6e 100644 --- a/util/mmap-alloc.c +++ b/util/mmap-alloc.c @@ -101,7 +101,7 @@ void *qemu_ram_mmap(int fd, size_t size, size_t align, bool shared) return ptr; } -void qemu_ram_munmap(void *ptr, size_t size) +void qemu_ram_munmap(void *ptr, size_t size, size_t align) { if (ptr) { /* Unmap both the RAM block and the guard page */ diff --git a/util/oslib-posix.c b/util/oslib-posix.c index 20ca141dec11..c1a196d71f02 100644 --- a/util/oslib-posix.c +++ b/util/oslib-posix.c @@ -142,7 +142,7 @@ void qemu_vfree(void *ptr) void qemu_anon_ram_free(void *ptr, size_t size) { trace_qemu_anon_ram_free(ptr, size); - qemu_ram_munmap(ptr, size); + qemu_ram_munmap(ptr, size, QEMU_VMALLOC_ALIGN); } void qemu_set_block(int fd) -- 1.8.3.1