Skip to content

Commit 19deb76

Browse files
rientjestorvalds
authored andcommitted
Revert "Revert "Revert "mm, thp: consolidate THP gfp handling into alloc_hugepage_direct_gfpmask""
This reverts commit 92717d4. Since commit a828260 ("Revert "mm, thp: restore node-local hugepage allocations"") is reverted in this series, it is better to restore the previous 5.2 behavior between the thp allocation and the page allocator rather than to attempt any consolidation or cleanup for a policy that is now reverted. It's less risky during an rc cycle and subsequent patches in this series further modify the same policy that the pre-5.3 behavior implements. Consolidation and cleanup can be done subsequent to a sane default page allocation strategy, so this patch reverts a cleanup done on a strategy that is now reverted and thus is the least risky option. Signed-off-by: David Rientjes <[email protected]> Cc: Andrea Arcangeli <[email protected]> Cc: Michal Hocko <[email protected]> Cc: Mel Gorman <[email protected]> Cc: Vlastimil Babka <[email protected]> Cc: Stefan Priebe - Profihost AG <[email protected]> Cc: "Kirill A. Shutemov" <[email protected]> Cc: Andrew Morton <[email protected]> Signed-off-by: Linus Torvalds <[email protected]>
1 parent ac79f78 commit 19deb76

File tree

4 files changed

+51
-22
lines changed

4 files changed

+51
-22
lines changed

include/linux/gfp.h

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -510,18 +510,22 @@ alloc_pages(gfp_t gfp_mask, unsigned int order)
510510
}
511511
extern struct page *alloc_pages_vma(gfp_t gfp_mask, int order,
512512
struct vm_area_struct *vma, unsigned long addr,
513-
int node);
513+
int node, bool hugepage);
514+
#define alloc_hugepage_vma(gfp_mask, vma, addr, order) \
515+
alloc_pages_vma(gfp_mask, order, vma, addr, numa_node_id(), true)
514516
#else
515517
#define alloc_pages(gfp_mask, order) \
516518
alloc_pages_node(numa_node_id(), gfp_mask, order)
517-
#define alloc_pages_vma(gfp_mask, order, vma, addr, node)\
519+
#define alloc_pages_vma(gfp_mask, order, vma, addr, node, false)\
520+
alloc_pages(gfp_mask, order)
521+
#define alloc_hugepage_vma(gfp_mask, vma, addr, order) \
518522
alloc_pages(gfp_mask, order)
519523
#endif
520524
#define alloc_page(gfp_mask) alloc_pages(gfp_mask, 0)
521525
#define alloc_page_vma(gfp_mask, vma, addr) \
522-
alloc_pages_vma(gfp_mask, 0, vma, addr, numa_node_id())
526+
alloc_pages_vma(gfp_mask, 0, vma, addr, numa_node_id(), false)
523527
#define alloc_page_vma_node(gfp_mask, vma, addr, node) \
524-
alloc_pages_vma(gfp_mask, 0, vma, addr, node)
528+
alloc_pages_vma(gfp_mask, 0, vma, addr, node, false)
525529

526530
extern unsigned long __get_free_pages(gfp_t gfp_mask, unsigned int order);
527531
extern unsigned long get_zeroed_page(gfp_t gfp_mask);

