Commit e2cbfa0f authored by Ma Wupeng's avatar Ma Wupeng Committed by Wupeng Ma
Browse files

mm/hugetlb: Allocate non-mirrored memory by default

hulk inclusion
category: feature
bugzilla: https://gitee.com/openeuler/kernel/issues/I8USBA


CVE: NA

--------------------------------

Previous memory allocation in memblock for hugetlb may use mirrored or
non-mirrored memory depends on the system's memory status. However this is
not suitable if hugetlb user want to alloc memory from non-mirrored memory
if memory reliable is enabled.

In order to solve this problem, hugetlb use MEMBLOCK_NOMIRROR flag to alloc
memory from non-mirrored region without fallback to mirrored region.

Signed-off-by: default avatarMa Wupeng <mawupeng1@huawei.com>
parent 64018b29
Loading
Loading
Loading
Loading
+16 −2
Original line number Diff line number Diff line
@@ -3246,6 +3246,20 @@ struct folio *alloc_hugetlb_folio(struct vm_area_struct *vma,
	return ERR_PTR(-ENOSPC);
}

static void *__init __alloc_bootmem_huge_page_inner(phys_addr_t size,
						    phys_addr_t align,
						    phys_addr_t min_addr,
						    phys_addr_t max_addr,
						    int nid)
{
	if (!mem_reliable_is_enabled())
		return memblock_alloc_try_nid_raw(size, align, min_addr,
						  max_addr, nid);

	return memblock_alloc_try_nid_raw_flags(size, align, min_addr, max_addr,
						nid, MEMBLOCK_NOMIRROR);
}

int alloc_bootmem_huge_page(struct hstate *h, int nid)
	__attribute__ ((weak, alias("__alloc_bootmem_huge_page")));
int __alloc_bootmem_huge_page(struct hstate *h, int nid)
@@ -3260,7 +3274,7 @@ int __alloc_bootmem_huge_page(struct hstate *h, int nid)

	/* do node specific alloc */
	if (nid != NUMA_NO_NODE) {
		m = memblock_alloc_try_nid_raw(huge_page_size(h), huge_page_size(h),
		m = __alloc_bootmem_huge_page_inner(huge_page_size(h), huge_page_size(h),
				0, MEMBLOCK_ALLOC_ACCESSIBLE, nid);
		if (!m)
			return 0;
@@ -3268,7 +3282,7 @@ int __alloc_bootmem_huge_page(struct hstate *h, int nid)
	}
	/* allocate from next node when distributing huge pages */
	for_each_node_mask_to_alloc(h, nr_nodes, node, &node_states[N_MEMORY]) {
		m = memblock_alloc_try_nid_raw(
		m = __alloc_bootmem_huge_page_inner(
				huge_page_size(h), huge_page_size(h),
				0, MEMBLOCK_ALLOC_ACCESSIBLE, node);
		/*