From patchwork Wed Aug 15 12:40:22 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Tokarev X-Patchwork-Id: 177641 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 923752C00A0 for ; Wed, 15 Aug 2012 22:40:34 +1000 (EST) Received: from localhost ([::1]:52534 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1T1ctk-0003tI-Ns for incoming@patchwork.ozlabs.org; Wed, 15 Aug 2012 08:40:32 -0400 Received: from eggs.gnu.org ([208.118.235.92]:37763) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1T1cte-0003tD-LP for qemu-devel@nongnu.org; Wed, 15 Aug 2012 08:40:27 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1T1ctd-0003Rc-DO for qemu-devel@nongnu.org; Wed, 15 Aug 2012 08:40:26 -0400 Received: from isrv.corpit.ru ([86.62.121.231]:52541) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1T1ctd-0003RY-6D for qemu-devel@nongnu.org; Wed, 15 Aug 2012 08:40:25 -0400 Received: from [192.168.88.2] (mjt.vpn.tls.msk.ru [192.168.177.99]) by isrv.corpit.ru (Postfix) with ESMTP id B81FCA0F48; Wed, 15 Aug 2012 16:40:23 +0400 (MSK) Message-ID: <502B98B6.60904@msgid.tls.msk.ru> Date: Wed, 15 Aug 2012 16:40:22 +0400 From: Michael Tokarev Organization: Telecom Service, JSC User-Agent: Mozilla/5.0 (X11; Linux i686 on x86_64; rv:10.0.5) Gecko/20120624 Icedove/10.0.5 MIME-Version: 1.0 To: Andrea Arcangeli X-Enigmail-Version: 1.4.1 OpenPGP: id=804465C5 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 86.62.121.231 Cc: qemu-devel , Avi Kivity Subject: [Qemu-devel] qemu and transparent huge pages X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Quite some time ago there was a thread on qemu-devel, started by Andrea, about modifying qemu to better use transparent huge pages: http://lists.gnu.org/archive/html/qemu-devel/2010-03/msg01250.html That thread hasn't reached any conclusion, but some time after that Avi implemented a similar change: commit 36b586284e678da28df3af9fd0907d2b16f9311c Author: Avi Kivity Date: Mon Sep 5 11:07:05 2011 +0300 qemu_vmalloc: align properly for transparent hugepages and KVM 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 region to avoid fragmentation. Signed-off-by: Avi Kivity Signed-off-by: Anthony Liguori (why it is 64bit-only is a different, unrelated question). But apparently, THP does not work still, even with 2Mb alignment: when running a guest, AnonHugePages in /proc/meminfo stays at 0 - either in kvm mode or in tcg mode. Any idea why? What else is needed for THP to work? This is quite a frequent question in #kvm IRC channel, and I always suggested using -mem-path for this, but I'm curios why it doesn't work automatically when it probably should? Thanks, /mjt 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 @@ void *qemu_memalign(size_t alignment, size_t size) 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; }