Remove extent dereferences from the deallocation fast paths.

This commit is contained in:
Jason Evans
2017-03-17 02:45:12 -07:00
parent 4f341412e5
commit 51a2ec92a1
8 changed files with 113 additions and 87 deletions

View File

@@ -1719,7 +1719,7 @@ arena_ralloc(tsdn_t *tsdn, arena_t *arena, extent_t *extent, void *ptr,
copysize = (usize < oldsize) ? usize : oldsize;
memcpy(ret, ptr, copysize);
isdalloct(tsdn, extent, ptr, oldsize, tcache, true);
isdalloct(tsdn, ptr, oldsize, tcache, true);
return ret;
}

View File

@@ -282,14 +282,12 @@ ckh_grow(tsd_t *tsd, ckh_t *ckh) {
ckh->lg_curbuckets = lg_curcells - LG_CKH_BUCKET_CELLS;
if (!ckh_rebuild(ckh, tab)) {
idalloctm(tsd_tsdn(tsd), iealloc(tsd_tsdn(tsd), tab),
tab, NULL, true, true);
idalloctm(tsd_tsdn(tsd), tab, NULL, true, true);
break;
}
/* Rebuilding failed, so back out partially rebuilt table. */
idalloctm(tsd_tsdn(tsd), iealloc(tsd_tsdn(tsd), ckh->tab),
ckh->tab, NULL, true, true);
idalloctm(tsd_tsdn(tsd), ckh->tab, NULL, true, true);
ckh->tab = tab;
ckh->lg_curbuckets = lg_prevbuckets;
}
@@ -331,8 +329,7 @@ ckh_shrink(tsd_t *tsd, ckh_t *ckh) {
ckh->lg_curbuckets = lg_curcells - LG_CKH_BUCKET_CELLS;
if (!ckh_rebuild(ckh, tab)) {
idalloctm(tsd_tsdn(tsd), iealloc(tsd_tsdn(tsd), tab), tab, NULL,
true, true);
idalloctm(tsd_tsdn(tsd), tab, NULL, true, true);
#ifdef CKH_COUNT
ckh->nshrinks++;
#endif
@@ -340,8 +337,7 @@ ckh_shrink(tsd_t *tsd, ckh_t *ckh) {
}
/* Rebuilding failed, so back out partially rebuilt table. */
idalloctm(tsd_tsdn(tsd), iealloc(tsd_tsdn(tsd), ckh->tab), ckh->tab,
NULL, true, true);
idalloctm(tsd_tsdn(tsd), ckh->tab, NULL, true, true);
ckh->tab = tab;
ckh->lg_curbuckets = lg_prevbuckets;
#ifdef CKH_COUNT
@@ -422,8 +418,7 @@ ckh_delete(tsd_t *tsd, ckh_t *ckh) {
(unsigned long long)ckh->nrelocs);
#endif
idalloctm(tsd_tsdn(tsd), iealloc(tsd_tsdn(tsd), ckh->tab), ckh->tab,
NULL, true, true);
idalloctm(tsd_tsdn(tsd), ckh->tab, NULL, true, true);
if (config_debug) {
memset(ckh, JEMALLOC_FREE_JUNK, sizeof(ckh_t));
}

View File

@@ -310,8 +310,8 @@ a0ialloc(size_t size, bool zero, bool is_internal) {
}
static void
a0idalloc(extent_t *extent, void *ptr, bool is_internal) {
idalloctm(TSDN_NULL, extent, ptr, false, is_internal, true);
a0idalloc(void *ptr, bool is_internal) {
idalloctm(TSDN_NULL, ptr, false, is_internal, true);
}
void *
@@ -321,7 +321,7 @@ a0malloc(size_t size) {
void
a0dalloc(void *ptr) {
a0idalloc(iealloc(NULL, ptr), ptr, true);
a0idalloc(ptr, true);
}
/*
@@ -358,7 +358,7 @@ bootstrap_free(void *ptr) {
return;
}
a0idalloc(iealloc(NULL, ptr), ptr, false);
a0idalloc(ptr, false);
}
void
@@ -2008,17 +2008,15 @@ irealloc_prof(tsd_t *tsd, extent_t *old_extent, void *old_ptr, size_t old_usize,
JEMALLOC_INLINE_C void
ifree(tsd_t *tsd, void *ptr, tcache_t *tcache, bool slow_path) {
extent_t *extent;
size_t usize;
witness_assert_lockless(tsd_tsdn(tsd));
assert(ptr != NULL);
assert(malloc_initialized() || IS_INITIALIZER);
extent = iealloc(tsd_tsdn(tsd), ptr);
size_t usize;
if (config_prof && opt_prof) {
usize = isalloc(tsd_tsdn(tsd), ptr);
extent_t *extent = iealloc(tsd_tsdn(tsd), ptr);
prof_free(tsd, extent, ptr, usize);
} else if (config_stats) {
usize = isalloc(tsd_tsdn(tsd), ptr);
@@ -2028,21 +2026,21 @@ ifree(tsd_t *tsd, void *ptr, tcache_t *tcache, bool slow_path) {
}
if (likely(!slow_path)) {
idalloctm(tsd_tsdn(tsd), extent, ptr, tcache, false, false);
idalloctm(tsd_tsdn(tsd), ptr, tcache, false, false);
} else {
idalloctm(tsd_tsdn(tsd), extent, ptr, tcache, false, true);
idalloctm(tsd_tsdn(tsd), ptr, tcache, false, true);
}
}
JEMALLOC_INLINE_C void
isfree(tsd_t *tsd, extent_t *extent, void *ptr, size_t usize, tcache_t *tcache,
bool slow_path) {
isfree(tsd_t *tsd, void *ptr, size_t usize, tcache_t *tcache, bool slow_path) {
witness_assert_lockless(tsd_tsdn(tsd));
assert(ptr != NULL);
assert(malloc_initialized() || IS_INITIALIZER);
if (config_prof && opt_prof) {
extent_t *extent = iealloc(tsd_tsdn(tsd), ptr);
prof_free(tsd, extent, ptr, usize);
}
if (config_stats) {
@@ -2050,9 +2048,9 @@ isfree(tsd_t *tsd, extent_t *extent, void *ptr, size_t usize, tcache_t *tcache,
}
if (likely(!slow_path)) {
isdalloct(tsd_tsdn(tsd), extent, ptr, usize, tcache, false);
isdalloct(tsd_tsdn(tsd), ptr, usize, tcache, false);
} else {
isdalloct(tsd_tsdn(tsd), extent, ptr, usize, tcache, true);
isdalloct(tsd_tsdn(tsd), ptr, usize, tcache, true);
}
}
@@ -2667,14 +2665,12 @@ inallocx(tsdn_t *tsdn, size_t size, int flags) {
JEMALLOC_EXPORT void JEMALLOC_NOTHROW
je_sdallocx(void *ptr, size_t size, int flags) {
tsd_t *tsd;
extent_t *extent;
size_t usize;
tcache_t *tcache;
assert(ptr != NULL);
assert(malloc_initialized() || IS_INITIALIZER);
tsd = tsd_fetch();
extent = iealloc(tsd_tsdn(tsd), ptr);
usize = inallocx(tsd_tsdn(tsd), size, flags);
assert(usize == isalloc(tsd_tsdn(tsd), ptr));
@@ -2691,9 +2687,9 @@ je_sdallocx(void *ptr, size_t size, int flags) {
UTRACE(ptr, 0, 0);
if (likely(!malloc_slow)) {
isfree(tsd, extent, ptr, usize, tcache, false);
isfree(tsd, ptr, usize, tcache, false);
} else {
isfree(tsd, extent, ptr, usize, tcache, true);
isfree(tsd, ptr, usize, tcache, true);
}
witness_assert_lockless(tsd_tsdn(tsd));
}

View File

@@ -303,8 +303,7 @@ large_ralloc(tsdn_t *tsdn, arena_t *arena, extent_t *extent, size_t usize,
size_t copysize = (usize < oldusize) ? usize : oldusize;
memcpy(ret, extent_addr_get(extent), copysize);
isdalloct(tsdn, extent, extent_addr_get(extent), oldusize, tcache,
true);
isdalloct(tsdn, extent_addr_get(extent), oldusize, tcache, true);
return ret;
}

View File

@@ -582,8 +582,7 @@ prof_gctx_try_destroy(tsd_t *tsd, prof_tdata_t *tdata_self, prof_gctx_t *gctx,
prof_leave(tsd, tdata_self);
/* Destroy gctx. */
malloc_mutex_unlock(tsd_tsdn(tsd), gctx->lock);
idalloctm(tsd_tsdn(tsd), iealloc(tsd_tsdn(tsd), gctx), gctx,
NULL, true, true);
idalloctm(tsd_tsdn(tsd), gctx, NULL, true, true);
} else {
/*
* Compensate for increment in prof_tctx_destroy() or
@@ -697,8 +696,7 @@ prof_tctx_destroy(tsd_t *tsd, prof_tctx_t *tctx) {
}
if (destroy_tctx) {
idalloctm(tsd_tsdn(tsd), iealloc(tsd_tsdn(tsd), tctx), tctx,
NULL, true, true);
idalloctm(tsd_tsdn(tsd), tctx, NULL, true, true);
}
}
@@ -730,8 +728,8 @@ prof_lookup_global(tsd_t *tsd, prof_bt_t *bt, prof_tdata_t *tdata,
if (ckh_insert(tsd, &bt2gctx, btkey.v, gctx.v)) {
/* OOM. */
prof_leave(tsd, tdata);
idalloctm(tsd_tsdn(tsd), iealloc(tsd_tsdn(tsd),
gctx.v), gctx.v, NULL, true, true);
idalloctm(tsd_tsdn(tsd), gctx.v, NULL, true,
true);
return true;
}
new_gctx = true;
@@ -755,8 +753,7 @@ prof_lookup_global(tsd_t *tsd, prof_bt_t *bt, prof_tdata_t *tdata,
if (tgctx.v != NULL) {
/* Lost race to insert. */
idalloctm(tsd_tsdn(tsd), iealloc(tsd_tsdn(tsd),
tgctx.v), tgctx.v, NULL, true, true);
idalloctm(tsd_tsdn(tsd), tgctx.v, NULL, true, true);
}
}
prof_leave(tsd, tdata);
@@ -828,8 +825,7 @@ prof_lookup(tsd_t *tsd, prof_bt_t *bt) {
if (new_gctx) {
prof_gctx_try_destroy(tsd, tdata, gctx, tdata);
}
idalloctm(tsd_tsdn(tsd), iealloc(tsd_tsdn(tsd), ret.v),
ret.v, NULL, true, true);
idalloctm(tsd_tsdn(tsd), ret.v, NULL, true, true);
return NULL;
}
malloc_mutex_lock(tsd_tsdn(tsd), gctx->lock);
@@ -1240,9 +1236,8 @@ prof_gctx_finish(tsd_t *tsd, prof_gctx_tree_t *gctxs) {
to_destroy);
tctx_tree_remove(&gctx->tctxs,
to_destroy);
idalloctm(tsd_tsdn(tsd),
iealloc(tsd_tsdn(tsd), to_destroy),
to_destroy, NULL, true, true);
idalloctm(tsd_tsdn(tsd), to_destroy,
NULL, true, true);
} else {
next = NULL;
}
@@ -1910,8 +1905,7 @@ prof_tdata_init_impl(tsd_t *tsd, uint64_t thr_uid, uint64_t thr_discrim,
if (ckh_new(tsd, &tdata->bt2tctx, PROF_CKH_MINITEMS, prof_bt_hash,
prof_bt_keycomp)) {
idalloctm(tsd_tsdn(tsd), iealloc(tsd_tsdn(tsd), tdata), tdata,
NULL, true, true);
idalloctm(tsd_tsdn(tsd), tdata, NULL, true, true);
return NULL;
}
@@ -1967,12 +1961,10 @@ prof_tdata_destroy_locked(tsd_t *tsd, prof_tdata_t *tdata,
assert(prof_tdata_should_destroy_unlocked(tdata, even_if_attached));
if (tdata->thread_name != NULL) {
idalloctm(tsd_tsdn(tsd), iealloc(tsd_tsdn(tsd),
tdata->thread_name), tdata->thread_name, NULL, true, true);
idalloctm(tsd_tsdn(tsd), tdata->thread_name, NULL, true, true);
}
ckh_delete(tsd, &tdata->bt2tctx);
idalloctm(tsd_tsdn(tsd), iealloc(tsd_tsdn(tsd), tdata), tdata, NULL,
true, true);
idalloctm(tsd_tsdn(tsd), tdata, NULL, true, true);
}
static void
@@ -2169,8 +2161,7 @@ prof_thread_name_set(tsd_t *tsd, const char *thread_name) {
}
if (tdata->thread_name != NULL) {
idalloctm(tsd_tsdn(tsd), iealloc(tsd_tsdn(tsd),
tdata->thread_name), tdata->thread_name, NULL, true, true);
idalloctm(tsd_tsdn(tsd), tdata->thread_name, NULL, true, true);
tdata->thread_name = NULL;
}
if (strlen(s) > 0) {

View File

@@ -389,8 +389,7 @@ tcache_destroy(tsd_t *tsd, tcache_t *tcache) {
prof_idump(tsd_tsdn(tsd));
}
idalloctm(tsd_tsdn(tsd), iealloc(tsd_tsdn(tsd), tcache), tcache, NULL,
true, true);
idalloctm(tsd_tsdn(tsd), tcache, NULL, true, true);
}
void