I have a several custom allocators that provide different means to allocate memory based on different policies. One of them allocates memory on a defined NUMA node. The interface to the allocator is straight-forward
template<typename config>
class NumaNodeStrategy
{
public:
static void *allocate(const size_t sz){}
static void *reallocate(void *old, size_t sz, size_t old_sz){}
static void deallocate(void *p, size_t sz){}
};
The allocation itself is handled using the hwloc_alloc_membind_nodeset()
methods with the according parameters set for allocation policies etc. Howver, hwloc only provides methods for allocation and free'ing memory and I was wondering how should I implement reallocate()
.
Two possible solutions:
- Allocate new memory area and
memcpy()
the data - Use
hwloc_set_membind_nodeset()
to set the memory allocation / binding policy for the nodeset and use plainmalloc()
/posix_memalign()
andrealloc()
.
Can anyone help me in getting this right?
Update:
I try to make the question more specific: Is there a possibility to perform a realloc()
using hwloc
without allocating new memory and moving the pages around?