Skip to content

Commit

Permalink
mm: page_alloc: only check the zone id check if pages are buddies
Browse files Browse the repository at this point in the history
A node/zone index is used to check if pages are compatible for merging
but this happens unconditionally even if the buddy page is not free. Defer
the calculation as long as possible. Ideally we would check the zone boundary
but nodes can overlap.

Signed-off-by: Mel Gorman <[email protected]>
Acked-by: Johannes Weiner <[email protected]>
Acked-by: Rik van Riel <[email protected]>
Cc: Vlastimil Babka <[email protected]>
Cc: Jan Kara <[email protected]>
Cc: Michal Hocko <[email protected]>
Cc: Hugh Dickins <[email protected]>
Cc: Dave Hansen <[email protected]>
Cc: Theodore Ts'o <[email protected]>
Cc: "Paul E. McKenney" <[email protected]>
Cc: Oleg Nesterov <[email protected]>
Cc: Peter Zijlstra <[email protected]>
Signed-off-by: Andrew Morton <[email protected]>
Signed-off-by: Linus Torvalds <[email protected]>
  • Loading branch information
Mel Gorman authored and torvalds committed Jun 4, 2014
1 parent 664eedd commit d34c5fa
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions mm/page_alloc.c
Original file line number Diff line number Diff line change
Expand Up @@ -509,16 +509,26 @@ static inline int page_is_buddy(struct page *page, struct page *buddy,
if (!pfn_valid_within(page_to_pfn(buddy)))
return 0;

if (page_zone_id(page) != page_zone_id(buddy))
return 0;

if (page_is_guard(buddy) && page_order(buddy) == order) {
VM_BUG_ON_PAGE(page_count(buddy) != 0, buddy);

if (page_zone_id(page) != page_zone_id(buddy))
return 0;

return 1;
}

if (PageBuddy(buddy) && page_order(buddy) == order) {
VM_BUG_ON_PAGE(page_count(buddy) != 0, buddy);

/*
* zone check is done late to avoid uselessly
* calculating zone/node ids for pages that could
* never merge.
*/
if (page_zone_id(page) != page_zone_id(buddy))
return 0;

return 1;
}
return 0;
Expand Down

0 comments on commit d34c5fa

Please sign in to comment.