Community
cancel
Showing results for 
Search instead for 
Did you mean: 
Ramya_J_
Beginner
58 Views

TBBMalloc memory_pool memalign and

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);

}

 

 

0 Kudos
6 Replies
RafSchietekat
Black Belt
58 Views

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.

Ramya_J_
Beginner
58 Views

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 ?

RafSchietekat
Black Belt
58 Views

"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?

58 Views

concur with Raf about rml::pool_aligned_malloc. Won't it work for you, Ramya?

RafSchietekat
Black Belt
58 Views

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...

Ramya_J_
Beginner
58 Views

Thank you very much. rml::pool_aligned_malloc was what I needed.

Reply