Skip to content

Commit 8fe7804

Browse files
rientjestorvalds
authored andcommitted
mm, thp: restructure thp avoidance of light synchronous migration
__GFP_NO_KSWAPD, once the way to determine if an allocation was for thp or not, has gained more users. Their use is not necessarily wrong, they are trying to do a memory allocation that can easily fail without disturbing kswapd, so the bit has gained additional usecases. This restructures the check to determine whether MIGRATE_SYNC_LIGHT should be used for memory compaction in the page allocator. Rather than testing solely for __GFP_NO_KSWAPD, test for all bits that must be set for thp allocations. This also moves the check to be done only after the page allocator is aborted for deferred or contended memory compaction since setting migration_mode for this case is pointless. Signed-off-by: David Rientjes <rientjes@google.com> Cc: Mel Gorman <mgorman@suse.de> Cc: Rik van Riel <riel@redhat.com> Cc: Johannes Weiner <hannes@cmpxchg.org> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
1 parent e972a07 commit 8fe7804

1 file changed

Lines changed: 9 additions & 8 deletions

File tree

‎mm/page_alloc.c‎

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2638,14 +2638,6 @@ __alloc_pages_slowpath(gfp_t gfp_mask, unsigned int order,
26382638
if (page)
26392639
goto got_pg;
26402640

2641-
/*
2642-
* It can become very expensive to allocate transparent hugepages at
2643-
* fault, so use asynchronous memory compaction for THP unless it is
2644-
* khugepaged trying to collapse.
2645-
*/
2646-
if (!(gfp_mask & __GFP_NO_KSWAPD) || (current->flags & PF_KTHREAD))
2647-
migration_mode = MIGRATE_SYNC_LIGHT;
2648-
26492641
/*
26502642
* If compaction is deferred for high-order allocations, it is because
26512643
* sync compaction recently failed. In this is the case and the caller
@@ -2656,6 +2648,15 @@ __alloc_pages_slowpath(gfp_t gfp_mask, unsigned int order,
26562648
(gfp_mask & __GFP_NO_KSWAPD))
26572649
goto nopage;
26582650

2651+
/*
2652+
* It can become very expensive to allocate transparent hugepages at
2653+
* fault, so use asynchronous memory compaction for THP unless it is
2654+
* khugepaged trying to collapse.
2655+
*/
2656+
if ((gfp_mask & GFP_TRANSHUGE) != GFP_TRANSHUGE ||
2657+
(current->flags & PF_KTHREAD))
2658+
migration_mode = MIGRATE_SYNC_LIGHT;
2659+
26592660
/* Try direct reclaim and then allocating */
26602661
page = __alloc_pages_direct_reclaim(gfp_mask, order,
26612662
zonelist, high_zoneidx,

0 commit comments

Comments
 (0)