Extract bin shard selection out of bin locking
This commit is contained in:
parent
ddb8dc4ad0
commit
f28cc2bc87
@ -85,7 +85,7 @@ arena_t *arena_new(tsdn_t *tsdn, unsigned ind, extent_hooks_t *extent_hooks);
|
|||||||
bool arena_init_huge(void);
|
bool arena_init_huge(void);
|
||||||
bool arena_is_huge(unsigned arena_ind);
|
bool arena_is_huge(unsigned arena_ind);
|
||||||
arena_t *arena_choose_huge(tsd_t *tsd);
|
arena_t *arena_choose_huge(tsd_t *tsd);
|
||||||
bin_t *arena_bin_choose_lock(tsdn_t *tsdn, arena_t *arena, szind_t binind,
|
bin_t *arena_bin_choose(tsdn_t *tsdn, arena_t *arena, szind_t binind,
|
||||||
unsigned *binshard);
|
unsigned *binshard);
|
||||||
void arena_boot(sc_data_t *sc_data);
|
void arena_boot(sc_data_t *sc_data);
|
||||||
void arena_prefork0(tsdn_t *tsdn, arena_t *arena);
|
void arena_prefork0(tsdn_t *tsdn, arena_t *arena);
|
||||||
|
32
src/arena.c
32
src/arena.c
@ -739,21 +739,20 @@ arena_bin_refill_slabcur_no_fresh_slab(tsdn_t *tsdn, arena_t *arena,
|
|||||||
return (bin->slabcur == NULL);
|
return (bin->slabcur == NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Choose a bin shard and return the locked bin. */
|
|
||||||
bin_t *
|
bin_t *
|
||||||
arena_bin_choose_lock(tsdn_t *tsdn, arena_t *arena, szind_t binind,
|
arena_bin_choose(tsdn_t *tsdn, arena_t *arena, szind_t binind,
|
||||||
unsigned *binshard) {
|
unsigned *binshard_p) {
|
||||||
bin_t *bin;
|
unsigned binshard;
|
||||||
if (tsdn_null(tsdn) || tsd_arena_get(tsdn_tsd(tsdn)) == NULL) {
|
if (tsdn_null(tsdn) || tsd_arena_get(tsdn_tsd(tsdn)) == NULL) {
|
||||||
*binshard = 0;
|
binshard = 0;
|
||||||
} else {
|
} else {
|
||||||
*binshard = tsd_binshardsp_get(tsdn_tsd(tsdn))->binshard[binind];
|
binshard = tsd_binshardsp_get(tsdn_tsd(tsdn))->binshard[binind];
|
||||||
}
|
}
|
||||||
assert(*binshard < bin_infos[binind].n_shards);
|
assert(binshard < bin_infos[binind].n_shards);
|
||||||
bin = &arena->bins[binind].bin_shards[*binshard];
|
if (binshard_p != NULL) {
|
||||||
malloc_mutex_lock(tsdn, &bin->lock);
|
*binshard_p = binshard;
|
||||||
|
}
|
||||||
return bin;
|
return &arena->bins[binind].bin_shards[binshard];
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
@ -797,11 +796,12 @@ arena_cache_bin_fill_small(tsdn_t *tsdn, arena_t *arena,
|
|||||||
edata_t *fresh_slab = NULL;
|
edata_t *fresh_slab = NULL;
|
||||||
bool alloc_and_retry = false;
|
bool alloc_and_retry = false;
|
||||||
unsigned filled = 0;
|
unsigned filled = 0;
|
||||||
|
|
||||||
bin_t *bin;
|
|
||||||
unsigned binshard;
|
unsigned binshard;
|
||||||
|
bin_t *bin = arena_bin_choose(tsdn, arena, binind, &binshard);
|
||||||
|
|
||||||
label_refill:
|
label_refill:
|
||||||
bin = arena_bin_choose_lock(tsdn, arena, binind, &binshard);
|
malloc_mutex_lock(tsdn, &bin->lock);
|
||||||
|
|
||||||
while (filled < nfill) {
|
while (filled < nfill) {
|
||||||
/* Try batch-fill from slabcur first. */
|
/* Try batch-fill from slabcur first. */
|
||||||
edata_t *slabcur = bin->slabcur;
|
edata_t *slabcur = bin->slabcur;
|
||||||
@ -854,6 +854,7 @@ label_refill:
|
|||||||
bin->stats.nfills++;
|
bin->stats.nfills++;
|
||||||
cache_bin->tstats.nrequests = 0;
|
cache_bin->tstats.nrequests = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
malloc_mutex_unlock(tsdn, &bin->lock);
|
malloc_mutex_unlock(tsdn, &bin->lock);
|
||||||
|
|
||||||
if (alloc_and_retry) {
|
if (alloc_and_retry) {
|
||||||
@ -906,8 +907,9 @@ arena_malloc_small(tsdn_t *tsdn, arena_t *arena, szind_t binind, bool zero) {
|
|||||||
const bin_info_t *bin_info = &bin_infos[binind];
|
const bin_info_t *bin_info = &bin_infos[binind];
|
||||||
size_t usize = sz_index2size(binind);
|
size_t usize = sz_index2size(binind);
|
||||||
unsigned binshard;
|
unsigned binshard;
|
||||||
bin_t *bin = arena_bin_choose_lock(tsdn, arena, binind, &binshard);
|
bin_t *bin = arena_bin_choose(tsdn, arena, binind, &binshard);
|
||||||
|
|
||||||
|
malloc_mutex_lock(tsdn, &bin->lock);
|
||||||
edata_t *fresh_slab = NULL;
|
edata_t *fresh_slab = NULL;
|
||||||
void *ret = arena_bin_malloc_no_fresh_slab(tsdn, arena, bin, binind);
|
void *ret = arena_bin_malloc_no_fresh_slab(tsdn, arena, bin, binind);
|
||||||
if (ret == NULL) {
|
if (ret == NULL) {
|
||||||
|
11
src/tcache.c
11
src/tcache.c
@ -454,9 +454,9 @@ tcache_bin_flush_impl(tsd_t *tsd, tcache_t *tcache, cache_bin_t *cache_bin,
|
|||||||
* thread's arena, so the stats didn't get merged.
|
* thread's arena, so the stats didn't get merged.
|
||||||
* Manually do so now.
|
* Manually do so now.
|
||||||
*/
|
*/
|
||||||
unsigned binshard;
|
bin_t *bin = arena_bin_choose(tsdn, tcache_arena,
|
||||||
bin_t *bin = arena_bin_choose_lock(tsdn, tcache_arena,
|
binind, NULL);
|
||||||
binind, &binshard);
|
malloc_mutex_lock(tsdn, &bin->lock);
|
||||||
bin->stats.nflushes++;
|
bin->stats.nflushes++;
|
||||||
bin->stats.nrequests += cache_bin->tstats.nrequests;
|
bin->stats.nrequests += cache_bin->tstats.nrequests;
|
||||||
cache_bin->tstats.nrequests = 0;
|
cache_bin->tstats.nrequests = 0;
|
||||||
@ -751,9 +751,8 @@ tcache_stats_merge(tsdn_t *tsdn, tcache_t *tcache, arena_t *arena) {
|
|||||||
for (unsigned i = 0; i < nhbins; i++) {
|
for (unsigned i = 0; i < nhbins; i++) {
|
||||||
cache_bin_t *cache_bin = &tcache->bins[i];
|
cache_bin_t *cache_bin = &tcache->bins[i];
|
||||||
if (i < SC_NBINS) {
|
if (i < SC_NBINS) {
|
||||||
unsigned binshard;
|
bin_t *bin = arena_bin_choose(tsdn, arena, i, NULL);
|
||||||
bin_t *bin = arena_bin_choose_lock(tsdn, arena, i,
|
malloc_mutex_lock(tsdn, &bin->lock);
|
||||||
&binshard);
|
|
||||||
bin->stats.nrequests += cache_bin->tstats.nrequests;
|
bin->stats.nrequests += cache_bin->tstats.nrequests;
|
||||||
malloc_mutex_unlock(tsdn, &bin->lock);
|
malloc_mutex_unlock(tsdn, &bin->lock);
|
||||||
} else {
|
} else {
|
||||||
|
Loading…
Reference in New Issue
Block a user