Commit 6a85a5ad29a2582ae347ac3f38baa9e2e5daab5b

Authored by Mel Gorman
Committed by Jiri Slaby
1 parent dc2786f0c1

mm: page_alloc: only check the zone id check if pages are buddies

commit d34c5fa06fade08a689fc171bf756fba2858ae73 upstream.

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 <mgorman@suse.de>
Acked-by: Johannes Weiner <hannes@cmpxchg.org>
Acked-by: Rik van Riel <riel@redhat.com>
Cc: Vlastimil Babka <vbabka@suse.cz>
Cc: Jan Kara <jack@suse.cz>
Cc: Michal Hocko <mhocko@suse.cz>
Cc: Hugh Dickins <hughd@google.com>
Cc: Dave Hansen <dave.hansen@intel.com>
Cc: Theodore Ts'o <tytso@mit.edu>
Cc: "Paul E. McKenney" <paulmck@linux.vnet.ibm.com>
Cc: Oleg Nesterov <oleg@redhat.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Mel Gorman <mgorman@suse.de>
Signed-off-by: Jiri Slaby <jslaby@suse.cz>

Showing 1 changed file with 13 additions and 3 deletions Side-by-side Diff

... ... @@ -505,16 +505,26 @@
505 505 if (!pfn_valid_within(page_to_pfn(buddy)))
506 506 return 0;
507 507  
508   - if (page_zone_id(page) != page_zone_id(buddy))
509   - return 0;
510   -
511 508 if (page_is_guard(buddy) && page_order(buddy) == order) {
512 509 VM_BUG_ON(page_count(buddy) != 0);
  510 +
  511 + if (page_zone_id(page) != page_zone_id(buddy))
  512 + return 0;
  513 +
513 514 return 1;
514 515 }
515 516  
516 517 if (PageBuddy(buddy) && page_order(buddy) == order) {
517 518 VM_BUG_ON(page_count(buddy) != 0);
  519 +
  520 + /*
  521 + * zone check is done late to avoid uselessly
  522 + * calculating zone/node ids for pages that could
  523 + * never merge.
  524 + */
  525 + if (page_zone_id(page) != page_zone_id(buddy))
  526 + return 0;
  527 +
518 528 return 1;
519 529 }
520 530 return 0;