替换ptmalloc,使用tcmalloc和jemalloc

文章探讨了Linux上默认的ptmalloc内存分配器的原理和问题,如内存碎片、线程同步开销等,并介绍了Google的tcmalloc如何通过三级缓存优化多线程分配,以及Facebook的jemalloc如何通过精细化内存分区和多线程优化提高性能。tcmalloc适合小内存分配,但在大内存场景下可能引发锁竞争。jemalloc则在多核环境下表现出色,但内存占用相对较高。

ptmalloc

目前,linux上使用的ptmalloc实现对内存的管理,其时glibc的默认内存分配器。

ptmalloc的内存分配器中,分为主分配区main_area和非主分配区no_main_area。
 1. 主分配区和非主分配区形成一个环形链表进行管理。
 2. 每一个分配区利用互斥锁使线程对于该分配区的访问互斥。
 3. 每个进程只有一个主分配区,也可以允许有多个非主分配区。
 4. ptmalloc根据系统对分配区的争用动态增加分配区的大小,分配区的数量一旦增加,则不会减少。
 5. 主分配区可以使用brk和mmap来分配,而非主分配区只能使用mmap来映射内存块
 6. 申请小内存时会产生很多内存碎片,ptmalloc在整理时也需要对分配区做加锁操作。

分配释放步骤:

1、线程会尝试对分配区加锁,加锁成功,则分配完成,加锁失败,则遍历分配区。

2、释放分配区,同样会获取分配区的锁,获取到才可以释放内存

其实现目前存在如下问题:

  • 如果后分配的内存先释放,无法及时归还系统。因为 ptmalloc 收缩内存是从 top chunk 开始,如果与 top chunk 相邻的 chunk 不能释放, top chunk 以下的 chunk 都无法释放。
  • 内存不能在线程间移动,多线程使用内存不均衡将导致内存浪费
  • 每个chunk至少8字节的开销很大
  • 不定期分配长生命周期的内存容易造成内存碎片,不利于回收。
  • 加锁耗时,在内存分配和释放时,会首先加锁。

所以就有了tcmalloc和jemalloc

tcmalloc

tcmalloc是Google开发的内存分配器,在Golang、Chrome中都有使用该分配器进行内存分配。有效的优化了ptmalloc中存在的问题。

TCMalloc是专门对多线并发的内存管理而设计的,TCMalloc 实现了三级缓存,分别是ThreadCache(线程级缓存),Central Cache(中央缓存:CentralFreeeList),PageHeap(页缓存),最后两级需要加锁访问。实现了线程级的无锁内存分配。如图为内存分配

 

ThreadCache中包含一个链表数组FreeList list_[kNumClasses],维护了不同规格的空闲内存的链表;当申请内存的时候可以直接根据大小寻找恰当的规则的内存。如果ThreadCache的对象不够了,就从 CentralCache 进行批量分配;如果 CentralCache 依然没有,就从PageHeap申请Span;Tcmalloc一次最少向系统申请1MB的内存,默认情况下,使用sbrk申请,在sbrk失败的时候,使用mmap申请。

缺点:

tcmalloc使用自旋锁虽然减少了加锁效率,但是如果使用大内存较多的情况下,内存在Central Cache或者Page Heap加锁分配。而tcmalloc对大小内存的分配过于保守,在一些内存需求较大的服务(如推荐系统),小内存上限过低,当请求量上来,锁冲突严重,CPU使用率将指数暴增。

jemalloc

jemalloc是facebook,目前在firefox,android,redis中都有使用。 jemalloc最大的优势还是其强大的多核/多线程分配能力。

 

jemalloc 按照内存分配请求的尺寸,分了 small object (例如 1 – 57344B)、 large object (例如 57345 – 4MB )、 huge object (例如 4MB以上)。jemalloc同样有一层线程缓存的内存名字叫tcache,当分配的内存大小小于tcache_maxclass时,jemalloc会首先在tcache的small object以及large object中查找分配,tcache不中则从arena中申请run,并将剩余的区域缓存到tcache。若arena找不到合适大小的内存块, 则向系统申请内存。当申请大小大于tcache_maxclass且大小小于huge大小的内存块时,则直接从arena开始分配。而huge object的内存不归arena管理, 直接采用mmap从system memory中申请,并由一棵与arena独立的红黑树进行管理。

jemalloc的优势

  • 多线程下加锁大大减少

推荐使用:

jemalloc,相对多核环境稳定,占用内存较多,但现在内存占用基本不太时服务器的瓶颈。

参考来源

https://www.cyningsun.com/07-07-2018/memory-allocator-contrasts.html

http://jemalloc.net/

