ia64/xen-unstable

changeset 6315:0f69e0adddb0

Fix dom0 memory allocation.
Signed-off-by: Keir Fraser <keir@xensource.com>
author kaf24@firebug.cl.cam.ac.uk
date Sun Aug 21 08:14:36 2005 +0000 (2005-08-21)
parents 19ef6202d75f
children 6721abf6b16d
files xen/arch/x86/domain_build.c
line diff
     1.1 --- a/xen/arch/x86/domain_build.c	Sun Aug 21 00:10:30 2005 +0000
     1.2 +++ b/xen/arch/x86/domain_build.c	Sun Aug 21 08:14:36 2005 +0000
     1.3 @@ -69,11 +69,21 @@ boolean_param("dom0_translate", opt_dom0
     1.4  #define round_pgup(_p)    (((_p)+(PAGE_SIZE-1))&PAGE_MASK)
     1.5  #define round_pgdown(_p)  ((_p)&PAGE_MASK)
     1.6  
     1.7 -static struct pfn_info *alloc_largest(struct domain *d, unsigned long max)
     1.8 +static struct pfn_info *alloc_chunk(struct domain *d, unsigned long max_pages)
     1.9  {
    1.10      struct pfn_info *page;
    1.11 -    unsigned int order = get_order(max)+PAGE_SHIFT-1;
    1.12 -    if ( (max & (max-1)) != 0 )
    1.13 +    unsigned int order;
    1.14 +    /*
    1.15 +     * Allocate up to 2MB at a time:
    1.16 +     *  1. This prevents overflow of get_order() when allocating more than
    1.17 +     *     4GB to domain 0 on a PAE machine.
    1.18 +     *  2. It prevents allocating very large chunks from DMA pools before
    1.19 +     *     the >4GB pool is fully depleted.
    1.20 +     */
    1.21 +    if ( max_pages > (2UL << (20 - PAGE_SHIFT)) )
    1.22 +        max_pages = 2UL << (20 - PAGE_SHIFT);
    1.23 +    order = get_order(max_pages << PAGE_SHIFT);
    1.24 +    if ( (max_pages & (max_pages-1)) != 0 )
    1.25          order--;
    1.26      while ( (page = alloc_domheap_pages(d, order, 0)) == NULL )
    1.27          if ( order-- == 0 )
    1.28 @@ -608,7 +618,7 @@ int construct_dom0(struct domain *d,
    1.29      }
    1.30      while ( pfn < nr_pages )
    1.31      {
    1.32 -        if ( (page = alloc_largest(d, nr_pages - d->tot_pages)) == NULL )
    1.33 +        if ( (page = alloc_chunk(d, nr_pages - d->tot_pages)) == NULL )
    1.34              panic("Not enough RAM for DOM0 reservation.\n");
    1.35          while ( pfn < d->tot_pages )
    1.36          {