From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([140.186.70.92]:40253) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1R0UD1-00051s-Na for qemu-devel@nongnu.org; Mon, 05 Sep 2011 04:07:15 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1R0UD0-00050q-BR for qemu-devel@nongnu.org; Mon, 05 Sep 2011 04:07:11 -0400 Received: from mx1.redhat.com ([209.132.183.28]:6289) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1R0UCz-00050i-Tz for qemu-devel@nongnu.org; Mon, 05 Sep 2011 04:07:10 -0400 Received: from int-mx01.intmail.prod.int.phx2.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id p85879GS025748 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Mon, 5 Sep 2011 04:07:09 -0400 Received: from cleopatra.tlv.redhat.com (cleopatra.tlv.redhat.com [10.35.255.11]) by int-mx01.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id p85878e3020680 for ; Mon, 5 Sep 2011 04:07:08 -0400 From: Avi Kivity Date: Mon, 5 Sep 2011 11:07:05 +0300 Message-Id: <1315210025-17727-1-git-send-email-avi@redhat.com> Subject: [Qemu-devel] [PATCH] qemu_vmalloc: align properly for transparent hugepages and KVM List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org 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 --- oslib-posix.c | 14 +++++++++++++- 1 files changed, 13 insertions(+), 1 deletions(-) diff --git a/oslib-posix.c b/oslib-posix.c index 196099c..a304fb0 100644 --- a/oslib-posix.c +++ b/oslib-posix.c @@ -35,6 +35,13 @@ 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" @@ -80,7 +87,12 @@ int qemu_daemon(int nochdir, int noclose) 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; } -- 1.7.6.1