Commit 5265047a authored by David Rientjes's avatar David Rientjes Committed by Linus Torvalds
Browse files

mm, thp: really limit transparent hugepage allocation to local node

Commit 077fcf11 ("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 9f1b868a ("mm: thp: khugepaged: add policy for finding target
node") suffers from a similar problem for khugepaged, which is also fixed.

Fixes: 077fcf11 ("mm/thp: allocate transparent hugepages on local node")
Fixes: 9f1b868a

 ("mm: thp: khugepaged: add policy for finding target node")
Signed-off-by: default avatarDavid Rientjes <>
Acked-by: default avatarVlastimil Babka <>
Cc: Christoph Lameter <>
Cc: Pekka Enberg <>
Cc: Joonsoo Kim <>
Cc: Johannes Weiner <>
Cc: Mel Gorman <>
Cc: Pravin Shelar <>
Cc: Jarno Rajahalme <>
Cc: Li Zefan <>
Cc: Greg Thelen <>
Cc: Tejun Heo <>
Signed-off-by: default avatarAndrew Morton <>
Signed-off-by: default avatarLinus Torvalds <>
parent 4167e9b2
......@@ -2328,8 +2328,14 @@ static struct page
struct vm_area_struct *vma, unsigned long address,
int node)
gfp_t flags;
VM_BUG_ON_PAGE(*hpage, *hpage);
/* Only allocate from the target node */
flags = alloc_hugepage_gfpmask(khugepaged_defrag(), __GFP_OTHER_NODE) |
* Before allocating the hugepage, release the mmap_sem read lock.
* The allocation can take potentially a long time if it involves
......@@ -2338,8 +2344,7 @@ static struct page
*hpage = alloc_pages_exact_node(node, alloc_hugepage_gfpmask(
khugepaged_defrag(), __GFP_OTHER_NODE), HPAGE_PMD_ORDER);
*hpage = alloc_pages_exact_node(node, flags, HPAGE_PMD_ORDER);
if (unlikely(!*hpage)) {
*hpage = ERR_PTR(-ENOMEM);
......@@ -1986,7 +1986,8 @@ alloc_pages_vma(gfp_t gfp, int order, struct vm_area_struct *vma,
nmask = policy_nodemask(gfp, pol);
if (!nmask || node_isset(node, *nmask)) {
page = alloc_pages_exact_node(node, gfp, order);
page = alloc_pages_exact_node(node,
gfp | __GFP_THISNODE, order);
goto out;
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment