X-Git-Url: https://git.ozlabs.org/?a=blobdiff_plain;f=ccan%2Falloc%2Falloc.c;h=40b5b6ec6ddbedd9f16cb0aade0e75960727e809;hb=93aefd2838428f991ddb09ea36f9ac338b1c7084;hp=8e0b72aa0432227990f7b053f6620020fd53dcac;hpb=27ae4a224e578362fc1f4effdaabac9f112f190f;p=ccan diff --git a/ccan/alloc/alloc.c b/ccan/alloc/alloc.c index 8e0b72aa..40b5b6ec 100644 --- a/ccan/alloc/alloc.c +++ b/ccan/alloc/alloc.c @@ -133,7 +133,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 +404,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); @@ -489,6 +490,8 @@ static unsigned long break_up_large_page(struct header *head, for (i = 1; i < SMALL_PAGES_PER_LARGE_PAGE; i++) { struct page_header *ph = from_pgnum(head, lpage + i, sp_bits); + /* Initialize this: huge_alloc reads it. */ + ph->elements_used = 0; add_small_page_to_freelist(head, ph, sp_bits); }