From: Keir Fraser Date: Wed, 9 Apr 2008 14:25:16 +0000 (+0100) Subject: hvm: Allocate memory for hvm domains in batches. X-Git-Tag: 3.3.0-rc1~243^2~45 X-Git-Url: http://xenbits.xensource.com/gitweb?a=commitdiff_plain;h=be4ba1347005e812b8046551a426272e27952af2;p=xen.git hvm: Allocate memory for hvm domains in batches. Without this change, dom0 is unresponsive while the hvm domain's physmap is populated in xen. Signed-off-by: Tim Deegan --- diff --git a/tools/libxc/xc_hvm_build.c b/tools/libxc/xc_hvm_build.c index 2dd1d52f01..ae3178b0e1 100644 --- a/tools/libxc/xc_hvm_build.c +++ b/tools/libxc/xc_hvm_build.c @@ -158,7 +158,7 @@ static int setup_guest(int xc_handle, { xen_pfn_t *page_array = NULL; unsigned long i, nr_pages = (unsigned long)memsize << (20 - PAGE_SHIFT); - unsigned long special_page_nr, entry_eip; + unsigned long special_page_nr, entry_eip, cur_pages; struct xen_add_to_physmap xatp; struct shared_info *shared_info; void *e820_page; @@ -209,12 +209,23 @@ static int setup_guest(int xc_handle, for ( i = HVM_BELOW_4G_RAM_END >> PAGE_SHIFT; i < nr_pages; i++ ) page_array[i] += HVM_BELOW_4G_MMIO_LENGTH >> PAGE_SHIFT; - /* Allocate memory for HVM guest, skipping VGA hole 0xA0000-0xC0000. */ + /* + * Allocate memory for HVM guest, skipping VGA hole 0xA0000-0xC0000. + * We allocate pages in batches of no more than 2048 to ensure that + * we can be preempted and hence dom0 remains responsive. + */ rc = xc_domain_memory_populate_physmap( xc_handle, dom, 0xa0, 0, 0, &page_array[0x00]); - if ( rc == 0 ) + cur_pages = 0xc0; + while ( (rc == 0) && (nr_pages > cur_pages) ) + { + unsigned long count = nr_pages - cur_pages; + if ( count > 2048 ) + count = 2048; rc = xc_domain_memory_populate_physmap( - xc_handle, dom, nr_pages - 0xc0, 0, 0, &page_array[0xc0]); + xc_handle, dom, count, 0, 0, &page_array[cur_pages]); + cur_pages += count; + } if ( rc != 0 ) { PERROR("Could not allocate memory for HVM guest.\n");