Convert arena->dss_prec synchronization to atomics.

This commit is contained in:
Jason Evans 2017-02-12 16:34:36 -08:00
parent 0721b895ff
commit b779522b9b
4 changed files with 10 additions and 17 deletions

View File

@ -60,8 +60,8 @@ bool arena_ralloc_no_move(tsdn_t *tsdn, extent_t *extent, void *ptr,
size_t oldsize, size_t size, size_t extra, bool zero);
void *arena_ralloc(tsdn_t *tsdn, arena_t *arena, extent_t *extent, void *ptr,
size_t oldsize, size_t size, size_t alignment, bool zero, tcache_t *tcache);
dss_prec_t arena_dss_prec_get(tsdn_t *tsdn, arena_t *arena);
bool arena_dss_prec_set(tsdn_t *tsdn, arena_t *arena, dss_prec_t dss_prec);
dss_prec_t arena_dss_prec_get(arena_t *arena);
bool arena_dss_prec_set(arena_t *arena, dss_prec_t dss_prec);
ssize_t arena_decay_time_default_get(void);
bool arena_decay_time_default_set(ssize_t decay_time);
void arena_basic_stats_merge(tsdn_t *tsdn, arena_t *arena,

View File

@ -156,7 +156,7 @@ struct arena_s {
*/
size_t extent_sn_next;
/* Synchronization: lock. */
/* Synchronization: atomic. */
dss_prec_t dss_prec;
/*

View File

@ -1404,23 +1404,16 @@ arena_ralloc(tsdn_t *tsdn, arena_t *arena, extent_t *extent, void *ptr,
}
dss_prec_t
arena_dss_prec_get(tsdn_t *tsdn, arena_t *arena) {
dss_prec_t ret;
malloc_mutex_lock(tsdn, &arena->lock);
ret = arena->dss_prec;
malloc_mutex_unlock(tsdn, &arena->lock);
return ret;
arena_dss_prec_get(arena_t *arena) {
return (dss_prec_t)atomic_read_u((unsigned *)&arena->dss_prec);
}
bool
arena_dss_prec_set(tsdn_t *tsdn, arena_t *arena, dss_prec_t dss_prec) {
arena_dss_prec_set(arena_t *arena, dss_prec_t dss_prec) {
if (!have_dss) {
return (dss_prec != dss_prec_disabled);
}
malloc_mutex_lock(tsdn, &arena->lock);
arena->dss_prec = dss_prec;
malloc_mutex_unlock(tsdn, &arena->lock);
atomic_write_u((unsigned *)&arena->dss_prec, dss_prec);
return false;
}
@ -1442,7 +1435,7 @@ static void
arena_basic_stats_merge_locked(arena_t *arena, unsigned *nthreads,
const char **dss, ssize_t *decay_time, size_t *nactive, size_t *ndirty) {
*nthreads += arena_nthreads_get(arena, false);
*dss = dss_prec_names[arena->dss_prec];
*dss = dss_prec_names[arena_dss_prec_get(arena)];
*decay_time = arena->decay.time;
*nactive += atomic_read_zu(&arena->nactive);
*ndirty += extents_npages_get(&arena->extents_cached);

View File

@ -1767,11 +1767,11 @@ arena_i_dss_ctl(tsd_t *tsd, const size_t *mib, size_t miblen, void *oldp,
} else {
arena_t *arena = arena_get(tsd_tsdn(tsd), arena_ind, false);
if (arena == NULL || (dss_prec != dss_prec_limit &&
arena_dss_prec_set(tsd_tsdn(tsd), arena, dss_prec))) {
arena_dss_prec_set(arena, dss_prec))) {
ret = EFAULT;
goto label_return;
}
dss_prec_old = arena_dss_prec_get(tsd_tsdn(tsd), arena);
dss_prec_old = arena_dss_prec_get(arena);
}
dss = dss_prec_names[dss_prec_old];