Change tsdn to tsd for profiling code path

This commit is contained in:
Yinan Zhang 2019-11-22 11:42:01 -08:00
parent b55419f9b9
commit 6945371778
8 changed files with 50 additions and 52 deletions

View File

@ -41,7 +41,7 @@ arena_choose_maybe_huge(tsd_t *tsd, arena_t *arena, size_t size) {
} }
JEMALLOC_ALWAYS_INLINE void JEMALLOC_ALWAYS_INLINE void
arena_prof_info_get(tsdn_t *tsdn, const void *ptr, alloc_ctx_t *alloc_ctx, arena_prof_info_get(tsd_t *tsd, const void *ptr, alloc_ctx_t *alloc_ctx,
prof_info_t *prof_info) { prof_info_t *prof_info) {
cassert(config_prof); cassert(config_prof);
assert(ptr != NULL); assert(ptr != NULL);
@ -52,15 +52,15 @@ arena_prof_info_get(tsdn_t *tsdn, const void *ptr, alloc_ctx_t *alloc_ctx,
/* Static check. */ /* Static check. */
if (alloc_ctx == NULL) { if (alloc_ctx == NULL) {
extent = iealloc(tsdn, ptr); extent = iealloc(tsd_tsdn(tsd), ptr);
is_slab = extent_slab_get(extent); is_slab = extent_slab_get(extent);
} else if (!unlikely(is_slab = alloc_ctx->slab)) { } else if (!unlikely(is_slab = alloc_ctx->slab)) {
extent = iealloc(tsdn, ptr); extent = iealloc(tsd_tsdn(tsd), ptr);
} }
if (unlikely(!is_slab)) { if (unlikely(!is_slab)) {
/* extent must have been initialized at this point. */ /* extent must have been initialized at this point. */
large_prof_info_get(tsdn, extent, prof_info); large_prof_info_get(extent, prof_info);
} else { } else {
memset(prof_info, 0, sizeof(prof_info_t)); memset(prof_info, 0, sizeof(prof_info_t));
prof_info->prof_tctx = (prof_tctx_t *)(uintptr_t)1U; prof_info->prof_tctx = (prof_tctx_t *)(uintptr_t)1U;
@ -68,41 +68,41 @@ arena_prof_info_get(tsdn_t *tsdn, const void *ptr, alloc_ctx_t *alloc_ctx,
} }
JEMALLOC_ALWAYS_INLINE void JEMALLOC_ALWAYS_INLINE void
arena_prof_tctx_set(tsdn_t *tsdn, const void *ptr, size_t usize, arena_prof_tctx_set(tsd_t *tsd, const void *ptr, size_t usize,
alloc_ctx_t *alloc_ctx, prof_tctx_t *tctx) { alloc_ctx_t *alloc_ctx, prof_tctx_t *tctx) {
cassert(config_prof); cassert(config_prof);
assert(ptr != NULL); assert(ptr != NULL);
/* Static check. */ /* Static check. */
if (alloc_ctx == NULL) { if (alloc_ctx == NULL) {
extent_t *extent = iealloc(tsdn, ptr); extent_t *extent = iealloc(tsd_tsdn(tsd), ptr);
if (unlikely(!extent_slab_get(extent))) { if (unlikely(!extent_slab_get(extent))) {
large_prof_tctx_set(tsdn, extent, tctx); large_prof_tctx_set(extent, tctx);
} }
} else { } else {
if (unlikely(!alloc_ctx->slab)) { if (unlikely(!alloc_ctx->slab)) {
large_prof_tctx_set(tsdn, iealloc(tsdn, ptr), tctx); large_prof_tctx_set(iealloc(tsd_tsdn(tsd), ptr), tctx);
} }
} }
} }
static inline void static inline void
arena_prof_tctx_reset(tsdn_t *tsdn, const void *ptr, prof_tctx_t *tctx) { arena_prof_tctx_reset(tsd_t *tsd, const void *ptr, prof_tctx_t *tctx) {
cassert(config_prof); cassert(config_prof);
assert(ptr != NULL); assert(ptr != NULL);
extent_t *extent = iealloc(tsdn, ptr); extent_t *extent = iealloc(tsd_tsdn(tsd), ptr);
assert(!extent_slab_get(extent)); assert(!extent_slab_get(extent));
large_prof_tctx_reset(tsdn, extent); large_prof_tctx_reset(extent);
} }
JEMALLOC_ALWAYS_INLINE void JEMALLOC_ALWAYS_INLINE void
arena_prof_alloc_time_set(tsdn_t *tsdn, const void *ptr, nstime_t t) { arena_prof_alloc_time_set(tsd_t *tsd, const void *ptr, nstime_t t) {
cassert(config_prof); cassert(config_prof);
assert(ptr != NULL); assert(ptr != NULL);
extent_t *extent = iealloc(tsdn, ptr); extent_t *extent = iealloc(tsd_tsdn(tsd), ptr);
assert(!extent_slab_get(extent)); assert(!extent_slab_get(extent));
large_prof_alloc_time_set(extent, t); large_prof_alloc_time_set(extent, t);
} }

View File

@ -22,10 +22,9 @@ void large_dalloc_prep_junked_locked(tsdn_t *tsdn, extent_t *extent);
void large_dalloc_finish(tsdn_t *tsdn, extent_t *extent); void large_dalloc_finish(tsdn_t *tsdn, extent_t *extent);
void large_dalloc(tsdn_t *tsdn, extent_t *extent); void large_dalloc(tsdn_t *tsdn, extent_t *extent);
size_t large_salloc(tsdn_t *tsdn, const extent_t *extent); size_t large_salloc(tsdn_t *tsdn, const extent_t *extent);
void large_prof_info_get(tsdn_t *tsdn, const extent_t *extent, void large_prof_info_get(const extent_t *extent, prof_info_t *prof_info);
prof_info_t *prof_info); void large_prof_tctx_set(extent_t *extent, prof_tctx_t *tctx);
void large_prof_tctx_set(tsdn_t *tsdn, extent_t *extent, prof_tctx_t *tctx); void large_prof_tctx_reset(extent_t *extent);
void large_prof_tctx_reset(tsdn_t *tsdn, extent_t *extent);
void large_prof_alloc_time_set(extent_t *extent, nstime_t time); void large_prof_alloc_time_set(extent_t *extent, nstime_t time);
#endif /* JEMALLOC_INTERNAL_LARGE_EXTERNS_H */ #endif /* JEMALLOC_INTERNAL_LARGE_EXTERNS_H */

View File

@ -49,7 +49,7 @@ bool prof_idump_accum_impl(tsdn_t *tsdn, uint64_t accumbytes);
void prof_idump_rollback_impl(tsdn_t *tsdn, size_t usize); void prof_idump_rollback_impl(tsdn_t *tsdn, size_t usize);
void prof_alloc_rollback(tsd_t *tsd, prof_tctx_t *tctx, bool updated); void prof_alloc_rollback(tsd_t *tsd, prof_tctx_t *tctx, bool updated);
void prof_malloc_sample_object(tsdn_t *tsdn, const void *ptr, size_t usize, void prof_malloc_sample_object(tsd_t *tsd, const void *ptr, size_t usize,
prof_tctx_t *tctx); prof_tctx_t *tctx);
void prof_free_sampled_object(tsd_t *tsd, size_t usize, prof_info_t *prof_info); void prof_free_sampled_object(tsd_t *tsd, size_t usize, prof_info_t *prof_info);
void bt_init(prof_bt_t *bt, void **vec); void bt_init(prof_bt_t *bt, void **vec);

View File

@ -40,38 +40,38 @@ prof_tdata_get(tsd_t *tsd, bool create) {
} }
JEMALLOC_ALWAYS_INLINE void JEMALLOC_ALWAYS_INLINE void
prof_info_get(tsdn_t *tsdn, const void *ptr, alloc_ctx_t *alloc_ctx, prof_info_get(tsd_t *tsd, const void *ptr, alloc_ctx_t *alloc_ctx,
prof_info_t *prof_info) { prof_info_t *prof_info) {
cassert(config_prof); cassert(config_prof);
assert(ptr != NULL); assert(ptr != NULL);
assert(prof_info != NULL); assert(prof_info != NULL);
arena_prof_info_get(tsdn, ptr, alloc_ctx, prof_info); arena_prof_info_get(tsd, ptr, alloc_ctx, prof_info);
} }
JEMALLOC_ALWAYS_INLINE void JEMALLOC_ALWAYS_INLINE void
prof_tctx_set(tsdn_t *tsdn, const void *ptr, size_t usize, prof_tctx_set(tsd_t *tsd, const void *ptr, size_t usize,
alloc_ctx_t *alloc_ctx, prof_tctx_t *tctx) { alloc_ctx_t *alloc_ctx, prof_tctx_t *tctx) {
cassert(config_prof); cassert(config_prof);
assert(ptr != NULL); assert(ptr != NULL);
arena_prof_tctx_set(tsdn, ptr, usize, alloc_ctx, tctx); arena_prof_tctx_set(tsd, ptr, usize, alloc_ctx, tctx);
} }
JEMALLOC_ALWAYS_INLINE void JEMALLOC_ALWAYS_INLINE void
prof_tctx_reset(tsdn_t *tsdn, const void *ptr, prof_tctx_t *tctx) { prof_tctx_reset(tsd_t *tsd, const void *ptr, prof_tctx_t *tctx) {
cassert(config_prof); cassert(config_prof);
assert(ptr != NULL); assert(ptr != NULL);
arena_prof_tctx_reset(tsdn, ptr, tctx); arena_prof_tctx_reset(tsd, ptr, tctx);
} }
JEMALLOC_ALWAYS_INLINE void JEMALLOC_ALWAYS_INLINE void
prof_alloc_time_set(tsdn_t *tsdn, const void *ptr, nstime_t t) { prof_alloc_time_set(tsd_t *tsd, const void *ptr, nstime_t t) {
cassert(config_prof); cassert(config_prof);
assert(ptr != NULL); assert(ptr != NULL);
arena_prof_alloc_time_set(tsdn, ptr, t); arena_prof_alloc_time_set(tsd, ptr, t);
} }
JEMALLOC_ALWAYS_INLINE bool JEMALLOC_ALWAYS_INLINE bool
@ -129,16 +129,16 @@ prof_alloc_prep(tsd_t *tsd, size_t usize, bool prof_active, bool update) {
} }
JEMALLOC_ALWAYS_INLINE void JEMALLOC_ALWAYS_INLINE void
prof_malloc(tsdn_t *tsdn, const void *ptr, size_t usize, alloc_ctx_t *alloc_ctx, prof_malloc(tsd_t *tsd, const void *ptr, size_t usize, alloc_ctx_t *alloc_ctx,
prof_tctx_t *tctx) { prof_tctx_t *tctx) {
cassert(config_prof); cassert(config_prof);
assert(ptr != NULL); assert(ptr != NULL);
assert(usize == isalloc(tsdn, ptr)); assert(usize == isalloc(tsd_tsdn(tsd), ptr));
if (unlikely((uintptr_t)tctx > (uintptr_t)1U)) { if (unlikely((uintptr_t)tctx > (uintptr_t)1U)) {
prof_malloc_sample_object(tsdn, ptr, usize, tctx); prof_malloc_sample_object(tsd, ptr, usize, tctx);
} else { } else {
prof_tctx_set(tsdn, ptr, usize, alloc_ctx, prof_tctx_set(tsd, ptr, usize, alloc_ctx,
(prof_tctx_t *)(uintptr_t)1U); (prof_tctx_t *)(uintptr_t)1U);
} }
} }
@ -172,9 +172,9 @@ prof_realloc(tsd_t *tsd, const void *ptr, size_t usize, prof_tctx_t *tctx,
moved = (ptr != old_ptr); moved = (ptr != old_ptr);
if (unlikely(sampled)) { if (unlikely(sampled)) {
prof_malloc_sample_object(tsd_tsdn(tsd), ptr, usize, tctx); prof_malloc_sample_object(tsd, ptr, usize, tctx);
} else if (moved) { } else if (moved) {
prof_tctx_set(tsd_tsdn(tsd), ptr, usize, NULL, prof_tctx_set(tsd, ptr, usize, NULL,
(prof_tctx_t *)(uintptr_t)1U); (prof_tctx_t *)(uintptr_t)1U);
} else if (unlikely(old_sampled)) { } else if (unlikely(old_sampled)) {
/* /*
@ -183,10 +183,10 @@ prof_realloc(tsd_t *tsd, const void *ptr, size_t usize, prof_tctx_t *tctx,
* to do here in the presence of explicit knowledge re: moved * to do here in the presence of explicit knowledge re: moved
* state. * state.
*/ */
prof_tctx_reset(tsd_tsdn(tsd), ptr, tctx); prof_tctx_reset(tsd, ptr, tctx);
} else { } else {
prof_info_t prof_info; prof_info_t prof_info;
prof_info_get(tsd_tsdn(tsd), ptr, NULL, &prof_info); prof_info_get(tsd, ptr, NULL, &prof_info);
assert((uintptr_t)prof_info.prof_tctx == (uintptr_t)1U); assert((uintptr_t)prof_info.prof_tctx == (uintptr_t)1U);
} }
@ -205,7 +205,7 @@ prof_realloc(tsd_t *tsd, const void *ptr, size_t usize, prof_tctx_t *tctx,
JEMALLOC_ALWAYS_INLINE void JEMALLOC_ALWAYS_INLINE void
prof_free(tsd_t *tsd, const void *ptr, size_t usize, alloc_ctx_t *alloc_ctx) { prof_free(tsd_t *tsd, const void *ptr, size_t usize, alloc_ctx_t *alloc_ctx) {
prof_info_t prof_info; prof_info_t prof_info;
prof_info_get(tsd_tsdn(tsd), ptr, alloc_ctx, &prof_info); prof_info_get(tsd, ptr, alloc_ctx, &prof_info);
cassert(config_prof); cassert(config_prof);
assert(usize == isalloc(tsd_tsdn(tsd), ptr)); assert(usize == isalloc(tsd_tsdn(tsd), ptr));

View File

@ -2171,7 +2171,7 @@ imalloc_body(static_opts_t *sopts, dynamic_opts_t *dopts, tsd_t *tsd) {
prof_alloc_rollback(tsd, tctx, true); prof_alloc_rollback(tsd, tctx, true);
goto label_oom; goto label_oom;
} }
prof_malloc(tsd_tsdn(tsd), allocation, usize, &alloc_ctx, tctx); prof_malloc(tsd, allocation, usize, &alloc_ctx, tctx);
} else { } else {
assert(!opt_prof); assert(!opt_prof);
allocation = imalloc_no_sample(sopts, dopts, tsd, size, usize, allocation = imalloc_no_sample(sopts, dopts, tsd, size, usize,
@ -3010,7 +3010,7 @@ 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, size_t alignment, size_t *usize, bool zero, tcache_t *tcache,
arena_t *arena, alloc_ctx_t *alloc_ctx, hook_ralloc_args_t *hook_args) { arena_t *arena, alloc_ctx_t *alloc_ctx, hook_ralloc_args_t *hook_args) {
prof_info_t old_prof_info; prof_info_t old_prof_info;
prof_info_get(tsd_tsdn(tsd), old_ptr, alloc_ctx, &old_prof_info); prof_info_get(tsd, old_ptr, alloc_ctx, &old_prof_info);
bool prof_active = prof_active_get_unlocked(); bool prof_active = prof_active_get_unlocked();
prof_tctx_t *tctx = prof_alloc_prep(tsd, *usize, prof_active, false); prof_tctx_t *tctx = prof_alloc_prep(tsd, *usize, prof_active, false);
void *p; void *p;
@ -3261,7 +3261,7 @@ JEMALLOC_ALWAYS_INLINE size_t
ixallocx_prof(tsd_t *tsd, void *ptr, size_t old_usize, size_t size, ixallocx_prof(tsd_t *tsd, void *ptr, size_t old_usize, size_t size,
size_t extra, size_t alignment, bool zero, alloc_ctx_t *alloc_ctx) { size_t extra, size_t alignment, bool zero, alloc_ctx_t *alloc_ctx) {
prof_info_t old_prof_info; prof_info_t old_prof_info;
prof_info_get(tsd_tsdn(tsd), ptr, alloc_ctx, &old_prof_info); prof_info_get(tsd, ptr, alloc_ctx, &old_prof_info);
/* /*
* usize isn't knowable before ixalloc() returns when extra is non-zero. * usize isn't knowable before ixalloc() returns when extra is non-zero.
* Therefore, compute its maximum possible value and use that in * Therefore, compute its maximum possible value and use that in

View File

@ -368,19 +368,18 @@ large_salloc(tsdn_t *tsdn, const extent_t *extent) {
} }
void void
large_prof_info_get(tsdn_t *tsdn, const extent_t *extent, large_prof_info_get(const extent_t *extent, prof_info_t *prof_info) {
prof_info_t *prof_info) {
extent_prof_info_get(extent, prof_info); extent_prof_info_get(extent, prof_info);
} }
void void
large_prof_tctx_set(tsdn_t *tsdn, extent_t *extent, prof_tctx_t *tctx) { large_prof_tctx_set(extent_t *extent, prof_tctx_t *tctx) {
extent_prof_tctx_set(extent, tctx); extent_prof_tctx_set(extent, tctx);
} }
void void
large_prof_tctx_reset(tsdn_t *tsdn, extent_t *extent) { large_prof_tctx_reset(extent_t *extent) {
large_prof_tctx_set(tsdn, extent, (prof_tctx_t *)(uintptr_t)1U); large_prof_tctx_set(extent, (prof_tctx_t *)(uintptr_t)1U);
} }
void void

View File

@ -165,17 +165,17 @@ prof_alloc_rollback(tsd_t *tsd, prof_tctx_t *tctx, bool updated) {
} }
void void
prof_malloc_sample_object(tsdn_t *tsdn, const void *ptr, size_t usize, prof_malloc_sample_object(tsd_t *tsd, const void *ptr, size_t usize,
prof_tctx_t *tctx) { prof_tctx_t *tctx) {
prof_tctx_set(tsdn, ptr, usize, NULL, tctx); prof_tctx_set(tsd, ptr, usize, NULL, tctx);
/* Get the current time and set this in the extent_t. We'll read this /* Get the current time and set this in the extent_t. We'll read this
* when free() is called. */ * when free() is called. */
nstime_t t = NSTIME_ZERO_INITIALIZER; nstime_t t = NSTIME_ZERO_INITIALIZER;
nstime_update(&t); nstime_update(&t);
prof_alloc_time_set(tsdn, ptr, t); prof_alloc_time_set(tsd, ptr, t);
malloc_mutex_lock(tsdn, tctx->tdata->lock); malloc_mutex_lock(tsd_tsdn(tsd), tctx->tdata->lock);
tctx->cnts.curobjs++; tctx->cnts.curobjs++;
tctx->cnts.curbytes += usize; tctx->cnts.curbytes += usize;
if (opt_prof_accum) { if (opt_prof_accum) {
@ -183,7 +183,7 @@ prof_malloc_sample_object(tsdn_t *tsdn, const void *ptr, size_t usize,
tctx->cnts.accumbytes += usize; tctx->cnts.accumbytes += usize;
} }
tctx->prepared = false; tctx->prepared = false;
malloc_mutex_unlock(tsdn, tctx->tdata->lock); malloc_mutex_unlock(tsd_tsdn(tsd), tctx->tdata->lock);
} }
void void

View File

@ -1,7 +1,7 @@
#include "test/jemalloc_test.h" #include "test/jemalloc_test.h"
TEST_BEGIN(test_prof_realloc) { TEST_BEGIN(test_prof_realloc) {
tsdn_t *tsdn; tsd_t *tsd;
int flags; int flags;
void *p, *q; void *p, *q;
prof_info_t prof_info_p, prof_info_q; prof_info_t prof_info_p, prof_info_q;
@ -9,13 +9,13 @@ TEST_BEGIN(test_prof_realloc) {
test_skip_if(!config_prof); test_skip_if(!config_prof);
tsdn = tsdn_fetch(); tsd = tsd_fetch();
flags = MALLOCX_TCACHE_NONE; flags = MALLOCX_TCACHE_NONE;
prof_cnt_all(&curobjs_0, NULL, NULL, NULL); prof_cnt_all(&curobjs_0, NULL, NULL, NULL);
p = mallocx(1024, flags); p = mallocx(1024, flags);
assert_ptr_not_null(p, "Unexpected mallocx() failure"); assert_ptr_not_null(p, "Unexpected mallocx() failure");
prof_info_get(tsdn, p, NULL, &prof_info_p); prof_info_get(tsd, p, NULL, &prof_info_p);
assert_ptr_ne(prof_info_p.prof_tctx, (prof_tctx_t *)(uintptr_t)1U, assert_ptr_ne(prof_info_p.prof_tctx, (prof_tctx_t *)(uintptr_t)1U,
"Expected valid tctx"); "Expected valid tctx");
prof_cnt_all(&curobjs_1, NULL, NULL, NULL); prof_cnt_all(&curobjs_1, NULL, NULL, NULL);
@ -25,7 +25,7 @@ TEST_BEGIN(test_prof_realloc) {
q = rallocx(p, 2048, flags); q = rallocx(p, 2048, flags);
assert_ptr_ne(p, q, "Expected move"); assert_ptr_ne(p, q, "Expected move");
assert_ptr_not_null(p, "Unexpected rmallocx() failure"); assert_ptr_not_null(p, "Unexpected rmallocx() failure");
prof_info_get(tsdn, q, NULL, &prof_info_q); prof_info_get(tsd, q, NULL, &prof_info_q);
assert_ptr_ne(prof_info_q.prof_tctx, (prof_tctx_t *)(uintptr_t)1U, assert_ptr_ne(prof_info_q.prof_tctx, (prof_tctx_t *)(uintptr_t)1U,
"Expected valid tctx"); "Expected valid tctx");
prof_cnt_all(&curobjs_2, NULL, NULL, NULL); prof_cnt_all(&curobjs_2, NULL, NULL, NULL);