]> xenbits.xensource.com Git - people/liuw/libxenctrl-split/mini-os.git/commitdiff
Mini-OS: Fix alignment in maybe_split()
authorKeir Fraser <keir.fraser@citrix.com>
Thu, 14 Feb 2008 09:22:33 +0000 (09:22 +0000)
committerKeir Fraser <keir.fraser@citrix.com>
Thu, 14 Feb 2008 09:22:33 +0000 (09:22 +0000)
Needed on ia64, speeds up on x86.
Signed-off-by: Samuel Thibault <samuel.thibault@eu.citrix.com>
lib/xmalloc.c

index 9e59c9f8349242aaaf35d41cb9bb7367d46a5207..d4c3941738167992434da2528f7d1e966843edb1 100644 (file)
@@ -62,10 +62,19 @@ struct xmalloc_pad
     size_t hdr_size;
 };
 
+/* Return size, increased to alignment with align. */
+static inline size_t align_up(size_t size, size_t align)
+{
+    return (size + align - 1) & ~(align - 1);
+}
+
 static void maybe_split(struct xmalloc_hdr *hdr, size_t size, size_t block)
 {
     struct xmalloc_hdr *extra;
-    size_t leftover = block - size;
+    size_t leftover;
+    size = align_up(size, __alignof__(struct xmalloc_hdr));
+    size = align_up(size, __alignof__(struct xmalloc_pad));
+    leftover = block - size;
 
     /* If enough is left to make a block, put it on free list. */
     if ( leftover >= (2 * (sizeof(struct xmalloc_hdr) + sizeof(struct xmalloc_pad))) )
@@ -100,12 +109,6 @@ static struct xmalloc_hdr *xmalloc_new_page(size_t size)
     return hdr;
 }
 
-/* Return size, increased to alignment with align. */
-static inline size_t align_up(size_t size, size_t align)
-{
-    return (size + align - 1) & ~(align - 1);
-}
-
 /* Big object?  Just use the page allocator. */
 static void *xmalloc_whole_pages(size_t size, size_t align)
 {