Skip to content

Commit 5265047

Browse files
rientjestorvalds
authored andcommitted
mm, thp: really limit transparent hugepage allocation to local node
Commit 077fcf1 ("mm/thp: allocate transparent hugepages on local node") restructured alloc_hugepage_vma() with the intent of only allocating transparent hugepages locally when there was not an effective interleave mempolicy. alloc_pages_exact_node() does not limit the allocation to the single node, however, but rather prefers it. This is because __GFP_THISNODE is not set which would cause the node-local nodemask to be passed. Without it, only a nodemask that prefers the local node is passed. Fix this by passing __GFP_THISNODE and falling back to small pages when the allocation fails. Commit 9f1b868 ("mm: thp: khugepaged: add policy for finding target node") suffers from a similar problem for khugepaged, which is also fixed. Fixes: 077fcf1 ("mm/thp: allocate transparent hugepages on local node") Fixes: 9f1b868 ("mm: thp: khugepaged: add policy for finding target node") Signed-off-by: David Rientjes <[email protected]> Acked-by: Vlastimil Babka <[email protected]> Cc: Christoph Lameter <[email protected]> Cc: Pekka Enberg <[email protected]> Cc: Joonsoo Kim <[email protected]> Cc: Johannes Weiner <[email protected]> Cc: Mel Gorman <[email protected]> Cc: Pravin Shelar <[email protected]> Cc: Jarno Rajahalme <[email protected]> Cc: Li Zefan <[email protected]> Cc: Greg Thelen <[email protected]> Cc: Tejun Heo <[email protected]> Signed-off-by: Andrew Morton <[email protected]> Signed-off-by: Linus Torvalds <[email protected]>
1 parent 4167e9b commit 5265047

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed

mm/huge_memory.c

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2328,8 +2328,14 @@ static struct page
23282328
struct vm_area_struct *vma, unsigned long address,
23292329
int node)
23302330
{
2331+
gfp_t flags;
2332+
23312333
VM_BUG_ON_PAGE(*hpage, *hpage);
23322334

2335+
/* Only allocate from the target node */
2336+
flags = alloc_hugepage_gfpmask(khugepaged_defrag(), __GFP_OTHER_NODE) |
2337+
__GFP_THISNODE;
2338+
23332339
/*
23342340
* Before allocating the hugepage, release the mmap_sem read lock.
23352341
* The allocation can take potentially a long time if it involves
@@ -2338,8 +2344,7 @@ static struct page
23382344
*/
23392345
up_read(&mm->mmap_sem);
23402346

2341-
*hpage = alloc_pages_exact_node(node, alloc_hugepage_gfpmask(
2342-
khugepaged_defrag(), __GFP_OTHER_NODE), HPAGE_PMD_ORDER);
2347+
*hpage = alloc_pages_exact_node(node, flags, HPAGE_PMD_ORDER);
23432348
if (unlikely(!*hpage)) {
23442349
count_vm_event(THP_COLLAPSE_ALLOC_FAILED);
23452350
*hpage = ERR_PTR(-ENOMEM);

mm/mempolicy.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1986,7 +1986,8 @@ alloc_pages_vma(gfp_t gfp, int order, struct vm_area_struct *vma,
19861986
nmask = policy_nodemask(gfp, pol);
19871987
if (!nmask || node_isset(node, *nmask)) {
19881988
mpol_cond_put(pol);
1989-
page = alloc_pages_exact_node(node, gfp, order);
1989+
page = alloc_pages_exact_node(node,
1990+
gfp | __GFP_THISNODE, order);
19901991
goto out;
19911992
}
19921993
}

0 commit comments

Comments
 (0)