diff --git a/include/jemalloc/internal/base_inlines.h b/include/jemalloc/internal/base_inlines.h index aec0e2e1..221fca81 100644 --- a/include/jemalloc/internal/base_inlines.h +++ b/include/jemalloc/internal/base_inlines.h @@ -3,7 +3,7 @@ static inline unsigned base_ind_get(const base_t *base) { - return base->ind; + return ehooks_ind_get(&base->ehooks); } static inline bool diff --git a/include/jemalloc/internal/base_structs.h b/include/jemalloc/internal/base_structs.h index fb7e68a4..ff1fdfb3 100644 --- a/include/jemalloc/internal/base_structs.h +++ b/include/jemalloc/internal/base_structs.h @@ -20,9 +20,6 @@ struct base_block_s { }; struct base_s { - /* Associated arena's index within the arenas array. */ - unsigned ind; - /* * User-configurable extent hook functions. */ diff --git a/include/jemalloc/internal/ehooks.h b/include/jemalloc/internal/ehooks.h index 6f4f950c..23ab29cd 100644 --- a/include/jemalloc/internal/ehooks.h +++ b/include/jemalloc/internal/ehooks.h @@ -20,6 +20,12 @@ extern const extent_hooks_t ehooks_default_extent_hooks; typedef struct ehooks_s ehooks_t; struct ehooks_s { + /* + * The user-visible id that goes with the ehooks (i.e. that of the base + * they're a part of, the associated arena's index within the arenas + * array). + */ + unsigned ind; /* Logically an extent_hooks_t *. */ atomic_p_t ptr; }; @@ -80,7 +86,12 @@ ehooks_post_reentrancy(tsdn_t *tsdn) { } /* Beginning of the public API. */ -void ehooks_init(ehooks_t *ehooks, extent_hooks_t *extent_hooks); +void ehooks_init(ehooks_t *ehooks, extent_hooks_t *extent_hooks, unsigned ind); + +static inline unsigned +ehooks_ind_get(const ehooks_t *ehooks) { + return ehooks->ind; +} static inline void ehooks_set_extent_hooks_ptr(ehooks_t *ehooks, extent_hooks_t *extent_hooks) { diff --git a/src/base.c b/src/base.c index 76d76557..ad3fe83c 100644 --- a/src/base.c +++ b/src/base.c @@ -346,7 +346,7 @@ base_new(tsdn_t *tsdn, unsigned ind, extent_hooks_t *extent_hooks) { * memory, and then initialize the ehooks within the base_t. */ ehooks_t fake_ehooks; - ehooks_init(&fake_ehooks, extent_hooks); + ehooks_init(&fake_ehooks, extent_hooks, ind); base_block_t *block = base_block_alloc(tsdn, NULL, &fake_ehooks, ind, &pind_last, &extent_sn_next, sizeof(base_t), QUANTUM); @@ -359,8 +359,7 @@ base_new(tsdn_t *tsdn, unsigned ind, extent_hooks_t *extent_hooks) { size_t base_size = ALIGNMENT_CEILING(sizeof(base_t), base_alignment); base_t *base = (base_t *)base_extent_bump_alloc_helper(&block->edata, &gap_size, base_size, base_alignment); - base->ind = ind; - ehooks_init(&base->ehooks, extent_hooks); + ehooks_init(&base->ehooks, extent_hooks, ind); if (malloc_mutex_init(&base->mtx, "base", WITNESS_RANK_BASE, malloc_mutex_rank_exclusive)) { base_unmap(tsdn, &fake_ehooks, ind, block, block->size); @@ -411,7 +410,7 @@ extent_hooks_t * base_extent_hooks_set(base_t *base, extent_hooks_t *extent_hooks) { extent_hooks_t *old_extent_hooks = ehooks_get_extent_hooks_ptr(&base->ehooks); - ehooks_init(&base->ehooks, extent_hooks); + ehooks_init(&base->ehooks, extent_hooks, ehooks_ind_get(&base->ehooks)); return old_extent_hooks; } diff --git a/src/ehooks.c b/src/ehooks.c index 51b1514a..2fb2c4c4 100644 --- a/src/ehooks.c +++ b/src/ehooks.c @@ -4,7 +4,9 @@ #include "jemalloc/internal/ehooks.h" #include "jemalloc/internal/extent_mmap.h" -void ehooks_init(ehooks_t *ehooks, extent_hooks_t *extent_hooks) { +void +ehooks_init(ehooks_t *ehooks, extent_hooks_t *extent_hooks, unsigned ind) { + ehooks->ind = ind; ehooks_set_extent_hooks_ptr(ehooks, extent_hooks); }