aboutsummaryrefslogtreecommitdiffstats
path: root/mm/page_alloc.c
diff options
context:
space:
mode:
authorKyongHo Cho <pullip.cho@samsung.com>2011-01-13 18:47:24 -0500
committerLinus Torvalds <torvalds@linux-foundation.org>2011-01-13 20:32:48 -0500
commit43506fad21ca3d8dc59e768ff458f7c5e5c01086 (patch)
treeb594f240a780e3547341530fedabb6ac4735ff41 /mm/page_alloc.c
parent5520e89485252c759ee60d313e9422447659947b (diff)
mm/page_alloc.c: simplify calculation of combined index of adjacent buddy lists
The previous approach of calucation of combined index was page_idx & ~(1 << order)) but we have same result with page_idx & buddy_idx This reduces instructions slightly as well as enhances readability. [akpm@linux-foundation.org: coding-style fixes] [akpm@linux-foundation.org: fix used-unintialised warning] Signed-off-by: KyongHo Cho <pullip.cho@samsung.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'mm/page_alloc.c')
-rw-r--r--mm/page_alloc.c25
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 */
430static 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
438static inline unsigned long 430static 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]);