Skip to contentSkip to conversation

mm : kill combined_idx

PATCH In review Huang Shijie 3 participants 4 messages Dec 21, 2009 – Dec 22, 2009

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 mm : kill combined_idx

In more then half of all the cases, `page' is head of the buddy pair {page, buddy} in __free_one_page. That is because the allocation logic always picks the head of a chunk, and puts the rest back to the buddy system.

So calculating the combined page is not needed but waste some cycles in more then half of all the cases.Just do the calculation when page' is bigger then the buddy'.

---
 mm/page_alloc.c |    8 ++++----
 1 files changed, 4 insertions(+), 4 deletions(-)
mm/page_alloc.c +4 -4
index 4e86965..42351bf 100644
@@ -464,7 +464,6 @@ static inline void __free_one_page(struct page *page,
 	VM_BUG_ON(bad_range(zone, page));
 
 	while (order < MAX_ORDER-1) {
-		unsigned long combined_idx;
 		struct page *buddy;
 
 		buddy = __page_find_buddy(page, page_idx, order);
@@ -475,9 +474,10 @@ static inline void __free_one_page(struct page *page,
 		list_del(&buddy->lru);
 		zone->free_area[order].nr_free--;
 		rmv_page_order(buddy);
-		combined_idx = __find_combined_index(page_idx, order);
-		page = page + (combined_idx - page_idx);
-		page_idx = combined_idx;
+		if (page > buddy) { /* keep `page' the head of the buddy pair */
+			page = buddy;
+			page_idx = __find_combined_index(page_idx, order);
+		}
 		order++;
 	}
 	set_page_order(page, order);
Signature · 7 lines
1.6.0.6

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected].  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
#1 lore raw
Quoted 9 lines · On Mon, 21 Dec 2009 11:32:27 +0800 Huang Shijie <[email protected]> wrote:

In more then half of all the cases, `page' is head of the buddy pair {page, buddy} in __free_one_page. That is because the allocation logic always picks the head of a chunk, and puts the rest back to the buddy system.

So calculating the combined page is not needed but waste some cycles in more then half of all the cases.Just do the calculation when page' is bigger then the buddy'.

Hmm...As far as I remember, this code design was for avoiding "if". Is this compare+jump is better than add+xor ?

Thanks,
-Kame

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

#2 lore raw
Quoted 7 lines · KAMEZAWA Hiroyuki
Quoted 4 lines · On Mon, 21 Dec 2009 11:32:27 +0800 Huang Shijie <[email protected]> wrote:

In more then half of all the cases, `page' is head of the buddy pair {page, buddy} in __free_one_page. That is because the allocation logic always picks the head of a chunk, and puts the rest back to the buddy system.

Quoted 9 lines
Quoted 5 lines

So calculating the combined page is not needed but waste some cycles in more then half of all the cases.Just do the calculation when page' is bigger then the buddy'.

Hmm...As far as I remember, this code design was for avoiding "if". Is this compare+jump is better than add+xor ?

Agreed. It's not clear that a compare+jump is cheaper than the add+xor. How often it's the case that the page is the higher or lower half of the buddy would depend heavily on the allocation/free pattern making it hard, if not possible, to predict which is the more common case.

Signature · 9 lines
Mel Gorman
Part-time Phd Student                          Linux Technology Center
University of Limerick                         IBM Dublin Software Lab

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected].  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
#3 lore raw
Quoted 6 lines
Quoted 5 lines

Hmm...As far as I remember, this code design was for avoiding "if". Is this compare+jump is better than add+xor ?

Quoted 6 lines

Agreed. It's not clear that a compare+jump is cheaper than the add+xor. How often it's the case that the page is the higher or lower half of the buddy would depend heavily on the allocation/free pattern making it hard, if not possible, to predict which is the more common case.

ok. thanks a lot.

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>