Skip to content

Commit d0f14f7

Browse files
lkpdnakpm00
authored andcommitted
hugetlb: prioritize surplus allocation from current node
Previously, surplus allocations triggered by mmap were typically made from the node where the process was running. On a page fault, the area was reliably dequeued from the hugepage_freelists for that node. However, since commit 003af99 ("hugetlb: force allocating surplus hugepages on mempolicy allowed nodes"), dequeue_hugetlb_folio_vma() may fall back to other nodes unnecessarily even if there is no MPOL_BIND policy, causing folios to be dequeued from nodes other than the current one. Also, allocating from the node where the current process is running is likely to result in a performance win, as mmap-ing processes often touch the area not so long after allocation. This change minimizes surprises for users relying on the previous behavior while maintaining the benefit introduced by the commit. So, prioritize the node the current process is running on when possible. Link: https://lkml.kernel.org/r/[email protected] Signed-off-by: Koichiro Den <[email protected]> Acked-by: Aristeu Rozanski <[email protected]> Cc: Aristeu Rozanski <[email protected]> Cc: David Hildenbrand <[email protected]> Cc: Muchun Song <[email protected]> Cc: Vishal Moola (Oracle) <[email protected]> Signed-off-by: Andrew Morton <[email protected]>
1 parent d5ea5e5 commit d0f14f7

File tree

1 file changed

+17
-3
lines changed

1 file changed

+17
-3
lines changed

mm/hugetlb.c

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2463,7 +2463,13 @@ static int gather_surplus_pages(struct hstate *h, long delta)
24632463
long needed, allocated;
24642464
bool alloc_ok = true;
24652465
int node;
2466-
nodemask_t *mbind_nodemask = policy_mbind_nodemask(htlb_alloc_mask(h));
2466+
nodemask_t *mbind_nodemask, alloc_nodemask;
2467+
2468+
mbind_nodemask = policy_mbind_nodemask(htlb_alloc_mask(h));
2469+
if (mbind_nodemask)
2470+
nodes_and(alloc_nodemask, *mbind_nodemask, cpuset_current_mems_allowed);
2471+
else
2472+
alloc_nodemask = cpuset_current_mems_allowed;
24672473

24682474
lockdep_assert_held(&hugetlb_lock);
24692475
needed = (h->resv_huge_pages + delta) - h->free_huge_pages;
@@ -2479,8 +2485,16 @@ static int gather_surplus_pages(struct hstate *h, long delta)
24792485
spin_unlock_irq(&hugetlb_lock);
24802486
for (i = 0; i < needed; i++) {
24812487
folio = NULL;
2482-
for_each_node_mask(node, cpuset_current_mems_allowed) {
2483-
if (!mbind_nodemask || node_isset(node, *mbind_nodemask)) {
2488+
2489+
/* Prioritize current node */
2490+
if (node_isset(numa_mem_id(), alloc_nodemask))
2491+
folio = alloc_surplus_hugetlb_folio(h, htlb_alloc_mask(h),
2492+
numa_mem_id(), NULL);
2493+
2494+
if (!folio) {
2495+
for_each_node_mask(node, alloc_nodemask) {
2496+
if (node == numa_mem_id())
2497+
continue;
24842498
folio = alloc_surplus_hugetlb_folio(h, htlb_alloc_mask(h),
24852499
node, NULL);
24862500
if (folio)

0 commit comments

Comments
 (0)