Skip to contentSkip to conversation

linux/balloon: prefer using pages from balloon in alloc_empty_pages_and_pagevec()

PATCH In review Jan Beulich 2 participants 7 messages Dec 16, 2009 – Dec 18, 2009 Xen hypervisor interface

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 linux/balloon: prefer using pages from balloon in alloc_empty_pages_and_pagevec()

This is both faster and less demanding on kernel resources.

Likely also something that could be done in the pv-ops tree (though it would need some adjustment to deal with the balloon_order!=0 case).

drivers/xen/balloon/balloon.c +11 -0
@@ -607,6 +607,17 @@ struct page **alloc_empty_pages_and_page
 		return NULL;
 
 	for (i = 0; i < nr_pages; i++) {
+		balloon_lock(flags);
+		page = balloon_first_page();
+		if (page && !PageHighMem(page)) {
+			UNLIST_PAGE(page);
+			bs.balloon_low--;
+			balloon_unlock(flags);
+			pagevec[i] = page;
+			continue;
+		}
+		balloon_unlock(flags);
+
 		page = pagevec[i] = alloc_page(GFP_KERNEL|__GFP_COLD);
 		if (page == NULL)
 			goto err;
#1 lore raw
Quoted 3 lines
Quoted 1 line
Quoted 1 line

"Jan Beulich" <[email protected]> 16.12.09 16:13 >>>

Likely also something that could be done in the pv-ops tree (though it would need some adjustment to deal with the balloon_order!=0 case).

... which seems to be broken at present anyway: The main loops in {alloc,free}_empty_pages_and_pagevec() both did not get their upper bound updated correctly (should be npages, but was left to be nr_pages), for alloc_empty_pages_and_pagevec() the wrong value is also being used to allocate pagevec[] (though I really think that this shouldn't allocate more than a nr_pages vector to avoid a rather large but unnecessary kmalloc() when nr_pages is small), and in its error path only a single page gets freed (rather than the whole balloon_order chunk).

Jan

#2 lore raw
Quoted 9 lines · Jan Beulich

... which seems to be broken at present anyway: The main loops in {alloc,free}_empty_pages_and_pagevec() both did not get their upper bound updated correctly (should be npages, but was left to be nr_pages), for alloc_empty_pages_and_pagevec() the wrong value is also being used to allocate pagevec[] (though I really think that this shouldn't allocate more than a nr_pages vector to avoid a rather large but unnecessary kmalloc() when nr_pages is small), and in its error path only a single page gets freed (rather than the whole balloon_order chunk).

You are correct. The endpoint of the main loops should be npages, as should the variable used in the kmalloc().

I could only allocate the pagevec to be nr_pages and just fill it in with the partial order 9 page rather than rounding it up. I'll ponder that.

I don't see anything wrong with the error path. It correctly walks back down the pagevec and frees all the pages it's allocated so far.

Dave McCracken
Oracle Corp.

#3 lore raw
Quoted 3 lines
Quoted 1 line
Quoted 1 line

Dave McCracken <[email protected]> 17.12.09 21:33 >>>

I don't see anything wrong with the error path. It correctly walks back down the pagevec and frees all the pages it's allocated so far.

Oh, you're probably looking at the code past the err: label, but I was referring to the handling of a failed apply_to_page_range().

Jan

#4 lore raw
Quoted 7 lines · Jan Beulich
Quoted 4 lines
Quoted 1 line
Quoted 1 line

Dave McCracken <[email protected]> 17.12.09 21:33 >>>

I don't see anything wrong with the error path. It correctly walks back down the pagevec and frees all the pages it's allocated so far.

Oh, you're probably looking at the code past the err: label, but I was referring to the handling of a failed apply_to_page_range().

Ok, yeah. It frees up the page that's currently being worked on, then jumps to err: to clean up all the other pages in the pagevec and free the pagevec. Is there something wrong about it that I'm missing?

Dave McCracken
Oracle Corp

#5 lore raw
Quoted 7 lines
Quoted 1 line
Quoted 1 line

Dave McCracken <[email protected]> 18.12.09 15:32 >>>

Quoted 5 lines · Jan Beulich
Quoted 4 lines
Quoted 1 line
Quoted 1 line

Dave McCracken <[email protected]> 17.12.09 21:33 >>>

I don't see anything wrong with the error path. It correctly walks back down the pagevec and frees all the pages it's allocated so far.

Quoted 6 lines
Quoted 2 lines

Oh, you're probably looking at the code past the err: label, but I was referring to the handling of a failed apply_to_page_range().

Ok, yeah. It frees up the page that's currently being worked on, then jumps to err: to clean up all the other pages in the pagevec and free the pagevec. Is there something wrong about it that I'm missing?

It should __free_pages(..., order) rather than __free_page(...).

Jan

#6 lore raw
Quoted 5 lines · Jan Beulich
Quoted 3 lines

Ok, yeah. It frees up the page that's currently being worked on, then jumps to err: to clean up all the other pages in the pagevec and free the pagevec. Is there something wrong about it that I'm missing?

It should __free_pages(..., order) rather than __free_page(...).

Gah, you're right. Of course. Sorry. I'll add that fix to my patch.

Dave McCracken