From 4c46e11365566ec03723c46356cd524f4abd7fd8 Mon Sep 17 00:00:00 2001 From: David Goldblatt Date: Fri, 29 Jan 2021 21:22:57 -0800 Subject: [PATCH] Cache an arena's index in the arena. This saves us a pointer hop down some perf-sensitive paths. --- include/jemalloc/internal/arena_inlines_a.h | 2 +- include/jemalloc/internal/arena_structs.h | 6 ++++++ src/arena.c | 1 + 3 files changed, 8 insertions(+), 1 deletion(-) diff --git a/include/jemalloc/internal/arena_inlines_a.h b/include/jemalloc/internal/arena_inlines_a.h index b83d0e8e..8568358c 100644 --- a/include/jemalloc/internal/arena_inlines_a.h +++ b/include/jemalloc/internal/arena_inlines_a.h @@ -3,7 +3,7 @@ static inline unsigned arena_ind_get(const arena_t *arena) { - return base_ind_get(arena->base); + return arena->ind; } static inline void diff --git a/include/jemalloc/internal/arena_structs.h b/include/jemalloc/internal/arena_structs.h index baa7031c..913184d3 100644 --- a/include/jemalloc/internal/arena_structs.h +++ b/include/jemalloc/internal/arena_structs.h @@ -83,6 +83,12 @@ struct arena_s { */ bins_t bins[SC_NBINS]; + /* + * A cached copy of base->ind. This can get accessed on hot paths; + * looking it up in base requires an extra pointer hop / cache miss. + */ + unsigned ind; + /* * Base allocator, from which arena metadata are allocated. * diff --git a/src/arena.c b/src/arena.c index 56c34af5..7836e27d 100644 --- a/src/arena.c +++ b/src/arena.c @@ -1475,6 +1475,7 @@ arena_new(tsdn_t *tsdn, unsigned ind, extent_hooks_t *extent_hooks) { arena->base = base; /* Set arena before creating background threads. */ arena_set(ind, arena); + arena->ind = ind; nstime_init_update(&arena->create_time);