ia64/xen-unstable

changeset 10539:b4e328334392

[BALLOON] Add fallback code so that e.g. a domain ballooned too far down can still
(slowly) recover.

Signed-off-by: Jan Beulich <jbeulich@novell.com>
author kaf24@firebug.cl.cam.ac.uk
date Tue Jun 27 11:43:04 2006 +0100 (2006-06-27)
parents ab63f44d948e
children 7154e0416313
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	Tue Jun 27 11:35:29 2006 +0100
     1.2 +++ b/linux-2.6-xen-sparse/drivers/xen/balloon/balloon.c	Tue Jun 27 11:43:04 2006 +0100
     1.3 @@ -172,7 +172,7 @@ static unsigned long current_target(void
     1.4  
     1.5  static int increase_reservation(unsigned long nr_pages)
     1.6  {
     1.7 -	unsigned long *frame_list, pfn, i, flags;
     1.8 +	unsigned long *frame_list, frame, pfn, i, flags;
     1.9  	struct page   *page;
    1.10  	long           rc;
    1.11  	struct xen_memory_reservation reservation = {
    1.12 @@ -185,8 +185,11 @@ static int increase_reservation(unsigned
    1.13  		nr_pages = PAGE_SIZE / sizeof(unsigned long);
    1.14  
    1.15  	frame_list = (unsigned long *)__get_free_page(GFP_KERNEL);
    1.16 -	if (frame_list == NULL)
    1.17 -		return -ENOMEM;
    1.18 +	if (frame_list == NULL) {
    1.19 +		frame_list = &frame;
    1.20 +		if (nr_pages > 1)
    1.21 +			nr_pages = 1;
    1.22 +	}
    1.23  
    1.24  	balloon_lock(flags);
    1.25  
    1.26 @@ -202,14 +205,17 @@ static int increase_reservation(unsigned
    1.27  	rc = HYPERVISOR_memory_op(
    1.28  		XENMEM_populate_physmap, &reservation);
    1.29  	if (rc < nr_pages) {
    1.30 -		int ret;
    1.31 -		/* We hit the Xen hard limit: reprobe. */
    1.32 -		set_xen_guest_handle(reservation.extent_start, frame_list);
    1.33 -		reservation.nr_extents   = rc;
    1.34 -		ret = HYPERVISOR_memory_op(XENMEM_decrease_reservation,
    1.35 -				&reservation);
    1.36 -		BUG_ON(ret != rc);
    1.37 -		hard_limit = current_pages + rc - driver_pages;
    1.38 +		if (rc > 0) {
    1.39 +			int ret;
    1.40 +
    1.41 +			/* We hit the Xen hard limit: reprobe. */
    1.42 +			reservation.nr_extents = rc;
    1.43 +			ret = HYPERVISOR_memory_op(XENMEM_decrease_reservation,
    1.44 +					&reservation);
    1.45 +			BUG_ON(ret != rc);
    1.46 +		}
    1.47 +		if (rc >= 0)
    1.48 +			hard_limit = current_pages + rc - driver_pages;
    1.49  		goto out;
    1.50  	}
    1.51  
    1.52 @@ -247,14 +253,15 @@ static int increase_reservation(unsigned
    1.53   out:
    1.54  	balloon_unlock(flags);
    1.55  
    1.56 -	free_page((unsigned long)frame_list);
    1.57 +	if (frame_list != &frame)
    1.58 +		free_page((unsigned long)frame_list);
    1.59  
    1.60  	return 0;
    1.61  }
    1.62  
    1.63  static int decrease_reservation(unsigned long nr_pages)
    1.64  {
    1.65 -	unsigned long *frame_list, pfn, i, flags;
    1.66 +	unsigned long *frame_list, frame, pfn, i, flags;
    1.67  	struct page   *page;
    1.68  	void          *v;
    1.69  	int            need_sleep = 0;
    1.70 @@ -269,8 +276,11 @@ static int decrease_reservation(unsigned
    1.71  		nr_pages = PAGE_SIZE / sizeof(unsigned long);
    1.72  
    1.73  	frame_list = (unsigned long *)__get_free_page(GFP_KERNEL);
    1.74 -	if (frame_list == NULL)
    1.75 -		return -ENOMEM;
    1.76 +	if (frame_list == NULL) {
    1.77 +		frame_list = &frame;
    1.78 +		if (nr_pages > 1)
    1.79 +			nr_pages = 1;
    1.80 +	}
    1.81  
    1.82  	for (i = 0; i < nr_pages; i++) {
    1.83  		if ((page = alloc_page(GFP_HIGHUSER)) == NULL) {
    1.84 @@ -321,7 +331,8 @@ static int decrease_reservation(unsigned
    1.85  
    1.86  	balloon_unlock(flags);
    1.87  
    1.88 -	free_page((unsigned long)frame_list);
    1.89 +	if (frame_list != &frame)
    1.90 +		free_page((unsigned long)frame_list);
    1.91  
    1.92  	return need_sleep;
    1.93  }