To make good use of transparent hugepages, KVM requires that guest-physical
and host-virtual addresses share the low 21 bits (as opposed to just the low
12 bits normally required).
Adjust qemu_vmalloc() to honor that requirement. Ignore it for small regions
to avoid fragmentation.
Signed-off-by: Avi Kivity <avi@redhat.com>
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
extern int daemon(int, int);
#endif
+#if defined(__linux__) && defined(__x86_64__)
+ /* Use 2MB alignment so transparent hugepages can be used by KVM */
+# define QEMU_VMALLOC_ALIGN (512 * 4096)
+#else
+# define QEMU_VMALLOC_ALIGN getpagesize()
+#endif
+
#include "config-host.h"
#include "sysemu.h"
#include "trace.h"
void *qemu_vmalloc(size_t size)
{
void *ptr;
- ptr = qemu_memalign(getpagesize(), size);
+ size_t align = QEMU_VMALLOC_ALIGN;
+
+ if (size < align) {
+ align = getpagesize();
+ }
+ ptr = qemu_memalign(align, size);
trace_qemu_vmalloc(size, ptr);
return ptr;
}