From patchwork Thu Mar 11 15:14:27 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrea Arcangeli X-Patchwork-Id: 47342 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [199.232.76.165]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 6B78FB6EEB for ; Fri, 12 Mar 2010 02:33:05 +1100 (EST) Received: from localhost ([127.0.0.1]:43790 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1NpkNi-000869-5c for incoming@patchwork.ozlabs.org; Thu, 11 Mar 2010 10:33:02 -0500 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1Npk5p-00083L-KF for qemu-devel@nongnu.org; Thu, 11 Mar 2010 10:14:33 -0500 Received: from [199.232.76.173] (port=59350 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Npk5o-00081u-Pd for qemu-devel@nongnu.org; Thu, 11 Mar 2010 10:14:32 -0500 Received: from Debian-exim by monty-python.gnu.org with spam-scanned (Exim 4.60) (envelope-from ) id 1Npk5n-0001x6-Ci for qemu-devel@nongnu.org; Thu, 11 Mar 2010 10:14:32 -0500 Received: from mx1.redhat.com ([209.132.183.28]:1613) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1Npk5m-0001wi-UZ for qemu-devel@nongnu.org; Thu, 11 Mar 2010 10:14:31 -0500 Received: from int-mx08.intmail.prod.int.phx2.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by mx1.redhat.com (8.13.8/8.13.8) with ESMTP id o2BFETdf032262 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Thu, 11 Mar 2010 10:14:29 -0500 Received: from random.random (ovpn01.gateway.prod.ext.phx2.redhat.com [10.5.9.1]) by int-mx08.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id o2BFERjx014405 for ; Thu, 11 Mar 2010 10:14:28 -0500 Date: Thu, 11 Mar 2010 16:14:27 +0100 From: Andrea Arcangeli To: qemu-devel@nongnu.org Message-ID: <20100311151427.GE5677@random.random> MIME-Version: 1.0 Content-Disposition: inline X-Scanned-By: MIMEDefang 2.67 on 10.5.11.21 X-detected-operating-system: by monty-python.gnu.org: Genre and OS details not recognized. Subject: [Qemu-devel] [PATCH QEMU] transparent hugepage support X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org 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); +#endif #ifdef MADV_MERGEABLE madvise(new_block->host, size, MADV_MERGEABLE); #endif +#ifdef MADV_HUGEPAGE + madvise(new_block->host, size, MADV_HUGEPAGE); +#endif } new_block->offset = last_ram_offset; new_block->length = size; diff --git a/target-i386/cpu.h b/target-i386/cpu.h index ef7d951..26044eb 100644 --- a/target-i386/cpu.h +++ b/target-i386/cpu.h @@ -873,6 +873,7 @@ uint64_t cpu_get_tsc(CPUX86State *env); #define X86_DUMP_CCOP 0x0002 /* dump qemu flag cache */ #define TARGET_PAGE_BITS 12 +#define TARGET_HPAGE_BITS (TARGET_PAGE_BITS+9) #define cpu_init cpu_x86_init #define cpu_exec cpu_x86_exec