From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1NpkgO-0003Yp-Qe for qemu-devel@nongnu.org; Thu, 11 Mar 2010 10:52:20 -0500 Received: from [199.232.76.173] (port=38608 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1NpkgO-0003YJ-F2 for qemu-devel@nongnu.org; Thu, 11 Mar 2010 10:52:20 -0500 Received: from Debian-exim by monty-python.gnu.org with spam-scanned (Exim 4.60) (envelope-from ) id 1NpkgN-000630-Kw for qemu-devel@nongnu.org; Thu, 11 Mar 2010 10:52:20 -0500 Received: from mx1.redhat.com ([209.132.183.28]:5622) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1NpkgN-00062w-8x for qemu-devel@nongnu.org; Thu, 11 Mar 2010 10:52:19 -0500 Received: from int-mx04.intmail.prod.int.phx2.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.17]) by mx1.redhat.com (8.13.8/8.13.8) with ESMTP id o2BFqIu6029658 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Thu, 11 Mar 2010 10:52:18 -0500 Received: from cleopatra.tlv.redhat.com (cleopatra.tlv.redhat.com [10.35.255.11]) by int-mx04.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id o2BFqHhr031554 for ; Thu, 11 Mar 2010 10:52:18 -0500 Message-ID: <4B9911B0.5000302@redhat.com> Date: Thu, 11 Mar 2010 17:52:16 +0200 From: Avi Kivity MIME-Version: 1.0 Subject: Re: [Qemu-devel] [PATCH QEMU] transparent hugepage support References: <20100311151427.GE5677@random.random> In-Reply-To: <20100311151427.GE5677@random.random> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Andrea Arcangeli Cc: qemu-devel@nongnu.org On 03/11/2010 05:14 PM, Andrea Arcangeli wrote: > From: Andrea Arcangeli > > This will allow proper alignment so NPT/EPT can take advantage of linux host > backing the guest memory with hugepages (only relevant for KVM and not for QEMU > that has no NPT/EPT support). To complete it, it will also notify > the kernel that this memory is important to be backed by hugepages with > madvise (needed for both KVM and QEMU). > > Signed-off-by: Andrea Arcangeli > --- > > diff --git a/exec.c b/exec.c > index 891e0ee..aedd133 100644 > --- a/exec.c > +++ b/exec.c > @@ -2628,11 +2628,25 @@ ram_addr_t qemu_ram_alloc(ram_addr_t size) > PROT_EXEC|PROT_READ|PROT_WRITE, > MAP_SHARED | MAP_ANONYMOUS, -1, 0); > #else > - new_block->host = qemu_vmalloc(size); > -#endif > +#if defined(__linux__)&& defined(TARGET_HPAGE_BITS) > + if (!kvm_enabled()) > +#endif > + new_block->host = qemu_vmalloc(size); > +#if defined(__linux__)&& defined(TARGET_HPAGE_BITS) > + else > + /* > + * Align on HPAGE_SIZE so "(gfn ^ pfn)& > + * (HPAGE_SIZE-1) == 0" to allow KVM to take advantage > + * of hugepages with NPT/EPT. > + */ > + new_block->host = qemu_memalign(1<< TARGET_HPAGE_BITS, size); > That is a little wasteful. How about a hint to mmap() requesting proper alignment (MAP_HPAGE_ALIGN)? Failing that, modify qemu_memalign() to trim excess memory. Come to think of it, posix_memalign() needs to do that (but doesn't). > +#endif > #ifdef MADV_MERGEABLE > madvise(new_block->host, size, MADV_MERGEABLE); > #endif > +#ifdef MADV_HUGEPAGE > + madvise(new_block->host, size, MADV_HUGEPAGE); > +#endif > } -- error compiling committee.c: too many arguments to function