Skip to contentSkip to conversation

shmem: avoid huge pages for small files

PATCH Superseded Kirill A. Shutemov 1 participant 1 message Oct 18, 2016

Subsystems (4)

v3 of 4 Superseded Latest is v4 →

lore
Share & tools
lore
#0 lore raw

PATCH v3 1/1 shmem: avoid huge pages for small files

Huge pages are detrimental for small file: they causes noticible overhead on both allocation performance and memory footprint.

This patch aimed to address this issue by avoiding huge pages until file grown to specified size. This would cover most of the cases where huge pages causes regressions in performance.

By default the minimal file size to allocate huge pages is equal to size of huge page.

Depending on how well CPU microarchitecture deals with huge pages, you might need to set it higher in order to balance out overhead with benefit of huge pages.

In other case, if it's known in advance that specific mount would be populated with large files, you might want to set it to zero to get huge pages allocated from the beginning.

We add two handle to specify minimal file size for huge pages:

- mount option 'huge_min_size';

- sysfs file /sys/kernel/mm/transparent_hugepage/shmem_min_size for

    in-kernel tmpfs mount;

Few notes:

- if shmem_enabled is set to 'force', the limit is ignored. We still want to generate as many pages as possible for functional testing.

- the limit doesn't affect khugepaged behaviour: it still can collapse

    pages based on its settings;

- remount of the filesystem doesn't affect previously allocated pages,

    but the limit is applied for new allocations;
---
 Documentation/vm/transhuge.txt |  6 +++++
 include/linux/huge_mm.h        |  1 +
 include/linux/shmem_fs.h       |  1 +
 mm/huge_memory.c               |  1 +
 mm/shmem.c                     | 56 ++++++++++++++++++++++++++++++++++++++----
 5 files changed, 60 insertions(+), 5 deletions(-)
Documentation/vm/transhuge.txt +6 -0
index 2ec6adb5a4ce..2d861d72e135 100644
@@ -238,6 +238,12 @@ values:
   - "force":
     Force the huge option on for all - very useful for testing;
 
+There's limit on minimal file size before kernel starts allocate huge
+pages for it. By default it's size of huge page.
+
+You can adjust the limit using "huge_min_size=" mount option or
+/sys/kernel/mm/transparent_hugepage/shmem_min_size for in-kernel mount.
+
 == Need of application restart ==
 
 The transparent_hugepage/enabled values and tmpfs mount option only affect
include/linux/huge_mm.h +1 -0
index 9b9f65d99873..515b96a5a592 100644
@@ -52,6 +52,7 @@ extern ssize_t single_hugepage_flag_show(struct kobject *kobj,
 				struct kobj_attribute *attr, char *buf,
 				enum transparent_hugepage_flag flag);
 extern struct kobj_attribute shmem_enabled_attr;
+extern struct kobj_attribute shmem_min_size_attr;
 
 #define HPAGE_PMD_ORDER (HPAGE_PMD_SHIFT-PAGE_SHIFT)
 #define HPAGE_PMD_NR (1<<HPAGE_PMD_ORDER)
include/linux/shmem_fs.h +1 -0
index ff078e7043b6..e7c3bddc6335 100644
@@ -31,6 +31,7 @@ struct shmem_sb_info {
 	spinlock_t stat_lock;	    /* Serialize shmem_sb_info changes */
 	umode_t mode;		    /* Mount mode for root directory */
 	unsigned char huge;	    /* Whether to try for hugepages */
+	loff_t huge_min_size;       /* No hugepages if i_size less than this */
 	kuid_t uid;		    /* Mount uid for root directory */
 	kgid_t gid;		    /* Mount gid for root directory */
 	struct mempolicy *mpol;     /* default memory policy for mappings */
mm/huge_memory.c +1 -0
index cdcd25cb30fe..fa133eb5bf62 100644
@@ -309,6 +309,7 @@ static struct attribute *hugepage_attr[] = {
 	&use_zero_page_attr.attr,
 #if defined(CONFIG_SHMEM) && defined(CONFIG_TRANSPARENT_HUGE_PAGECACHE)
 	&shmem_enabled_attr.attr,
+	&shmem_min_size_attr.attr,
 #endif
 #ifdef CONFIG_DEBUG_VM
 	&debug_cow_attr.attr,
mm/shmem.c +51 -5

124 lines not on this page · raw message

Signature · 1 line
2.9.3