From: "Jan Beulich" Subject: [PATCH] linux/balloon: fix accounting for HVM-with-PoD case Date: Mon, 01 Feb 2010 12:52:30 +0000 Message-ID: <4B66DC9E020000780002CF6A@vpn.id2.novell.com> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=__Part153F359E.0__=" Return-path: List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xensource.com Errors-To: xen-devel-bounces@lists.xensource.com To: xen-devel@lists.xensource.com List-Id: xen-devel@lists.xenproject.org This is a MIME message. If you are reading this text, you may want to consider changing to a mail reader or gateway that understands how to properly handle MIME multipart messages. --=__Part153F359E.0__= Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: quoted-printable Content-Disposition: inline With PoD, ballooning down a guest to the target set through xenstore based on its totalram_pages value isn't sufficient, since that value doesn't include all the pages assigned to the guest. Since the delta is static, determine it once at load time. Signed-off-by: Jan Beulich --- sle11-2010-01-12.orig/drivers/xen/balloon/balloon.c 2009-08-31 = 11:48:33.000000000 +0200 +++ sle11-2010-01-12/drivers/xen/balloon/balloon.c 2010-02-01 = 13:35:47.000000000 +0100 @@ -90,6 +90,18 @@ static unsigned long frame_list[PAGE_SIZ #define dec_totalhigh_pages() ((void)0) #endif =20 +#ifndef CONFIG_XEN +/* + * In HVM guests accounting here uses the Xen visible values, but the = kernel + * determined totalram_pages value shouldn't get altered. Since totalram_p= ages + * includes neither the kernel static image nor any memory allocated = prior to + * or from the bootmem allocator, we have to synchronize the two values. + */ +static unsigned long __read_mostly totalram_bias; +#else +#define totalram_bias 0 +#endif + /* List of ballooned pages, threaded through the mem_map array. */ static LIST_HEAD(ballooned_pages); =20 @@ -305,7 +317,7 @@ static int increase_reservation(unsigned } =20 bs.current_pages +=3D rc; - totalram_pages =3D bs.current_pages; + totalram_pages =3D bs.current_pages - totalram_bias; =20 out: balloon_unlock(flags); @@ -385,7 +397,7 @@ static int decrease_reservation(unsigned BUG_ON(ret !=3D nr_pages); =20 bs.current_pages -=3D nr_pages; - totalram_pages =3D bs.current_pages; + totalram_pages =3D bs.current_pages - totalram_bias; =20 balloon_unlock(flags); =20 @@ -524,7 +536,19 @@ static struct notifier_block xenstore_no =20 static int __init balloon_init(void) { -#if defined(CONFIG_X86) && defined(CONFIG_XEN)=20 +#if !defined(CONFIG_XEN) +# ifndef XENMEM_get_pod_target +# define XENMEM_get_pod_target 17 + typedef struct xen_pod_target { + uint64_t target_pages; + uint64_t tot_pages; + uint64_t pod_cache_pages; + uint64_t pod_entries; + domid_t domid; + } xen_pod_target_t; +# endif + xen_pod_target_t pod_target =3D { .domid =3D DOMID_SELF }; +#elif defined(CONFIG_X86) unsigned long pfn; struct page *page; #endif @@ -538,7 +562,20 @@ static int __init balloon_init(void) bs.current_pages =3D min(xen_start_info->nr_pages, max_pfn); totalram_pages =3D bs.current_pages; #else=20 - bs.current_pages =3D totalram_pages;=20 + totalram_bias =3D HYPERVISOR_memory_op( + HYPERVISOR_memory_op(XENMEM_get_pod_target, + &pod_target) !=3D -ENOSYS + ? XENMEM_maximum_reservation + : XENMEM_current_reservation, + &pod_target.domid); + if ((long)totalram_bias !=3D -ENOSYS) { + BUG_ON(totalram_bias < totalram_pages); + bs.current_pages =3D totalram_bias; + totalram_bias -=3D totalram_pages; + } else { + totalram_bias =3D 0; + bs.current_pages =3D totalram_pages; + } #endif bs.target_pages =3D bs.current_pages; bs.balloon_low =3D 0; @@ -671,7 +708,7 @@ struct page **alloc_empty_pages_and_page goto err; } =20 - totalram_pages =3D --bs.current_pages; + totalram_pages =3D --bs.current_pages - totalram_bias; =20 balloon_unlock(flags); } --=__Part153F359E.0__= Content-Type: text/plain; name="xenlinux-balloon-hvm-bias.patch" Content-Transfer-Encoding: quoted-printable Content-Disposition: attachment; filename="xenlinux-balloon-hvm-bias.patch" Subject: fix balloon driver accounting for HVM-with-PoD case=0A=0AWith = PoD, ballooning down a guest to the target set through xenstore=0Abased on = its totalram_pages value isn't sufficient, since that value=0Adoesn't = include all the pages assigned to the guest. Since the delta=0Ais static, = determine it once at load time.=0A=0ASigned-off-by: Jan Beulich =0A=0A--- sle11-2010-01-12.orig/drivers/xen/balloon/balloon.c = 2009-08-31 11:48:33.000000000 +0200=0A+++ sle11-2010-01-12/drivers/xen/ball= oon/balloon.c 2010-02-01 13:35:47.000000000 +0100=0A@@ -90,6 +90,18 @@ = static unsigned long frame_list[PAGE_SIZ=0A #define dec_totalhigh_pages() = ((void)0)=0A #endif=0A =0A+#ifndef CONFIG_XEN=0A+/*=0A+ * In HVM guests = accounting here uses the Xen visible values, but the kernel=0A+ * = determined totalram_pages value shouldn't get altered. Since totalram_pages= =0A+ * includes neither the kernel static image nor any memory allocated = prior to=0A+ * or from the bootmem allocator, we have to synchronize the = two values.=0A+ */=0A+static unsigned long __read_mostly totalram_bias;=0A+= #else=0A+#define totalram_bias 0=0A+#endif=0A+=0A /* List of ballooned = pages, threaded through the mem_map array. */=0A static LIST_HEAD(ballooned= _pages);=0A =0A@@ -305,7 +317,7 @@ static int increase_reservation(unsigned= =0A }=0A =0A bs.current_pages +=3D rc;=0A- totalram_pages =3D = bs.current_pages;=0A+ totalram_pages =3D bs.current_pages - totalram_bias= ;=0A =0A out:=0A balloon_unlock(flags);=0A@@ -385,7 +397,7 @@ = static int decrease_reservation(unsigned=0A BUG_ON(ret !=3D nr_pages);= =0A =0A bs.current_pages -=3D nr_pages;=0A- totalram_pages =3D = bs.current_pages;=0A+ totalram_pages =3D bs.current_pages - totalram_bias= ;=0A =0A balloon_unlock(flags);=0A =0A@@ -524,7 +536,19 @@ static = struct notifier_block xenstore_no=0A =0A static int __init balloon_init(voi= d)=0A {=0A-#if defined(CONFIG_X86) && defined(CONFIG_XEN) =0A+#if = !defined(CONFIG_XEN)=0A+# ifndef XENMEM_get_pod_target=0A+# define = XENMEM_get_pod_target 17=0A+ typedef struct xen_pod_target {=0A+ = uint64_t target_pages;=0A+ uint64_t tot_pages;=0A+ = uint64_t pod_cache_pages;=0A+ uint64_t pod_entries;=0A+ = domid_t domid;=0A+ } xen_pod_target_t;=0A+# endif=0A+ xen_pod_tar= get_t pod_target =3D { .domid =3D DOMID_SELF };=0A+#elif defined(CONFIG_X86= )=0A unsigned long pfn;=0A struct page *page;=0A #endif=0A@@ -538,7 = +562,20 @@ static int __init balloon_init(void)=0A bs.current_pages = =3D min(xen_start_info->nr_pages, max_pfn);=0A totalram_pages =3D = bs.current_pages;=0A #else =0A- bs.current_pages =3D totalram_pages; =0A+ = totalram_bias =3D HYPERVISOR_memory_op(=0A+ HYPERVISOR_memory_o= p(XENMEM_get_pod_target,=0A+ &pod_target) !=3D = -ENOSYS=0A+ ? XENMEM_maximum_reservation=0A+ : = XENMEM_current_reservation,=0A+ &pod_target.domid);=0A+ if = ((long)totalram_bias !=3D -ENOSYS) {=0A+ BUG_ON(totalram_bia= s < totalram_pages);=0A+ bs.current_pages =3D totalram_bias;= =0A+ totalram_bias -=3D totalram_pages;=0A+ } else {=0A+ = totalram_bias =3D 0;=0A+ bs.current_pages =3D totalram_pages= ;=0A+ }=0A #endif=0A bs.target_pages =3D bs.current_pages;=0A = bs.balloon_low =3D 0;=0A@@ -671,7 +708,7 @@ struct page **alloc_empty_pag= es_and_page=0A goto err;=0A }=0A =0A- = totalram_pages =3D --bs.current_pages;=0A+ totalram_pages =3D = --bs.current_pages - totalram_bias;=0A =0A balloon_unlock(flag= s);=0A }=0A --=__Part153F359E.0__= Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline _______________________________________________ Xen-devel mailing list Xen-devel@lists.xensource.com http://lists.xensource.com/xen-devel --=__Part153F359E.0__=--