mm/huge_memory.c

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -645,30 +645,30 @@ static vm_fault_t __do_huge_pmd_anonymous_page(struct vm_fault *vmf,
645645
* available
646646
* never: never stall for any thp allocation
647647
*/
648-
static inline gfp_t alloc_hugepage_direct_gfpmask(struct vm_area_struct *vma, unsigned long addr)
648+
static inline gfp_t alloc_hugepage_direct_gfpmask(struct vm_area_struct *vma)
649649
{
650650
const bool vma_madvised = !!(vma->vm_flags & VM_HUGEPAGE);
651-
const gfp_t gfp_mask = GFP_TRANSHUGE_LIGHT | __GFP_THISNODE;
652651

653652
/* Always do synchronous compaction */
654653
if (test_bit(TRANSPARENT_HUGEPAGE_DEFRAG_DIRECT_FLAG, &transparent_hugepage_flags))
655-
return GFP_TRANSHUGE | __GFP_THISNODE |
656-
(vma_madvised ? 0 : __GFP_NORETRY);
654+
return GFP_TRANSHUGE | (vma_madvised ? 0 : __GFP_NORETRY);
657655

658656
/* Kick kcompactd and fail quickly */
659657
if (test_bit(TRANSPARENT_HUGEPAGE_DEFRAG_KSWAPD_FLAG, &transparent_hugepage_flags))
660-
return gfp_mask | __GFP_KSWAPD_RECLAIM;
658+
return GFP_TRANSHUGE_LIGHT | __GFP_KSWAPD_RECLAIM;
661659

662660
/* Synchronous compaction if madvised, otherwise kick kcompactd */
663661
if (test_bit(TRANSPARENT_HUGEPAGE_DEFRAG_KSWAPD_OR_MADV_FLAG, &transparent_hugepage_flags))
664-
return gfp_mask | (vma_madvised ? __GFP_DIRECT_RECLAIM :
665-
__GFP_KSWAPD_RECLAIM);
662+
return GFP_TRANSHUGE_LIGHT |
663+
(vma_madvised ? __GFP_DIRECT_RECLAIM :
664+
__GFP_KSWAPD_RECLAIM);
666665

667666
/* Only do synchronous compaction if madvised */
668667
if (test_bit(TRANSPARENT_HUGEPAGE_DEFRAG_REQ_MADV_FLAG, &transparent_hugepage_flags))
669-
return gfp_mask | (vma_madvised ? __GFP_DIRECT_RECLAIM : 0);
668+
return GFP_TRANSHUGE_LIGHT |
669+
(vma_madvised ? __GFP_DIRECT_RECLAIM : 0);
670670

671-
return gfp_mask;
671+
return GFP_TRANSHUGE_LIGHT;
672672
}
673673

674674
/* Caller must hold page table lock. */
@@ -740,8 +740,8 @@ vm_fault_t do_huge_pmd_anonymous_page(struct vm_fault *vmf)
740740
pte_free(vma->vm_mm, pgtable);
741741
return ret;
742742
}
743-
gfp = alloc_hugepage_direct_gfpmask(vma, haddr);
744-
page = alloc_pages_vma(gfp, HPAGE_PMD_ORDER, vma, haddr, numa_node_id());
743+
gfp = alloc_hugepage_direct_gfpmask(vma);
744+
page = alloc_hugepage_vma(gfp, vma, haddr, HPAGE_PMD_ORDER);
745745
if (unlikely(!page)) {
746746
count_vm_event(THP_FAULT_FALLBACK);
747747
return VM_FAULT_FALLBACK;
@@ -1348,9 +1348,8 @@ vm_fault_t do_huge_pmd_wp_page(struct vm_fault *vmf, pmd_t orig_pmd)
13481348
alloc:
13491349
if (__transparent_hugepage_enabled(vma) &&
13501350
!transparent_hugepage_debug_cow()) {
1351-
huge_gfp = alloc_hugepage_direct_gfpmask(vma, haddr);
1352-
new_page = alloc_pages_vma(huge_gfp, HPAGE_PMD_ORDER, vma,
1353-
haddr, numa_node_id());
1351+
huge_gfp = alloc_hugepage_direct_gfpmask(vma);
1352+
new_page = alloc_hugepage_vma(huge_gfp, vma, haddr, HPAGE_PMD_ORDER);
13541353
} else
13551354
new_page = NULL;
13561355

mm/mempolicy.c

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1180,8 +1180,8 @@ static struct page *new_page(struct page *page, unsigned long start)
11801180
} else if (PageTransHuge(page)) {
11811181
struct page *thp;
11821182

1183-
thp = alloc_pages_vma(GFP_TRANSHUGE, HPAGE_PMD_ORDER, vma,
1184-
address, numa_node_id());
1183+
thp = alloc_hugepage_vma(GFP_TRANSHUGE, vma, address,
1184+
HPAGE_PMD_ORDER);
11851185
if (!thp)
11861186
return NULL;
11871187
prep_transhuge_page(thp);
@@ -2083,6 +2083,7 @@ static struct page *alloc_page_interleave(gfp_t gfp, unsigned order,
20832083
* @vma: Pointer to VMA or NULL if not available.
20842084
* @addr: Virtual Address of the allocation. Must be inside the VMA.
20852085
* @node: Which node to prefer for allocation (modulo policy).
2086+
* @hugepage: for hugepages try only the preferred node if possible
20862087
*
20872088
* This function allocates a page from the kernel page pool and applies
20882089
* a NUMA policy associated with the VMA or the current process.
@@ -2093,7 +2094,7 @@ static struct page *alloc_page_interleave(gfp_t gfp, unsigned order,
20932094
*/
20942095
struct page *
20952096
alloc_pages_vma(gfp_t gfp, int order, struct vm_area_struct *vma,
2096-
unsigned long addr, int node)
2097+
unsigned long addr, int node, bool hugepage)
20972098
{
20982099
struct mempolicy *pol;
20992100
struct page *page;
@@ -2111,6 +2112,31 @@ alloc_pages_vma(gfp_t gfp, int order, struct vm_area_struct *vma,
21112112
goto out;
21122113
}
21132114

2115+
if (unlikely(IS_ENABLED(CONFIG_TRANSPARENT_HUGEPAGE) && hugepage)) {
2116+
int hpage_node = node;
2117+
2118+
/*
2119+
* For hugepage allocation and non-interleave policy which
2120+
* allows the current node (or other explicitly preferred
2121+
* node) we only try to allocate from the current/preferred
2122+
* node and don't fall back to other nodes, as the cost of
2123+
* remote accesses would likely offset THP benefits.
2124+
*
2125+
* If the policy is interleave, or does not allow the current
2126+
* node in its nodemask, we allocate the standard way.
2127+
*/
2128+
if (pol->mode == MPOL_PREFERRED && !(pol->flags & MPOL_F_LOCAL))
2129+
hpage_node = pol->v.preferred_node;
2130+
2131+
nmask = policy_nodemask(gfp, pol);
2132+
if (!nmask || node_isset(hpage_node, *nmask)) {
2133+
mpol_cond_put(pol);
2134+
page = __alloc_pages_node(hpage_node,
2135+
gfp | __GFP_THISNODE, order);
2136+
goto out;
2137+
}
2138+
}
2139+
21142140
nmask = policy_nodemask(gfp, pol);
21152141
preferred_nid = policy_node(gfp, pol, node);
21162142
page = __alloc_pages_nodemask(gfp, order, preferred_nid, nmask);

mm/shmem.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1466,7 +1466,7 @@ static struct page *shmem_alloc_hugepage(gfp_t gfp,
14661466

14671467
shmem_pseudo_vma_init(&pvma, info, hindex);
14681468
page = alloc_pages_vma(gfp | __GFP_COMP | __GFP_NORETRY | __GFP_NOWARN,
1469-
HPAGE_PMD_ORDER, &pvma, 0, numa_node_id());
1469+
HPAGE_PMD_ORDER, &pvma, 0, numa_node_id(), true);
14701470
shmem_pseudo_vma_destroy(&pvma);
14711471
if (page)
14721472
prep_transhuge_page(page);

0 commit comments

Comments
 (0)