Using scalable malloc with preload (Linux)

Using scalable malloc with preload (Linux)

Hello,

I am working on a large application, where I suspect serialization due to the many allocation/deallocation calls. I would like to give the TBB allocation routines a try, but replacing all of the calls is not an option because the source code is way too big.

Other memory libararies like horde provide the possibility to replace the standard routines at runtime. This is realized by setting the PRELOAD environment variable to the library. All that is needed from the library is to provide the memory routines with the same name and interface. It would be nice if TBB had the same functionality.

We already tried to write a wrapper, but the overhead was to big. The major obstacle is to avoid the recursive call of malloc. (scalable_malloc obviously calls malloc).

Kind regards

Thomas

2 posts / 0 new
Last post
For more complete information about compiler optimizations, see our Optimization Notice.

Recursive call of malloc is one of the things that prevent us from providing the exact "malloc" interface, without the "scalable_" prefix. Another thing is that other platforms (e.g. Windows) do not have LD_PRELOAD and so there will be conflict of names at link stage. One more reason is that the TBB allocator uses some pthread calls (e.g. pthread_get_specific for thread-local storage) that might in theory call malloc - so even if the use of malloc is eliminated, there is some risk of circular dependence.

What I might suggest to you is:
- if your app mostly uses C++ operators new and delete, override the operators to use scalable_malloc etc. It is fully supported by the C++ standard.
- if your app mostly uses malloc/free, you might try to #define malloc scalable_malloc and etc, and recompile. E.g. you might try adding -Dmalloc=scalable_malloc to the compilation line for each file, or create a special header file that does this redefinition, or might be add those into tbb/scalable_allocator.h and include itwhenever you need malloc.
- possibly the best way is to profile your application and find the places where malloc calls are most heavy,and start with replacing just these calls.

We are working on mechanisms to make global replacement of malloc etc. with scalable_malloc possible in future versions of TBB.

Leave a Comment

Please sign in to add a comment. Not a member? Join today