debuggers.hg

changeset 21074:4152a3ce90a7

x86: adjust available memory calculation for Dom0 construction

With a large number of CPUs, the amount of memory needed to construct
the vCPU structures for Dom0 becomes significant and hence should be
accounted for when calculating the amount of memory to pass to Dom0.

Signed-off-by: Jan Beulich <jbeulich@novell.com>

Add code comments and clean up compute_dom0_nr_pages() invocation.

Signed-off-by: Keir Fraser <keir.fraser@citrix.com>
author Keir Fraser <keir.fraser@citrix.com>
date Thu Mar 11 17:40:35 2010 +0000 (2010-03-11)
parents c9f795ff78b1
children 9300248eaad2
files xen/arch/x86/domain_build.c
line diff
     1.1 --- a/xen/arch/x86/domain_build.c	Thu Mar 11 17:15:54 2010 +0000
     1.2 +++ b/xen/arch/x86/domain_build.c	Thu Mar 11 17:40:35 2010 +0000
     1.3 @@ -143,17 +143,20 @@ static struct page_info * __init alloc_c
     1.4  }
     1.5  
     1.6  static unsigned long __init compute_dom0_nr_pages(
     1.7 -#ifdef __x86_64__
     1.8 -    unsigned long vstart, unsigned long vend, size_t sizeof_long)
     1.9 -#else
    1.10 -    void)
    1.11 -#endif
    1.12 +    struct domain *d, struct elf_dom_parms *parms, unsigned long initrd_len)
    1.13  {
    1.14      unsigned long avail = avail_domheap_pages() + initial_images_nrpages();
    1.15      unsigned long nr_pages = dom0_nrpages;
    1.16      unsigned long min_pages = dom0_min_nrpages;
    1.17      unsigned long max_pages = dom0_max_nrpages;
    1.18  
    1.19 +    /* Reserve memory for further dom0 vcpu-struct allocations... */
    1.20 +    avail -= (opt_dom0_max_vcpus - 1UL)
    1.21 +             << get_order_from_bytes(sizeof(struct vcpu));
    1.22 +    /* ...and compat_l4's, if needed. */
    1.23 +    if ( is_pv_32on64_domain(d) )
    1.24 +        avail -= opt_dom0_max_vcpus - 1;
    1.25 +
    1.26      /*
    1.27       * If domain 0 allocation isn't specified, reserve 1/16th of available
    1.28       * memory for things like DMA buffers. This reservation is clamped to 
    1.29 @@ -173,8 +176,8 @@ static unsigned long __init compute_dom0
    1.30      nr_pages = min(nr_pages, avail);
    1.31  
    1.32  #ifdef __x86_64__
    1.33 -    if ( vstart && dom0_nrpages <= 0 &&
    1.34 -         (dom0_min_nrpages <= 0 || nr_pages > min_pages) )
    1.35 +    if ( (parms->p2m_base == UNSET_ADDR) && (dom0_nrpages <= 0) &&
    1.36 +         ((dom0_min_nrpages <= 0) || (nr_pages > min_pages)) )
    1.37      {
    1.38          /*
    1.39           * Legacy Linux kernels (i.e. such without a XEN_ELFNOTE_INIT_P2M
    1.40 @@ -184,7 +187,12 @@ static unsigned long __init compute_dom0
    1.41           * allocation doesn't consume more than about half the space that's
    1.42           * available between params.virt_base and the address space end.
    1.43           */
    1.44 -        unsigned long end = vend + nr_pages * sizeof_long;
    1.45 +        unsigned long vstart, vend, end;
    1.46 +        size_t sizeof_long = is_pv_32bit_domain(d) ? sizeof(int) : sizeof(long);
    1.47 +
    1.48 +        vstart = parms->virt_base;
    1.49 +        vend = round_pgup(parms->virt_kend) + round_pgup(initrd_len);
    1.50 +        end = vend + nr_pages * sizeof_long;
    1.51  
    1.52          if ( end > vstart )
    1.53              end += end - vstart;
    1.54 @@ -367,20 +375,10 @@ int __init construct_dom0(
    1.55      {
    1.56          d->arch.is_32bit_pv = d->arch.has_32bit_shinfo = 1;
    1.57          v->vcpu_info = (void *)&d->shared_info->compat.vcpu_info[0];
    1.58 +    }
    1.59 +#endif
    1.60  
    1.61 -        nr_pages = compute_dom0_nr_pages(parms.virt_base,
    1.62 -            round_pgup(parms.virt_kend) + round_pgup(initrd_len),
    1.63 -            sizeof(unsigned int));
    1.64 -    }
    1.65 -    else if (parms.p2m_base != UNSET_ADDR)
    1.66 -        nr_pages = compute_dom0_nr_pages(0, 0, 0);
    1.67 -    else
    1.68 -        nr_pages = compute_dom0_nr_pages(parms.virt_base,
    1.69 -            round_pgup(parms.virt_kend) + round_pgup(initrd_len),
    1.70 -            sizeof(unsigned long));
    1.71 -#else
    1.72 -    nr_pages = compute_dom0_nr_pages();
    1.73 -#endif
    1.74 +    nr_pages = compute_dom0_nr_pages(d, &parms, initrd_len);
    1.75  
    1.76      if ( parms.pae == PAEKERN_extended_cr3 )
    1.77              set_bit(VMASST_TYPE_pae_extended_cr3, &d->vm_assist);