jemalloc如何工作?有什么好处? [英] How does jemalloc work? What are the benefits?

查看:248
本文介绍了jemalloc如何工作?有什么好处?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Firefox 3带有一个新的分配器: jemalloc



分配器更好。 Google的最佳搜索结果并没有提供任何进一步的信息,但我对它的工作原理感兴趣。

$ c> jemalloc 首先出现在FreeBSD上,一个是杰森·埃文斯(Jason Evans),因此是je。如果我没有写过一个名为 paxos 的操作系统,我会嘲笑他是自负的。

a href =http://people.freebsd.org/~jasone/jemalloc/bsdcan2006/jemalloc.pdf =noreferrer>本PDF 了解详情。这是一个白皮书,详细描述算法是如何工作的。

主要的好处是在多处理器和多线程系统中的可扩展性,部分是通过使用多个领域(从原始内存块进行分配)。

在单线程情况下,对于多个竞技场没有真正的好处,所以使用单个竞技场。然而,在多线程的情况下,创建了许多舞台(处理器数量是竞技场的四倍),并且以循环方式将线程分配给这些舞台这意味着可以减少锁定争用,因为当多个线程可能会调用 malloc free 并发,他们只会在共享同一个竞技场的情况下进行竞争。另外, jemalloc 会尝试针对缓存区域进行优化,因为自从两个线程在不同的舞台上不会互相影响。 从RAM中获取数据的行为要比使用CPU高速缓存中的数据慢得多(概念上与从RAM快速获取和从磁盘慢速获取之间的区别没有什么不同)。为此,它首先尝试最大限度地减少内存使用,因为这更有可能确保应用程序的整个工作集在缓存中。



而且,它试图确保分配是连续的,因为分配在一起的内存往往是一起使用的。

在白皮书中,这些策略似乎给出了类似的性能目前最好的单线程使用算法,同时为多线程的使用提供改进。

Firefox 3 came with a new allocator: jemalloc.

I have heard at several places that this new allocator is better. The top Google results don't gave any further information though and I am interested in how exactly it works.

解决方案

jemalloc first appeared for FreeBSD, the brainchild of one "Jason Evans", hence the "je". I would ridicule him for being egotistical had I not once written an operating system called paxos :-)

See this PDF for full details. It's a white paper describing in detail how the algorithms work.

The main benefit is scalability in multi-processor and multi-threaded systems achieved, in part, by using multiple arenas (the chunks of raw memory from which allocations are made).

In single-threaded situations, there is no real benefit to multiple arenas so a single arena is used.

However, in multi-threaded situations, many arenas are created (four times as many arenas as there are processors), and threads are assigned to these arenas in a round-robin fashion.

This means that lock contention can be reduced since, while multiple threads may call malloc or free concurrently, they'll only contend if they share the same arena. Two threads with different arenas will not affect each other.

In addition, jemalloc tries to optimise for cache locality since the act of fetching data from RAM is much slower than using data already in the CPU caches (no different in concept to the difference between fast fetching from RAM versus slow fetching from disk). To that end, it first tries to minimise memory usage overall since that is more likely to ensure the application's entire working set is in cache.

And, where that can't be achieved, it tries to ensure that allocations are contiguous, since memory allocated together tends to be used together.

From the white paper, these strategies seem to give similar performance to current best algorithms for single threaded use while offering improvements for multi-threaded usage.

这篇关于jemalloc如何工作?有什么好处?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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