Create a const array with only a small bin to size map

This commit is contained in:
Ben Maurer 2014-04-16 14:31:24 -07:00
parent 6c39f9e059
commit 021136ce4d
5 changed files with 17 additions and 7 deletions

View File

@ -385,6 +385,7 @@ extern ssize_t opt_lg_dirty_mult;
* and all accesses are via the SMALL_SIZE2BIN macro. * and all accesses are via the SMALL_SIZE2BIN macro.
*/ */
extern uint8_t const small_size2bin[]; extern uint8_t const small_size2bin[];
extern uint32_t const small_bin2size[];
#define SMALL_SIZE2BIN(s) (small_size2bin[(s-1) >> LG_TINY_MIN]) #define SMALL_SIZE2BIN(s) (small_size2bin[(s-1) >> LG_TINY_MIN])
extern arena_bin_info_t arena_bin_info[NBINS]; extern arena_bin_info_t arena_bin_info[NBINS];
@ -964,7 +965,7 @@ arena_salloc(const void *ptr, bool demote)
assert(arena_mapbits_large_get(chunk, pageind) != 0 || assert(arena_mapbits_large_get(chunk, pageind) != 0 ||
arena_ptr_small_binind_get(ptr, arena_mapbits_get(chunk, arena_ptr_small_binind_get(ptr, arena_mapbits_get(chunk,
pageind)) == binind); pageind)) == binind);
ret = arena_bin_info[binind].reg_size; ret = small_bin2size[binind];
} }
return (ret); return (ret);

View File

@ -602,7 +602,7 @@ s2u(size_t size)
{ {
if (size <= SMALL_MAXCLASS) if (size <= SMALL_MAXCLASS)
return (arena_bin_info[SMALL_SIZE2BIN(size)].reg_size); return (small_bin2size[SMALL_SIZE2BIN(size)]);
if (size <= arena_maxclass) if (size <= arena_maxclass)
return (PAGE_CEILING(size)); return (PAGE_CEILING(size));
return (CHUNK_CEILING(size)); return (CHUNK_CEILING(size));
@ -645,7 +645,7 @@ sa2u(size_t size, size_t alignment)
if (usize <= arena_maxclass && alignment <= PAGE) { if (usize <= arena_maxclass && alignment <= PAGE) {
if (usize <= SMALL_MAXCLASS) if (usize <= SMALL_MAXCLASS)
return (arena_bin_info[SMALL_SIZE2BIN(usize)].reg_size); return (small_bin2size[SMALL_SIZE2BIN(usize)]);
return (PAGE_CEILING(usize)); return (PAGE_CEILING(usize));
} else { } else {
size_t run_size; size_t run_size;

View File

@ -346,6 +346,7 @@ rtree_set
s2u s2u
sa2u sa2u
set_errno set_errno
small_bin2size
small_size2bin small_size2bin
stats_cactive stats_cactive
stats_cactive_add stats_cactive_add

View File

@ -266,14 +266,14 @@ tcache_alloc_small(tcache_t *tcache, size_t size, bool zero)
binind = SMALL_SIZE2BIN(size); binind = SMALL_SIZE2BIN(size);
assert(binind < NBINS); assert(binind < NBINS);
tbin = &tcache->tbins[binind]; tbin = &tcache->tbins[binind];
size = arena_bin_info[binind].reg_size; size = small_bin2size[binind];
ret = tcache_alloc_easy(tbin); ret = tcache_alloc_easy(tbin);
if (ret == NULL) { if (ret == NULL) {
ret = tcache_alloc_small_hard(tcache, tbin, binind); ret = tcache_alloc_small_hard(tcache, tbin, binind);
if (ret == NULL) if (ret == NULL)
return (NULL); return (NULL);
} }
assert(tcache_salloc(ret) == arena_bin_info[binind].reg_size); assert(tcache_salloc(ret) == size);
if (zero == false) { if (zero == false) {
if (config_fill) { if (config_fill) {
@ -296,7 +296,7 @@ tcache_alloc_small(tcache_t *tcache, size_t size, bool zero)
if (config_stats) if (config_stats)
tbin->tstats.nrequests++; tbin->tstats.nrequests++;
if (config_prof) if (config_prof)
tcache->prof_accumbytes += arena_bin_info[binind].reg_size; tcache->prof_accumbytes += size;
tcache_event(tcache); tcache_event(tcache);
return (ret); return (ret);
} }

View File

@ -7,6 +7,14 @@
ssize_t opt_lg_dirty_mult = LG_DIRTY_MULT_DEFAULT; ssize_t opt_lg_dirty_mult = LG_DIRTY_MULT_DEFAULT;
arena_bin_info_t arena_bin_info[NBINS]; arena_bin_info_t arena_bin_info[NBINS];
JEMALLOC_ALIGNED(CACHELINE)
const uint32_t small_bin2size[NBINS] = {
#define SIZE_CLASS(bin, delta, size) \
size,
SIZE_CLASSES
#undef SIZE_CLASS
};
JEMALLOC_ALIGNED(CACHELINE) JEMALLOC_ALIGNED(CACHELINE)
const uint8_t small_size2bin[] = { const uint8_t small_size2bin[] = {
#define S2B_8(i) i, #define S2B_8(i) i,
@ -1615,7 +1623,7 @@ arena_malloc_small(arena_t *arena, size_t size, bool zero)
binind = SMALL_SIZE2BIN(size); binind = SMALL_SIZE2BIN(size);
assert(binind < NBINS); assert(binind < NBINS);
bin = &arena->bins[binind]; bin = &arena->bins[binind];
size = arena_bin_info[binind].reg_size; size = small_bin2size[binind];
malloc_mutex_lock(&bin->lock); malloc_mutex_lock(&bin->lock);
if ((run = bin->runcur) != NULL && run->nfree > 0) if ((run = bin->runcur) != NULL && run->nfree > 0)