mirror of
https://github.com/jemalloc/jemalloc.git
synced 2026-07-23 17:17:19 +03:00
Remove generic experimental hooks
This commit is contained in:
parent
3f9d8ca3d0
commit
ff2c2548a3
20 changed files with 25 additions and 1636 deletions
17
src/arena.c
17
src/arena.c
|
|
@ -1694,8 +1694,7 @@ arena_ralloc_move_helper(tsdn_t *tsdn, arena_t *arena, size_t usize,
|
|||
|
||||
void *
|
||||
arena_ralloc(tsdn_t *tsdn, arena_t *arena, void *ptr, size_t oldsize,
|
||||
size_t size, size_t alignment, bool zero, bool slab, tcache_t *tcache,
|
||||
hook_ralloc_args_t *hook_args) {
|
||||
size_t size, size_t alignment, bool zero, bool slab, tcache_t *tcache) {
|
||||
size_t usize = alignment == 0 ? sz_s2u(size) : sz_sa2u(size, alignment);
|
||||
if (unlikely(usize == 0 || size > SC_LARGE_MAXCLASS)) {
|
||||
return NULL;
|
||||
|
|
@ -1707,18 +1706,13 @@ arena_ralloc(tsdn_t *tsdn, arena_t *arena, void *ptr, size_t oldsize,
|
|||
UNUSED size_t newsize;
|
||||
if (!arena_ralloc_no_move(
|
||||
tsdn, ptr, oldsize, usize, 0, zero, &newsize)) {
|
||||
hook_invoke_expand(hook_args->is_realloc
|
||||
? hook_expand_realloc
|
||||
: hook_expand_rallocx,
|
||||
ptr, oldsize, usize, (uintptr_t)ptr,
|
||||
hook_args->args);
|
||||
return ptr;
|
||||
}
|
||||
}
|
||||
|
||||
if (oldsize >= SC_LARGE_MINCLASS && usize >= SC_LARGE_MINCLASS) {
|
||||
return large_ralloc(tsdn, arena, ptr, usize, alignment, zero,
|
||||
tcache, hook_args);
|
||||
tcache);
|
||||
}
|
||||
|
||||
/*
|
||||
|
|
@ -1731,13 +1725,6 @@ arena_ralloc(tsdn_t *tsdn, arena_t *arena, void *ptr, size_t oldsize,
|
|||
return NULL;
|
||||
}
|
||||
|
||||
hook_invoke_alloc(
|
||||
hook_args->is_realloc ? hook_alloc_realloc : hook_alloc_rallocx,
|
||||
ret, (uintptr_t)ret, hook_args->args);
|
||||
hook_invoke_dalloc(
|
||||
hook_args->is_realloc ? hook_dalloc_realloc : hook_dalloc_rallocx,
|
||||
ptr, hook_args->args);
|
||||
|
||||
/*
|
||||
* Junk/zero-filling were already done by
|
||||
* ipalloc()/arena_malloc().
|
||||
|
|
|
|||
49
src/ctl.c
49
src/ctl.c
|
|
@ -361,8 +361,6 @@ CTL_PROTO(stats_retained)
|
|||
CTL_PROTO(stats_pinned)
|
||||
CTL_PROTO(stats_zero_reallocs)
|
||||
CTL_PROTO(approximate_stats_active)
|
||||
CTL_PROTO(experimental_hooks_install)
|
||||
CTL_PROTO(experimental_hooks_remove)
|
||||
CTL_PROTO(experimental_hooks_prof_backtrace)
|
||||
CTL_PROTO(experimental_hooks_prof_dump)
|
||||
CTL_PROTO(experimental_hooks_prof_sample)
|
||||
|
|
@ -887,8 +885,6 @@ static const ctl_named_node_t stats_node[] = {
|
|||
};
|
||||
|
||||
static const ctl_named_node_t experimental_hooks_node[] = {
|
||||
{NAME("install"), CTL(experimental_hooks_install)},
|
||||
{NAME("remove"), CTL(experimental_hooks_remove)},
|
||||
{NAME("prof_backtrace"), CTL(experimental_hooks_prof_backtrace)},
|
||||
{NAME("prof_dump"), CTL(experimental_hooks_prof_dump)},
|
||||
{NAME("prof_sample"), CTL(experimental_hooks_prof_sample)},
|
||||
|
|
@ -4223,51 +4219,6 @@ label_return:
|
|||
return ret;
|
||||
}
|
||||
|
||||
static int
|
||||
experimental_hooks_install_ctl(tsd_t *tsd, const size_t *mib, size_t miblen,
|
||||
void *oldp, size_t *oldlenp, void *newp, size_t newlen) {
|
||||
int ret;
|
||||
if (oldp == NULL || oldlenp == NULL || newp == NULL) {
|
||||
ret = EINVAL;
|
||||
goto label_return;
|
||||
}
|
||||
/*
|
||||
* Note: this is a *private* struct. This is an experimental interface;
|
||||
* forcing the user to know the jemalloc internals well enough to
|
||||
* extract the ABI hopefully ensures nobody gets too comfortable with
|
||||
* this API, which can change at a moment's notice.
|
||||
*/
|
||||
hooks_t hooks;
|
||||
WRITE(hooks, hooks_t);
|
||||
void *handle = hook_install(tsd_tsdn(tsd), &hooks);
|
||||
if (handle == NULL) {
|
||||
ret = EAGAIN;
|
||||
goto label_return;
|
||||
}
|
||||
READ(handle, void *);
|
||||
|
||||
ret = 0;
|
||||
label_return:
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int
|
||||
experimental_hooks_remove_ctl(tsd_t *tsd, const size_t *mib, size_t miblen,
|
||||
void *oldp, size_t *oldlenp, void *newp, size_t newlen) {
|
||||
int ret;
|
||||
WRITEONLY();
|
||||
void *handle = NULL;
|
||||
WRITE(handle, void *);
|
||||
if (handle == NULL) {
|
||||
ret = EINVAL;
|
||||
goto label_return;
|
||||
}
|
||||
hook_remove(tsd_tsdn(tsd), handle);
|
||||
ret = 0;
|
||||
label_return:
|
||||
return ret;
|
||||
}
|
||||
|
||||
/*
|
||||
* Output six memory utilization entries for an input pointer, the first one of
|
||||
* type (void *) and the remaining five of type size_t, describing the following
|
||||
|
|
|
|||
192
src/hook.c
192
src/hook.c
|
|
@ -1,192 +0,0 @@
|
|||
#include "jemalloc/internal/jemalloc_preamble.h"
|
||||
|
||||
#include "jemalloc/internal/hook.h"
|
||||
|
||||
#include "jemalloc/internal/atomic.h"
|
||||
#include "jemalloc/internal/mutex.h"
|
||||
#include "jemalloc/internal/seq.h"
|
||||
|
||||
typedef struct hooks_internal_s hooks_internal_t;
|
||||
struct hooks_internal_s {
|
||||
hooks_t hooks;
|
||||
bool in_use;
|
||||
};
|
||||
|
||||
seq_define(hooks_internal_t, hooks)
|
||||
|
||||
static atomic_u_t nhooks = ATOMIC_INIT(0);
|
||||
static seq_hooks_t hooks[HOOK_MAX];
|
||||
static malloc_mutex_t hooks_mu;
|
||||
|
||||
bool
|
||||
hook_boot(void) {
|
||||
return malloc_mutex_init(
|
||||
&hooks_mu, "hooks", WITNESS_RANK_HOOK, malloc_mutex_rank_exclusive);
|
||||
}
|
||||
|
||||
static void *
|
||||
hook_install_locked(hooks_t *to_install) {
|
||||
hooks_internal_t hooks_internal;
|
||||
for (int i = 0; i < HOOK_MAX; i++) {
|
||||
bool success = seq_try_load_hooks(&hooks_internal, &hooks[i]);
|
||||
/* We hold mu; no concurrent access. */
|
||||
assert(success);
|
||||
if (!hooks_internal.in_use) {
|
||||
hooks_internal.hooks = *to_install;
|
||||
hooks_internal.in_use = true;
|
||||
seq_store_hooks(&hooks[i], &hooks_internal);
|
||||
atomic_store_u(&nhooks,
|
||||
atomic_load_u(&nhooks, ATOMIC_RELAXED) + 1,
|
||||
ATOMIC_RELAXED);
|
||||
return &hooks[i];
|
||||
}
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void *
|
||||
hook_install(tsdn_t *tsdn, hooks_t *to_install) {
|
||||
malloc_mutex_lock(tsdn, &hooks_mu);
|
||||
void *ret = hook_install_locked(to_install);
|
||||
if (ret != NULL) {
|
||||
tsd_global_slow_inc(tsdn);
|
||||
}
|
||||
malloc_mutex_unlock(tsdn, &hooks_mu);
|
||||
return ret;
|
||||
}
|
||||
|
||||
static void
|
||||
hook_remove_locked(seq_hooks_t *to_remove) {
|
||||
hooks_internal_t hooks_internal;
|
||||
bool success = seq_try_load_hooks(&hooks_internal, to_remove);
|
||||
/* We hold mu; no concurrent access. */
|
||||
assert(success);
|
||||
/* Should only remove hooks that were added. */
|
||||
assert(hooks_internal.in_use);
|
||||
hooks_internal.in_use = false;
|
||||
seq_store_hooks(to_remove, &hooks_internal);
|
||||
atomic_store_u(&nhooks, atomic_load_u(&nhooks, ATOMIC_RELAXED) - 1,
|
||||
ATOMIC_RELAXED);
|
||||
}
|
||||
|
||||
void
|
||||
hook_remove(tsdn_t *tsdn, void *opaque) {
|
||||
if (config_debug) {
|
||||
char *hooks_begin = (char *)&hooks[0];
|
||||
char *hooks_end = (char *)&hooks[HOOK_MAX];
|
||||
char *hook = (char *)opaque;
|
||||
assert(hooks_begin <= hook && hook < hooks_end
|
||||
&& (hook - hooks_begin) % sizeof(seq_hooks_t) == 0);
|
||||
}
|
||||
malloc_mutex_lock(tsdn, &hooks_mu);
|
||||
hook_remove_locked((seq_hooks_t *)opaque);
|
||||
tsd_global_slow_dec(tsdn);
|
||||
malloc_mutex_unlock(tsdn, &hooks_mu);
|
||||
}
|
||||
|
||||
#define FOR_EACH_HOOK_BEGIN(hooks_internal_ptr) \
|
||||
for (int for_each_hook_counter = 0; for_each_hook_counter < HOOK_MAX; \
|
||||
for_each_hook_counter++) { \
|
||||
bool for_each_hook_success = seq_try_load_hooks( \
|
||||
(hooks_internal_ptr), &hooks[for_each_hook_counter]); \
|
||||
if (!for_each_hook_success) { \
|
||||
continue; \
|
||||
} \
|
||||
if (!(hooks_internal_ptr)->in_use) { \
|
||||
continue; \
|
||||
}
|
||||
#define FOR_EACH_HOOK_END }
|
||||
|
||||
static bool *
|
||||
hook_reentrantp(void) {
|
||||
/*
|
||||
* We prevent user reentrancy within hooks. This is basically just a
|
||||
* thread-local bool that triggers an early-exit.
|
||||
*
|
||||
* We don't fold in_hook into reentrancy. There are two reasons for
|
||||
* this:
|
||||
* - Right now, we turn on reentrancy during things like extent hook
|
||||
* execution. Allocating during extent hooks is not officially
|
||||
* supported, but we don't want to break it for the time being. These
|
||||
* sorts of allocations should probably still be hooked, though.
|
||||
* - If a hook allocates, we may want it to be relatively fast (after
|
||||
* all, it executes on every allocator operation). Turning on
|
||||
* reentrancy is a fairly heavyweight mode (disabling tcache,
|
||||
* redirecting to arena 0, etc.). It's possible we may one day want
|
||||
* to turn on reentrant mode here, if it proves too difficult to keep
|
||||
* this working. But that's fairly easy for us to see; OTOH, people
|
||||
* not using hooks because they're too slow is easy for us to miss.
|
||||
*
|
||||
* The tricky part is
|
||||
* that this code might get invoked even if we don't have access to tsd.
|
||||
* This function mimics getting a pointer to thread-local data, except
|
||||
* that it might secretly return a pointer to some global data if we
|
||||
* know that the caller will take the early-exit path.
|
||||
* If we return a bool that indicates that we are reentrant, then the
|
||||
* caller will go down the early exit path, leaving the global
|
||||
* untouched.
|
||||
*/
|
||||
static bool in_hook_global = true;
|
||||
tsdn_t *tsdn = tsdn_fetch();
|
||||
bool *in_hook = tsdn_in_hookp_get(tsdn);
|
||||
if (in_hook != NULL) {
|
||||
return in_hook;
|
||||
}
|
||||
return &in_hook_global;
|
||||
}
|
||||
|
||||
#define HOOK_PROLOGUE \
|
||||
if (likely(atomic_load_u(&nhooks, ATOMIC_RELAXED) == 0)) { \
|
||||
return; \
|
||||
} \
|
||||
bool *in_hook = hook_reentrantp(); \
|
||||
if (*in_hook) { \
|
||||
return; \
|
||||
} \
|
||||
*in_hook = true;
|
||||
|
||||
#define HOOK_EPILOGUE *in_hook = false;
|
||||
|
||||
void
|
||||
hook_invoke_alloc(hook_alloc_t type, void *result, uintptr_t result_raw,
|
||||
uintptr_t args_raw[3]) {
|
||||
HOOK_PROLOGUE
|
||||
|
||||
hooks_internal_t hook;
|
||||
FOR_EACH_HOOK_BEGIN(&hook)
|
||||
hook_alloc h = hook.hooks.alloc_hook;
|
||||
if (h != NULL) {
|
||||
h(hook.hooks.extra, type, result, result_raw, args_raw);
|
||||
}
|
||||
FOR_EACH_HOOK_END
|
||||
|
||||
HOOK_EPILOGUE
|
||||
}
|
||||
|
||||
void
|
||||
hook_invoke_dalloc(hook_dalloc_t type, void *address, uintptr_t args_raw[3]) {
|
||||
HOOK_PROLOGUE
|
||||
hooks_internal_t hook;
|
||||
FOR_EACH_HOOK_BEGIN(&hook)
|
||||
hook_dalloc h = hook.hooks.dalloc_hook;
|
||||
if (h != NULL) {
|
||||
h(hook.hooks.extra, type, address, args_raw);
|
||||
}
|
||||
FOR_EACH_HOOK_END
|
||||
HOOK_EPILOGUE
|
||||
}
|
||||
|
||||
void
|
||||
hook_invoke_expand(hook_expand_t type, void *address, size_t old_usize,
|
||||
size_t new_usize, uintptr_t result_raw, uintptr_t args_raw[4]) {
|
||||
HOOK_PROLOGUE
|
||||
hooks_internal_t hook;
|
||||
FOR_EACH_HOOK_BEGIN(&hook)
|
||||
hook_expand h = hook.hooks.expand_hook;
|
||||
if (h != NULL) {
|
||||
h(hook.hooks.extra, type, address, old_usize, new_usize,
|
||||
result_raw, args_raw);
|
||||
}
|
||||
FOR_EACH_HOOK_END
|
||||
HOOK_EPILOGUE
|
||||
}
|
||||
|
|
@ -11,7 +11,6 @@
|
|||
#include "jemalloc/internal/extent_mmap.h"
|
||||
#include "jemalloc/internal/fxp.h"
|
||||
#include "jemalloc/internal/san.h"
|
||||
#include "jemalloc/internal/hook.h"
|
||||
#include "jemalloc/internal/jemalloc_init.h"
|
||||
#include "jemalloc/internal/jemalloc_internal_types.h"
|
||||
#include "jemalloc/internal/log.h"
|
||||
|
|
@ -776,14 +775,6 @@ malloc_default(size_t size) {
|
|||
dopts.item_size = size;
|
||||
|
||||
imalloc(&sopts, &dopts);
|
||||
/*
|
||||
* Note that this branch gets optimized away -- it immediately follows
|
||||
* the check on tsd_fast that sets sopts.slow.
|
||||
*/
|
||||
if (sopts.slow) {
|
||||
uintptr_t args[3] = {size};
|
||||
hook_invoke_alloc(hook_alloc_malloc, ret, (uintptr_t)ret, args);
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
|
@ -832,12 +823,6 @@ JEMALLOC_ATTR(nonnull(1))
|
|||
dopts.alignment = alignment;
|
||||
|
||||
ret = imalloc(&sopts, &dopts);
|
||||
if (sopts.slow) {
|
||||
uintptr_t args[3] = {
|
||||
(uintptr_t)memptr, (uintptr_t)alignment, (uintptr_t)size};
|
||||
hook_invoke_alloc(
|
||||
hook_alloc_posix_memalign, *memptr, (uintptr_t)ret, args);
|
||||
}
|
||||
|
||||
LOG("core.posix_memalign.exit", "result: %d, alloc ptr: %p", ret,
|
||||
*memptr);
|
||||
|
|
@ -875,11 +860,6 @@ JEMALLOC_ATTR(malloc) JEMALLOC_ALLOC_SIZE(2)
|
|||
dopts.alignment = alignment;
|
||||
|
||||
imalloc(&sopts, &dopts);
|
||||
if (sopts.slow) {
|
||||
uintptr_t args[3] = {(uintptr_t)alignment, (uintptr_t)size};
|
||||
hook_invoke_alloc(
|
||||
hook_alloc_aligned_alloc, ret, (uintptr_t)ret, args);
|
||||
}
|
||||
|
||||
LOG("core.aligned_alloc.exit", "result: %p", ret);
|
||||
|
||||
|
|
@ -910,10 +890,6 @@ JEMALLOC_ATTR(malloc) JEMALLOC_ALLOC_SIZE2(1, 2)
|
|||
dopts.zero = true;
|
||||
|
||||
imalloc(&sopts, &dopts);
|
||||
if (sopts.slow) {
|
||||
uintptr_t args[3] = {(uintptr_t)num, (uintptr_t)size};
|
||||
hook_invoke_alloc(hook_alloc_calloc, ret, (uintptr_t)ret, args);
|
||||
}
|
||||
|
||||
LOG("core.calloc.exit", "result: %p", ret);
|
||||
|
||||
|
|
@ -1056,8 +1032,6 @@ free_default(void *ptr) {
|
|||
tcache_t *tcache = tcache_get_from_ind(tsd,
|
||||
TCACHE_IND_AUTOMATIC, /* slow */ true,
|
||||
/* is_alloc */ false);
|
||||
uintptr_t args_raw[3] = {(uintptr_t)ptr};
|
||||
hook_invoke_dalloc(hook_dalloc_free, ptr, args_raw);
|
||||
ifree(tsd, ptr, tcache, /* slow */ true);
|
||||
}
|
||||
|
||||
|
|
@ -1125,11 +1099,6 @@ JEMALLOC_ATTR(malloc) je_memalign(size_t alignment, size_t size) {
|
|||
dopts.alignment = alignment;
|
||||
|
||||
imalloc(&sopts, &dopts);
|
||||
if (sopts.slow) {
|
||||
uintptr_t args[3] = {alignment, size};
|
||||
hook_invoke_alloc(
|
||||
hook_alloc_memalign, ret, (uintptr_t)ret, args);
|
||||
}
|
||||
|
||||
LOG("core.memalign.exit", "result: %p", ret);
|
||||
return ret;
|
||||
|
|
@ -1163,10 +1132,6 @@ JEMALLOC_ATTR(malloc) je_valloc(size_t size) {
|
|||
dopts.alignment = PAGE;
|
||||
|
||||
imalloc(&sopts, &dopts);
|
||||
if (sopts.slow) {
|
||||
uintptr_t args[3] = {size};
|
||||
hook_invoke_alloc(hook_alloc_valloc, ret, (uintptr_t)ret, args);
|
||||
}
|
||||
|
||||
LOG("core.valloc.exit", "result: %p\n", ret);
|
||||
return ret;
|
||||
|
|
@ -1204,11 +1169,6 @@ JEMALLOC_ATTR(malloc) je_pvalloc(size_t size) {
|
|||
dopts.alignment = PAGE;
|
||||
|
||||
imalloc(&sopts, &dopts);
|
||||
if (sopts.slow) {
|
||||
uintptr_t args[3] = {size};
|
||||
hook_invoke_alloc(
|
||||
hook_alloc_pvalloc, ret, (uintptr_t)ret, args);
|
||||
}
|
||||
|
||||
LOG("core.pvalloc.exit", "result: %p\n", ret);
|
||||
return ret;
|
||||
|
|
@ -1397,11 +1357,6 @@ JEMALLOC_ATTR(malloc) JEMALLOC_ALLOC_SIZE(1)
|
|||
}
|
||||
|
||||
imalloc(&sopts, &dopts);
|
||||
if (sopts.slow) {
|
||||
uintptr_t args[3] = {size, flags};
|
||||
hook_invoke_alloc(
|
||||
hook_alloc_mallocx, ret, (uintptr_t)ret, args);
|
||||
}
|
||||
|
||||
LOG("core.mallocx.exit", "result: %p", ret);
|
||||
return ret;
|
||||
|
|
@ -1410,7 +1365,7 @@ JEMALLOC_ATTR(malloc) JEMALLOC_ALLOC_SIZE(1)
|
|||
static void *
|
||||
irallocx_prof_sample(tsdn_t *tsdn, void *old_ptr, size_t old_usize,
|
||||
size_t usize, size_t alignment, bool zero, tcache_t *tcache, arena_t *arena,
|
||||
prof_tctx_t *tctx, hook_ralloc_args_t *hook_args) {
|
||||
prof_tctx_t *tctx) {
|
||||
void *p;
|
||||
|
||||
if (tctx == NULL) {
|
||||
|
|
@ -1427,15 +1382,14 @@ irallocx_prof_sample(tsdn_t *tsdn, void *old_ptr, size_t old_usize,
|
|||
size_t bumped_usize = sz_sa2u(usize, alignment);
|
||||
p = iralloct_explicit_slab(tsdn, old_ptr, old_usize,
|
||||
bumped_usize, alignment, zero, /* slab */ false, tcache,
|
||||
arena, hook_args);
|
||||
arena);
|
||||
if (p == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
arena_prof_promote(tsdn, p, usize, bumped_usize);
|
||||
} else {
|
||||
p = iralloct_explicit_slab(tsdn, old_ptr, old_usize, usize,
|
||||
alignment, zero, /* slab */ false, tcache, arena,
|
||||
hook_args);
|
||||
alignment, zero, /* slab */ false, tcache, arena);
|
||||
}
|
||||
assert(prof_sample_aligned(p));
|
||||
|
||||
|
|
@ -1445,7 +1399,7 @@ irallocx_prof_sample(tsdn_t *tsdn, void *old_ptr, size_t old_usize,
|
|||
JEMALLOC_ALWAYS_INLINE void *
|
||||
irallocx_prof(tsd_t *tsd, void *old_ptr, size_t old_usize, size_t size,
|
||||
size_t alignment, size_t usize, bool zero, tcache_t *tcache, arena_t *arena,
|
||||
emap_alloc_ctx_t *alloc_ctx, hook_ralloc_args_t *hook_args) {
|
||||
emap_alloc_ctx_t *alloc_ctx) {
|
||||
prof_info_t old_prof_info;
|
||||
prof_info_get_and_reset_recent(tsd, old_ptr, alloc_ctx, &old_prof_info);
|
||||
bool prof_active = prof_active_get_unlocked();
|
||||
|
|
@ -1454,10 +1408,10 @@ irallocx_prof(tsd_t *tsd, void *old_ptr, size_t old_usize, size_t size,
|
|||
void *p;
|
||||
if (unlikely(tctx != PROF_TCTX_SENTINEL)) {
|
||||
p = irallocx_prof_sample(tsd_tsdn(tsd), old_ptr, old_usize,
|
||||
usize, alignment, zero, tcache, arena, tctx, hook_args);
|
||||
usize, alignment, zero, tcache, arena, tctx);
|
||||
} else {
|
||||
p = iralloct(tsd_tsdn(tsd), old_ptr, old_usize, size, alignment,
|
||||
usize, zero, tcache, arena, hook_args);
|
||||
usize, zero, tcache, arena);
|
||||
}
|
||||
if (unlikely(p == NULL)) {
|
||||
prof_alloc_rollback(tsd, tctx);
|
||||
|
|
@ -1506,17 +1460,15 @@ do_rallocx(void *ptr, size_t size, int flags, bool is_realloc) {
|
|||
goto label_oom;
|
||||
}
|
||||
|
||||
hook_ralloc_args_t hook_args = {
|
||||
is_realloc, {(uintptr_t)ptr, size, flags, 0}};
|
||||
if (config_prof && opt_prof) {
|
||||
p = irallocx_prof(tsd, ptr, old_usize, size, alignment, usize,
|
||||
zero, tcache, arena, &alloc_ctx, &hook_args);
|
||||
zero, tcache, arena, &alloc_ctx);
|
||||
if (unlikely(p == NULL)) {
|
||||
goto label_oom;
|
||||
}
|
||||
} else {
|
||||
p = iralloct(tsd_tsdn(tsd), ptr, old_usize, size, alignment,
|
||||
usize, zero, tcache, arena, &hook_args);
|
||||
usize, zero, tcache, arena);
|
||||
if (unlikely(p == NULL)) {
|
||||
goto label_oom;
|
||||
}
|
||||
|
|
@ -1582,8 +1534,6 @@ do_realloc_nonnull_zero(void *ptr) {
|
|||
tcache_t *tcache = tcache_get_from_ind(tsd,
|
||||
TCACHE_IND_AUTOMATIC, /* slow */ true,
|
||||
/* is_alloc */ false);
|
||||
uintptr_t args[3] = {(uintptr_t)ptr, 0};
|
||||
hook_invoke_dalloc(hook_dalloc_realloc, ptr, args);
|
||||
ifree(tsd, ptr, tcache, true);
|
||||
|
||||
check_entry_exit_locking(tsd_tsdn(tsd));
|
||||
|
|
@ -1634,11 +1584,6 @@ JEMALLOC_ALLOC_SIZE(2) je_realloc(void *ptr, size_t size) {
|
|||
dopts.item_size = size;
|
||||
|
||||
imalloc(&sopts, &dopts);
|
||||
if (sopts.slow) {
|
||||
uintptr_t args[3] = {(uintptr_t)ptr, size};
|
||||
hook_invoke_alloc(
|
||||
hook_alloc_realloc, ret, (uintptr_t)ret, args);
|
||||
}
|
||||
LOG("core.realloc.exit", "result: %p", ret);
|
||||
return ret;
|
||||
}
|
||||
|
|
@ -1818,12 +1763,6 @@ je_xallocx(void *ptr, size_t size, size_t extra, int flags) {
|
|||
junk_alloc_callback(excess_start, excess_len);
|
||||
}
|
||||
label_not_resized:
|
||||
if (unlikely(!tsd_fast(tsd))) {
|
||||
uintptr_t args[4] = {(uintptr_t)ptr, size, extra, flags};
|
||||
hook_invoke_expand(hook_expand_xallocx, ptr, old_usize, usize,
|
||||
(uintptr_t)usize, args);
|
||||
}
|
||||
|
||||
UTRACE(ptr, size, ptr);
|
||||
check_entry_exit_locking(tsd_tsdn(tsd));
|
||||
|
||||
|
|
@ -1877,8 +1816,6 @@ je_dallocx(void *ptr, int flags) {
|
|||
tsd_assert_fast(tsd);
|
||||
ifree(tsd, ptr, tcache, false);
|
||||
} else {
|
||||
uintptr_t args_raw[3] = {(uintptr_t)ptr, flags};
|
||||
hook_invoke_dalloc(hook_dalloc_dallocx, ptr, args_raw);
|
||||
ifree(tsd, ptr, tcache, true);
|
||||
}
|
||||
check_entry_exit_locking(tsd_tsdn(tsd));
|
||||
|
|
@ -1916,8 +1853,6 @@ sdallocx_default(void *ptr, size_t size, int flags) {
|
|||
tsd_assert_fast(tsd);
|
||||
isfree(tsd, ptr, usize, tcache, false);
|
||||
} else {
|
||||
uintptr_t args_raw[3] = {(uintptr_t)ptr, size, flags};
|
||||
hook_invoke_dalloc(hook_dalloc_sdallocx, ptr, args_raw);
|
||||
isfree(tsd, ptr, usize, tcache, true);
|
||||
}
|
||||
check_entry_exit_locking(tsd_tsdn(tsd));
|
||||
|
|
|
|||
|
|
@ -7,7 +7,6 @@
|
|||
#include "jemalloc/internal/emap.h"
|
||||
#include "jemalloc/internal/extent_dss.h"
|
||||
#include "jemalloc/internal/extent_mmap.h"
|
||||
#include "jemalloc/internal/hook.h"
|
||||
#include "jemalloc/internal/jemalloc_fork.h"
|
||||
#include "jemalloc/internal/jemalloc_init.h"
|
||||
#include "jemalloc/internal/malloc_io.h"
|
||||
|
|
@ -234,7 +233,6 @@ malloc_init_hard_a0_locked(void) {
|
|||
if (arenas_management_boot()) {
|
||||
return true;
|
||||
}
|
||||
hook_boot();
|
||||
experimental_thread_events_boot();
|
||||
/*
|
||||
* Create enough scaffolding to allow recursive allocation in
|
||||
|
|
|
|||
13
src/large.c
13
src/large.c
|
|
@ -184,8 +184,7 @@ large_ralloc_move_helper(
|
|||
|
||||
void *
|
||||
large_ralloc(tsdn_t *tsdn, arena_t *arena, void *ptr, size_t usize,
|
||||
size_t alignment, bool zero, tcache_t *tcache,
|
||||
hook_ralloc_args_t *hook_args) {
|
||||
size_t alignment, bool zero, tcache_t *tcache) {
|
||||
edata_t *edata = emap_edata_lookup(tsdn, &arena_emap_global, ptr);
|
||||
|
||||
size_t oldusize = edata_usize_get(edata);
|
||||
|
|
@ -196,9 +195,6 @@ large_ralloc(tsdn_t *tsdn, arena_t *arena, void *ptr, size_t usize,
|
|||
|
||||
/* Try to avoid moving the allocation. */
|
||||
if (!large_ralloc_no_move(tsdn, edata, usize, usize, zero)) {
|
||||
hook_invoke_expand(hook_args->is_realloc ? hook_expand_realloc
|
||||
: hook_expand_rallocx,
|
||||
ptr, oldusize, usize, (uintptr_t)ptr, hook_args->args);
|
||||
return edata_addr_get(edata);
|
||||
}
|
||||
|
||||
|
|
@ -213,13 +209,6 @@ large_ralloc(tsdn_t *tsdn, arena_t *arena, void *ptr, size_t usize,
|
|||
return NULL;
|
||||
}
|
||||
|
||||
hook_invoke_alloc(
|
||||
hook_args->is_realloc ? hook_alloc_realloc : hook_alloc_rallocx,
|
||||
ret, (uintptr_t)ret, hook_args->args);
|
||||
hook_invoke_dalloc(
|
||||
hook_args->is_realloc ? hook_dalloc_realloc : hook_dalloc_rallocx,
|
||||
ptr, hook_args->args);
|
||||
|
||||
size_t copysize = (usize < oldusize) ? usize : oldusize;
|
||||
memcpy(ret, edata_addr_get(edata), copysize);
|
||||
isdalloct(tsdn, edata_addr_get(edata), oldusize, tcache, NULL, true);
|
||||
|
|
|
|||
52
src/tsd.c
52
src/tsd.c
|
|
@ -63,9 +63,6 @@ typedef ql_head(tsd_t) tsd_list_t;
|
|||
static tsd_list_t tsd_nominal_tsds = ql_head_initializer(tsd_nominal_tsds);
|
||||
static malloc_mutex_t tsd_nominal_tsds_lock;
|
||||
|
||||
/* How many slow-path-enabling features are turned on. */
|
||||
static atomic_u32_t tsd_global_slow_count = ATOMIC_INIT(0);
|
||||
|
||||
static bool
|
||||
tsd_in_nominal_list(tsd_t *tsd) {
|
||||
tsd_t *tsd_list;
|
||||
|
|
@ -104,59 +101,12 @@ tsd_remove_nominal(tsd_t *tsd) {
|
|||
malloc_mutex_unlock(tsd_tsdn(tsd), &tsd_nominal_tsds_lock);
|
||||
}
|
||||
|
||||
static void
|
||||
tsd_force_recompute(tsdn_t *tsdn) {
|
||||
/*
|
||||
* The stores to tsd->state here need to synchronize with the exchange
|
||||
* in tsd_slow_update.
|
||||
*/
|
||||
atomic_fence(ATOMIC_RELEASE);
|
||||
malloc_mutex_lock(tsdn, &tsd_nominal_tsds_lock);
|
||||
tsd_t *remote_tsd;
|
||||
ql_foreach (remote_tsd, &tsd_nominal_tsds, TSD_MANGLE(tsd_link)) {
|
||||
assert(tsd_atomic_load(&remote_tsd->state, ATOMIC_RELAXED)
|
||||
<= tsd_state_nominal_max);
|
||||
tsd_atomic_store(&remote_tsd->state,
|
||||
tsd_state_nominal_recompute, ATOMIC_RELAXED);
|
||||
/* See comments in te_recompute_fast_threshold(). */
|
||||
atomic_fence(ATOMIC_SEQ_CST);
|
||||
te_next_event_fast_set_non_nominal(remote_tsd);
|
||||
}
|
||||
malloc_mutex_unlock(tsdn, &tsd_nominal_tsds_lock);
|
||||
}
|
||||
|
||||
void
|
||||
tsd_global_slow_inc(tsdn_t *tsdn) {
|
||||
atomic_fetch_add_u32(&tsd_global_slow_count, 1, ATOMIC_RELAXED);
|
||||
/*
|
||||
* We unconditionally force a recompute, even if the global slow count
|
||||
* was already positive. If we didn't, then it would be possible for us
|
||||
* to return to the user, have the user synchronize externally with some
|
||||
* other thread, and then have that other thread not have picked up the
|
||||
* update yet (since the original incrementing thread might still be
|
||||
* making its way through the tsd list).
|
||||
*/
|
||||
tsd_force_recompute(tsdn);
|
||||
}
|
||||
|
||||
void
|
||||
tsd_global_slow_dec(tsdn_t *tsdn) {
|
||||
atomic_fetch_sub_u32(&tsd_global_slow_count, 1, ATOMIC_RELAXED);
|
||||
/* See the note in ..._inc(). */
|
||||
tsd_force_recompute(tsdn);
|
||||
}
|
||||
|
||||
static bool
|
||||
tsd_local_slow(tsd_t *tsd) {
|
||||
return !tsd_tcache_enabled_get(tsd)
|
||||
|| tsd_reentrancy_level_get(tsd) > 0;
|
||||
}
|
||||
|
||||
bool
|
||||
tsd_global_slow(void) {
|
||||
return atomic_load_u32(&tsd_global_slow_count, ATOMIC_RELAXED) > 0;
|
||||
}
|
||||
|
||||
/******************************************************************************/
|
||||
|
||||
static uint8_t
|
||||
|
|
@ -165,7 +115,7 @@ tsd_state_compute(tsd_t *tsd) {
|
|||
return tsd_state_get(tsd);
|
||||
}
|
||||
/* We're in *a* nominal state; but which one? */
|
||||
if (malloc_slow || tsd_local_slow(tsd) || tsd_global_slow()) {
|
||||
if (malloc_slow || tsd_local_slow(tsd)) {
|
||||
return tsd_state_nominal_slow;
|
||||
} else {
|
||||
return tsd_state_nominal;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue