Linux tcmalloc/jemalloc 和内存池之间(以及选择的原因)有什么区别?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/9866145/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-06 05:24:06  来源:igfitidea点击:

What are the differences between (and reasons to choose) tcmalloc/jemalloc and memory pools?

clinuxmemorymalloctcmalloc

提问by Mickey Shine

tcmalloc/jemalloc are improved memory allocators, and memory pool is also introduced for better memory allocation. So what are the differences between them and how to choose them in my application?

tcmalloc/jemalloc 是改进的内存分配器,并且还引入了内存池以获得更好的内存分配。那么它们之间有什么区别以及如何在我的应用程序中选择它们呢?

回答by ritesh sangani

It depends upon requirement of your program. If your program has more dynamic memory allocations, then you need to choose a memory allocator, from available allocators, which would generate most optimal performance out of your program.

这取决于您的程序的要求。如果你的程序有更多的动态内存分配,那么你需要从可用的分配器中选择一个内存分配器,它可以让你的程序产生最佳的性能。

For good memory management you need to meet the following requirements at minimum:

要获得良好的内存管理,您至少需要满足以下要求:

  1. Check if your system has enough memory to process data.
  2. Are you albe to allocate from the available memory ?
  3. Returning the used memory / deallocated memory to the pool (program or operating system)
  1. 检查您的系统是否有足够的内存来处理数据。
  2. 您是否要从可用内存中分配?
  3. 将使用过的内存/释放的内存返回到池中(程序或操作系统)

The ability of a good memory manager can be tested on basis of (at the bare minimum) its efficiency in retriving / allocating and returning / dellaocating memory. (There are many more conditions like cache locality, managing overhead, VM environments, small or large environments, threaded environment etc..)

一个好的内存管理器的能力可以根据(至少)它在检索/分配和返回/释放内存方面的效率来测试。(还有更多条件,例如缓存位置、管理开销、VM 环境、小型或大型环境、线程环境等。)

With respect to tcmalloc and jemalloc there are many people who have done comparisions. With reference to one of the comparisions:

关于tcmalloc和jemalloc,有很多人做过对比。参考其中一项比较:

http://ithare.com/testing-memory-allocators-ptmalloc2-tcmalloc-hoard-jemalloc-while-trying-to-simulate-real-world-loads/

http://ithare.com/testing-memory-allocators-ptmalloc2-tcmalloc-hoard-jemalloc-while-trying-to-simulate-real-world-loads/

tcmalloc scores over all other in terms of CPU cycles per allocation if the number of threads are less. jemalloc is very close to tcmalloc but better than ptmalloc (std glibc implementation).

如果线程数较少,则 tcmalloc 在每次分配的 CPU 周期方面得分高于其他所有。jemalloc 与 tcmalloc 非常接近,但比 ptmalloc(std glibc 实现)更好。

In terms of memory overhead jemalloc is the best, seconded by ptmalloc, followed by tcmalloc.

就内存开销而言,jemalloc 是最好的,其次是 ptmalloc,其次是 tcmalloc。

Overall it can be said that jemalloc scores over others. You can also read more about jemalloc here:

总的来说可以说 jemalloc 得分超过其他人。您还可以在此处阅读有关 jemalloc 的更多信息:

https://www.facebook.com/notes/facebook-engineering/scalable-memory-allocation-using-jemalloc/480222803919

https://www.facebook.com/notes/facebook-engineering/scalable-memory-allocation-using-jemalloc/480222803919

I have just quoted from tests done and published by other people and have not tested it myself. I hope this could be a good starting point for you and use it to test and select the most optimal for your application.

我刚刚引用了其他人完成和发布的测试,并没有自己测试过。我希望这对您来说是一个很好的起点,并使用它来测试和选择最适合您的应用程序。