debuggers.hg

changeset 21080:bc0087c3e75e

Reduce boot-time memory fragmentation

On certain NUMA configurations having init_node_heap() consume the
first few pages of a new node's memory for internal data structures
leads to unnecessary memory fragmentation, which can - with
sufficiently many nodes - result in there not remaining enough memory
below 4G for Dom0 to set up its swiotlb and PCI-consistent buffers.

Since alloc_boot_pages() generally consumes from the end of available
regions, make init_node_heap() prefer the end of such regions too (so
that fragmentation occurs at only one end of a region).

(Adjustment from first version: Use the tail of the region when the
end addresses alignment is less or equal to the beginning one's, not
just when it's less.)

Further, in order to prefer allocations from higher memory locations,
insert memory regions in reverse order in end_boot_allocator(), with
the exception of inserting one region residing on the boot CPU's node
first (for the statically allocated structures - used for the first
node seen - to be used for this node).

Finally, reduce MAX_ORDER on x86 to the maximum useful value (1Gb), so
that the reservation of a page on node boundaries (again leading to
fragmentation) can be avoided as much as possible (having node
boundaries on less the 1Gb aligned addresses is expected to be rare,
if found in practice at all).

Signed-off-by: Jan Beulich <jbeulich@novell.com>
author Keir Fraser <keir.fraser@citrix.com>
date Mon Mar 15 13:24:33 2010 +0000 (2010-03-15)
parents 25446394d21f
children 257589edefb3
files xen/common/page_alloc.c xen/include/asm-x86/config.h
line diff
     1.1 --- a/xen/common/page_alloc.c	Mon Mar 15 13:23:07 2010 +0000
     1.2 +++ b/xen/common/page_alloc.c	Mon Mar 15 13:24:33 2010 +0000
     1.3 @@ -231,7 +231,7 @@ static long midsize_alloc_zone_pages;
     1.4  static DEFINE_SPINLOCK(heap_lock);
     1.5  
     1.6  static unsigned long init_node_heap(int node, unsigned long mfn,
     1.7 -                                    unsigned long nr)
     1.8 +                                    unsigned long nr, bool_t *use_tail)
     1.9  {
    1.10      /* First node to be discovered has its heap metadata statically alloced. */
    1.11      static heap_by_zone_and_order_t _heap_static;
    1.12 @@ -250,12 +250,20 @@ static unsigned long init_node_heap(int 
    1.13          needed = 0;
    1.14      }
    1.15  #ifdef DIRECTMAP_VIRT_END
    1.16 +    else if ( *use_tail && nr >= needed &&
    1.17 +              (mfn + nr) <= (virt_to_mfn(DIRECTMAP_VIRT_END - 1) + 1) )
    1.18 +    {
    1.19 +        _heap[node] = mfn_to_virt(mfn + nr - needed);
    1.20 +        avail[node] = mfn_to_virt(mfn + nr - 1) +
    1.21 +                      PAGE_SIZE - sizeof(**avail) * NR_ZONES;
    1.22 +    }
    1.23      else if ( nr >= needed &&
    1.24                (mfn + needed) <= (virt_to_mfn(DIRECTMAP_VIRT_END - 1) + 1) )
    1.25      {
    1.26          _heap[node] = mfn_to_virt(mfn);
    1.27          avail[node] = mfn_to_virt(mfn + needed - 1) +
    1.28                        PAGE_SIZE - sizeof(**avail) * NR_ZONES;
    1.29 +        *use_tail = 0;
    1.30      }
    1.31  #endif
    1.32      else if ( get_order_from_bytes(sizeof(**_heap)) ==
    1.33 @@ -812,15 +820,24 @@ static void init_heap_pages(
    1.34  
    1.35          if ( unlikely(!avail[nid_curr]) )
    1.36          {
    1.37 +            unsigned long s = page_to_mfn(pg + i);
    1.38 +            unsigned long e = page_to_mfn(pg + nr_pages - 1) + 1;
    1.39 +            bool_t use_tail = (nid_curr == phys_to_nid(pfn_to_paddr(e - 1))) &&
    1.40 +                              !(s & ((1UL << MAX_ORDER) - 1)) &&
    1.41 +                              (find_first_set_bit(e) <= find_first_set_bit(s));
    1.42              unsigned long n;
    1.43  
    1.44 -            n = init_node_heap(nid_curr, page_to_mfn(pg+i), nr_pages - i);
    1.45 -            if ( n )
    1.46 +            n = init_node_heap(nid_curr, page_to_mfn(pg+i), nr_pages - i,
    1.47 +                               &use_tail);
    1.48 +            BUG_ON(i + n > nr_pages);
    1.49 +            if ( n && !use_tail )
    1.50              {
    1.51 -                BUG_ON(i + n > nr_pages);
    1.52                  i += n - 1;
    1.53                  continue;
    1.54              }
    1.55 +            if ( i + n == nr_pages )
    1.56 +                break;
    1.57 +            nr_pages -= n;
    1.58          }
    1.59  
    1.60          /*
    1.61 @@ -870,6 +887,17 @@ void __init end_boot_allocator(void)
    1.62      for ( i = 0; i < nr_bootmem_regions; i++ )
    1.63      {
    1.64          struct bootmem_region *r = &bootmem_region_list[i];
    1.65 +        if ( (r->s < r->e) &&
    1.66 +             (phys_to_nid(pfn_to_paddr(r->s)) == cpu_to_node(0)) )
    1.67 +        {
    1.68 +            init_heap_pages(mfn_to_page(r->s), r->e - r->s);
    1.69 +            r->e = r->s;
    1.70 +            break;
    1.71 +        }
    1.72 +    }
    1.73 +    for ( i = nr_bootmem_regions; i-- > 0; )
    1.74 +    {
    1.75 +        struct bootmem_region *r = &bootmem_region_list[i];
    1.76          if ( r->s < r->e )
    1.77              init_heap_pages(mfn_to_page(r->s), r->e - r->s);
    1.78      }
     2.1 --- a/xen/include/asm-x86/config.h	Mon Mar 15 13:23:07 2010 +0000
     2.2 +++ b/xen/include/asm-x86/config.h	Mon Mar 15 13:24:33 2010 +0000
     2.3 @@ -26,6 +26,7 @@
     2.4  #define CONFIG_NUMA 1
     2.5  #define CONFIG_DISCONTIGMEM 1
     2.6  #define CONFIG_NUMA_EMU 1
     2.7 +#define CONFIG_PAGEALLOC_MAX_ORDER (2 * PAGETABLE_ORDER)
     2.8  
     2.9  /* Intel P4 currently has largest cache line (L2 line size is 128 bytes). */
    2.10  #define CONFIG_X86_L1_CACHE_SHIFT 7