xen/balloon: simplify test for the end of usable RAM
[pandora-kernel.git] / drivers / xen / balloon.c
index 5dfd8f8..9efb993 100644 (file)
@@ -565,7 +565,9 @@ static int __init balloon_init(void)
 
        pr_info("xen/balloon: Initialising balloon driver.\n");
 
-       balloon_stats.current_pages = xen_pv_domain() ? min(xen_start_info->nr_pages, max_pfn) : max_pfn;
+       balloon_stats.current_pages = xen_pv_domain()
+               ? min(xen_start_info->nr_pages - xen_released_pages, max_pfn)
+               : max_pfn;
        balloon_stats.target_pages  = balloon_stats.current_pages;
        balloon_stats.balloon_low   = 0;
        balloon_stats.balloon_high  = 0;
@@ -584,16 +586,16 @@ static int __init balloon_init(void)
 #endif
 
        /*
-        * Initialise the balloon with excess memory space.  We need
-        * to make sure we don't add memory which doesn't exist or
-        * logically exist.  The E820 map can be trimmed to be smaller
-        * than the amount of physical memory due to the mem= command
-        * line parameter.  And if this is a 32-bit non-HIGHMEM kernel
-        * on a system with memory which requires highmem to access,
-        * don't try to use it.
+        * Initialize the balloon with pages from the extra memory
+        * region (see arch/x86/xen/setup.c).
+        *
+        * If the amount of usable memory has been limited (e.g., with
+        * the 'mem' command line parameter), don't add pages beyond
+        * this limit.
         */
-       extra_pfn_end = min(min(max_pfn, e820_end_of_ram_pfn()),
-                           (unsigned long)PFN_DOWN(xen_extra_mem_start + xen_extra_mem_size));
+       extra_pfn_end = min(max_pfn,
+                           (unsigned long)PFN_DOWN(xen_extra_mem_start
+                                                   + xen_extra_mem_size));
        for (pfn = PFN_UP(xen_extra_mem_start);
             pfn < extra_pfn_end;
             pfn++) {