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;
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 = {
.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);
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;
.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) {
balloon_unlock(flags);
- if (frame_list != &frame)
- free_page((unsigned long)frame_list);
-
return need_sleep;
}