C ++内存分配机制性能比较(tcmalloc vs. jemalloc) [英] C++ memory allocation mechanism performance comparison (tcmalloc vs. jemalloc)

查看:1644
本文介绍了C ++内存分配机制性能比较(tcmalloc vs. jemalloc)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个应用程序分配大量内存,我正在考虑使用比malloc更好的内存分配机制。

I have an application which allocates lots of memory and I am considering using a better memory allocation mechanism than malloc.

我的主要选项是:jemalloc和tcmalloc。

My main options are: jemalloc and tcmalloc. Is there any benefits in using any of them over the other?

http://locklessinc.com/benchmarks.shtml
,它提到了每个人的一些优点和缺点。

There is a good comparison between some mechanisms (including the author's proprietary mechanism -- lockless) in http://locklessinc.com/benchmarks.shtml and it mentions some pros and cons of each of them.

由于这两种机制都是活跃的并且不断改进。

Given that both of the mechanisms are active and constantly improving. Does anyone have any insight or experience about the relative performance of these two?

推荐答案

如果我记得正确,主要的区别是:多线程项目。

If I remember correctly, the main difference was with multi-threaded projects.

这两个库试图通过线程从不同的缓存中挑选内存来取消内存获取,但它们有不同的策略:

Both libraries try to de-contention memory acquire by having threads pick the memory from different caches, but they have different strategies:


  • jemalloc (由Facebook使用) li> tcmalloc (来自Google)维护着一个缓存池,并且线程为缓存创建了一个自然亲和关系,但可能会更改

  • jemalloc (used by Facebook) maintains a cache per thread
  • tcmalloc (from Google) maintains a pool of caches, and threads develop a "natural" affinity for a cache, but may change

如果我记得正确,这又导致了线程管理方面的一个重要区别。

This led, once again if I remember correctly, to an important difference in term of thread management.

    $例如使用池
  • tcmalloc / code>在创建/销毁线程时更快

  • jemalloc is faster if threads are static, for example using pools
  • tcmalloc is faster when threads are created/destructed

还有一个问题,因为 jemalloc 使新的缓存适应新的线程ID,突然的线程将留下你的(大部分)空缓存在随后的平静阶段。

There is also the problem that since jemalloc spin new caches to accommodate new thread ids, having a sudden spike of threads will leave you with (mostly) empty caches in the subsequent calm phase.

因此,我建议在一般情况下使用 tcmalloc ,并为非常具体的用法保留 jemalloc 在应用程序的生命周期内线程数量的低变化)。

As a result, I would recommend tcmalloc in the general case, and reserve jemalloc for very specific usages (low variation on the number of threads during the lifetime of the application).

这篇关于C ++内存分配机制性能比较(tcmalloc vs. jemalloc)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