diff --git a/include/jemalloc/internal/arena_inlines_b.h b/include/jemalloc/internal/arena_inlines_b.h index 917a4916..a6135ee7 100644 --- a/include/jemalloc/internal/arena_inlines_b.h +++ b/include/jemalloc/internal/arena_inlines_b.h @@ -8,6 +8,12 @@ #include "jemalloc/internal/sz.h" #include "jemalloc/internal/ticker.h" +static inline arena_t * +arena_get_from_extent(extent_t *extent) { + return (arena_t *)atomic_load_p(&arenas[extent_arena_ind_get(extent)], + ATOMIC_RELAXED); +} + JEMALLOC_ALWAYS_INLINE bool arena_has_default_hooks(arena_t *arena) { return (extent_hooks_get(arena) == &extent_hooks_default); diff --git a/src/arena.c b/src/arena.c index 37f4b556..e096f3a6 100644 --- a/src/arena.c +++ b/src/arena.c @@ -1565,8 +1565,7 @@ arena_prof_promote(tsdn_t *tsdn, void *ptr, size_t usize) { extent_t *extent = rtree_extent_read(tsdn, &extents_rtree, rtree_ctx, (uintptr_t)ptr, true); - arena_t *arena = atomic_load_p(&arenas[extent_arena_ind_get(extent)], - ATOMIC_RELAXED); + arena_t *arena = arena_get_from_extent(extent); szind_t szind = sz_size2index(usize); extent_szind_set(extent, szind); @@ -1731,8 +1730,7 @@ arena_dalloc_bin(tsdn_t *tsdn, arena_t *arena, extent_t *extent, void *ptr) { void arena_dalloc_small(tsdn_t *tsdn, void *ptr) { extent_t *extent = iealloc(tsdn, ptr); - arena_t *arena = atomic_load_p(&arenas[extent_arena_ind_get(extent)], - ATOMIC_RELAXED); + arena_t *arena = arena_get_from_extent(extent); arena_dalloc_bin(tsdn, arena, extent, ptr); arena_decay_tick(tsdn, arena); @@ -1768,8 +1766,7 @@ arena_ralloc_no_move(tsdn_t *tsdn, void *ptr, size_t oldsize, size_t size, goto done; } - arena_t *arena = atomic_load_p( - &arenas[extent_arena_ind_get(extent)], ATOMIC_RELAXED); + arena_t *arena = arena_get_from_extent(extent); arena_decay_tick(tsdn, arena); ret = false; } else if (oldsize >= SC_LARGE_MINCLASS diff --git a/src/ctl.c b/src/ctl.c index a29be194..6bd534a7 100644 --- a/src/ctl.c +++ b/src/ctl.c @@ -2612,8 +2612,7 @@ arenas_lookup_ctl(tsd_t *tsd, const size_t *mib, if (extent == NULL) goto label_return; - arena = atomic_load_p(&arenas[extent_arena_ind_get(extent)], - ATOMIC_RELAXED); + arena = arena_get_from_extent(extent); if (arena == NULL) goto label_return; diff --git a/src/large.c b/src/large.c index 40afa623..13d8e56c 100644 --- a/src/large.c +++ b/src/large.c @@ -94,8 +94,7 @@ large_dalloc_maybe_junk_t *JET_MUTABLE large_dalloc_maybe_junk = static bool large_ralloc_no_move_shrink(tsdn_t *tsdn, extent_t *extent, size_t usize) { - arena_t *arena = atomic_load_p(&arenas[extent_arena_ind_get(extent)], - ATOMIC_RELAXED); + arena_t *arena = arena_get_from_extent(extent); size_t oldusize = extent_usize_get(extent); extent_hooks_t *extent_hooks = extent_hooks_get(arena); size_t diff = extent_size_get(extent) - (usize + sz_large_pad); @@ -131,8 +130,7 @@ large_ralloc_no_move_shrink(tsdn_t *tsdn, extent_t *extent, size_t usize) { static bool large_ralloc_no_move_expand(tsdn_t *tsdn, extent_t *extent, size_t usize, bool zero) { - arena_t *arena = atomic_load_p(&arenas[extent_arena_ind_get(extent)], - ATOMIC_RELAXED); + arena_t *arena = arena_get_from_extent(extent); size_t oldusize = extent_usize_get(extent); extent_hooks_t *extent_hooks = extent_hooks_get(arena); size_t trailsize = usize - oldusize; @@ -232,18 +230,14 @@ large_ralloc_no_move(tsdn_t *tsdn, extent_t *extent, size_t usize_min, /* Attempt to expand the allocation in-place. */ if (!large_ralloc_no_move_expand(tsdn, extent, usize_max, zero)) { - arena_decay_tick(tsdn, - atomic_load_p(&arenas[extent_arena_ind_get(extent)], - ATOMIC_RELAXED)); + arena_decay_tick(tsdn, arena_get_from_extent(extent)); return false; } /* Try again, this time with usize_min. */ if (usize_min < usize_max && usize_min > oldusize && large_ralloc_no_move_expand(tsdn, extent, usize_min, zero)) { - arena_decay_tick(tsdn, atomic_load_p( - &arenas[extent_arena_ind_get(extent)], - ATOMIC_RELAXED)); + arena_decay_tick(tsdn, arena_get_from_extent(extent)); return false; } } @@ -253,17 +247,14 @@ large_ralloc_no_move(tsdn_t *tsdn, extent_t *extent, size_t usize_min, * the new size. */ if (oldusize >= usize_min && oldusize <= usize_max) { - arena_decay_tick(tsdn, atomic_load_p( - &arenas[extent_arena_ind_get(extent)], ATOMIC_RELAXED)); + arena_decay_tick(tsdn, arena_get_from_extent(extent)); return false; } /* Attempt to shrink the allocation in-place. */ if (oldusize > usize_max) { if (!large_ralloc_no_move_shrink(tsdn, extent, usize_max)) { - arena_decay_tick(tsdn, atomic_load_p( - &arenas[extent_arena_ind_get(extent)], - ATOMIC_RELAXED)); + arena_decay_tick(tsdn, arena_get_from_extent(extent)); return false; } } @@ -357,20 +348,18 @@ large_dalloc_finish_impl(tsdn_t *tsdn, arena_t *arena, extent_t *extent) { void large_dalloc_prep_junked_locked(tsdn_t *tsdn, extent_t *extent) { - large_dalloc_prep_impl(tsdn, atomic_load_p( - &arenas[extent_arena_ind_get(extent)], ATOMIC_RELAXED), extent, true); + large_dalloc_prep_impl(tsdn, arena_get_from_extent(extent), extent, + true); } void large_dalloc_finish(tsdn_t *tsdn, extent_t *extent) { - large_dalloc_finish_impl(tsdn, atomic_load_p( - &arenas[extent_arena_ind_get(extent)], ATOMIC_RELAXED), extent); + large_dalloc_finish_impl(tsdn, arena_get_from_extent(extent), extent); } void large_dalloc(tsdn_t *tsdn, extent_t *extent) { - arena_t *arena = atomic_load_p( - &arenas[extent_arena_ind_get(extent)], ATOMIC_RELAXED); + arena_t *arena = arena_get_from_extent(extent); large_dalloc_prep_impl(tsdn, arena, extent, false); large_dalloc_finish_impl(tsdn, arena, extent); arena_decay_tick(tsdn, arena);