Skip to content

Commit 00ccf40

Browse files
osalvadorvilardagaakpm00
authored andcommitted
mm, hugetlb: avoid passing a null nodemask when there is mbind policy
Before trying to allocate a page, gather_surplus_pages() sets up a nodemask for the nodes we can allocate from, but instead of passing the nodemask down the road to the page allocator, it iterates over the nodes within that nodemask right there, meaning that the page allocator will receive a preferred_nid and a null nodemask. This is a problem when using a memory policy, because it might be that the page allocator ends up using a node as a fallback which is not represented in the policy. Avoid that by passing the nodemask directly to the page allocator, so it can filter out fallback nodes that are not part of the nodemask. Link: https://lkml.kernel.org/r/[email protected] Signed-off-by: Oscar Salvador <[email protected]> Reviewed-by: Vlastimil Babka <[email protected]> Cc: David Hildenbrand <[email protected]> Cc: Muchun Song <[email protected]> Signed-off-by: Andrew Morton <[email protected]>
1 parent f736953 commit 00ccf40

File tree

1 file changed

+6
-16
lines changed

1 file changed

+6
-16
lines changed

mm/hugetlb.c

Lines changed: 6 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2419,7 +2419,6 @@ static int gather_surplus_pages(struct hstate *h, long delta)
24192419
long i;
24202420
long needed, allocated;
24212421
bool alloc_ok = true;
2422-
int node;
24232422
nodemask_t *mbind_nodemask, alloc_nodemask;
24242423

24252424
mbind_nodemask = policy_mbind_nodemask(htlb_alloc_mask(h));
@@ -2443,21 +2442,12 @@ static int gather_surplus_pages(struct hstate *h, long delta)
24432442
for (i = 0; i < needed; i++) {
24442443
folio = NULL;
24452444

2446-
/* Prioritize current node */
2447-
if (node_isset(numa_mem_id(), alloc_nodemask))
2448-
folio = alloc_surplus_hugetlb_folio(h, htlb_alloc_mask(h),
2449-
numa_mem_id(), NULL);
2450-
2451-
if (!folio) {
2452-
for_each_node_mask(node, alloc_nodemask) {
2453-
if (node == numa_mem_id())
2454-
continue;
2455-
folio = alloc_surplus_hugetlb_folio(h, htlb_alloc_mask(h),
2456-
node, NULL);
2457-
if (folio)
2458-
break;
2459-
}
2460-
}
2445+
/*
2446+
* It is okay to use NUMA_NO_NODE because we use numa_mem_id()
2447+
* down the road to pick the current node if that is the case.
2448+
*/
2449+
folio = alloc_surplus_hugetlb_folio(h, htlb_alloc_mask(h),
2450+
NUMA_NO_NODE, &alloc_nodemask);
24612451
if (!folio) {
24622452
alloc_ok = false;
24632453
break;

0 commit comments

Comments
 (0)