mm: hugetlb: introduce CONFIG_HUGETLB_PAGE_FREE_VMEMMAP_DEFAULT_ON
authorMuchun Song <songmuchun@bytedance.com>
Thu, 1 Jul 2021 01:48:28 +0000 (18:48 -0700)
committerLinus Torvalds <torvalds@linux-foundation.org>
Thu, 1 Jul 2021 03:47:26 +0000 (20:47 -0700)
When using HUGETLB_PAGE_FREE_VMEMMAP, the freeing unused vmemmap pages
associated with each HugeTLB page is default off.  Now the vmemmap is PMD
mapped.  So there is no side effect when this feature is enabled with no
HugeTLB pages in the system.  Someone may want to enable this feature in
the compiler time instead of using boot command line.  So add a config to
make it default on when someone do not want to enable it via command line.

Link: https://lkml.kernel.org/r/20210616094915.34432-4-songmuchun@bytedance.com
Signed-off-by: Muchun Song <songmuchun@bytedance.com>
Cc: Chen Huang <chenhuang5@huawei.com>
Cc: David Hildenbrand <david@redhat.com>
Cc: Jonathan Corbet <corbet@lwn.net>
Cc: Michal Hocko <mhocko@suse.com>
Cc: Mike Kravetz <mike.kravetz@oracle.com>
Cc: Oscar Salvador <osalvador@suse.de>
Cc: Xiongchun Duan <duanxiongchun@bytedance.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Documentation/admin-guide/kernel-parameters.txt
fs/Kconfig
mm/hugetlb_vmemmap.c

index 7a7da02..c4e3442 100644 (file)
                        on:  enable the feature
                        off: disable the feature
 
+                       Built with CONFIG_HUGETLB_PAGE_FREE_VMEMMAP_DEFAULT_ON=y,
+                       the default is on.
+
                        This is not compatible with memory_hotplug.memmap_on_memory.
                        If both parameters are enabled, hugetlb_free_vmemmap takes
                        precedence over memory_hotplug.memmap_on_memory.
index 58a5345..a7749c1 100644 (file)
@@ -245,6 +245,16 @@ config HUGETLB_PAGE_FREE_VMEMMAP
        depends on X86_64
        depends on SPARSEMEM_VMEMMAP
 
+config HUGETLB_PAGE_FREE_VMEMMAP_DEFAULT_ON
+       bool "Default freeing vmemmap pages of HugeTLB to on"
+       default n
+       depends on HUGETLB_PAGE_FREE_VMEMMAP
+       help
+         When using HUGETLB_PAGE_FREE_VMEMMAP, the freeing unused vmemmap
+         pages associated with each HugeTLB page is default off. Say Y here
+         to enable freeing vmemmap pages of HugeTLB by default. It can then
+         be disabled on the command line via hugetlb_free_vmemmap=off.
+
 config MEMFD_CREATE
        def_bool TMPFS || HUGETLBFS
 
index 0680205..c540c21 100644 (file)
 #define RESERVE_VMEMMAP_NR             2U
 #define RESERVE_VMEMMAP_SIZE           (RESERVE_VMEMMAP_NR << PAGE_SHIFT)
 
-bool hugetlb_free_vmemmap_enabled;
+bool hugetlb_free_vmemmap_enabled = IS_ENABLED(CONFIG_HUGETLB_PAGE_FREE_VMEMMAP_DEFAULT_ON);
 
 static int __init early_hugetlb_free_vmemmap_param(char *buf)
 {
@@ -197,7 +197,9 @@ static int __init early_hugetlb_free_vmemmap_param(char *buf)
 
        if (!strcmp(buf, "on"))
                hugetlb_free_vmemmap_enabled = true;
-       else if (strcmp(buf, "off"))
+       else if (!strcmp(buf, "off"))
+               hugetlb_free_vmemmap_enabled = false;
+       else
                return -EINVAL;
 
        return 0;