ia64/xen-unstable

changeset 17057:b9b6caf06f8c

Mini-OS: Fix alignment in maybe_split()
Needed on ia64, speeds up on x86.
Signed-off-by: Samuel Thibault <samuel.thibault@eu.citrix.com>
author Keir Fraser <keir.fraser@citrix.com>
date Thu Feb 14 09:22:33 2008 +0000 (2008-02-14)
parents e1dde6f8bc87
children c1003b9e0bb8
files extras/mini-os/lib/xmalloc.c
line diff
     1.1 --- a/extras/mini-os/lib/xmalloc.c	Wed Feb 13 18:30:12 2008 +0000
     1.2 +++ b/extras/mini-os/lib/xmalloc.c	Thu Feb 14 09:22:33 2008 +0000
     1.3 @@ -62,10 +62,19 @@ struct xmalloc_pad
     1.4      size_t hdr_size;
     1.5  };
     1.6  
     1.7 +/* Return size, increased to alignment with align. */
     1.8 +static inline size_t align_up(size_t size, size_t align)
     1.9 +{
    1.10 +    return (size + align - 1) & ~(align - 1);
    1.11 +}
    1.12 +
    1.13  static void maybe_split(struct xmalloc_hdr *hdr, size_t size, size_t block)
    1.14  {
    1.15      struct xmalloc_hdr *extra;
    1.16 -    size_t leftover = block - size;
    1.17 +    size_t leftover;
    1.18 +    size = align_up(size, __alignof__(struct xmalloc_hdr));
    1.19 +    size = align_up(size, __alignof__(struct xmalloc_pad));
    1.20 +    leftover = block - size;
    1.21  
    1.22      /* If enough is left to make a block, put it on free list. */
    1.23      if ( leftover >= (2 * (sizeof(struct xmalloc_hdr) + sizeof(struct xmalloc_pad))) )
    1.24 @@ -100,12 +109,6 @@ static struct xmalloc_hdr *xmalloc_new_p
    1.25      return hdr;
    1.26  }
    1.27  
    1.28 -/* Return size, increased to alignment with align. */
    1.29 -static inline size_t align_up(size_t size, size_t align)
    1.30 -{
    1.31 -    return (size + align - 1) & ~(align - 1);
    1.32 -}
    1.33 -
    1.34  /* Big object?  Just use the page allocator. */
    1.35  static void *xmalloc_whole_pages(size_t size, size_t align)
    1.36  {