From mboxrd@z Thu Jan 1 00:00:00 1970 From: Samuel Thibault Subject: [PATCH] Mini-OS: Fix alignment in maybe_split() Date: Wed, 13 Feb 2008 13:55:38 +0000 Message-ID: <20080213135538.GA10579@implementation.uk.xensource.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Return-path: Content-Disposition: inline List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xensource.com Errors-To: xen-devel-bounces@lists.xensource.com To: xen-devel@lists.xensource.com List-Id: xen-devel@lists.xenproject.org Mini-OS: Fix alignment in maybe_split() Needed on ia-64, speeds up on x86. Signed-off-by: Samuel Thibault diff -r e85399173769 extras/mini-os/lib/xmalloc.c --- a/extras/mini-os/lib/xmalloc.c Tue Feb 12 16:59:08 2008 +0000 +++ b/extras/mini-os/lib/xmalloc.c Wed Feb 13 13:53:57 2008 +0000 @@ -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))) ) @@ -98,12 +107,6 @@ static struct xmalloc_hdr *xmalloc_new_p maybe_split(hdr, size, PAGE_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. */