Skip to content

Commit

Permalink
xen/balloon: account for pages released during memory setup
Browse files Browse the repository at this point in the history
In xen_memory_setup() pages that occur in gaps in the memory map are
released back to Xen.  This reduces the domain's current page count in
the hypervisor.  The Xen balloon driver does not correctly decrease
its initial current_pages count to reflect this.  If 'delta' pages are
released and the target is adjusted the resulting reservation is
always 'delta' less than the requested target.

This affects dom0 if the initial allocation of pages overlaps the PCI
memory region but won't affect most domU guests that have been setup
with pseudo-physical memory maps that don't have gaps.

Fix this by accouting for the released pages when starting the balloon
driver.

If the domain's targets are managed by xapi, the domain may eventually
run out of memory and die because xapi currently gets its target
calculations wrong and whenever it is restarted it always reduces the
target by 'delta'.

Signed-off-by: David Vrabel <david.vrabel@citrix.com>
Signed-off-by: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>
  • Loading branch information
David Vrabel authored and Konrad Rzeszutek Wilk committed Sep 29, 2011
1 parent d93dc5c commit aa24411
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 2 deletions.
7 changes: 6 additions & 1 deletion arch/x86/xen/setup.c
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ extern void xen_syscall32_target(void);
/* Amount of extra memory space we add to the e820 ranges */
phys_addr_t xen_extra_mem_start, xen_extra_mem_size;

/* Number of pages released from the initial allocation. */
unsigned long xen_released_pages;

/*
* The maximum amount of extra memory compared to the base size. The
* main scaling factor is the size of struct page. At extreme ratios
Expand Down Expand Up @@ -313,7 +316,9 @@ char * __init xen_memory_setup(void)
extra_pages = 0;
}

extra_pages += xen_return_unused_memory(xen_start_info->nr_pages, &e820);
xen_released_pages = xen_return_unused_memory(xen_start_info->nr_pages,
&e820);
extra_pages += xen_released_pages;

/*
* Clamp the amount of extra memory to a EXTRA_MEM_RATIO
Expand Down
4 changes: 3 additions & 1 deletion drivers/xen/balloon.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 2 additions & 0 deletions include/xen/page.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,6 @@

extern phys_addr_t xen_extra_mem_start, xen_extra_mem_size;

extern unsigned long xen_released_pages;

#endif /* _XEN_PAGE_H */

0 comments on commit aa24411

Please sign in to comment.