linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
* [RFC PATCH] mm: shm: round up tmpfs size to huge page size when huge=always
@ 2017-10-06 20:22 Yang Shi
  2017-10-08 12:56 ` Kirill A. Shutemov
  0 siblings, 1 reply; 8+ messages in thread
From: Yang Shi @ 2017-10-06 20:22 UTC (permalink / raw)
  To: kirill.shutemov, hughd, mhocko, akpm; +Cc: Yang Shi, linux-mm, linux-kernel

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 <yang.s@alibaba-inc.com>
---
 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

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org.  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>

^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2017-10-09 17:54 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-10-06 20:22 [RFC PATCH] mm: shm: round up tmpfs size to huge page size when huge=always Yang Shi
2017-10-08 12:56 ` Kirill A. Shutemov
2017-10-08 19:51   ` Yang Shi
2017-10-09  4:03     ` Kirill A. Shutemov
2017-10-09  6:48   ` Michal Hocko
2017-10-09 16:43     ` Yang Shi
2017-10-09 17:26       ` Michal Hocko
2017-10-09 17:54         ` Yang Shi

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox