diff options
-rw-r--r-- | mm/page_alloc.c | 25 |
1 files changed, 10 insertions, 15 deletions
diff --git a/mm/page_alloc.c b/mm/page_alloc.c index 9dfe49bceff4..bda1db301d44 100644 --- a/mm/page_alloc.c +++ b/mm/page_alloc.c | |||
@@ -427,18 +427,10 @@ static inline void rmv_page_order(struct page *page) | |||
427 | * | 427 | * |
428 | * Assumption: *_mem_map is contiguous at least up to MAX_ORDER | 428 | * Assumption: *_mem_map is contiguous at least up to MAX_ORDER |
429 | */ | 429 | */ |
430 | static inline struct page * | ||
431 | __page_find_buddy(struct page *page, unsigned long page_idx, unsigned int order) | ||
432 | { | ||
433 | unsigned long buddy_idx = page_idx ^ (1 << order); | ||
434 | |||
435 | return page + (buddy_idx - page_idx); | ||
436 | } | ||
437 | |||
438 | static inline unsigned long | 430 | static inline unsigned long |
439 | __find_combined_index(unsigned long page_idx, unsigned int order) | 431 | __find_buddy_index(unsigned long page_idx, unsigned int order) |
440 | { | 432 | { |
441 | return (page_idx & ~(1 << order)); | 433 | return page_idx ^ (1 << order); |
442 | } | 434 | } |
443 | 435 | ||
444 | /* | 436 | /* |
@@ -500,6 +492,7 @@ static inline void __free_one_page(struct page *page, | |||
500 | { | 492 | { |
501 | unsigned long page_idx; | 493 | unsigned long page_idx; |
502 | unsigned long combined_idx; | 494 | unsigned long combined_idx; |
495 | unsigned long uninitialized_var(buddy_idx); | ||
503 | struct page *buddy; | 496 | struct page *buddy; |
504 | 497 | ||
505 | if (unlikely(PageCompound(page))) | 498 | if (unlikely(PageCompound(page))) |
@@ -514,7 +507,8 @@ static inline void __free_one_page(struct page *page, | |||
514 | VM_BUG_ON(bad_range(zone, page)); | 507 | VM_BUG_ON(bad_range(zone, page)); |
515 | 508 | ||
516 | while (order < MAX_ORDER-1) { | 509 | while (order < MAX_ORDER-1) { |
517 | buddy = __page_find_buddy(page, page_idx, order); | 510 | buddy_idx = __find_buddy_index(page_idx, order); |
511 | buddy = page + (buddy_idx - page_idx); | ||
518 | if (!page_is_buddy(page, buddy, order)) | 512 | if (!page_is_buddy(page, buddy, order)) |
519 | break; | 513 | break; |
520 | 514 | ||
@@ -522,7 +516,7 @@ static inline void __free_one_page(struct page *page, | |||
522 | list_del(&buddy->lru); | 516 | list_del(&buddy->lru); |
523 | zone->free_area[order].nr_free--; | 517 | zone->free_area[order].nr_free--; |
524 | rmv_page_order(buddy); | 518 | rmv_page_order(buddy); |
525 | combined_idx = __find_combined_index(page_idx, order); | 519 | combined_idx = buddy_idx & page_idx; |
526 | page = page + (combined_idx - page_idx); | 520 | page = page + (combined_idx - page_idx); |
527 | page_idx = combined_idx; | 521 | page_idx = combined_idx; |
528 | order++; | 522 | order++; |
@@ -539,9 +533,10 @@ static inline void __free_one_page(struct page *page, | |||
539 | */ | 533 | */ |
540 | if ((order < MAX_ORDER-2) && pfn_valid_within(page_to_pfn(buddy))) { | 534 | if ((order < MAX_ORDER-2) && pfn_valid_within(page_to_pfn(buddy))) { |
541 | struct page *higher_page, *higher_buddy; | 535 | struct page *higher_page, *higher_buddy; |
542 | combined_idx = __find_combined_index(page_idx, order); | 536 | combined_idx = buddy_idx & page_idx; |
543 | higher_page = page + combined_idx - page_idx; | 537 | higher_page = page + (combined_idx - page_idx); |
544 | higher_buddy = __page_find_buddy(higher_page, combined_idx, order + 1); | 538 | buddy_idx = __find_buddy_index(combined_idx, order + 1); |
539 | higher_buddy = page + (buddy_idx - combined_idx); | ||
545 | if (page_is_buddy(higher_page, higher_buddy, order + 1)) { | 540 | if (page_is_buddy(higher_page, higher_buddy, order + 1)) { |
546 | list_add_tail(&page->lru, | 541 | list_add_tail(&page->lru, |
547 | &zone->free_area[order].free_list[migratetype]); | 542 | &zone->free_area[order].free_list[migratetype]); |