ia64/linux-2.6.18-xen.hg

changeset 897:329ea0ccb344

balloon: try harder to balloon up under memory pressure.

Currently if the balloon driver is unable to increase the guest's
reservation it assumes the failure was due to reaching its full
allocation, gives up on the ballooning operation and records the limit
it reached as the "hard limit". The driver will not try again until
the target is set again (even to the same value).

However it is possible that ballooning has in fact failed due to
memory pressure in the host and therefore it is desirable to keep
attempting to reach the target in case memory becomes available. The
most likely scenario is that some guests are ballooning down while
others are ballooning up and therefore there is temporary memory
pressure while things stabilise. You would not expect a well behaved
toolstack to ask a domain to balloon to more than its allocation nor
would you expect it to deliberately over-commit memory by setting
balloon targets which exceed the total host memory.

This patch drops the concept of a hard limit and causes the balloon
driver to retry increasing the reservation on a timer in the same
manner as when decreasing the reservation.

Also if we partially succeed in increasing the reservation
(i.e. receive less pages than we asked for) then we may as well keep
those pages rather than returning them to Xen.

Signed-off-by: Ian Campbell <ian.campbell@citrix.com>
author Keir Fraser <keir.fraser@citrix.com>
date Fri Jun 05 14:01:20 2009 +0100 (2009-06-05)
parents f59c5daed527
children ca12928cdafe
files drivers/xen/balloon/balloon.c drivers/xen/balloon/common.h drivers/xen/balloon/sysfs.c
line diff
     1.1 --- a/drivers/xen/balloon/balloon.c	Thu Jun 04 10:46:54 2009 +0100
     1.2 +++ b/drivers/xen/balloon/balloon.c	Fri Jun 05 14:01:20 2009 +0100
     1.3 @@ -188,7 +188,7 @@ static void balloon_alarm(unsigned long 
     1.4  
     1.5  static unsigned long current_target(void)
     1.6  {
     1.7 -	unsigned long target = min(bs.target_pages, bs.hard_limit);
     1.8 +	unsigned long target = bs.target_pages;
     1.9  	if (target > (bs.current_pages + bs.balloon_low + bs.balloon_high))
    1.10  		target = bs.current_pages + bs.balloon_low + bs.balloon_high;
    1.11  	return target;
    1.12 @@ -255,26 +255,12 @@ static int increase_reservation(unsigned
    1.13  	}
    1.14  
    1.15  	set_xen_guest_handle(reservation.extent_start, frame_list);
    1.16 -	reservation.nr_extents   = nr_pages;
    1.17 -	rc = HYPERVISOR_memory_op(
    1.18 -		XENMEM_populate_physmap, &reservation);
    1.19 -	if (rc < nr_pages) {
    1.20 -		if (rc > 0) {
    1.21 -			int ret;
    1.22 +	reservation.nr_extents = nr_pages;
    1.23 +	rc = HYPERVISOR_memory_op(XENMEM_populate_physmap, &reservation);
    1.24 +	if (rc < 0)
    1.25 +		goto out;
    1.26  
    1.27 -			/* We hit the Xen hard limit: reprobe. */
    1.28 -			reservation.nr_extents = rc;
    1.29 -			ret = HYPERVISOR_memory_op(XENMEM_decrease_reservation,
    1.30 -					&reservation);
    1.31 -			BUG_ON(ret != rc);
    1.32 -		}
    1.33 -		if (rc >= 0)
    1.34 -			bs.hard_limit = (bs.current_pages + rc -
    1.35 -					 bs.driver_pages);
    1.36 -		goto out;
    1.37 -	}
    1.38 -
    1.39 -	for (i = 0; i < nr_pages; i++) {
    1.40 +	for (i = 0; i < rc; i++) {
    1.41  		page = balloon_retrieve();
    1.42  		BUG_ON(page == NULL);
    1.43  
    1.44 @@ -302,13 +288,13 @@ static int increase_reservation(unsigned
    1.45  		balloon_free_page(page);
    1.46  	}
    1.47  
    1.48 -	bs.current_pages += nr_pages;
    1.49 +	bs.current_pages += rc;
    1.50  	totalram_pages = bs.current_pages;
    1.51  
    1.52   out:
    1.53  	balloon_unlock(flags);
    1.54  
    1.55 -	return 0;
    1.56 +	return rc < 0 ? rc : rc != nr_pages;
    1.57  }
    1.58  
    1.59  static int decrease_reservation(unsigned long nr_pages)
    1.60 @@ -420,7 +406,6 @@ static void balloon_process(void *unused
    1.61  void balloon_set_new_target(unsigned long target)
    1.62  {
    1.63  	/* No need for lock. Not read-modify-write updates. */
    1.64 -	bs.hard_limit   = ~0UL;
    1.65  	bs.target_pages = max(target, minimum_target());
    1.66  	schedule_work(&balloon_worker);
    1.67  }
    1.68 @@ -498,17 +483,11 @@ static int balloon_read(char *page, char
    1.69  		"Requested target:   %8lu kB\n"
    1.70  		"Low-mem balloon:    %8lu kB\n"
    1.71  		"High-mem balloon:   %8lu kB\n"
    1.72 -		"Driver pages:       %8lu kB\n"
    1.73 -		"Xen hard limit:     ",
    1.74 +		"Driver pages:       %8lu kB\n",
    1.75  		PAGES2KB(bs.current_pages), PAGES2KB(bs.target_pages), 
    1.76  		PAGES2KB(bs.balloon_low), PAGES2KB(bs.balloon_high),
    1.77  		PAGES2KB(bs.driver_pages));
    1.78  
    1.79 -	if (bs.hard_limit != ~0UL)
    1.80 -		len += sprintf(page + len, "%8lu kB\n",
    1.81 -			       PAGES2KB(bs.hard_limit));
    1.82 -	else
    1.83 -		len += sprintf(page + len, "     ??? kB\n");
    1.84  
    1.85  	*eof = 1;
    1.86  	return len;
    1.87 @@ -539,7 +518,6 @@ static int __init balloon_init(void)
    1.88  	bs.balloon_low   = 0;
    1.89  	bs.balloon_high  = 0;
    1.90  	bs.driver_pages  = 0UL;
    1.91 -	bs.hard_limit    = ~0UL;
    1.92  
    1.93  	init_timer(&balloon_timer);
    1.94  	balloon_timer.data = 0;
     2.1 --- a/drivers/xen/balloon/common.h	Thu Jun 04 10:46:54 2009 +0100
     2.2 +++ b/drivers/xen/balloon/common.h	Fri Jun 05 14:01:20 2009 +0100
     2.3 @@ -35,8 +35,6 @@ struct balloon_stats {
     2.4  	/* We aim for 'current allocation' == 'target allocation'. */
     2.5  	unsigned long current_pages;
     2.6  	unsigned long target_pages;
     2.7 -	/* We may hit the hard limit in Xen. If we do then we remember it. */
     2.8 -	unsigned long hard_limit;
     2.9  	/*
    2.10  	 * Drivers may alter the memory reservation independently, but they
    2.11  	 * must inform the balloon driver so we avoid hitting the hard limit.
     3.1 --- a/drivers/xen/balloon/sysfs.c	Thu Jun 04 10:46:54 2009 +0100
     3.2 +++ b/drivers/xen/balloon/sysfs.c	Fri Jun 05 14:01:20 2009 +0100
     3.3 @@ -53,9 +53,6 @@
     3.4  BALLOON_SHOW(current_kb, "%lu\n", PAGES2KB(bs.current_pages));
     3.5  BALLOON_SHOW(low_kb, "%lu\n", PAGES2KB(bs.balloon_low));
     3.6  BALLOON_SHOW(high_kb, "%lu\n", PAGES2KB(bs.balloon_high));
     3.7 -BALLOON_SHOW(hard_limit_kb,
     3.8 -	     (bs.hard_limit!=~0UL) ? "%lu\n" : "???\n",
     3.9 -	     (bs.hard_limit!=~0UL) ? PAGES2KB(bs.hard_limit) : 0);
    3.10  BALLOON_SHOW(driver_kb, "%lu\n", PAGES2KB(bs.driver_pages));
    3.11  
    3.12  static ssize_t show_target_kb(struct sys_device *dev, char *buf)
    3.13 @@ -96,7 +93,6 @@ static struct attribute *balloon_info_at
    3.14  	&attr_current_kb.attr,
    3.15  	&attr_low_kb.attr,
    3.16  	&attr_high_kb.attr,
    3.17 -	&attr_hard_limit_kb.attr,
    3.18  	&attr_driver_kb.attr,
    3.19  	NULL
    3.20  };