Skip to content

Commit 13ad59d

Browse files
tehcastertorvalds
authored andcommitted
mm, page_alloc: avoid page_to_pfn() when merging buddies
On architectures that allow memory holes, page_is_buddy() has to perform page_to_pfn() to check for the memory hole. After the previous patch, we have the pfn already available in __free_one_page(), which is the only caller of page_is_buddy(), so move the check there and avoid page_to_pfn(). Link: http://lkml.kernel.org/r/[email protected] Signed-off-by: Vlastimil Babka <[email protected]> Acked-by: Mel Gorman <[email protected]> Cc: Joonsoo Kim <[email protected]> Cc: Michal Hocko <[email protected]> Cc: "Kirill A. Shutemov" <[email protected]> Cc: Johannes Weiner <[email protected]> Signed-off-by: Andrew Morton <[email protected]> Signed-off-by: Linus Torvalds <[email protected]>
1 parent 76741e7 commit 13ad59d

File tree

2 files changed

+6
-6
lines changed

2 files changed

+6
-6
lines changed

mm/page_alloc.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -714,7 +714,7 @@ static inline void rmv_page_order(struct page *page)
714714
/*
715715
* This function checks whether a page is free && is the buddy
716716
* we can do coalesce a page and its buddy if
717-
* (a) the buddy is not in a hole &&
717+
* (a) the buddy is not in a hole (check before calling!) &&
718718
* (b) the buddy is in the buddy system &&
719719
* (c) a page and its buddy have the same order &&
720720
* (d) a page and its buddy are in the same zone.
@@ -729,9 +729,6 @@ static inline void rmv_page_order(struct page *page)
729729
static inline int page_is_buddy(struct page *page, struct page *buddy,
730730
unsigned int order)
731731
{
732-
if (!pfn_valid_within(page_to_pfn(buddy)))
733-
return 0;
734-
735732
if (page_is_guard(buddy) && page_order(buddy) == order) {
736733
if (page_zone_id(page) != page_zone_id(buddy))
737734
return 0;
@@ -808,6 +805,9 @@ static inline void __free_one_page(struct page *page,
808805
while (order < max_order - 1) {
809806
buddy_pfn = __find_buddy_pfn(pfn, order);
810807
buddy = page + (buddy_pfn - pfn);
808+
809+
if (!pfn_valid_within(buddy_pfn))
810+
goto done_merging;
811811
if (!page_is_buddy(page, buddy, order))
812812
goto done_merging;
813813
/*
@@ -862,7 +862,7 @@ static inline void __free_one_page(struct page *page,
862862
* so it's less likely to be used soon and more likely to be merged
863863
* as a higher order page
864864
*/
865-
if ((order < MAX_ORDER-2) && pfn_valid_within(page_to_pfn(buddy))) {
865+
if ((order < MAX_ORDER-2) && pfn_valid_within(buddy_pfn)) {
866866
struct page *higher_page, *higher_buddy;
867867
combined_pfn = buddy_pfn & pfn;
868868
higher_page = page + (combined_pfn - pfn);

mm/page_isolation.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ static void unset_migratetype_isolate(struct page *page, unsigned migratetype)
106106
buddy_pfn = __find_buddy_pfn(pfn, order);
107107
buddy = page + (buddy_pfn - pfn);
108108

109-
if (pfn_valid_within(page_to_pfn(buddy)) &&
109+
if (pfn_valid_within(buddy_pfn) &&
110110
!is_migrate_isolate_page(buddy)) {
111111
__isolate_free_page(page, order);
112112
isolated_page = true;

0 commit comments

Comments
 (0)