- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I am trying to use the TBBMalloc memory allocator instead of jemalloc.
How should the memalign be implemented using tbbmalloc pool?
tbb::memory_pool< std::allocator<char> > pool; // pool to store
typedef tbb::memory_pool_allocator<int> pool_allocator_t; // interface to STL containers
#include <jemalloc/jemalloc.h>
// Each thread "joins" the custom address space by figuring out what
// flags to pass to jemalloc for each address space, and storing them in this
// array.
extern __thread int as_flags[AS_COUNT];
void *jemalloc_calloc(int id, size_t nmemb, size_t bytes) {
int flags = as_flags[id] | MALLOCX_ZERO;
return je_mallocx(nmemb * bytes, flags);
}
void *jemalloc_memalign(int id, size_t boundary, size_t size) {
int flags = as_flags[id] | MALLOCX_ALIGN(boundary);
return je_mallocx(size, flags);
}
Link Copied
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Do you really need to allocate on top of another allocator, which is what tbb::memory_pool is for, specifically?
What kind of alignment do you really need (primitive types, cache lines, pages, ...)?
Do you really need a C++ allocator interface?
(Added) There doesn't seem to be a generally usable solution out-of-the-box, so some more information is required. Unless I overlooked something, of course.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
We have a large region of registered allocated memory buffer with network. Fixed memory pool is exactly what we want. We expose memalign to the users but fixed memory pool does not have an interface with memalign. Are there any suggestions for doing memalign and calloc with fixed memory pools ?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
"We have a large region of registered allocated memory buffer with network."
So the answer to my first question is "yes", and the original question was therefore somewhat misleading (std::allocator etc.)... My third question was to suggest the C interface for the scalable memory allocator in case the origin of the memory didn't matter, but it is now clear that it does, so that's ruled out now.
Hmm... fixed_pool derives from pool_base, which has a MemoryPool pointer, so is it a relatively simple matter to dig through to pool_aligned_malloc(), I wonder?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
concur with Raf about rml::pool_aligned_malloc. Won't it work for you, Ramya?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
There's still my second question above in #2. Various ranges of allocation size come with their own alignments. Even if this is not documented, it could get you started...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Thank you very much. rml::pool_aligned_malloc was what I needed.

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page