ia64/xen-unstable

changeset 19058:8df3c145923f

page_alloc: Fix x86_64's alloc_xenheap_pages() when system has >=4GB RAM.

Also do a few cleanups at the same time.

Signed-off-by: Keir Fraser <keir.fraser@citrix.com>
author Keir Fraser <keir.fraser@citrix.com>
date Mon Jan 19 17:40:28 2009 +0000 (2009-01-19)
parents c1320922d05e
children 0ab2b283e892
files xen/common/page_alloc.c
line diff
     1.1 --- a/xen/common/page_alloc.c	Fri Jan 16 15:43:59 2009 +0000
     1.2 +++ b/xen/common/page_alloc.c	Mon Jan 19 17:40:28 2009 +0000
     1.3 @@ -70,6 +70,8 @@ integer_param("dma_bits", dma_bitsize);
     1.4  #define scrub_page(p) clear_page(p)
     1.5  #endif
     1.6  
     1.7 +#define bits_to_zone(b) (((b) < (PAGE_SHIFT + 1)) ? 0 : ((b) - PAGE_SHIFT - 1))
     1.8 +
     1.9  static DEFINE_SPINLOCK(page_scrub_lock);
    1.10  LIST_HEAD(page_scrub_list);
    1.11  static unsigned long scrub_pages;
    1.12 @@ -706,7 +708,8 @@ void *alloc_xenheap_pages(unsigned int o
    1.13      ASSERT(!in_irq());
    1.14  
    1.15      pg = alloc_heap_pages(
    1.16 -        MEMZONE_XEN+1, 31, cpu_to_node(smp_processor_id()), order);
    1.17 +        MEMZONE_XEN+1, bits_to_zone(32),
    1.18 +        cpu_to_node(smp_processor_id()), order);
    1.19      if ( unlikely(pg == NULL) )
    1.20          goto no_memory;
    1.21  
    1.22 @@ -756,9 +759,10 @@ void init_domheap_pages(paddr_t ps, padd
    1.23      s_tot = round_pgup(ps) >> PAGE_SHIFT;
    1.24      e_tot = round_pgdown(pe) >> PAGE_SHIFT;
    1.25  
    1.26 -    zone = fls(s_tot);
    1.27 -    BUG_ON(zone <= MEMZONE_XEN + 1);
    1.28 -    for ( --zone; s_tot < e_tot; ++zone )
    1.29 +    zone = fls(s_tot) - 1;
    1.30 +    BUG_ON(zone <= MEMZONE_XEN);
    1.31 +
    1.32 +    while ( s_tot < e_tot )
    1.33      {
    1.34          unsigned long end = e_tot;
    1.35  
    1.36 @@ -767,6 +771,7 @@ void init_domheap_pages(paddr_t ps, padd
    1.37              end = 1UL << (zone + 1);
    1.38          init_heap_pages(zone, mfn_to_page(s_tot), end - s_tot);
    1.39          s_tot = end;
    1.40 +        zone++;
    1.41      }
    1.42  }
    1.43  
    1.44 @@ -827,7 +832,7 @@ struct page_info *alloc_domheap_pages(
    1.45  {
    1.46      struct page_info *pg = NULL;
    1.47      unsigned int bits = memflags >> _MEMF_bits, zone_hi = NR_ZONES - 1;
    1.48 -    unsigned int node = (uint8_t)((memflags >> _MEMF_node) - 1);
    1.49 +    unsigned int node = (uint8_t)((memflags >> _MEMF_node) - 1), dma_zone;
    1.50  
    1.51      ASSERT(!in_irq());
    1.52  
    1.53 @@ -835,16 +840,11 @@ struct page_info *alloc_domheap_pages(
    1.54          node = domain_to_node(d);
    1.55  
    1.56      bits = domain_clamp_alloc_bitsize(d, bits ? : (BITS_PER_LONG+PAGE_SHIFT));
    1.57 -    if ( bits <= (PAGE_SHIFT + 1) )
    1.58 +    if ( (zone_hi = min_t(unsigned int, bits_to_zone(bits), zone_hi)) == 0 )
    1.59          return NULL;
    1.60  
    1.61 -    bits -= PAGE_SHIFT + 1;
    1.62 -    if ( bits < zone_hi )
    1.63 -        zone_hi = bits;
    1.64 -
    1.65 -    if ( (dma_bitsize > PAGE_SHIFT) &&
    1.66 -         ((zone_hi + PAGE_SHIFT) >= dma_bitsize) )
    1.67 -        pg = alloc_heap_pages(dma_bitsize - PAGE_SHIFT, zone_hi, node, order);
    1.68 +    if ( dma_bitsize && ((dma_zone = bits_to_zone(dma_bitsize)) < zone_hi) )
    1.69 +        pg = alloc_heap_pages(dma_zone + 1, zone_hi, node, order);
    1.70  
    1.71      if ( (pg == NULL) &&
    1.72           ((pg = alloc_heap_pages(MEMZONE_XEN + 1, zone_hi,
    1.73 @@ -933,13 +933,11 @@ unsigned long avail_domheap_pages_region
    1.74  {
    1.75      int zone_lo, zone_hi;
    1.76  
    1.77 -    zone_lo = min_width ? (min_width - (PAGE_SHIFT + 1)) : (MEMZONE_XEN + 1);
    1.78 -    zone_lo = max_t(int, MEMZONE_XEN + 1, zone_lo);
    1.79 -    zone_lo = min_t(int, NR_ZONES - 1, zone_lo);
    1.80 +    zone_lo = min_width ? bits_to_zone(min_width) : (MEMZONE_XEN + 1);
    1.81 +    zone_lo = max_t(int, MEMZONE_XEN + 1, min_t(int, NR_ZONES - 1, zone_lo));
    1.82  
    1.83 -    zone_hi = max_width ? (max_width - (PAGE_SHIFT + 1)) : (NR_ZONES - 1);
    1.84 -    zone_hi = max_t(int, MEMZONE_XEN + 1, zone_hi);
    1.85 -    zone_hi = min_t(int, NR_ZONES - 1, zone_hi);
    1.86 +    zone_hi = max_width ? bits_to_zone(max_width) : (NR_ZONES - 1);
    1.87 +    zone_hi = max_t(int, MEMZONE_XEN + 1, min_t(int, NR_ZONES - 1, zone_hi));
    1.88  
    1.89      return avail_heap_pages(zone_lo, zone_hi, node);
    1.90  }