Intel® oneAPI Threading Building Blocks
Ask questions and share information about adding parallelism to your applications when using this threading library.

TBBMalloc memory_pool memalign and

Ramya_J_
Beginner
585 Views

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
Valued Contributor III
585 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.

0 Kudos
Ramya_J_
Beginner
585 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 ?

0 Kudos
RafSchietekat
Valued Contributor III
585 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?

0 Kudos
Vladimir_P_1234567890
586 Views

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

0 Kudos
RafSchietekat
Valued Contributor III
586 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...

0 Kudos
Ramya_J_
Beginner
586 Views

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

0 Kudos
Reply