Extent -> Ehooks: Move dalloc hook.
This commit is contained in:
parent
dc8b4e6e13
commit
bac8e2e5a6
@ -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,
|
size_t size, size_t alignment, bool *zero, bool *commit,
|
||||||
unsigned arena_ind);
|
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
|
static inline void
|
||||||
ehooks_pre_reentrancy(tsdn_t *tsdn) {
|
ehooks_pre_reentrancy(tsdn_t *tsdn) {
|
||||||
tsd_t *tsd = tsdn_null(tsdn) ? tsd_fetch() : tsdn_tsd(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
|
static inline bool
|
||||||
ehooks_dalloc(ehooks_t *ehooks, void *addr, size_t size, bool committed,
|
ehooks_dalloc(tsdn_t *tsdn, ehooks_t *ehooks, void *addr, size_t size,
|
||||||
unsigned arena_ind) {
|
bool committed, unsigned arena_ind) {
|
||||||
extent_hooks_t *extent_hooks = ehooks_get_extent_hooks_ptr(ehooks);
|
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;
|
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
|
static inline void
|
||||||
|
@ -81,7 +81,7 @@ base_unmap(tsdn_t *tsdn, ehooks_t *ehooks, unsigned ind, void *addr,
|
|||||||
} else {
|
} else {
|
||||||
tsd_t *tsd = tsdn_null(tsdn) ? tsd_fetch() : tsdn_tsd(tsdn);
|
tsd_t *tsd = tsdn_null(tsdn) ? tsd_fetch() : tsdn_tsd(tsdn);
|
||||||
pre_reentrancy(tsd, NULL);
|
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;
|
goto label_post_reentrancy;
|
||||||
}
|
}
|
||||||
if (!ehooks_decommit(ehooks, addr, size, 0, size, ind)) {
|
if (!ehooks_decommit(ehooks, addr, size, 0, size, ind)) {
|
||||||
|
14
src/ehooks.c
14
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,
|
ALIGNMENT_CEILING(alignment, PAGE), zero, commit,
|
||||||
arena_ind_get(arena));
|
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);
|
||||||
|
}
|
||||||
|
32
src/extent.c
32
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;
|
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,
|
static void extent_destroy_default(extent_hooks_t *extent_hooks, void *addr,
|
||||||
size_t size, bool committed, unsigned arena_ind);
|
size_t size, bool committed, unsigned arena_ind);
|
||||||
static bool extent_commit_default(extent_hooks_t *extent_hooks, void *addr,
|
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 = {
|
const extent_hooks_t extent_hooks_default = {
|
||||||
ehooks_default_alloc,
|
ehooks_default_alloc,
|
||||||
extent_dalloc_default,
|
ehooks_default_dalloc,
|
||||||
extent_destroy_default,
|
extent_destroy_default,
|
||||||
extent_commit_default,
|
extent_commit_default,
|
||||||
extent_decommit_default
|
extent_decommit_default
|
||||||
@ -1344,20 +1342,6 @@ extent_may_dalloc(void) {
|
|||||||
return !opt_retain;
|
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
|
static bool
|
||||||
extent_dalloc_wrapper_try(tsdn_t *tsdn, arena_t *arena, ehooks_t *ehooks,
|
extent_dalloc_wrapper_try(tsdn_t *tsdn, arena_t *arena, ehooks_t *ehooks,
|
||||||
extent_t *extent) {
|
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));
|
extent_addr_set(extent, extent_base_get(extent));
|
||||||
|
|
||||||
/* Try to deallocate. */
|
/* Try to deallocate. */
|
||||||
if (ehooks_are_default(ehooks)) {
|
err = ehooks_dalloc(tsdn, ehooks, extent_base_get(extent),
|
||||||
/* Call directly to propagate tsdn. */
|
extent_size_get(extent), extent_committed_get(extent),
|
||||||
err = extent_dalloc_default_impl(extent_base_get(extent),
|
arena_ind_get(arena));
|
||||||
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);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!err) {
|
if (!err) {
|
||||||
extent_dalloc(tsdn, arena, extent);
|
extent_dalloc(tsdn, arena, extent);
|
||||||
|
Loading…
Reference in New Issue
Block a user