From a6f3756e681cdcc094b31a2bb78f46387d2b1a91 Mon Sep 17 00:00:00 2001 From: Moinak Ghosh Date: Sun, 29 Jul 2012 00:36:20 +0530 Subject: [PATCH] Fix slab sizing. --- allocator.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/allocator.c b/allocator.c index b5bfd5a..99955a4 100644 --- a/allocator.c +++ b/allocator.c @@ -67,7 +67,6 @@ #define SLAB_START_POW2 8 /* 2 ^ SLAB_START_POW2 = SLAB_START. */ #define HTABLE_SZ 8192 -#define TWOM (2UL * 1024UL * 1024UL) #define ONEM (1UL * 1024UL * 1024UL) static const unsigned int bv[] = { @@ -125,7 +124,8 @@ slab_init() slab_sz *= 2; } - /* At this point slab_sz is 1M. So linear slots start at 1M. */ + /* Linear slots start at 1M. */ + slab_sz = ONEM; for (i = NUM_POW2; i < SLAB_POS_HASH; i++) { slabheads[i].avail = NULL; slabheads[i].next = NULL; @@ -382,9 +382,10 @@ slab_alloc(void *p, size_t size) /* Next slots are in intervals of 1M. */ div = size / ONEM; if (size % ONEM) div++; - if (div < NUM_LINEAR) slab = &slabheads[div + NUM_POW2]; + if (div < NUM_LINEAR) slab = &slabheads[div + NUM_POW2 - 1]; } } + if (!slab) { struct bufentry *buf = (struct bufentry *)malloc(sizeof (struct bufentry)); uint32_t hindx; @@ -510,4 +511,4 @@ slab_free(void *p, void *address) int slab_cache_add(size_t size) {} -#endif \ No newline at end of file +#endif