Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751872AbeAIKSP (ORCPT + 1 other); Tue, 9 Jan 2018 05:18:15 -0500 Received: from pegase1.c-s.fr ([93.17.236.30]:25307 "EHLO pegase1.c-s.fr" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751101AbeAIKSM (ORCPT ); Tue, 9 Jan 2018 05:18:12 -0500 From: Christophe Leroy Subject: [PATCH v2] powerpc/mm: Fix growth direction for hugepages mmaps with slice To: Benjamin Herrenschmidt , Paul Mackerras , Michael Ellerman , Scott Wood Cc: linux-kernel@vger.kernel.org, linuxppc-dev@lists.ozlabs.org Message-Id: <20180109101810.2471D6C6CF@localhost.localdomain> Date: Tue, 9 Jan 2018 11:18:10 +0100 (CET) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Return-Path: An application running with libhugetlbfs fails to allocate additional pages to HEAP due to the hugemap being done inconditionally as topdown mapping: mmap(0x10080000, 1572864, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS|0x40000, -1, 0) = 0x73e80000 [...] mmap(0x74000000, 1048576, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS|0x40000, -1, 0x180000) = 0x73d80000 munmap(0x73d80000, 1048576) = 0 [...] mmap(0x74000000, 1572864, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS|0x40000, -1, 0x180000) = 0x73d00000 munmap(0x73d00000, 1572864) = 0 [...] mmap(0x74000000, 1572864, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS|0x40000, -1, 0x180000) = 0x73d00000 munmap(0x73d00000, 1572864) = 0 [...] As one can see from the above strace log, mmap() allocates further pages below the initial one. This patch fixes it by taking into account MAP_GROWSDOWN flag. Fixes: d0f13e3c20b6f ("[POWERPC] Introduce address space "slices" ") Signed-off-by: Christophe Leroy --- v2: Added missing include arch/powerpc/mm/hugetlbpage.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/arch/powerpc/mm/hugetlbpage.c b/arch/powerpc/mm/hugetlbpage.c index 79e1378ee303..0eadf9f199de 100644 --- a/arch/powerpc/mm/hugetlbpage.c +++ b/arch/powerpc/mm/hugetlbpage.c @@ -19,6 +19,7 @@ #include #include #include +#include #include #include #include @@ -558,7 +559,8 @@ unsigned long hugetlb_get_unmapped_area(struct file *file, unsigned long addr, return radix__hugetlb_get_unmapped_area(file, addr, len, pgoff, flags); #endif - return slice_get_unmapped_area(addr, len, flags, mmu_psize, 1); + return slice_get_unmapped_area(addr, len, flags, mmu_psize, + flags & MAP_GROWSDOWN); } #endif -- 2.13.3