Skip to content
This repository has been archived by the owner on Jun 23, 2022. It is now read-only.

utility: refactor tls memory allocator #25

Merged
merged 1 commit into from
Apr 23, 2018

Conversation

shengofsun
Copy link
Contributor

remove c interface of tls memory allocator, and move
related code to utility module

remove c interface of tls memory allocator, and move
related code to utility module
@neverchanje
Copy link
Contributor

tls memory allocator 后面看看还是换成 tcmalloc 或者 jemalloc 吧。
可以讨论一下 tls transient allocator 的必要性:

块预分配:首先 block 预分配这种最基本的策略根本没必要实现,底层 allocator 从操作系统申请内存也是按 chunk 分的。所以外部碎片基本不存在。

线程安全:tls transient allocator 在内存分配和释放的时候都涉及到了原子操作(shared_ptr),带来了额外的开销,而 tcmalloc 和 jemalloc 的在释放小对象时都是无锁设计,。

When allocating a small object: (1) We map its size to the corresponding size-class. (2) Look in the corresponding free list in the thread cache for the current thread. (3) If the free list is not empty, we remove the first object from the list and return it. When following this fast path, TCMalloc acquires no locks at all. This helps speed-up allocation significantly because a lock/unlock pair takes approximately 100 nanoseconds on a 2.8 GHz Xeon.

它们都是在释放时把对象放到 thread local 的 cache 中,用于以后重复使用。

小对象优化:tcmalloc 和 jemalloc 对小对象的优化粒度更细,更适合调优。

@shengofsun
Copy link
Contributor Author

后面我会专门测试下tls memory allocator的效果,并尝试替换成tc/jemelloc, 不管怎样,有成熟的方案在,我们就没必要自己维护

Copy link
Member

@qinzuoyan qinzuoyan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Copy link
Contributor

@neverchanje neverchanje left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants