From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752814AbdJFUWZ (ORCPT ); Fri, 6 Oct 2017 16:22:25 -0400 Received: from out0-225.mail.aliyun.com ([140.205.0.225]:35363 "EHLO out0-225.mail.aliyun.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752696AbdJFUWY (ORCPT ); Fri, 6 Oct 2017 16:22:24 -0400 X-Alimail-AntiSpam: AC=PASS;BC=-1|-1;BR=01201311R181e4;FP=0|-1|-1|-1|0|-1|-1|-1;HT=e02c03310;MF=yang.s@alibaba-inc.com;NM=1;PH=DS;RN=7;SR=0;TI=SMTPD_---.93L05sI_1507321330; From: "Yang Shi" To: kirill.shutemov@linux.intel.com, hughd@google.com, mhocko@kernel.org, akpm@linux-foundation.org Cc: "Yang Shi" , , Subject: [RFC PATCH] mm: shm: round up tmpfs size to huge page size when huge=always Date: Sat, 07 Oct 2017 04:22:10 +0800 Message-Id: <1507321330-22525-1-git-send-email-yang.s@alibaba-inc.com> X-Mailer: git-send-email 1.8.3.1 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org When passing "huge=always" option for mounting tmpfs, THP is supposed to be allocated all the time when it can fit, but when the available space is smaller than the size of THP (2MB on x86), shmem fault handler still tries to allocate huge page every time, then fallback to regular 4K page allocation, i.e.: # mount -t tmpfs -o huge,size=3000k tmpfs /tmp # dd if=/dev/zero of=/tmp/test bs=1k count=2048 # dd if=/dev/zero of=/tmp/test1 bs=1k count=2048 The last dd command will handle 952 times page fault handler, then exit with -ENOSPC. Rounding up tmpfs size to THP size in order to use THP with "always" more efficiently. And, it will not wast too much memory (just allocate 511 extra pages in worst case). Signed-off-by: Yang Shi --- mm/shmem.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/mm/shmem.c b/mm/shmem.c index 07a1d22..b2b595d 100644 --- a/mm/shmem.c +++ b/mm/shmem.c @@ -3567,6 +3567,11 @@ static int shmem_parse_options(char *options, struct shmem_sb_info *sbinfo, } } sbinfo->mpol = mpol; +#ifdef CONFIG_TRANSPARENT_HUGE_PAGECACHE + /* Round up tmpfs size to huge page size */ + if (sbinfo->max_blocks && sbinfo->huge == SHMEM_HUGE_ALWAYS) + sbinfo->max_blocks = round_up(sbinf->max_blocks, HPAGE_PMD_NR); +#endif return 0; bad_val: -- 1.8.3.1