jemalloc java_jemalloc源码结构分析

一、5种malloc方法

1)tcache_alloc_small

2)arena_malloc_small

3)tcache_alloc_large

4)arena_malloc_large

5)huge_malloc

69c5a8ac3fa60e0848d784a6dd461da6.png//written in jemalloc_internal.h file

imalloct(size_t size, bool try_tcache, arena_t *arena)

{

assert(size!= 0);if (size <=arena_maxclass)return (arena_malloc(arena, size, false, try_tcache));else

return (huge_malloc(size, false, huge_dss_prec_get(arena)));

}

JEMALLOC_ALWAYS_INLINEvoid *imalloc(size_t size)

{return (imalloct(size, true, NULL));

}//written in arena.h

JEMALLOC_ALWAYS_INLINE void *arena_malloc(arena_t*arena, size_t size, bool zero, booltry_tcache)

{

tcache_t*tcache;

assert(size!= 0);

assert(size<=arena_maxclass);if (size <=SMALL_MAXCLASS) {if (try_tcache && (tcache = tcache_get(true)) !=NULL)return(tcache_alloc_small(tcache, size, zero));else{return(arena_malloc_small(choose_arena(arena), size,

zero));

}

}else{/** Initialize tcache after checking size in order to avoid

* infinite recursion during tcache initialization.*/

if (try_tcache && size <= tcache_maxclass && (tcache =tcache_get(true)) !=NULL)return(tcache_alloc_large(tcache, size, zero));else{return(arena_malloc_large(choose_arena(arena), size,

zero));

}

}

}

69c5a8ac3fa60e0848d784a6dd461da6.png

二、malloc时选择arena的机制

1)、先用arenas_tsd_get获得线程绑定变量arena;

2)、如果1)获得值为null,则扫描arenas数组,找到threads number为0或者最小的未卸载的arena;

3)、如果2)中扫描发现存在null插槽,则需要调用arenas_extend进行初始化null插槽;

4)、调用arenas_tsd_set设置线程绑定比变量arena。

//详细见jemalloc.c中函数

arena_t *choose_arena_hard(void)

原文:http://www.cnblogs.com/feika/p/3675711.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值