direct-io.hg

changeset 1299:fbb0f8e4a3f6

bitkeeper revision 1.861 (40768806O2IuZxUW1J9AghyEC4y2NQ)

Simplify the Xen binary buddy allocator. We only need free-block headers:
the free-block trailers were unnecessary.
author kaf24@scramble.cl.cam.ac.uk
date Fri Apr 09 11:24:54 2004 +0000 (2004-04-09)
parents de049ec69adc
children 22991e70f58f
files xen/common/page_alloc.c
line diff
     1.1 --- a/xen/common/page_alloc.c	Fri Apr 09 09:48:08 2004 +0000
     1.2 +++ b/xen/common/page_alloc.c	Fri Apr 09 11:24:54 2004 +0000
     1.3 @@ -116,7 +116,6 @@ static void map_free(unsigned long first
     1.4   */
     1.5  
     1.6  typedef struct chunk_head_st chunk_head_t;
     1.7 -typedef struct chunk_tail_st chunk_tail_t;
     1.8  
     1.9  struct chunk_head_st {
    1.10      chunk_head_t  *next;
    1.11 @@ -124,10 +123,6 @@ struct chunk_head_st {
    1.12      int            level;
    1.13  };
    1.14  
    1.15 -struct chunk_tail_st {
    1.16 -    int level;
    1.17 -};
    1.18 -
    1.19  /* Linked lists of free chunks of different powers-of-two in size. */
    1.20  #define FREELIST_SIZE ((sizeof(void*)<<3)-PAGE_SHIFT)
    1.21  static chunk_head_t *free_head[FREELIST_SIZE];
    1.22 @@ -170,17 +165,6 @@ static inline int HEAD_LEVEL(chunk_head_
    1.23      return l;
    1.24  }
    1.25  
    1.26 -/* Safe form of 'ct->level'. */
    1.27 -static inline int TAIL_LEVEL(chunk_tail_t *ct)
    1.28 -{
    1.29 -    int l;
    1.30 -    ASSERT(memguard_is_guarded(ct));
    1.31 -    UNGUARD(ct, 0);
    1.32 -    l = ct->level;
    1.33 -    GUARD(ct, 0);
    1.34 -    return l;
    1.35 -}
    1.36 -
    1.37  /* Safe form of '*ch->pprev = l'. */
    1.38  static inline void UPDATE_PREV_FORWARDLINK(chunk_head_t *ch, chunk_head_t *l)
    1.39  {
    1.40 @@ -210,7 +194,6 @@ static inline void UPDATE_NEXT_BACKLINK(
    1.41  #define GUARD(_p,_o) ((void)0)
    1.42  #define UNGUARD(_p,_o) ((void)0)
    1.43  #define HEAD_LEVEL(_ch) ((_ch)->level)
    1.44 -#define TAIL_LEVEL(_ct) ((_ct)->level)
    1.45  #define UPDATE_PREV_FORWARDLINK(_ch,_link) (*(_ch)->pprev = (_link))
    1.46  #define UPDATE_NEXT_BACKLINK(_ch,_link) ((_ch)->next->pprev = (_link))
    1.47  
    1.48 @@ -226,7 +209,6 @@ void __init init_page_allocator(unsigned
    1.49      int i;
    1.50      unsigned long range, bitmap_size, p, remaining;
    1.51      chunk_head_t *ch;
    1.52 -    chunk_tail_t *ct;
    1.53  
    1.54      for ( i = 0; i < FREELIST_SIZE; i++ )
    1.55      {
    1.56 @@ -268,14 +250,12 @@ void __init init_page_allocator(unsigned
    1.57          ch = (chunk_head_t *)p;
    1.58          p         += (1<<i);
    1.59          remaining -= (1<<i);
    1.60 -        ct = (chunk_tail_t *)p - 1;
    1.61          i -= PAGE_SHIFT;
    1.62          ch->level       = i;
    1.63          ch->next        = free_head[i];
    1.64          ch->pprev       = &free_head[i];
    1.65          ch->next->pprev = &ch->next;
    1.66          free_head[i]    = ch;
    1.67 -        ct->level       = i;
    1.68      }
    1.69  
    1.70      memguard_guard_range((void *)min, range);
    1.71 @@ -287,7 +267,6 @@ unsigned long __get_free_pages(int mask,
    1.72  {
    1.73      int i, attempts = 0;
    1.74      chunk_head_t *alloc_ch, *spare_ch;
    1.75 -    chunk_tail_t            *spare_ct;
    1.76      unsigned long           flags;
    1.77  
    1.78  retry:
    1.79 @@ -314,13 +293,11 @@ retry:
    1.80          /* Split into two equal parts. */
    1.81          i--;
    1.82          spare_ch = (chunk_head_t *)((char *)alloc_ch + (1<<(i+PAGE_SHIFT)));
    1.83 -        spare_ct = (chunk_tail_t *)((char *)spare_ch + (1<<(i+PAGE_SHIFT)))-1;
    1.84  
    1.85          /* Create new header for spare chunk. */
    1.86          spare_ch->level = i;
    1.87          spare_ch->next  = free_head[i];
    1.88          spare_ch->pprev = &free_head[i];
    1.89 -        spare_ct->level = i;
    1.90  
    1.91          /* Link in the spare chunk. */
    1.92          /* spare_ch->next->pprev = &spare_ch->next */
    1.93 @@ -334,7 +311,6 @@ retry:
    1.94      spin_unlock_irqrestore(&alloc_lock, flags);
    1.95  
    1.96  #ifdef MEMORY_GUARD
    1.97 -    /* Now we blast the contents of the block. */
    1.98      memset(alloc_ch, 0x55, 1 << (order + PAGE_SHIFT));
    1.99  #endif
   1.100  
   1.101 @@ -361,17 +337,12 @@ void __free_pages(unsigned long p, int o
   1.102  {
   1.103      unsigned long size = 1 << (order + PAGE_SHIFT);
   1.104      chunk_head_t *ch;
   1.105 -    chunk_tail_t *ct;
   1.106      unsigned long flags;
   1.107      unsigned long pfn = virt_to_phys((void *)p) >> PAGE_SHIFT;
   1.108  
   1.109      spin_lock_irqsave(&alloc_lock, flags);
   1.110  
   1.111  #ifdef MEMORY_GUARD
   1.112 -    /* Check that the block isn't already guarded. */
   1.113 -    if ( __put_user(1, (int*)p) )
   1.114 -        BUG();
   1.115 -    /* Now we blast the contents of the block. */
   1.116      memset((void *)p, 0xaa, size);
   1.117  #endif
   1.118  
   1.119 @@ -383,14 +354,13 @@ void __free_pages(unsigned long p, int o
   1.120          if ( (p & size) )
   1.121          {
   1.122              /* Merge with predecessor block? */
   1.123 -            if ( allocated_in_map(pfn-1) )
   1.124 +            if ( allocated_in_map(pfn-(1<<order)) )
   1.125                  break;
   1.126 -            ct = (chunk_tail_t *)p - 1;
   1.127 -            if ( TAIL_LEVEL(ct) != order )
   1.128 +            ch = (chunk_head_t *)(p - size);
   1.129 +            if ( HEAD_LEVEL(ch) != order )
   1.130                  break;
   1.131              p   -= size;
   1.132              pfn -= 1<<order;
   1.133 -            ch   = (chunk_head_t *)p;
   1.134          }
   1.135          else
   1.136          {
   1.137 @@ -415,8 +385,6 @@ void __free_pages(unsigned long p, int o
   1.138  
   1.139      /* Okay, add the final chunk to the appropriate free list. */
   1.140      ch = (chunk_head_t *)p;
   1.141 -    ct = (chunk_tail_t *)(p+size)-1;
   1.142 -    ct->level = order;
   1.143      ch->level = order;
   1.144      ch->pprev = &free_head[order];
   1.145      ch->next  = free_head[order];