From 6180cbd477ca35d2b2fe1edeb6b0aead1975f302 Mon Sep 17 00:00:00 2001 From: Christoffer Dall Date: Fri, 23 Feb 2018 13:56:50 -0500 Subject: [PATCH] util: align memory allocations to 2M on AArch64 For KVM to use Transparent Huge Pages (THP) we have to ensure that the alignment of the userspace address of the KVM memory slot and the IPA that the guest sees for a memory region have the same offset from the 2M huge page size boundary. One way to achieve this is to always align the IPA region at a 2M boundary and ensure that the mmap alignment is also at 2M. Unfortunately, we were only doing this for __arm__, not for __aarch64__, so add this simple condition. This fixes a performance regression using KVM/ARM on AArch64 platforms that showed a performance penalty of more than 50%, introduced by the following commit: 9fac18f (oslib: allocate PROT_NONE pages on top of RAM, 2015-09-10) We were only lucky before the above commit, because we were allocating large regions and naturally getting a 2M alignment on those allocations then. Backports commit ee1e0f8e5d3682c561edcdceccff72b9d9b16d8b from qemu --- qemu/util/oslib-posix.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/qemu/util/oslib-posix.c b/qemu/util/oslib-posix.c index 2e2f2cd4..23654de9 100644 --- a/qemu/util/oslib-posix.c +++ b/qemu/util/oslib-posix.c @@ -26,7 +26,8 @@ * THE SOFTWARE. */ -#if defined(__linux__) && (defined(__x86_64__) || defined(__arm__)) +#if defined(__linux__) && \ + (defined(__x86_64__) || defined(__arm__) || defined(__aarch64__)) /* Use 2 MiB alignment so transparent hugepages can be used by KVM. Valgrind does not support alignments larger than 1 MiB, therefore we need special code which handles running on Valgrind. */