one quesiton about the src code of jemalloc

HOU Zhengkun Zhengkun.Hou at alcatel-lucent.com
Thu Feb 5 16:51:27 PST 2015


Hi, all
when i read the src code of jemalloc of redis, i'm confused for below code in malloc_init_hard() function. do you know what's mean of IS_INITIALIZER, it said that it for: this thread is the initializing thread, and it is recursively allocating. what's the mean of the sentence? could you take an example for it? another question is if one thread is initializing, and this thread will wait for init_lock, after that thread finish the initializing. then the malloc_initialized will be set to true. then this thread will return false. but malloc_init_hard in invoked by je_malloc, so for this thread the je_malloc will be return false? and then allocated fail???? thanks for your time.
static bool
malloc_init_hard(void)
{
arena_t *init_arenas[1];
malloc_mutex_lock(&init_lock);
if (malloc_initialized || IS_INITIALIZER) {
* Another thread initialized the allocator before this one
* acquired init_lock, or this thread is the initializing
* thread, and it is recursively allocating.
*/
malloc_mutex_unlock(&init_lock);
return (false);
}
void *
je_malloc(size_t size)
{
void *ret;
size_t usize JEMALLOC_CC_SILENCE_INIT(0);
prof_thr_cnt_t *cnt JEMALLOC_CC_SILENCE_INIT(NULL);
if (malloc_init()) {
    ret = NULL;
    goto label_oom;
}
label_oom:
if (ret == NULL) {
if (config_xmalloc && opt_xmalloc) {
malloc_write(": Error in malloc(): "
"out of memory\n");
abort();
}
set_errno(ENOMEM);
}
if (config_prof && opt_prof && ret != NULL)
prof_malloc(ret, usize, cnt);
if (config_stats && ret != NULL) {
assert(usize == isalloc(ret, config_prof));
thread_allocated_tsd_get()->allocated += usize;
}
UTRACE(0, size, ret);
JEMALLOC_VALGRIND_MALLOC(ret != NULL, ret, usize, false);
return (ret);

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://jemalloc.net/mailman/jemalloc-discuss/attachments/20150206/42f3ba91/attachment.html>


More information about the jemalloc-discuss mailing list