[lkml]   [2017]   [Oct]   [6]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
Messages in this thread
Patch in this message
Subject[RFC PATCH] mm: shm: round up tmpfs size to huge page size when huge=always
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;
+ /* 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);
return 0;

 \ /
  Last update: 2017-10-06 22:22    [W:0.060 / U:1.148 seconds]
©2003-2018 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site