remove malloc_init() off the fastpath

This commit is contained in:
Dave Watson 2018-10-03 14:47:31 -07:00
parent 997d86acc6
commit 325e3305fc
4 changed files with 23 additions and 10 deletions

View File

@ -47,7 +47,6 @@ tsd_get_allocates(void) {
/* Get/set. */ /* Get/set. */
JEMALLOC_ALWAYS_INLINE tsd_t * JEMALLOC_ALWAYS_INLINE tsd_t *
tsd_get(bool init) { tsd_get(bool init) {
assert(tsd_booted);
return &tsd_tls; return &tsd_tls;
} }
JEMALLOC_ALWAYS_INLINE void JEMALLOC_ALWAYS_INLINE void

View File

@ -40,7 +40,6 @@ tsd_get_allocates(void) {
/* Get/set. */ /* Get/set. */
JEMALLOC_ALWAYS_INLINE tsd_t * JEMALLOC_ALWAYS_INLINE tsd_t *
tsd_get(bool init) { tsd_get(bool init) {
assert(tsd_booted);
return &tsd_tls; return &tsd_tls;
} }

View File

@ -2110,9 +2110,8 @@ label_invalid_alignment:
return EINVAL; return EINVAL;
} }
/* Returns the errno-style error code of the allocation. */ JEMALLOC_ALWAYS_INLINE bool
JEMALLOC_ALWAYS_INLINE int imalloc_init_check(static_opts_t *sopts, dynamic_opts_t *dopts) {
imalloc(static_opts_t *sopts, dynamic_opts_t *dopts) {
if (unlikely(!malloc_initialized()) && unlikely(malloc_init())) { if (unlikely(!malloc_initialized()) && unlikely(malloc_init())) {
if (config_xmalloc && unlikely(opt_xmalloc)) { if (config_xmalloc && unlikely(opt_xmalloc)) {
malloc_write(sopts->oom_string); malloc_write(sopts->oom_string);
@ -2122,6 +2121,16 @@ imalloc(static_opts_t *sopts, dynamic_opts_t *dopts) {
set_errno(ENOMEM); set_errno(ENOMEM);
*dopts->result = NULL; *dopts->result = NULL;
return false;
}
return true;
}
/* Returns the errno-style error code of the allocation. */
JEMALLOC_ALWAYS_INLINE int
imalloc(static_opts_t *sopts, dynamic_opts_t *dopts) {
if (tsd_get_allocates() && !imalloc_init_check(sopts, dopts)) {
return ENOMEM; return ENOMEM;
} }
@ -2134,6 +2143,10 @@ imalloc(static_opts_t *sopts, dynamic_opts_t *dopts) {
sopts->slow = false; sopts->slow = false;
return imalloc_body(sopts, dopts, tsd); return imalloc_body(sopts, dopts, tsd);
} else { } else {
if (!tsd_get_allocates() && !imalloc_init_check(sopts, dopts)) {
return ENOMEM;
}
sopts->slow = true; sopts->slow = true;
return imalloc_body(sopts, dopts, tsd); return imalloc_body(sopts, dopts, tsd);
} }

View File

@ -280,11 +280,13 @@ tsd_fetch_slow(tsd_t *tsd, bool minimal) {
tsd_slow_update(tsd); tsd_slow_update(tsd);
} else if (tsd_state_get(tsd) == tsd_state_uninitialized) { } else if (tsd_state_get(tsd) == tsd_state_uninitialized) {
if (!minimal) { if (!minimal) {
tsd_state_set(tsd, tsd_state_nominal); if (tsd_booted) {
tsd_slow_update(tsd); tsd_state_set(tsd, tsd_state_nominal);
/* Trigger cleanup handler registration. */ tsd_slow_update(tsd);
tsd_set(tsd); /* Trigger cleanup handler registration. */
tsd_data_init(tsd); tsd_set(tsd);
tsd_data_init(tsd);
}
} else { } else {
tsd_state_set(tsd, tsd_state_minimal_initialized); tsd_state_set(tsd, tsd_state_minimal_initialized);
tsd_set(tsd); tsd_set(tsd);