include/jemalloc/internal/log.h:42:1: 警告:空声明 [默认启用] struct log_var_s { ^ include/jemalloc/internal/log.h:62:31: 错误:expected declaration specifiers or ‘...’ before ‘log_var_t’ unsigned log_var_update_state(log_var_t *log_var); ^ include/jemalloc/internal/log.h:89:41: 错误:expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘{’ token log_impl_varargs(const char *name, ...) { ^ In file included from src/jemalloc.c:18:0: include/jemalloc/internal/spin.h:8:3: 错误:为形参‘spin_t’指定了存储类 } spin_t; ^ include/jemalloc/internal/spin.h:11:21: 错误:expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘{’ token spin_cpu_spinwait() { ^ include/jemalloc/internal/spin.h:21:15: 错误:expected declaration specifiers or ‘...’ before ‘spin_t’ spin_adaptive(spin_t *spin) { ^ src/jemalloc.c:29:5: 错误:expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘JEMALLOC_ATTR’ JEMALLOC_ATTR(weak) ^ src/jemalloc.c:32:1: 错误:形参‘opt_abort’已初始化 bool opt_abort = ^ src/jemalloc.c:32:6: 错误:形参‘opt_abort’重定义 bool opt_abort = ^ In file included from include/jemalloc/internal/tsd.h:7:0, from include/jemalloc/internal/mutex.h:6, from include/jemalloc/internal/extent_structs.h:7, from include/jemalloc/internal/jemalloc_internal_includes.h:54, from src/jemalloc.c:3: include/jemalloc/internal/jemalloc_internal_externs.h:11:13: 附注:‘opt_abort’的上一个定义在此 extern bool opt_abort; ^ src/jemalloc.c:39:1: 错误:形参‘opt_abort_conf’已初始化 bool opt_abort_conf = ^ src/jemalloc.c:39:6: 错误:形参‘opt_abort_conf’重定义 bool opt_abort_conf = ^ In file included from include/jemalloc/internal/tsd.h:7:0, from include/jemalloc/internal/mutex.h:6, from include/jemalloc/internal/extent_structs.h:7, from include/jemalloc/internal/jemalloc_internal_includes.h:54, from src/jemalloc.c:3: include/jemalloc/internal/jemalloc_internal_externs.h:12:13: 附注:‘opt_abort_conf’的上一个定义在此 extern bool opt_abort_conf; ^ src/jemalloc.c:47:1: 错误:形参‘opt_confirm_conf’已初始化 bool opt_confirm_conf = false; ^ src/jemalloc.c:47:6: 错误:形参‘opt_confirm_conf’重定义 bool opt_confirm_conf = false; ^ In file included from include/jemalloc/internal/tsd.h:7:0, from include/jemalloc/internal/mutex.h:6, from include/jemalloc/internal/extent_structs.h:7, from include/jemalloc/internal/jemalloc_internal_includes.h:54, from src/jemalloc.c:3: include/jemalloc/internal/jemalloc_internal_externs.h:13:13: 附注:‘opt_confirm_conf’的上一个定义在此 extern bool opt_confirm_conf; ^ src/jemalloc.c:48:1: 错误:形参‘opt_junk’已初始化 const char *opt_junk = ^ src/jemalloc.c:48:13: 错误:形参‘opt_junk’重定义 const char *opt_junk = ^ In file included from include/jemalloc/internal/tsd.h:7:0, from include/jemalloc/internal/mutex.h:6, from include/jemalloc/internal/extent_structs.h:7, from include/jemalloc/internal/jemalloc_internal_includes.h:54, from src/jemalloc.c:3: include/jemalloc/internal/jemalloc_internal_externs.h:14:20: 附注:‘opt_junk’的上一个定义在此 extern const char *opt_junk; ^ src/jemalloc.c:55:1: 错误:形参‘opt_junk_alloc’已初始化 bool opt_junk_alloc = ^ src/jemalloc.c:55:6: 错误:形参‘opt_junk_alloc’重定义 bool opt_junk_alloc = ^ In file included from include/jemalloc/internal/tsd.h:7:0, from include/jemalloc/internal/mutex.h:6, from include/jemalloc/internal/extent_structs.h:7, from include/jemalloc/internal/jemalloc_internal_includes.h:54, from src/jemalloc.c:3: include/jemalloc/internal/jemalloc_internal_externs.h:15:13: 附注:‘opt_junk_alloc’的上一个定义在此 extern bool opt_junk_alloc; ^ src/jemalloc.c:62:1: 错误:形参‘opt_junk_free’已初始化 bool opt_junk_free = ^ src/jemalloc.c:62:6: 错误:形参‘opt_junk_free’重定义 bool opt_junk_free = ^ In file included from include/jemalloc/internal/tsd.h:7:0, from include/jemalloc/internal/mutex.h:6, from include/jemalloc/internal/extent_structs.h:7, from include/jemalloc/internal/jemalloc_internal_includes.h:54, from src/jemalloc.c:3: include/jemalloc/internal/jemalloc_internal_externs.h:16:13: 附注:‘opt_junk_free’的上一个定义在此 extern bool opt_junk_free; ^ src/jemalloc.c:70:1: 错误:形参‘opt_utrace’已初始化 bool opt_utrace = false; ^ src/jemalloc.c:70:6: 错误:形参‘opt_utrace’重定义 bool opt_utrace = false; ^ In file included from include/jemalloc/internal/tsd.h:7:0, from include/jemalloc/internal/mutex.h:6, from include/jemalloc/internal/extent_structs.h:7, from include/jemalloc/internal/jemalloc_internal_includes.h:54, from src/jemalloc.c:3: include/jemalloc/internal/jemalloc_internal_externs.h:17:13: 附注:‘opt_utrace’的上一个定义在此 extern bool opt_utrace; ^ src/jemalloc.c:71:1: 错误:形参‘opt_xmalloc’已初始化 bool opt_xmalloc = false; ^ src/jemalloc.c:71:6: 错误:形参‘opt_xmalloc’重定义 bool opt_xmalloc = false; ^ In file included from include/jemalloc/internal/tsd.h:7:0, from include/jemalloc/internal/mutex.h:6, from include/jemalloc/internal/extent_structs.h:7, from include/jemalloc/internal/jemalloc_internal_includes.h:54, from src/jemalloc.c:3: include/jemalloc/internal/jemalloc_internal_externs.h:18:13: 附注:‘opt_xmalloc’的上一个定义在此 extern bool opt_xmalloc; ^ src/jemalloc.c:72:1: 错误:形参‘opt_zero’已初始化 bool opt_zero = false; ^ src/jemalloc.c:72:6: 错误:形参‘opt_zero’重定义 bool opt_zero = false; ^ In file included from include/jemalloc/internal/tsd.h:7:0, from include/jemalloc/internal/mutex.h:6, from include/jemalloc/internal/extent_structs.h:7, from include/jemalloc/internal/jemalloc_internal_includes.h:54, from src/jemalloc.c:3: include/jemalloc/internal/jemalloc_internal_externs.h:19:13: 附注:‘opt_zero’的上一个定义在此 extern bool opt_zero; ^ src/jemalloc.c:73:1: 错误:形参‘opt_narenas’已初始化 unsigned opt_narenas = 0; ^ src/jemalloc.c:73:10: 错误:形参‘opt_narenas’重定义 unsigned opt_narenas = 0; ^ In file included from include/jemalloc/internal/tsd.h:7:0, from include/jemalloc/internal/mutex.h:6, from include/jemalloc/internal/extent_structs.h:7, from include/jemalloc/internal/jemalloc_internal_includes.h:54, from src/jemalloc.c:3: include/jemalloc/internal/jemalloc_internal_externs.h:20:17: 附注:‘opt_narenas’的上一个定义在此 extern unsigned opt_narenas; ^ src/jemalloc.c:75:10: 错误:形参‘ncpus’重定义 unsigned ncpus; ^ In file included from include/jemalloc/internal/tsd.h:7:0, from include/jemalloc/internal/mutex.h:6, from include/jemalloc/internal/extent_structs.h:7, from include/jemalloc/internal/jemalloc_internal_includes.h:54, from src/jemalloc.c:3: include/jemalloc/internal/jemalloc_internal_externs.h:23:17: 附注:‘ncpus’的上一个定义在此 extern unsigned ncpus; ^ src/jemalloc.c:78:1: 错误:expected declaration specifiers before ‘malloc_mutex_t’ malloc_mutex_t arenas_lock; ^ src/jemalloc.c:89:1: 错误:expected declaration specifiers before ‘JEMALLOC_ALIGNED’ JEMALLOC_ALIGNED(CACHELINE) ^ src/jemalloc.c:91:19: 错误:expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘narenas_total’ static atomic_u_t narenas_total; /* Use narenas_total_*(). */ ^ src/jemalloc.c:93:18: 错误:为形参‘a0’指定了存储类 static arena_t *a0; /* arenas[0]. */ ^ src/jemalloc.c:94:11: 错误:形参‘narenas_auto’重定义 unsigned narenas_auto; ^ In file included from include/jemalloc/internal/tsd.h:7:0, from include/jemalloc/internal/mutex.h:6, from include/jemalloc/internal/extent_structs.h:7, from include/jemalloc/internal/jemalloc_internal_includes.h:54, from src/jemalloc.c:3: include/jemalloc/internal/jemalloc_internal_externs.h:26:17: 附注:‘narenas_auto’的上一个定义在此 extern unsigned narenas_auto; ^ src/jemalloc.c:95:11: 错误:形参‘manual_arena_base’重定义 unsigned manual_arena_base; ^ In file included from include/jemalloc/internal/tsd.h:7:0, from include/jemalloc/internal/mutex.h:6, from include/jemalloc/internal/extent_structs.h:7, from include/jemalloc/internal/jemalloc_internal_includes.h:54, from src/jemalloc.c:3: include/jemalloc/internal/jemalloc_internal_externs.h:29:17: 附注:‘manual_arena_base’的上一个定义在此 extern unsigned manual_arena_base; ^ src/jemalloc.c:102:3: 错误:为形参‘malloc_init_t’指定了存储类 } malloc_init_t; ^ src/jemalloc.c:103:22: 错误:expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘malloc_init_state’ static malloc_init_t malloc_init_state = malloc_init_uninitialized; ^ src/jemalloc.c:106:1: 错误:形参‘malloc_slow’已初始化 bool malloc_slow = true; ^ src/jemalloc.c:106:8: 错误:形参‘malloc_slow’重定义 bool malloc_slow = true; ^ In file included from include/jemalloc/internal/tsd.h:7:0, from include/jemalloc/internal/mutex.h:6, from include/jemalloc/internal/extent_structs.h:7, from include/jemalloc/internal/jemalloc_internal_includes.h:54, from src/jemalloc.c:3: include/jemalloc/internal/jemalloc_internal_externs.h:8:13: 附注:‘malloc_slow’的上一个定义在此 extern bool malloc_slow; ^ src/jemalloc.c:109:1: 警告:空声明 [默认启用] enum { ^ src/jemalloc.c:116:16: 错误:为形参‘malloc_slow_flags’指定了存储类 static uint8_t malloc_slow_flags; ^ src/jemalloc.c:123:19: 错误:为形参‘malloc_initializer’指定了存储类 static pthread_t malloc_initializer = NO_INITIALIZER; ^ src/jemalloc.c:123:1: 错误:形参‘malloc_initializer’已初始化 static pthread_t malloc_initializer = NO_INITIALIZER; ^ src/jemalloc.c:166:23: 错误:expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘init_lock’ static malloc_mutex_t init_lock = MALLOC_MUTEX_INITIALIZER; ^ src/jemalloc.c:166:59: 错误:expected declaration specifiers before ‘;’ token static malloc_mutex_t init_lock = MALLOC_MUTEX_INITIALIZER; ^ src/jemalloc.c:173:3: 错误:为形参‘malloc_utrace_t’指定了存储类 } malloc_utrace_t; ^ src/jemalloc.c:192:13: 错误:为形参‘had_conf_error’指定了存储类 static bool had_conf_error = false; ^ src/jemalloc.c:192:1: 错误:形参‘had_conf_error’已初始化 static bool had_conf_error = false; ^ src/jemalloc.c:200:13: 错误:为形参‘malloc_init_hard_a0’指定了存储类 static bool malloc_init_hard_a0(void); ^ src/jemalloc.c:201:13: 错误:为形参‘malloc_init_hard’指定了存储类 static bool malloc_init_hard(void); ^ src/jemalloc.c:209:26: 错误:expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘{’ token malloc_initialized(void) { ^ In file included from include/jemalloc/internal/jemalloc_preamble.h:34:0, from src/jemalloc.c:2: include/jemalloc/internal/jemalloc_internal_macros.h:7:34: 错误:expected declaration specifiers before ‘JEMALLOC_ATTR’ # define JEMALLOC_ALWAYS_INLINE JEMALLOC_ATTR(always_inline) static inline ^ src/jemalloc.c:213:1: 附注:in expansion of macro ‘JEMALLOC_ALWAYS_INLINE’ JEMALLOC_ALWAYS_INLINE bool ^ include/jemalloc/internal/jemalloc_internal_macros.h:7:34: 错误:expected declaration specifiers before ‘JEMALLOC_ATTR’ # define JEMALLOC_ALWAYS_INLINE JEMALLOC_ATTR(always_inline) static inline ^ src/jemalloc.c:221:1: 附注:in expansion of macro ‘JEMALLOC_ALWAYS_INLINE’ JEMALLOC_ALWAYS_INLINE bool ^ src/jemalloc.c:235:52: 错误:expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘{’ token a0ialloc(size_t size, bool zero, bool is_internal) { ^ src/jemalloc.c:245:40: 错误:expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘{’ token a0idalloc(void *ptr, bool is_internal) { ^ src/jemalloc.c:250:23: 错误:expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘{’ token a0malloc(size_t size) { ^ src/jemalloc.c:255:21: 错误:expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘{’ token a0dalloc(void *ptr) { ^ src/jemalloc.c:266:31: 错误:expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘{’ token bootstrap_malloc(size_t size) { ^ src/jemalloc.c:275:43: 错误:expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘{’ token bootstrap_calloc(size_t num, size_t size) { ^ src/jemalloc.c:288:27: 错误:expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘{’ token bootstrap_free(void *ptr) { ^ src/jemalloc.c:297:41: 错误:expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘{’ token arena_set(unsigned ind, arena_t *arena) { ^ src/jemalloc.c:302:37: 错误:expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘{’ token narenas_total_set(unsigned narenas) { ^ src/jemalloc.c:307:25: 错误:expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘{’ token narenas_total_inc(void) { ^ src/jemalloc.c:312:25: 错误:expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘{’ token narenas_total_get(void) { ^ src/jemalloc.c:318:19: 错误:expected declaration specifiers or ‘...’ before ‘tsdn_t’ arena_init_locked(tsdn_t *tsdn, unsigned ind, extent_hooks_t *extent_hooks) { ^ src/jemalloc.c:318:47: 错误:未知的类型名‘extent_hooks_t’ arena_init_locked(tsdn_t *tsdn, unsigned ind, extent_hooks_t *extent_hooks) { ^ src/jemalloc.c:346:36: 错误:expected declaration specifiers or ‘...’ before ‘tsdn_t’ arena_new_create_background_thread(tsdn_t *tsdn, unsigned ind) { ^ src/jemalloc.c:364:12: 错误:expected declaration specifiers or ‘...’ before ‘tsdn_t’ arena_init(tsdn_t *tsdn, unsigned ind, extent_hooks_t *extent_hooks) { ^ src/jemalloc.c:364:40: 错误:未知的类型名‘extent_hooks_t’ arena_init(tsdn_t *tsdn, unsigned ind, extent_hooks_t *extent_hooks) { ^ src/jemalloc.c:377:12: 错误:expected declaration specifiers or ‘...’ before ‘tsd_t’ arena_bind(tsd_t *tsd, unsigned ind, bool internal) { ^ src/jemalloc.c:397:15: 错误:expected declaration specifiers or ‘...’ before ‘tsd_t’ arena_migrate(tsd_t *tsd, unsigned oldind, unsigned newind) { ^ src/jemalloc.c:408:14: 错误:expected declaration specifiers or ‘...’ before ‘tsd_t’ arena_unbind(tsd_t *tsd, unsigned ind, bool internal) { ^ src/jemalloc.c:422:22: 错误:expected declaration specifiers or ‘...’ before ‘tsd_t’ arena_tdata_get_hard(tsd_t *tsd, unsigned ind) { ^ src/jemalloc.c:499:19: 错误:expected declaration specifiers or ‘...’ before ‘tsd_t’ arena_choose_hard(tsd_t *tsd, bool internal) { ^ src/jemalloc.c:613:16: 错误:expected declaration specifiers or ‘...’ before ‘tsd_t’ iarena_cleanup(tsd_t *tsd) { ^ src/jemalloc.c:623:15: 错误:expected declaration specifiers or ‘...’ before ‘tsd_t’ arena_cleanup(tsd_t *tsd) { ^ src/jemalloc.c:633:22: 错误:expected declaration specifiers or ‘...’ before ‘tsd_t’ arenas_tdata_cleanup(tsd_t *tsd) { ^ src/jemalloc.c:647:26: 错误:expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘{’ token stats_print_atexit(void) { ^ In file included from include/jemalloc/internal/jemalloc_preamble.h:34:0, from src/jemalloc.c:2: include/jemalloc/internal/jemalloc_internal_macros.h:7:34: 错误:expected declaration specifiers before ‘JEMALLOC_ATTR’ # define JEMALLOC_ALWAYS_INLINE JEMALLOC_ATTR(always_inline) static inline ^ src/jemalloc.c:683:1: 附注:in expansion of macro ‘JEMALLOC_ALWAYS_INLINE’ JEMALLOC_ALWAYS_INLINE void ^ src/jemalloc.c:712:42: 错误:expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘{’ token jemalloc_secure_getenv(const char *name) { ^ src/jemalloc.c:726:20: 错误:expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘{’ token malloc_ncpus(void) { ^ src/jemalloc.c:754:55: 错误:expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘{’ token init_opt_stats_print_opts(const char *v, size_t vlen) { ^ src/jemalloc.c:781:80: 错误:expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘{’ token size_t *vlen_left, size_t *slab_start, size_t *slab_end, size_t *new_size) { ^ src/jemalloc.c:824:39: 错误:expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘{’ token char const **v_p, size_t *vlen_p) { ^ src/jemalloc.c:898:33: 错误:expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘{’ token malloc_abort_invalid_conf(void) { ^ src/jemalloc.c:907:18: 错误:expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘{’ token size_t vlen) { ^ src/jemalloc.c:920:29: 错误:expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘{’ token malloc_slow_flag_init(void) { ^ src/jemalloc.c:938:67: 错误:expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘{’ token obtain_malloc_conf(unsigned which_source, char buf[PATH_MAX + 1]) { ^ src/jemalloc.c:1023:29: 错误:expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘{’ token char buf[PATH_MAX + 1]) { ^ src/jemalloc.c:1440:74: 错误:expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘{’ token malloc_conf_init(sc_data_t *sc_data, unsigned bin_shard_sizes[SC_NBINS]) { ^ src/jemalloc.c:1453:31: 错误:expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘{’ token malloc_init_hard_needed(void) { ^ src/jemalloc.c:1479:30: 错误:expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘{’ token malloc_init_hard_a0_locked() { ^ src/jemalloc.c:1564:27: 错误:expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘{’ token malloc_init_hard_a0(void) { ^ src/jemalloc.c:1575:35: 错误:expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘{’ token malloc_init_hard_recursible(void) { ^ src/jemalloc.c:1602:30: 错误:expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘{’ token malloc_narenas_default(void) { ^ src/jemalloc.c:1616:55: 错误:expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘{’ token percpu_arena_as_initialized(percpu_arena_mode_t mode) { ^ src/jemalloc.c:1628:27: 错误:expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘{’ token malloc_init_narenas(void) { ^ src/jemalloc.c:1704:26: 错误:expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘{’ token malloc_init_percpu(void) { ^ src/jemalloc.c:1709:31: 错误:expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘{’ token malloc_init_hard_finish(void) { ^ src/jemalloc.c:1721:26: 错误:expected declaration specifiers or ‘...’ before ‘tsdn_t’ malloc_init_hard_cleanup(tsdn_t *tsdn, bool reentrancy_set) { ^ src/jemalloc.c:1733:24: 错误:expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘{’ token malloc_init_hard(void) { ^ src/jemalloc.c:1815:30: 错误:为形参‘static_opts_t’指定了存储类 typedef struct static_opts_s static_opts_t; ^ src/jemalloc.c:1816:1: 警告:空声明 [默认启用] struct static_opts_s { ^ In file included from include/jemalloc/internal/jemalloc_preamble.h:34:0, from src/jemalloc.c:2: include/jemalloc/internal/jemalloc_internal_macros.h:7:34: 错误:expected declaration specifiers before ‘JEMALLOC_ATTR’ # define JEMALLOC_ALWAYS_INLINE JEMALLOC_ATTR(always_inline) static inline ^ src/jemalloc.c:1863:1: 附注:in expansion of macro ‘JEMALLOC_ALWAYS_INLINE’ JEMALLOC_ALWAYS_INLINE void ^ src/jemalloc.c:1886:31: 错误:为形参‘dynamic_opts_t’指定了存储类 typedef struct dynamic_opts_s dynamic_opts_t; ^ src/jemalloc.c:1887:1: 警告:空声明 [默认启用] struct dynamic_opts_s { ^ In file included from include/jemalloc/internal/jemalloc_preamble.h:34:0, from src/jemalloc.c:2: include/jemalloc/internal/jemalloc_internal_macros.h:7:34: 错误:expected declaration specifiers before ‘JEMALLOC_ATTR’ # define JEMALLOC_ALWAYS_INLINE JEMALLOC_ATTR(always_inline) static inline ^ src/jemalloc.c:1898:1: 附注:in expansion of macro ‘JEMALLOC_ALWAYS_INLINE’ JEMALLOC_ALWAYS_INLINE void ^ include/jemalloc/internal/jemalloc_internal_macros.h:7:34: 错误:expected declaration specifiers before ‘JEMALLOC_ATTR’ # define JEMALLOC_ALWAYS_INLINE JEMALLOC_ATTR(always_inline) static inline ^ src/jemalloc.c:1911:1: 附注:in expansion of macro ‘JEMALLOC_ALWAYS_INLINE’ JEMALLOC_ALWAYS_INLINE void * ^ include/jemalloc/internal/jemalloc_internal_macros.h:7:34: 错误:expected declaration specifiers before ‘JEMALLOC_ATTR’ # define JEMALLOC_ALWAYS_INLINE JEMALLOC_ATTR(always_inline) static inline ^ src/jemalloc.c:1953:1: 附注:in expansion of macro ‘JEMALLOC_ALWAYS_INLINE’ JEMALLOC_ALWAYS_INLINE void * ^ include/jemalloc/internal/jemalloc_internal_macros.h:7:34: 错误:expected declaration specifiers before ‘JEMALLOC_ATTR’ # define JEMALLOC_ALWAYS_INLINE JEMALLOC_ATTR(always_inline) static inline ^ src/jemalloc.c:1989:1: 附注:in expansion of macro ‘JEMALLOC_ALWAYS_INLINE’ JEMALLOC_ALWAYS_INLINE bool ^ include/jemalloc/internal/jemalloc_internal_macros.h:7:34: 错误:expected declaration specifiers before ‘JEMALLOC_ATTR’ # define JEMALLOC_ALWAYS_INLINE JEMALLOC_ATTR(always_inline) static inline ^ src/jemalloc.c:2027:1: 附注:in expansion of macro ‘JEMALLOC_ALWAYS_INLINE’ JEMALLOC_ALWAYS_INLINE int ^ include/jemalloc/internal/jemalloc_internal_macros.h:7:34: 错误:expected declaration specifiers before ‘JEMALLOC_ATTR’ # define JEMALLOC_ALWAYS_INLINE JEMALLOC_ATTR(always_inline) static inline ^ src/jemalloc.c:2227:1: 附注:in expansion of macro ‘JEMALLOC_ALWAYS_INLINE’ JEMALLOC_ALWAYS_INLINE bool ^ include/jemalloc/internal/jemalloc_internal_macros.h:7:34: 错误:expected declaration specifiers before ‘JEMALLOC_ATTR’ # define JEMALLOC_ALWAYS_INLINE JEMALLOC_ATTR(always_inline) static inline ^ src/jemalloc.c:2245:1: 附注:in expansion of macro ‘JEMALLOC_ALWAYS_INLINE’ JEMALLOC_ALWAYS_INLINE int ^ src/jemalloc.c:2269:1: 错误:expected declaration specifiers before ‘JEMALLOC_NOINLINE’ JEMALLOC_NOINLINE ^ src/jemalloc.c:2320:1: 错误:未知的类型名‘JEMALLOC_EXPORT’ JEMALLOC_EXPORT JEMALLOC_ALLOCATOR JEMALLOC_RESTRICT_RETURN ^ src/jemalloc.c:2320:36: 错误:expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘JEMALLOC_RESTRICT_RETURN’ JEMALLOC_EXPORT JEMALLOC_ALLOCATOR JEMALLOC_RESTRICT_RETURN ^ src/jemalloc.c:2391:1: 错误:expected declaration specifiers before ‘JEMALLOC_EXPORT’ JEMALLOC_EXPORT int JEMALLOC_NOTHROW ^ src/jemalloc.c:2430:1: 错误:未知的类型名‘JEMALLOC_EXPORT’ JEMALLOC_EXPORT JEMALLOC_ALLOCATOR JEMALLOC_RESTRICT_RETURN ^ src/jemalloc.c:2430:36: 错误:expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘JEMALLOC_RESTRICT_RETURN’ JEMALLOC_EXPORT JEMALLOC_ALLOCATOR JEMALLOC_RESTRICT_RETURN ^ src/jemalloc.c:2471:1: 错误:未知的类型名‘JEMALLOC_EXPORT’ JEMALLOC_EXPORT JEMALLOC_ALLOCATOR JEMALLOC_RESTRICT_RETURN ^ src/jemalloc.c:2471:36: 错误:expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘JEMALLOC_RESTRICT_RETURN’ JEMALLOC_EXPORT JEMALLOC_ALLOCATOR JEMALLOC_RESTRICT_RETURN ^ src/jemalloc.c:2506:22: 错误:expected declaration specifiers or ‘...’ before ‘tsd_t’ irealloc_prof_sample(tsd_t *tsd, void *old_ptr, size_t old_usize, size_t usize, ^ src/jemalloc.c:2507:24: 错误:expected declaration specifiers or ‘...’ before ‘hook_ralloc_args_t’ prof_tctx_t *tctx, hook_ralloc_args_t *hook_args) { ^ In file included from include/jemalloc/internal/jemalloc_preamble.h:34:0, from src/jemalloc.c:2: include/jemalloc/internal/jemalloc_internal_macros.h:7:34: 错误:expected declaration specifiers before ‘JEMALLOC_ATTR’ # define JEMALLOC_ALWAYS_INLINE JEMALLOC_ATTR(always_inline) static inline ^ src/jemalloc.c:2528:1: 附注:in expansion of macro ‘JEMALLOC_ALWAYS_INLINE’ JEMALLOC_ALWAYS_INLINE void * ^ include/jemalloc/internal/jemalloc_internal_macros.h:7:34: 错误:expected declaration specifiers before ‘JEMALLOC_ATTR’ # define JEMALLOC_ALWAYS_INLINE JEMALLOC_ATTR(always_inline) static inline ^ src/jemalloc.c:2555:1: 附注:in expansion of macro ‘JEMALLOC_ALWAYS_INLINE’ JEMALLOC_ALWAYS_INLINE void ^ include/jemalloc/internal/jemalloc_internal_macros.h:7:34: 错误:expected declaration specifiers before ‘JEMALLOC_ATTR’ # define JEMALLOC_ALWAYS_INLINE JEMALLOC_ATTR(always_inline) static inline ^ src/jemalloc.c:2594:1: 附注:in expansion of macro ‘JEMALLOC_ALWAYS_INLINE’ JEMALLOC_ALWAYS_INLINE void ^ src/jemalloc.c:2650:1: 错误:未知的类型名‘JEMALLOC_EXPORT’ JEMALLOC_EXPORT JEMALLOC_ALLOCATOR JEMALLOC_RESTRICT_RETURN ^ src/jemalloc.c:2650:36: 错误:expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘JEMALLOC_RESTRICT_RETURN’ JEMALLOC_EXPORT JEMALLOC_ALLOCATOR JEMALLOC_RESTRICT_RETURN ^ src/jemalloc.c:2769:1: 错误:expected declaration specifiers before ‘JEMALLOC_NOINLINE’ JEMALLOC_NOINLINE ^ In file included from include/jemalloc/internal/jemalloc_preamble.h:34:0, from src/jemalloc.c:2: include/jemalloc/internal/jemalloc_internal_macros.h:7:34: 错误:expected declaration specifiers before ‘JEMALLOC_ATTR’ # define JEMALLOC_ALWAYS_INLINE JEMALLOC_ATTR(always_inline) static inline ^ src/jemalloc.c:2805:1: 附注:in expansion of macro ‘JEMALLOC_ALWAYS_INLINE’ JEMALLOC_ALWAYS_INLINE ^ src/jemalloc.c:2862:1: 错误:expected declaration specifiers before ‘JEMALLOC_EXPORT’ JEMALLOC_EXPORT void JEMALLOC_NOTHROW ^ src/jemalloc.c:3095:1: 错误:未知的类型名‘JEMALLOC_EXPORT’ JEMALLOC_EXPORT JEMALLOC_ALLOCATOR JEMALLOC_RESTRICT_RETURN ^ src/jemalloc.c:3095:36: 错误:expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘JEMALLOC_RESTRICT_RETURN’ JEMALLOC_EXPORT JEMALLOC_ALLOCATOR JEMALLOC_RESTRICT_RETURN ^ src/jemalloc.c:3149:22: 错误:expected declaration specifiers or ‘...’ before ‘tsdn_t’ irallocx_prof_sample(tsdn_t *tsdn, void *old_ptr, size_t old_usize, ^ src/jemalloc.c:3151:24: 错误:expected declaration specifiers or ‘...’ before ‘hook_ralloc_args_t’ prof_tctx_t *tctx, hook_ralloc_args_t *hook_args) { ^ In file included from include/jemalloc/internal/jemalloc_preamble.h:34:0, from src/jemalloc.c:2: include/jemalloc/internal/jemalloc_internal_macros.h:7:34: 错误:expected declaration specifiers before ‘JEMALLOC_ATTR’ # define JEMALLOC_ALWAYS_INLINE JEMALLOC_ATTR(always_inline) static inline ^ src/jemalloc.c:3173:1: 附注:in expansion of macro ‘JEMALLOC_ALWAYS_INLINE’ JEMALLOC_ALWAYS_INLINE void * ^ src/jemalloc.c:3213:1: 错误:未知的类型名‘JEMALLOC_EXPORT’ JEMALLOC_EXPORT JEMALLOC_ALLOCATOR JEMALLOC_RESTRICT_RETURN ^ src/jemalloc.c:3213:36: 错误:expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘JEMALLOC_RESTRICT_RETURN’ JEMALLOC_EXPORT JEMALLOC_ALLOCATOR JEMALLOC_RESTRICT_RETURN ^ In file included from include/jemalloc/internal/jemalloc_preamble.h:34:0, from src/jemalloc.c:2: include/jemalloc/internal/jemalloc_internal_macros.h:7:34: 错误:expected declaration specifiers before ‘JEMALLOC_ATTR’ # define JEMALLOC_ALWAYS_INLINE JEMALLOC_ATTR(always_inline) static inline ^ src/jemalloc.c:3311:1: 附注:in expansion of macro ‘JEMALLOC_ALWAYS_INLINE’ JEMALLOC_ALWAYS_INLINE size_t ^ src/jemalloc.c:3325:22: 错误:expected declaration specifiers or ‘...’ before ‘tsdn_t’ ixallocx_prof_sample(tsdn_t *tsdn, void *ptr, size_t old_usize, size_t size, ^ In file included from include/jemalloc/internal/jemalloc_preamble.h:34:0, from src/jemalloc.c:2: include/jemalloc/internal/jemalloc_internal_macros.h:7:34: 错误:expected declaration specifiers before ‘JEMALLOC_ATTR’ # define JEMALLOC_ALWAYS_INLINE JEMALLOC_ATTR(always_inline) static inline ^ src/jemalloc.c:3338:1: 附注:in expansion of macro ‘JEMALLOC_ALWAYS_INLINE’ JEMALLOC_ALWAYS_INLINE size_t ^ src/jemalloc.c:3389:1: 错误:未知的类型名‘JEMALLOC_EXPORT’ JEMALLOC_EXPORT size_t JEMALLOC_NOTHROW ^ src/jemalloc.c:3389:24: 错误:expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘JEMALLOC_NOTHROW’ JEMALLOC_EXPORT size_t JEMALLOC_NOTHROW ^ src/jemalloc.c:3459:1: 错误:未知的类型名‘JEMALLOC_EXPORT’ JEMALLOC_EXPORT size_t JEMALLOC_NOTHROW ^ src/jemalloc.c:3459:24: 错误:expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘JEMALLOC_NOTHROW’ JEMALLOC_EXPORT size_t JEMALLOC_NOTHROW ^ src/jemalloc.c:3486:1: 错误:expected declaration specifiers before ‘JEMALLOC_EXPORT’ JEMALLOC_EXPORT void JEMALLOC_NOTHROW ^ In file included from include/jemalloc/internal/jemalloc_preamble.h:34:0, from src/jemalloc.c:2: include/jemalloc/internal/jemalloc_internal_macros.h:7:34: 错误:expected declaration specifiers before ‘JEMALLOC_ATTR’ # define JEMALLOC_ALWAYS_INLINE JEMALLOC_ATTR(always_inline) static inline ^ src/jemalloc.c:3533:1: 附注:in expansion of macro ‘JEMALLOC_ALWAYS_INLINE’ JEMALLOC_ALWAYS_INLINE size_t ^ src/jemalloc.c:3547:1: 错误:expected declaration specifiers before ‘JEMALLOC_NOINLINE’ JEMALLOC_NOINLINE void ^ src/jemalloc.c:3593:1: 错误:expected declaration specifiers before ‘JEMALLOC_EXPORT’ JEMALLOC_EXPORT void JEMALLOC_NOTHROW ^ src/jemalloc.c:3606:1: 错误:expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘je_sdallocx_noflags’ je_sdallocx_noflags(void *ptr, size_t size) { ^ src/jemalloc.c:3617:1: 错误:未知的类型名‘JEMALLOC_EXPORT’ JEMALLOC_EXPORT size_t JEMALLOC_NOTHROW ^ src/jemalloc.c:3617:24: 错误:expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘JEMALLOC_NOTHROW’ JEMALLOC_EXPORT size_t JEMALLOC_NOTHROW ^ src/jemalloc.c:3644:1: 错误:expected declaration specifiers before ‘JEMALLOC_EXPORT’ JEMALLOC_EXPORT int JEMALLOC_NOTHROW ^ src/jemalloc.c:3666:1: 错误:expected declaration specifiers before ‘JEMALLOC_EXPORT’ JEMALLOC_EXPORT int JEMALLOC_NOTHROW ^ src/jemalloc.c:3686:1: 错误:expected declaration specifiers before ‘JEMALLOC_EXPORT’ JEMALLOC_EXPORT int JEMALLOC_NOTHROW ^ src/jemalloc.c:3707:1: 错误:expected declaration specifiers before ‘JEMALLOC_EXPORT’ JEMALLOC_EXPORT void JEMALLOC_NOTHROW ^ src/jemalloc.c:3721:1: 错误:未知的类型名‘JEMALLOC_EXPORT’ JEMALLOC_EXPORT size_t JEMALLOC_NOTHROW ^ src/jemalloc.c:3721:24: 错误:expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘JEMALLOC_NOTHROW’ JEMALLOC_EXPORT size_t JEMALLOC_NOTHROW ^ src/jemalloc.c:3772:1: 错误:expected declaration specifiers before ‘JEMALLOC_ATTR’ JEMALLOC_ATTR(constructor) ^ src/jemalloc.c:3786:1: 错误:expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘{’ token { ^ src/jemalloc.c:3860:1: 错误:expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘{’ token { ^ src/jemalloc.c:3894:31: 错误:expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘{’ token jemalloc_postfork_child(void) { ^ src/jemalloc.c:3927:1: 错误:expected declaration specifiers before ‘JEMALLOC_EXPORT’ JEMALLOC_EXPORT int JEMALLOC_NOTHROW ^ In file included from include/jemalloc/internal/assert.h:1:0, from include/jemalloc/internal/bit_util.h:4, from include/jemalloc/internal/bitmap.h:5, from include/jemalloc/internal/arena_structs_a.h:4, from include/jemalloc/internal/jemalloc_internal_includes.h:53, from src/jemalloc.c:3: include/jemalloc/internal/malloc_io.h:54:8: 错误:原型函数定义中使用了旧式参数声明 size_t malloc_snprintf(char *str, size_t size, const char *format, ...) ^ src/jemalloc.c:3931:1: 错误:expected ‘{’ at end of input } ^ src/jemalloc.c:3931:1: 警告:在有返回值的函数中,控制流程到达函数尾 [-Wreturn-type] } ^ make: *** [src/jemalloc.sym.o] 错误 1
09-24
### Tomalloc、Jemalloc Glibc Malloc 的比较 #### 1. **Tomalloc** 尽管提到 `tomalloc`,但实际上并没有广泛使用的名为 `tomalloc` 的标准内存分配器。可能是拼写错误或者混淆了某些特定项目中的自定义实现。通常讨论中会涉及的是 `ptmalloc`(由 GNU libc 提供)其他知名分配器如 `jemalloc` `tcmalloc`。 不过假设存在某种称为 `tomalloc` 的假想或实验性分配器,其特性可以推测如下: - 如果它是一个轻量级的替代品,则可能专注于简化设计以减少复杂度。 - 可能针对嵌入式设备优化,在资源受限环境中表现良好。 - 性能特征取决于具体实现细节;如果没有公开文档说明,则难以进一步探讨[^4]。 --- #### 2. **Jemalloc** JeMalloc 是 FreeBSD 默认使用的高效动态内存管理库,并已被移植到 Linux 平台用于改进应用程序性能。以下是它的主要特点: - **线程友好型架构**:通过引入 per-thread caches (per thread arenas),有效降低了多线程环境下的锁争用问题,提升了并发处理能力。 - **碎片化控制机制**:相比传统的 malloc 实现,jemalloc 更加注重空间利用率,试图最小化外部内部碎片现象的发生概率。 - **可扩展性强**:支持多种调试选项以及统计接口,便于开发者监控内存使用状况并定位潜在泄漏点。 这些优势使得 jeamllloc 成为高性能服务器软件(例如 Redis、PostgreSQL 等)的理想选择之一[^3]。 --- #### 3. **Glibc Malloc (PtMallac)** GNU C Library 中集成的标准内存分配函数系列基于 ptmalloc2 发展而来。下面列举几个重要方面来描述它们之间的差异: - **历史沿革**: 原始版本是从 Doug Lea 所开发的 dlmalloct 进化而来的分支产物; 后续增加了 POSIX 线程兼容性的增强功能之后重新命名为 ptmalloct. - **适用范围广**: 几乎所有的 Unix/Linux 应用程序都默认依赖该组件来进行堆操作请求满足工作流程. - **局限之处**: 对于高度并行化的计算密集型任务而言,glibc 自带方案有时显得力不从心,因为全局锁定策略容易成为瓶颈所在. 值得注意的是,glibc 内部还包含了若干变体形式(比如 smallbin/treap),用来适应不同的应用场景需求变化趋势.[^1] --- #### 4. **总结对比表** | 特性/指标 | Jemalloc | Glibc Malloc | |----------------|------------------------------------|----------------------------------| | 主要目标 | 高效利用内存 | 综合平衡 | | 多线程支持 | 极佳 | 较差 | | 碎片化程度 | 很低 | 居中 | | 调试工具丰富 | 支持 | 不足 | 请注意以上表格仅作示意用途并不全面覆盖所有维度考量因素. --- ### 示例代码展示如何切换不同类型的allocator 可以通过设置 LD_PRELOAD 来强制加载指定路径下的 so 文件从而替换掉系统自带版本达到测试目的: ```bash export LD_PRELOAD=/usr/lib/libjemalloc.so ./your_program ``` 同样也可以尝试 tcmalloc : ```bash export LD_PRELOAD=/usr/lib/libtcmalloc_minimal.so ./another_test_case ``` ---
评论 1
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值