From patchwork Mon Sep 5 08:07:05 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Avi Kivity X-Patchwork-Id: 113320 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [140.186.70.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 0FD13B6F70 for ; Mon, 5 Sep 2011 18:07:23 +1000 (EST) Received: from localhost ([::1]:51995 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1R0UD9-00051z-JY for incoming@patchwork.ozlabs.org; Mon, 05 Sep 2011 04:07:19 -0400 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 Received: from s01.tlv.redhat.com (s01.tlv.redhat.com [10.35.255.8]) by cleopatra.tlv.redhat.com (Postfix) with ESMTP id E02D1250B57; Mon, 5 Sep 2011 11:07:07 +0300 (IDT) From: Avi Kivity To: qemu-devel@nongnu.org Date: Mon, 5 Sep 2011 11:07:05 +0300 Message-Id: <1315210025-17727-1-git-send-email-avi@redhat.com> X-Scanned-By: MIMEDefang 2.67 on 10.5.11.11 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH] qemu_vmalloc: align properly for transparent hugepages and KVM 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 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; }