From bac8e2e5a65a361dec4598419dd10d2b119e8d24 Mon Sep 17 00:00:00 2001 From: David Goldblatt Date: Tue, 3 Dec 2019 10:47:28 -0800 Subject: [PATCH] Extent -> Ehooks: Move dalloc hook. --- include/jemalloc/internal/ehooks.h | 20 ++++++++++++++----- src/base.c | 2 +- src/ehooks.c | 14 +++++++++++++ src/extent.c | 32 ++++-------------------------- 4 files changed, 34 insertions(+), 34 deletions(-) diff --git a/include/jemalloc/internal/ehooks.h b/include/jemalloc/internal/ehooks.h index 37087cac..dc03021a 100644 --- a/include/jemalloc/internal/ehooks.h +++ b/include/jemalloc/internal/ehooks.h @@ -18,6 +18,10 @@ 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); + static inline void ehooks_pre_reentrancy(tsdn_t *tsdn) { tsd_t *tsd = tsdn_null(tsdn) ? tsd_fetch() : tsdn_tsd(tsdn); @@ -89,14 +93,20 @@ ehooks_alloc(tsdn_t *tsdn, ehooks_t *ehooks, void *new_addr, size_t size, } static inline bool -ehooks_dalloc(ehooks_t *ehooks, void *addr, size_t size, bool committed, - unsigned arena_ind) { +ehooks_dalloc(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->dalloc == NULL) { + if (extent_hooks == &extent_hooks_default) { + return ehooks_default_dalloc_impl(addr, size); + } else if (extent_hooks->dalloc == NULL) { return true; + } else { + ehooks_pre_reentrancy(tsdn); + bool err = extent_hooks->dalloc(extent_hooks, addr, size, + committed, arena_ind); + ehooks_post_reentrancy(tsdn); + return err; } - return extent_hooks->dalloc(extent_hooks, addr, size, committed, - arena_ind); } static inline void diff --git a/src/base.c b/src/base.c index 4f47438f..52699c50 100644 --- a/src/base.c +++ b/src/base.c @@ -81,7 +81,7 @@ base_unmap(tsdn_t *tsdn, ehooks_t *ehooks, unsigned ind, void *addr, } else { tsd_t *tsd = tsdn_null(tsdn) ? tsd_fetch() : tsdn_tsd(tsdn); pre_reentrancy(tsd, NULL); - if (!ehooks_dalloc(ehooks, addr, size, true, ind)) { + if (!ehooks_dalloc(tsdn, ehooks, addr, size, true, ind)) { goto label_post_reentrancy; } if (!ehooks_decommit(ehooks, addr, size, 0, size, ind)) { diff --git a/src/ehooks.c b/src/ehooks.c index ba62b8da..9a266ef0 100644 --- a/src/ehooks.c +++ b/src/ehooks.c @@ -75,3 +75,17 @@ ehooks_default_alloc(extent_hooks_t *extent_hooks, void *new_addr, size_t size, ALIGNMENT_CEILING(alignment, PAGE), zero, commit, arena_ind_get(arena)); } + +bool +ehooks_default_dalloc_impl(void *addr, size_t size) { + if (!have_dss || !extent_in_dss(addr)) { + return extent_dalloc_mmap(addr, size); + } + return true; +} + +bool +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); +} diff --git a/src/extent.c b/src/extent.c index 96547a5e..676d7ac0 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 bool extent_dalloc_default(extent_hooks_t *extent_hooks, void *addr, - size_t size, bool committed, unsigned arena_ind); 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, @@ -58,7 +56,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, - extent_dalloc_default, + ehooks_default_dalloc, extent_destroy_default, extent_commit_default, extent_decommit_default @@ -1344,20 +1342,6 @@ extent_may_dalloc(void) { return !opt_retain; } -static bool -extent_dalloc_default_impl(void *addr, size_t size) { - if (!have_dss || !extent_in_dss(addr)) { - return extent_dalloc_mmap(addr, size); - } - return true; -} - -static bool -extent_dalloc_default(extent_hooks_t *extent_hooks, void *addr, size_t size, - bool committed, unsigned arena_ind) { - return extent_dalloc_default_impl(addr, size); -} - static bool extent_dalloc_wrapper_try(tsdn_t *tsdn, arena_t *arena, ehooks_t *ehooks, extent_t *extent) { @@ -1371,17 +1355,9 @@ extent_dalloc_wrapper_try(tsdn_t *tsdn, arena_t *arena, ehooks_t *ehooks, extent_addr_set(extent, extent_base_get(extent)); /* Try to deallocate. */ - if (ehooks_are_default(ehooks)) { - /* Call directly to propagate tsdn. */ - err = extent_dalloc_default_impl(extent_base_get(extent), - extent_size_get(extent)); - } else { - extent_hook_pre_reentrancy(tsdn, arena); - err = ehooks_dalloc(ehooks, extent_base_get(extent), - extent_size_get(extent), extent_committed_get(extent), - arena_ind_get(arena)); - extent_hook_post_reentrancy(tsdn); - } + err = ehooks_dalloc(tsdn, ehooks, extent_base_get(extent), + extent_size_get(extent), extent_committed_get(extent), + arena_ind_get(arena)); if (!err) { extent_dalloc(tsdn, arena, extent);