From 3a2b183d5fe86132d0830f720b3b8dbd6a29f7e9 Mon Sep 17 00:00:00 2001 From: Jason Evans Date: Tue, 7 Mar 2017 19:18:27 -0800 Subject: [PATCH] Convert arena_t's purging field to non-atomic bool. The decay mutex already protects all accesses. --- include/jemalloc/internal/arena_structs_b.h | 15 +++++++-------- src/arena.c | 9 +++++---- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/include/jemalloc/internal/arena_structs_b.h b/include/jemalloc/internal/arena_structs_b.h index ba8bb8ad..84c179e8 100644 --- a/include/jemalloc/internal/arena_structs_b.h +++ b/include/jemalloc/internal/arena_structs_b.h @@ -167,14 +167,6 @@ struct arena_s { /* Synchronization: atomic. */ dss_prec_t dss_prec; - /* - * 1/0 (true/false) if a thread is currently executing - * arena_purge_to_limit(). - * - * Synchronization: atomic. - */ - unsigned purging; - /* * Number of pages in active extents. * @@ -207,6 +199,13 @@ struct arena_s { extents_t extents_cached; extents_t extents_retained; + /* + * True if a thread is currently executing arena_purge_to_limit(). + * + * Synchronization: decay.mtx. + */ + bool purging; + /* * Next extent size class in a growing series to use when satisfying a * request via the extent hooks (only if !config_munmap). This limits diff --git a/src/arena.c b/src/arena.c index a3a1fdd7..cb0194ae 100644 --- a/src/arena.c +++ b/src/arena.c @@ -777,9 +777,10 @@ arena_purge_to_limit(tsdn_t *tsdn, arena_t *arena, size_t ndirty_limit) { witness_assert_depth_to_rank(tsdn, WITNESS_RANK_CORE, 1); malloc_mutex_assert_owner(tsdn, &arena->decay.mtx); - if (atomic_cas_u(&arena->purging, 0, 1)) { + if (arena->purging) { return; } + arena->purging = true; extent_hooks_t *extent_hooks = extent_hooks_get(arena); size_t npurge, npurged; @@ -809,7 +810,7 @@ arena_purge_to_limit(tsdn_t *tsdn, arena_t *arena, size_t ndirty_limit) { } label_return: - atomic_write_u(&arena->purging, 0); + arena->purging = false; } void @@ -934,7 +935,6 @@ arena_reset(tsd_t *tsd, arena_t *arena) { malloc_mutex_unlock(tsd_tsdn(tsd), &bin->lock); } - assert(atomic_read_u(&arena->purging) == 0); atomic_write_zu(&arena->nactive, 0); } @@ -1676,7 +1676,6 @@ arena_new(tsdn_t *tsdn, unsigned ind, extent_hooks_t *extent_hooks) { arena->dss_prec = extent_dss_prec_get(); - atomic_write_u(&arena->purging, 0); atomic_write_zu(&arena->nactive, 0); if (arena_decay_init(arena, arena_decay_time_default_get())) { @@ -1710,6 +1709,8 @@ arena_new(tsdn_t *tsdn, unsigned ind, extent_hooks_t *extent_hooks) { goto label_error; } + arena->purging = false; + if (!config_munmap) { arena->extent_grow_next = psz2ind(HUGEPAGE); }