X-Git-Url: http://git.ozlabs.org/?p=ccan;a=blobdiff_plain;f=ccan%2Falloc%2Falloc.c;h=0aac015595019aa1b201a0ab737655e19ef04cd6;hp=6cd96d8d8a3681713273f3ed45f8bcea59f49281;hb=c4c5fed020ba44b9930119672a36a1cb33aff090;hpb=e58a81a861ab3e6593b6f4962256f45d3da781aa diff --git a/ccan/alloc/alloc.c b/ccan/alloc/alloc.c index 6cd96d8d..0aac0155 100644 --- a/ccan/alloc/alloc.c +++ b/ccan/alloc/alloc.c @@ -11,6 +11,7 @@ #include #include #include +#include #include "config.h" /* @@ -133,7 +134,7 @@ static unsigned int size_to_bucket(unsigned long size) static unsigned int small_page_bits(unsigned long poolsize) { - return fls(poolsize / MAX_SMALL_PAGES / 2); + return fls(poolsize / MAX_SMALL_PAGES - 1); } static struct page_header *from_pgnum(struct header *head, @@ -404,6 +405,7 @@ void alloc_init(void *pool, unsigned long poolsize) /* Add the rest of the pages as large pages. */ i = SMALL_PAGES_PER_LARGE_PAGE; while ((i << sp_bits) + (1 << lp_bits) <= poolsize) { + assert(i < MAX_SMALL_PAGES); ph = from_pgnum(head, i, sp_bits); ph->elements_used = 0; add_large_page_to_freelist(head, ph, sp_bits); @@ -525,8 +527,9 @@ static bool huge_allocated(struct header *head, unsigned long offset) } /* They want something really big. Aim for contiguous pages (slow). */ -static void *unlikely_func huge_alloc(void *pool, unsigned long poolsize, - unsigned long size, unsigned long align) +static COLD_ATTRIBUTE +void *huge_alloc(void *pool, unsigned long poolsize, + unsigned long size, unsigned long align) { struct header *head = pool; struct huge_alloc *ha; @@ -644,8 +647,8 @@ done: return (char *)pool + ha->off; } -static void unlikely_func huge_free(struct header *head, - unsigned long poolsize, void *free) +static COLD_ATTRIBUTE void +huge_free(struct header *head, unsigned long poolsize, void *free) { unsigned long i, off, pgnum, free_off = (char *)free - (char *)head; unsigned int sp_bits, lp_bits; @@ -680,7 +683,8 @@ static void unlikely_func huge_free(struct header *head, alloc_free(head, poolsize, ha); } -static unsigned long unlikely_func huge_size(struct header *head, void *p) +static COLD_ATTRIBUTE unsigned long +huge_size(struct header *head, void *p) { unsigned long i, off = (char *)p - (char *)head; struct huge_alloc *ha;