ia64/xen-unstable

changeset 10590:9b35fada9e65

Use a static page for the frame_list in the balloon driver.
Simplifies code and robustifies against oom situations.

Signed-off-by: Steven Hand <steven@xensource.com>
author shand@kneesaa.uk.xensource.com
date Thu Jun 29 11:17:24 2006 +0100 (2006-06-29)
parents cb9443bfdff8
children 3d40e2f509fc
files linux-2.6-xen-sparse/drivers/xen/balloon/balloon.c
line diff
     1.1 --- a/linux-2.6-xen-sparse/drivers/xen/balloon/balloon.c	Thu Jun 29 10:48:07 2006 +0100
     1.2 +++ b/linux-2.6-xen-sparse/drivers/xen/balloon/balloon.c	Thu Jun 29 11:17:24 2006 +0100
     1.3 @@ -75,6 +75,9 @@ DEFINE_SPINLOCK(balloon_lock);
     1.4  static unsigned long current_pages;
     1.5  static unsigned long target_pages;
     1.6  
     1.7 +/* We increase/decrease in batches which fit in a page */
     1.8 +static unsigned long frame_list[PAGE_SIZE / sizeof(unsigned long)]; 
     1.9 +
    1.10  /* VM /proc information for memory */
    1.11  extern unsigned long totalram_pages;
    1.12  
    1.13 @@ -172,7 +175,7 @@ static unsigned long current_target(void
    1.14  
    1.15  static int increase_reservation(unsigned long nr_pages)
    1.16  {
    1.17 -	unsigned long *frame_list, frame, pfn, i, flags;
    1.18 +	unsigned long  pfn, i, flags;
    1.19  	struct page   *page;
    1.20  	long           rc;
    1.21  	struct xen_memory_reservation reservation = {
    1.22 @@ -181,15 +184,8 @@ static int increase_reservation(unsigned
    1.23  		.domid        = DOMID_SELF
    1.24  	};
    1.25  
    1.26 -	if (nr_pages > (PAGE_SIZE / sizeof(unsigned long)))
    1.27 -		nr_pages = PAGE_SIZE / sizeof(unsigned long);
    1.28 -
    1.29 -	frame_list = (unsigned long *)__get_free_page(GFP_KERNEL);
    1.30 -	if (frame_list == NULL) {
    1.31 -		frame_list = &frame;
    1.32 -		if (nr_pages > 1)
    1.33 -			nr_pages = 1;
    1.34 -	}
    1.35 +	if (nr_pages > ARRAY_SIZE(frame_list))
    1.36 +		nr_pages = ARRAY_SIZE(frame_list);
    1.37  
    1.38  	balloon_lock(flags);
    1.39  
    1.40 @@ -253,15 +249,12 @@ static int increase_reservation(unsigned
    1.41   out:
    1.42  	balloon_unlock(flags);
    1.43  
    1.44 -	if (frame_list != &frame)
    1.45 -		free_page((unsigned long)frame_list);
    1.46 -
    1.47  	return 0;
    1.48  }
    1.49  
    1.50  static int decrease_reservation(unsigned long nr_pages)
    1.51  {
    1.52 -	unsigned long *frame_list, frame, pfn, i, flags;
    1.53 +	unsigned long  pfn, i, flags;
    1.54  	struct page   *page;
    1.55  	void          *v;
    1.56  	int            need_sleep = 0;
    1.57 @@ -272,15 +265,8 @@ static int decrease_reservation(unsigned
    1.58  		.domid        = DOMID_SELF
    1.59  	};
    1.60  
    1.61 -	if (nr_pages > (PAGE_SIZE / sizeof(unsigned long)))
    1.62 -		nr_pages = PAGE_SIZE / sizeof(unsigned long);
    1.63 -
    1.64 -	frame_list = (unsigned long *)__get_free_page(GFP_KERNEL);
    1.65 -	if (frame_list == NULL) {
    1.66 -		frame_list = &frame;
    1.67 -		if (nr_pages > 1)
    1.68 -			nr_pages = 1;
    1.69 -	}
    1.70 +	if (nr_pages > ARRAY_SIZE(frame_list))
    1.71 +		nr_pages = ARRAY_SIZE(frame_list);
    1.72  
    1.73  	for (i = 0; i < nr_pages; i++) {
    1.74  		if ((page = alloc_page(GFP_HIGHUSER)) == NULL) {
    1.75 @@ -331,9 +317,6 @@ static int decrease_reservation(unsigned
    1.76  
    1.77  	balloon_unlock(flags);
    1.78  
    1.79 -	if (frame_list != &frame)
    1.80 -		free_page((unsigned long)frame_list);
    1.81 -
    1.82  	return need_sleep;
    1.83  }
    1.84