diff --git a/include/jemalloc/internal/ehooks.h b/include/jemalloc/internal/ehooks.h index dc03021a..07094d91 100644 --- a/include/jemalloc/internal/ehooks.h +++ b/include/jemalloc/internal/ehooks.h @@ -17,10 +17,12 @@ void *ehooks_default_alloc_impl(tsdn_t *tsdn, void *new_addr, size_t size, void *ehooks_default_alloc(extent_hooks_t *extent_hooks, void *new_addr, size_t size, size_t alignment, bool *zero, bool *commit, unsigned arena_ind); - bool ehooks_default_dalloc_impl(void *addr, size_t size); bool ehooks_default_dalloc(extent_hooks_t *extent_hooks, void *addr, size_t size, bool committed, unsigned arena_ind); +void ehooks_default_destroy_impl(void *addr, size_t size); +void ehooks_default_destroy(extent_hooks_t *extent_hooks, void *addr, + size_t size, bool committed, unsigned arena_ind); static inline void ehooks_pre_reentrancy(tsdn_t *tsdn) { @@ -110,13 +112,19 @@ ehooks_dalloc(tsdn_t *tsdn, ehooks_t *ehooks, void *addr, size_t size, } static inline void -ehooks_destroy(ehooks_t *ehooks, void *addr, size_t size, bool committed, - unsigned arena_ind) { +ehooks_destroy(tsdn_t *tsdn, ehooks_t *ehooks, void *addr, size_t size, + bool committed, unsigned arena_ind) { extent_hooks_t *extent_hooks = ehooks_get_extent_hooks_ptr(ehooks); - if (extent_hooks->destroy == NULL) { + if (extent_hooks == &extent_hooks_default) { + return ehooks_default_destroy_impl(addr, size); + } else if (extent_hooks->destroy == NULL) { return; + } else { + ehooks_pre_reentrancy(tsdn); + extent_hooks->destroy(extent_hooks, addr, size, committed, + arena_ind); + ehooks_post_reentrancy(tsdn); } - extent_hooks->destroy(extent_hooks, addr, size, committed, arena_ind); } static inline bool diff --git a/src/ehooks.c b/src/ehooks.c index 9a266ef0..ad6fd24e 100644 --- a/src/ehooks.c +++ b/src/ehooks.c @@ -89,3 +89,17 @@ ehooks_default_dalloc(extent_hooks_t *extent_hooks, void *addr, size_t size, bool committed, unsigned arena_ind) { return ehooks_default_dalloc_impl(addr, size); } + +void +ehooks_default_destroy_impl(void *addr, size_t size) { + if (!have_dss || !extent_in_dss(addr)) { + pages_unmap(addr, size); + } +} + +void +ehooks_default_destroy(extent_hooks_t *extent_hooks, void *addr, size_t size, + bool committed, unsigned arena_ind) { + ehooks_default_destroy_impl(addr, size); +} + diff --git a/src/extent.c b/src/extent.c index 676d7ac0..271fe4a3 100644 --- a/src/extent.c +++ b/src/extent.c @@ -19,8 +19,6 @@ mutex_pool_t extent_mutex_pool; size_t opt_lg_extent_max_active_fit = LG_EXTENT_MAX_ACTIVE_FIT_DEFAULT; -static void extent_destroy_default(extent_hooks_t *extent_hooks, void *addr, - size_t size, bool committed, unsigned arena_ind); static bool extent_commit_default(extent_hooks_t *extent_hooks, void *addr, size_t size, size_t offset, size_t length, unsigned arena_ind); static bool extent_commit_impl(tsdn_t *tsdn, arena_t *arena, ehooks_t *ehooks, @@ -57,7 +55,7 @@ static bool extent_merge_impl(tsdn_t *tsdn, arena_t *arena, ehooks_t *ehooks, const extent_hooks_t extent_hooks_default = { ehooks_default_alloc, ehooks_default_dalloc, - extent_destroy_default, + ehooks_default_destroy, extent_commit_default, extent_decommit_default #ifdef PAGES_CAN_PURGE_LAZY @@ -1421,19 +1419,6 @@ extent_dalloc_wrapper(tsdn_t *tsdn, arena_t *arena, ehooks_t *ehooks, false); } -static void -extent_destroy_default_impl(void *addr, size_t size) { - if (!have_dss || !extent_in_dss(addr)) { - pages_unmap(addr, size); - } -} - -static void -extent_destroy_default(extent_hooks_t *extent_hooks, void *addr, size_t size, - bool committed, unsigned arena_ind) { - extent_destroy_default_impl(addr, size); -} - void extent_destroy_wrapper(tsdn_t *tsdn, arena_t *arena, ehooks_t *ehooks, extent_t *extent) { @@ -1448,17 +1433,9 @@ extent_destroy_wrapper(tsdn_t *tsdn, arena_t *arena, ehooks_t *ehooks, extent_addr_set(extent, extent_base_get(extent)); /* Try to destroy; silently fail otherwise. */ - if (ehooks_are_default(ehooks)) { - /* Call directly to propagate tsdn. */ - extent_destroy_default_impl(extent_base_get(extent), - extent_size_get(extent)); - } else if (!ehooks_destroy_is_noop(ehooks)) { - extent_hook_pre_reentrancy(tsdn, arena); - ehooks_destroy(ehooks, extent_base_get(extent), - extent_size_get(extent), extent_committed_get(extent), - arena_ind_get(arena)); - extent_hook_post_reentrancy(tsdn); - } + ehooks_destroy(tsdn, ehooks, extent_base_get(extent), + extent_size_get(extent), extent_committed_get(extent), + arena_ind_get(arena)); extent_dalloc(tsdn, arena, extent); }