Non-Blocking Memory Allocator

Started by
9 comments, last by the_edd 13 years, 3 months ago
Hello!

I am looking for a cross-platform, open source, ANSI-C, non-blocking memory allocator. That's pretty specific, but hopefully there is one out there :).

I am looking for this because I have an application that has several threads. Each thread malloc's ~80 MB of memory each cycle for inter-thread communication, and each thread cycles about ~1000 times a second (because the threads cleanup up after each other the memory usage idles around ~150 MB per thread). After profiling my application I noticed one of the slowest things was memory management, because if two threads where allocating or freeing memory at the same time one thread would have to wait for the other too finish before it could continue. It makes sense that this would cause a performance drop, because that ~80MB is composed of thousands of malloc's/free's, and that's done ~1000 times a second per thread.

I could implement one of the several methods for multithreaded memory management solutions (buckets, free lists, etc), but for the sake of time and simplicity, is there a pre-existing non-blocking memory allocator that someone can refer me to?

Thanks!
Advertisement
Why don't you just pre-allocate ~200MB per thread and just use placement new to allocate. I guess I'm saying just make your own memory manager, but if each worker thread has it's own pool from which assigned jobs allocate, you don't have to worry about making it thread-safe

Why don't you just pre-allocate ~200MB per thread and just use placement new to allocate. I guess I'm saying just make your own memory manager, but if each worker thread has it's own pool from which assigned jobs allocate, you don't have to worry about making it thread-safe

Thank you for your reply Palidine! I am not looking for how to implement a memory manager (as I already know how :P), but for the sake of simplicity and time I am looking for a pre-existing one. Thanks anyways!
Intel's TBB has a mostly non-blocking general purpose allocator, but it's C++. But you can still use malloc/free with it.

You can also easily roll your own in Windows by creating a non-serializing heap via HeapCreate for each thread, although that may not have the kind of ideal performance characteristics that you're looking for.
You might want to try tcmalloc, which is part of google's perftools. I haven't used it myself, but I've heard that for small allocations in multiple threads it works pretty well.
Seconding tcmalloc. It works pretty well and is a fairly easy drop-in.

Wielder of the Sacred Wands
[Work - ArenaNet] [Epoch Language] [Scribblings]

Picked up an article from HackerNews on the facebook blog recently. Apparently, they've improved on tcmalloc for their use cases and hardware, at least.

Hello!

I am looking for a cross-platform, open source, ANSI-C, non-blocking memory allocator. That's pretty specific, but hopefully there is one out there :).

I am looking for this because I have an application that has several threads. Each thread malloc's ~80 MB of memory each cycle for inter-thread communication, and each thread cycles about ~1000 times a second (because the threads cleanup up after each other the memory usage idles around ~150 MB per thread). After profiling my application I noticed one of the slowest things was memory management, because if two threads where allocating or freeing memory at the same time one thread would have to wait for the other too finish before it could continue. It makes sense that this would cause a performance drop, because that ~80MB is composed of thousands of malloc's/free's, and that's done ~1000 times a second per thread.

I could implement one of the several methods for multithreaded memory management solutions (buckets, free lists, etc), but for the sake of time and simplicity, is there a pre-existing non-blocking memory allocator that someone can refer me to?

Thanks!


If your program allocates 80MB of memory each loop, per thread then the obvious choice is to reuse the first alloc and do not de alloc it. Then, your problem is solved.
Wisdom is knowing when to shut up, so try it.
--Game Development http://nolimitsdesigns.com: Reliable UDP library, Threading library, Math Library, UI Library. Take a look, its all free.
jemalloc. Just throwing it in.
Holy crap I started a blog - http://unobvious.typepad.com/

If your program allocates 80MB of memory each loop, per thread then the obvious choice is to reuse the first alloc and do not de alloc it. Then, your problem is solved.

It fluctuates around 80 MB, so pre-allocating the memory isn't an option.


Thanks everybody for your replies! I am going to check out each of those but tcmalloc looks the most promising so far. Thanks again! :)

This topic is closed to new replies.

Advertisement