From: shand@kneesaa.uk.xensource.com Date: Thu, 29 Jun 2006 10:17:24 +0000 (+0100) Subject: Use a static page for the frame_list in the balloon driver. X-Git-Tag: archive/raspbian/4.8.0-1+rpi1~1^2~15912^2~43 X-Git-Url: https://dgit.raspbian.org/?a=commitdiff_plain;h=8692316a65d11bf0854ef5e26bd24caf14451af5;p=xen.git Use a static page for the frame_list in the balloon driver. Simplifies code and robustifies against oom situations. Signed-off-by: Steven Hand --- diff --git a/linux-2.6-xen-sparse/drivers/xen/balloon/balloon.c b/linux-2.6-xen-sparse/drivers/xen/balloon/balloon.c index 471f5c76da..dcddf01ad7 100644 --- a/linux-2.6-xen-sparse/drivers/xen/balloon/balloon.c +++ b/linux-2.6-xen-sparse/drivers/xen/balloon/balloon.c @@ -75,6 +75,9 @@ DEFINE_SPINLOCK(balloon_lock); static unsigned long current_pages; static unsigned long target_pages; +/* We increase/decrease in batches which fit in a page */ +static unsigned long frame_list[PAGE_SIZE / sizeof(unsigned long)]; + /* VM /proc information for memory */ extern unsigned long totalram_pages; @@ -172,7 +175,7 @@ static unsigned long current_target(void) static int increase_reservation(unsigned long nr_pages) { - unsigned long *frame_list, frame, pfn, i, flags; + unsigned long pfn, i, flags; struct page *page; long rc; struct xen_memory_reservation reservation = { @@ -181,15 +184,8 @@ static int increase_reservation(unsigned long nr_pages) .domid = DOMID_SELF }; - if (nr_pages > (PAGE_SIZE / sizeof(unsigned long))) - nr_pages = PAGE_SIZE / sizeof(unsigned long); - - frame_list = (unsigned long *)__get_free_page(GFP_KERNEL); - if (frame_list == NULL) { - frame_list = &frame; - if (nr_pages > 1) - nr_pages = 1; - } + if (nr_pages > ARRAY_SIZE(frame_list)) + nr_pages = ARRAY_SIZE(frame_list); balloon_lock(flags); @@ -253,15 +249,12 @@ static int increase_reservation(unsigned long nr_pages) out: balloon_unlock(flags); - if (frame_list != &frame) - free_page((unsigned long)frame_list); - return 0; } static int decrease_reservation(unsigned long nr_pages) { - unsigned long *frame_list, frame, pfn, i, flags; + unsigned long pfn, i, flags; struct page *page; void *v; int need_sleep = 0; @@ -272,15 +265,8 @@ static int decrease_reservation(unsigned long nr_pages) .domid = DOMID_SELF }; - if (nr_pages > (PAGE_SIZE / sizeof(unsigned long))) - nr_pages = PAGE_SIZE / sizeof(unsigned long); - - frame_list = (unsigned long *)__get_free_page(GFP_KERNEL); - if (frame_list == NULL) { - frame_list = &frame; - if (nr_pages > 1) - nr_pages = 1; - } + if (nr_pages > ARRAY_SIZE(frame_list)) + nr_pages = ARRAY_SIZE(frame_list); for (i = 0; i < nr_pages; i++) { if ((page = alloc_page(GFP_HIGHUSER)) == NULL) { @@ -331,9 +317,6 @@ static int decrease_reservation(unsigned long nr_pages) balloon_unlock(flags); - if (frame_list != &frame) - free_page((unsigned long)frame_list); - return need_sleep; }