From: Liu Shixin liushixin2@huawei.com
hulk inclusion category: feature bugzilla: 46904, https://gitee.com/openeuler/kernel/issues/I4QSHG CVE: NA
--------------------------------
When THP is enabled, the allocation of a page(order=0) may be converted to an allocation of pages(order>0). In this case, the allocation will skip the dhugetlb_pool. When we want to use dynamic hugetlb feature, we have to disable THP for now.
Signed-off-by: Liu Shixin liushixin2@huawei.com Reviewed-by: Kefeng Wang wangkefeng.wang@huawei.com Signed-off-by: Zheng Zengkai zhengzengkai@huawei.com --- include/linux/dynamic_hugetlb.h | 2 ++ mm/dynamic_hugetlb.c | 2 +- mm/huge_memory.c | 13 +++++++++++++ 3 files changed, 16 insertions(+), 1 deletion(-)
diff --git a/include/linux/dynamic_hugetlb.h b/include/linux/dynamic_hugetlb.h index 05bc55ef831b..237a7329ff64 100644 --- a/include/linux/dynamic_hugetlb.h +++ b/include/linux/dynamic_hugetlb.h @@ -9,6 +9,7 @@
#ifdef CONFIG_DYNAMIC_HUGETLB
+extern bool enable_dhugetlb; extern struct static_key_false dhugetlb_enabled_key; #define dhugetlb_enabled (static_branch_unlikely(&dhugetlb_enabled_key))
@@ -106,6 +107,7 @@ void free_huge_page_to_dhugetlb_pool(struct page *page, bool restore_reserve);
#else
+#define enable_dhugetlb 0 #define dhugetlb_enabled 0
struct dhugetlb_pool {}; diff --git a/mm/dynamic_hugetlb.c b/mm/dynamic_hugetlb.c index 1faac3b4572b..e9f5348bcccd 100644 --- a/mm/dynamic_hugetlb.c +++ b/mm/dynamic_hugetlb.c @@ -15,7 +15,7 @@ #include <trace/events/dynamic_hugetlb.h> #endif
-static bool enable_dhugetlb = false; +bool enable_dhugetlb = false; DEFINE_STATIC_KEY_FALSE(dhugetlb_enabled_key);
#define hugepage_index(pfn) ((pfn) >> (PUD_SHIFT - PAGE_SHIFT)) diff --git a/mm/huge_memory.c b/mm/huge_memory.c index acb2e2c9e043..37704a21b3dc 100644 --- a/mm/huge_memory.c +++ b/mm/huge_memory.c @@ -33,6 +33,7 @@ #include <linux/oom.h> #include <linux/numa.h> #include <linux/page_owner.h> +#include <linux/dynamic_hugetlb.h>
#include <asm/tlb.h> #include <asm/pgalloc.h> @@ -392,6 +393,18 @@ static int __init hugepage_init(void) return -EINVAL; }
+ /* + * When we alloc some pages(order = 0), system may help us to alloc a page(order > 0) + * due to transparent hugepage. This result dynamic hugetlb to be skipped. + * Actually, using dynamic hugetlb means we have already optimized the program, so we + * should not use transparent hugepage in addition. (May result negative optimization) + */ + if (enable_dhugetlb) { + transparent_hugepage_flags = 0; + pr_info("transparent hugepage is disabled due to confilct with dynamic hugetlb\n"); + return -EINVAL; + } + /* * hugepages can't be allocated by the buddy allocator */