|
|
cd9d16 |
From d12ac10d3ce10d3e1c9b23aeca397caa74be49d3 Mon Sep 17 00:00:00 2001
|
|
|
cd9d16 |
From: Avi Kivity <avi@redhat.com>
|
|
|
cd9d16 |
Date: Mon, 5 Sep 2011 11:07:05 +0300
|
|
|
cd9d16 |
Subject: [PATCH] qemu_vmalloc: align properly for transparent hugepages and
|
|
|
cd9d16 |
KVM
|
|
|
cd9d16 |
MIME-Version: 1.0
|
|
|
cd9d16 |
Content-Type: text/plain; charset=UTF-8
|
|
|
cd9d16 |
Content-Transfer-Encoding: 8bit
|
|
|
cd9d16 |
|
|
|
cd9d16 |
To make good use of transparent hugepages, KVM requires that guest-physical
|
|
|
cd9d16 |
and host-virtual addresses share the low 21 bits (as opposed to just the low
|
|
|
cd9d16 |
12 bits normally required).
|
|
|
cd9d16 |
|
|
|
cd9d16 |
Adjust qemu_vmalloc() to honor that requirement. Ignore it for small regions
|
|
|
cd9d16 |
to avoid fragmentation.
|
|
|
cd9d16 |
|
|
|
cd9d16 |
Signed-off-by: Avi Kivity <avi@redhat.com>
|
|
|
cd9d16 |
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
|
|
|
cd9d16 |
(cherry picked from commit 36b586284e678da28df3af9fd0907d2b16f9311c)
|
|
|
cd9d16 |
|
|
|
cd9d16 |
Signed-off-by: Bruce Rogers <brogers@suse.com>
|
|
|
cd9d16 |
Signed-off-by: Andreas Färber <afaerber@suse.de>
|
|
|
cd9d16 |
---
|
|
|
cd9d16 |
oslib-posix.c | 14 +++++++++++++-
|
|
|
cd9d16 |
1 file changed, 13 insertions(+), 1 deletion(-)
|
|
|
cd9d16 |
|
|
|
cd9d16 |
diff --git a/oslib-posix.c b/oslib-posix.c
|
|
|
cd9d16 |
index 196099c..a304fb0 100644
|
|
|
cd9d16 |
--- a/oslib-posix.c
|
|
|
cd9d16 |
+++ b/oslib-posix.c
|
|
|
cd9d16 |
@@ -35,6 +35,13 @@
|
|
|
cd9d16 |
extern int daemon(int, int);
|
|
|
cd9d16 |
#endif
|
|
|
cd9d16 |
|
|
|
cd9d16 |
+#if defined(__linux__) && defined(__x86_64__)
|
|
|
cd9d16 |
+ /* Use 2MB alignment so transparent hugepages can be used by KVM */
|
|
|
cd9d16 |
+# define QEMU_VMALLOC_ALIGN (512 * 4096)
|
|
|
cd9d16 |
+#else
|
|
|
cd9d16 |
+# define QEMU_VMALLOC_ALIGN getpagesize()
|
|
|
cd9d16 |
+#endif
|
|
|
cd9d16 |
+
|
|
|
cd9d16 |
#include "config-host.h"
|
|
|
cd9d16 |
#include "sysemu.h"
|
|
|
cd9d16 |
#include "trace.h"
|
|
|
cd9d16 |
@@ -80,7 +87,12 @@ void *qemu_memalign(size_t alignment, size_t size)
|
|
|
cd9d16 |
void *qemu_vmalloc(size_t size)
|
|
|
cd9d16 |
{
|
|
|
cd9d16 |
void *ptr;
|
|
|
cd9d16 |
- ptr = qemu_memalign(getpagesize(), size);
|
|
|
cd9d16 |
+ size_t align = QEMU_VMALLOC_ALIGN;
|
|
|
cd9d16 |
+
|
|
|
cd9d16 |
+ if (size < align) {
|
|
|
cd9d16 |
+ align = getpagesize();
|
|
|
cd9d16 |
+ }
|
|
|
cd9d16 |
+ ptr = qemu_memalign(align, size);
|
|
|
cd9d16 |
trace_qemu_vmalloc(size, ptr);
|
|
|
cd9d16 |
return ptr;
|
|
|
cd9d16 |
}
|
|
|
cd9d16 |
--
|
|
|
cd9d16 |
1.7.11.2
|
|
|
cd9d16 |
|