From: "Jan Beulich" Subject: [PATCH] balloon: don't fail reservation changes with -ENOMEM Date: Fri, 23 Jun 2006 14:33:31 +0200 Message-ID: <449BFBBB.76E4.0078.0@novell.com> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=__PartE3C6318B.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. --=__PartE3C6318B.0__= Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Content-Disposition: inline Add fallback code so that e.g. a domain ballooned too far down can still (slowly) recover. Signed-off-by: Jan Beulich --=__PartE3C6318B.0__= Content-Type: text/plain; name="xenlinux-balloon-no-enomem.patch" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="xenlinux-balloon-no-enomem.patch" Index: head-2006-06-13/drivers/xen/balloon/balloon.c =================================================================== --- head-2006-06-13.orig/drivers/xen/balloon/balloon.c 2006-06-14 10:14:07.000000000 +0200 +++ head-2006-06-13/drivers/xen/balloon/balloon.c 2006-06-14 10:14:15.000000000 +0200 @@ -172,7 +172,7 @@ static unsigned long current_target(void static int increase_reservation(unsigned long nr_pages) { - unsigned long *frame_list, pfn, i, flags; + unsigned long *frame_list, frame, pfn, i, flags; struct page *page; long rc; struct xen_memory_reservation reservation = { @@ -185,8 +185,11 @@ static int increase_reservation(unsigned nr_pages = PAGE_SIZE / sizeof(unsigned long); frame_list = (unsigned long *)__get_free_page(GFP_KERNEL); - if (frame_list == NULL) - return -ENOMEM; + if (frame_list == NULL) { + frame_list = &frame; + if (nr_pages > 1) + nr_pages = 1; + } balloon_lock(flags); @@ -202,14 +205,17 @@ static int increase_reservation(unsigned rc = HYPERVISOR_memory_op( XENMEM_populate_physmap, &reservation); if (rc < nr_pages) { - int ret; - /* We hit the Xen hard limit: reprobe. */ - set_xen_guest_handle(reservation.extent_start, frame_list); - reservation.nr_extents = rc; - ret = HYPERVISOR_memory_op(XENMEM_decrease_reservation, - &reservation); - BUG_ON(ret != rc); - hard_limit = current_pages + rc - driver_pages; + if (rc > 0) { + int ret; + + /* We hit the Xen hard limit: reprobe. */ + reservation.nr_extents = rc; + ret = HYPERVISOR_memory_op(XENMEM_decrease_reservation, + &reservation); + BUG_ON(ret != rc); + } + if (rc >= 0) + hard_limit = current_pages + rc - driver_pages; goto out; } @@ -247,14 +253,15 @@ static int increase_reservation(unsigned out: balloon_unlock(flags); - free_page((unsigned long)frame_list); + if (frame_list != &frame) + free_page((unsigned long)frame_list); return 0; } static int decrease_reservation(unsigned long nr_pages) { - unsigned long *frame_list, pfn, i, flags; + unsigned long *frame_list, frame, pfn, i, flags; struct page *page; void *v; int need_sleep = 0; @@ -269,8 +276,11 @@ static int decrease_reservation(unsigned nr_pages = PAGE_SIZE / sizeof(unsigned long); frame_list = (unsigned long *)__get_free_page(GFP_KERNEL); - if (frame_list == NULL) - return -ENOMEM; + if (frame_list == NULL) { + frame_list = &frame; + if (nr_pages > 1) + nr_pages = 1; + } for (i = 0; i < nr_pages; i++) { if ((page = alloc_page(GFP_HIGHUSER)) == NULL) { @@ -321,7 +331,8 @@ static int decrease_reservation(unsigned balloon_unlock(flags); - free_page((unsigned long)frame_list); + if (frame_list != &frame) + free_page((unsigned long)frame_list); return need_sleep; } --=__PartE3C6318B.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 --=__PartE3C6318B.0__=--