From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([140.186.70.92]:46557) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1R25uA-0005o7-F9 for qemu-devel@nongnu.org; Fri, 09 Sep 2011 14:34:23 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1R25u9-0002rc-HS for qemu-devel@nongnu.org; Fri, 09 Sep 2011 14:34:22 -0400 Received: from mail-gy0-f173.google.com ([209.85.160.173]:34994) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1R25u9-0002rV-Ep for qemu-devel@nongnu.org; Fri, 09 Sep 2011 14:34:21 -0400 Received: by gye5 with SMTP id 5so2169528gye.4 for ; Fri, 09 Sep 2011 11:34:20 -0700 (PDT) Message-ID: <4E6A5C2A.8060601@codemonkey.ws> Date: Fri, 09 Sep 2011 13:34:18 -0500 From: Anthony Liguori MIME-Version: 1.0 References: <1315210025-17727-1-git-send-email-avi@redhat.com> In-Reply-To: <1315210025-17727-1-git-send-email-avi@redhat.com> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Subject: Re: [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: Avi Kivity Cc: qemu-devel@nongnu.org On 09/05/2011 03:07 AM, Avi Kivity wrote: > 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 Applied. Thanks. Regards, Anthony Liguori > --- > 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; > }