Skip to content

Commit

Permalink
mm, compaction: skip compound pages by order in free scanner
Browse files Browse the repository at this point in the history
[ Upstream commit 9fcd6d2 ]

The compaction free scanner is looking for PageBuddy() pages and
skipping all others.  For large compound pages such as THP or hugetlbfs,
we can save a lot of iterations if we skip them at once using their
compound_order().  This is generally unsafe and we can read a bogus
value of order due to a race, but if we are careful, the only danger is
skipping too much.

When tested with stress-highalloc from mmtests on 4GB system with 1GB
hugetlbfs pages, the vmstat compact_free_scanned count decreased by at
least 15%.

Signed-off-by: Vlastimil Babka <[email protected]>
Cc: Minchan Kim <[email protected]>
Cc: Mel Gorman <[email protected]>
Acked-by: Joonsoo Kim <[email protected]>
Acked-by: Michal Nazarewicz <[email protected]>
Cc: Naoya Horiguchi <[email protected]>
Cc: Christoph Lameter <[email protected]>
Cc: Rik van Riel <[email protected]>
Cc: David Rientjes <[email protected]>
Signed-off-by: Andrew Morton <[email protected]>
Signed-off-by: Linus Torvalds <[email protected]>
Signed-off-by: Sasha Levin <[email protected]>
  • Loading branch information
tehcaster authored and sashalevin committed Jul 11, 2016
1 parent c5ad331 commit 6838542
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions mm/compaction.c
Original file line number Diff line number Diff line change
Expand Up @@ -431,6 +431,24 @@ static unsigned long isolate_freepages_block(struct compact_control *cc,

if (!valid_page)
valid_page = page;

/*
* For compound pages such as THP and hugetlbfs, we can save
* potentially a lot of iterations if we skip them at once.
* The check is racy, but we can consider only valid values
* and the only danger is skipping too much.
*/
if (PageCompound(page)) {
unsigned int comp_order = compound_order(page);

if (likely(comp_order < MAX_ORDER)) {
blockpfn += (1UL << comp_order) - 1;
cursor += (1UL << comp_order) - 1;
}

goto isolate_fail;
}

if (!PageBuddy(page))
goto isolate_fail;

Expand Down Expand Up @@ -490,6 +508,13 @@ static unsigned long isolate_freepages_block(struct compact_control *cc,

}

/*
* There is a tiny chance that we have read bogus compound_order(),
* so be careful to not go outside of the pageblock.
*/
if (unlikely(blockpfn > end_pfn))
blockpfn = end_pfn;

trace_mm_compaction_isolate_freepages(*start_pfn, blockpfn,
nr_scanned, total_isolated);

Expand Down

0 comments on commit 6838542

Please sign in to comment.