From: Dan Magenheimer Subject: RE: linux: try harder to balloon up under memory pressure. Date: Fri, 5 Jun 2009 07:30:26 -0700 (PDT) Message-ID: References: <1244199426.27370.158.camel@zakaz.uk.xensource.com> Mime-Version: 1.0 Content-Type: text/plain; charset=Windows-1252 Content-Transfer-Encoding: quoted-printable Return-path: In-Reply-To: <1244199426.27370.158.camel@zakaz.uk.xensource.com> List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xensource.com Errors-To: xen-devel-bounces@lists.xensource.com To: Ian Campbell , xen-devel Cc: Jeremy Fitzhardinge , Keir Fraser List-Id: xen-devel@lists.xenproject.org Excellent! I think this explains a weirdness I saw a year ago when working on self-ballooning, and also a problem I saw under certain conditions for tmem, that I had communicated offline to Jeremy last month (because I was looking at the pvops driver at the time) but never got around to understanding in detail. Suggestion: Perhaps the balloon_timer interval should be configurable via sysfs? > -----Original Message----- > From: Ian Campbell [mailto:Ian.Campbell@eu.citrix.com] > Sent: Friday, June 05, 2009 4:57 AM > To: xen-devel > Cc: Keir Fraser > Subject: [Xen-devel] linux: try harder to balloon up under memory > pressure. >=20 >=20 > 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). >=20 > 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. >=20 > 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. >=20 > 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. >=20 > This patch is for the 2.6.18-xen tree. >=20 > Signed-off-by: Ian Campbell >=20 > diff -r fd9c565657b8 drivers/xen/balloon/balloon.c > --- a/drivers/xen/balloon/balloon.c=09Thu Jun 04 16:26:49 2009 +0100 > +++ b/drivers/xen/balloon/balloon.c=09Fri Jun 05 11:56:22 2009 +0100 > @@ -188,7 +188,7 @@ > =20 > static unsigned long current_target(void) > { > -=09unsigned long target =3D min(bs.target_pages, bs.hard_limit); > +=09unsigned long target =3D bs.target_pages; > =09if (target > (bs.current_pages + bs.balloon_low +=20 > bs.balloon_high)) > =09=09target =3D bs.current_pages + bs.balloon_low +=20 > bs.balloon_high; > =09return target; > @@ -255,26 +255,12 @@ > =09} > =20 > =09set_xen_guest_handle(reservation.extent_start, frame_list); > -=09reservation.nr_extents =3D nr_pages; > -=09rc =3D HYPERVISOR_memory_op( > -=09=09XENMEM_populate_physmap, &reservation); > -=09if (rc < nr_pages) { > -=09=09if (rc > 0) { > -=09=09=09int ret; > +=09reservation.nr_extents =3D nr_pages; > +=09rc =3D HYPERVISOR_memory_op(XENMEM_populate_physmap,=20 > &reservation); > +=09if (rc < 0) > +=09=09goto out; > =20 > -=09=09=09/* We hit the Xen hard limit: reprobe. */ > -=09=09=09reservation.nr_extents =3D rc; > -=09=09=09ret =3D=20 > HYPERVISOR_memory_op(XENMEM_decrease_reservation, > -=09=09=09=09=09&reservation); > -=09=09=09BUG_ON(ret !=3D rc); > -=09=09} > -=09=09if (rc >=3D 0) > -=09=09=09bs.hard_limit =3D (bs.current_pages + rc - > -=09=09=09=09=09 bs.driver_pages); > -=09=09goto out; > -=09} > - > -=09for (i =3D 0; i < nr_pages; i++) { > +=09for (i =3D 0; i < rc; i++) { > =09=09page =3D balloon_retrieve(); > =09=09BUG_ON(page =3D=3D NULL); > =20 > @@ -302,13 +288,13 @@ > =09=09balloon_free_page(page); > =09} > =20 > -=09bs.current_pages +=3D nr_pages; > +=09bs.current_pages +=3D rc; > =09totalram_pages =3D bs.current_pages; > =20 > out: > =09balloon_unlock(flags); > =20 > -=09return 0; > +=09return rc < 0 ? rc : rc !=3D nr_pages; > } > =20 > static int decrease_reservation(unsigned long nr_pages) > @@ -420,7 +406,6 @@ > void balloon_set_new_target(unsigned long target) > { > =09/* No need for lock. Not read-modify-write updates. */ > -=09bs.hard_limit =3D ~0UL; > =09bs.target_pages =3D max(target, minimum_target()); > =09schedule_work(&balloon_worker); > } > @@ -498,17 +483,11 @@ > =09=09"Requested target: %8lu kB\n" > =09=09"Low-mem balloon: %8lu kB\n" > =09=09"High-mem balloon: %8lu kB\n" > -=09=09"Driver pages: %8lu kB\n" > -=09=09"Xen hard limit: ", > +=09=09"Driver pages: %8lu kB\n", > =09=09PAGES2KB(bs.current_pages), PAGES2KB(bs.target_pages),=20 > =09=09PAGES2KB(bs.balloon_low), PAGES2KB(bs.balloon_high), > =09=09PAGES2KB(bs.driver_pages)); > =20 > -=09if (bs.hard_limit !=3D ~0UL) > -=09=09len +=3D sprintf(page + len, "%8lu kB\n", > -=09=09=09 PAGES2KB(bs.hard_limit)); > -=09else > -=09=09len +=3D sprintf(page + len, " ??? kB\n"); > =20 > =09*eof =3D 1; > =09return len; > @@ -539,7 +518,6 @@ > =09bs.balloon_low =3D 0; > =09bs.balloon_high =3D 0; > =09bs.driver_pages =3D 0UL; > -=09bs.hard_limit =3D ~0UL; > =20 > =09init_timer(&balloon_timer); > =09balloon_timer.data =3D 0; > diff -r fd9c565657b8 drivers/xen/balloon/common.h > --- a/drivers/xen/balloon/common.h=09Thu Jun 04 16:26:49 2009 +0100 > +++ b/drivers/xen/balloon/common.h=09Fri Jun 05 11:56:22 2009 +0100 > @@ -35,8 +35,6 @@ > =09/* We aim for 'current allocation' =3D=3D 'target allocation'. */ > =09unsigned long current_pages; > =09unsigned long target_pages; > -=09/* We may hit the hard limit in Xen. If we do then we=20 > remember it. */ > -=09unsigned long hard_limit; > =09/* > =09 * Drivers may alter the memory reservation=20 > independently, but they > =09 * must inform the balloon driver so we avoid hitting=20 > the hard limit. > diff -r fd9c565657b8 drivers/xen/balloon/sysfs.c > --- a/drivers/xen/balloon/sysfs.c=09Thu Jun 04 16:26:49 2009 +0100 > +++ b/drivers/xen/balloon/sysfs.c=09Fri Jun 05 11:56:22 2009 +0100 > @@ -53,9 +53,6 @@ > BALLOON_SHOW(current_kb, "%lu\n", PAGES2KB(bs.current_pages)); > BALLOON_SHOW(low_kb, "%lu\n", PAGES2KB(bs.balloon_low)); > BALLOON_SHOW(high_kb, "%lu\n", PAGES2KB(bs.balloon_high)); > -BALLOON_SHOW(hard_limit_kb, > -=09 (bs.hard_limit!=3D~0UL) ? "%lu\n" : "???\n", > -=09 (bs.hard_limit!=3D~0UL) ? PAGES2KB(bs.hard_limit) : 0); > BALLOON_SHOW(driver_kb, "%lu\n", PAGES2KB(bs.driver_pages)); > =20 > static ssize_t show_target_kb(struct sys_device *dev, char *buf) > @@ -96,7 +93,6 @@ > =09&attr_current_kb.attr, > =09&attr_low_kb.attr, > =09&attr_high_kb.attr, > -=09&attr_hard_limit_kb.attr, > =09&attr_driver_kb.attr, > =09NULL > }; >=20 >=20 >=20 > _______________________________________________ > Xen-devel mailing list > Xen-devel@lists.xensource.com > http://lists.xensource.com/xen-devel >