Commit 72a95efd authored by Liu Shixin's avatar Liu Shixin Committed by Zheng Zengkai
Browse files

mm/huge_memory: disable THP when dynamic hugetlb is enabled

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: default avatarLiu Shixin <liushixin2@huawei.com>
Reviewed-by: default avatarKefeng Wang <wangkefeng.wang@huawei.com>
Signed-off-by: default avatarZheng Zengkai <zhengzengkai@huawei.com>
parent 7278ccd6
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -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 {};
+1 −1
Original line number Diff line number Diff line
@@ -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))
+13 −0
Original line number Diff line number Diff line
@@ -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
	 */