ia64/xen-unstable

changeset 17418:aee133a8e5e7

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 <Tim.Deegan@citrix.com>
author Keir Fraser <keir.fraser@citrix.com>
date Wed Apr 09 15:25:16 2008 +0100 (2008-04-09)
parents e64d17985df5
children 3cac47973e15
files tools/libxc/xc_hvm_build.c
line diff
     1.1 --- a/tools/libxc/xc_hvm_build.c	Wed Apr 09 15:19:09 2008 +0100
     1.2 +++ b/tools/libxc/xc_hvm_build.c	Wed Apr 09 15:25:16 2008 +0100
     1.3 @@ -158,7 +158,7 @@ static int setup_guest(int xc_handle,
     1.4  {
     1.5      xen_pfn_t *page_array = NULL;
     1.6      unsigned long i, nr_pages = (unsigned long)memsize << (20 - PAGE_SHIFT);
     1.7 -    unsigned long special_page_nr, entry_eip;
     1.8 +    unsigned long special_page_nr, entry_eip, cur_pages;
     1.9      struct xen_add_to_physmap xatp;
    1.10      struct shared_info *shared_info;
    1.11      void *e820_page;
    1.12 @@ -209,12 +209,23 @@ static int setup_guest(int xc_handle,
    1.13      for ( i = HVM_BELOW_4G_RAM_END >> PAGE_SHIFT; i < nr_pages; i++ )
    1.14          page_array[i] += HVM_BELOW_4G_MMIO_LENGTH >> PAGE_SHIFT;
    1.15  
    1.16 -    /* Allocate memory for HVM guest, skipping VGA hole 0xA0000-0xC0000. */
    1.17 +    /*
    1.18 +     * Allocate memory for HVM guest, skipping VGA hole 0xA0000-0xC0000.
    1.19 +     * We allocate pages in batches of no more than 2048 to ensure that
    1.20 +     * we can be preempted and hence dom0 remains responsive.
    1.21 +     */
    1.22      rc = xc_domain_memory_populate_physmap(
    1.23          xc_handle, dom, 0xa0, 0, 0, &page_array[0x00]);
    1.24 -    if ( rc == 0 )
    1.25 +    cur_pages = 0xc0;
    1.26 +    while ( (rc == 0) && (nr_pages > cur_pages) )
    1.27 +    {
    1.28 +        unsigned long count = nr_pages - cur_pages;
    1.29 +        if ( count > 2048 )
    1.30 +            count = 2048;
    1.31          rc = xc_domain_memory_populate_physmap(
    1.32 -            xc_handle, dom, nr_pages - 0xc0, 0, 0, &page_array[0xc0]);
    1.33 +            xc_handle, dom, count, 0, 0, &page_array[cur_pages]);
    1.34 +        cur_pages += count;
    1.35 +    }
    1.36      if ( rc != 0 )
    1.37      {
    1.38          PERROR("Could not allocate memory for HVM guest.\n");