#include <rte_malloc.h>
#include "malloc_elem.h"
#include "malloc_heap.h"
+#include "malloc_heap.c"
-static struct malloc_heap malloc_heap[RTE_MAX_NUMA_NODES] = {
- { .initialised = NOT_INITIALISED }
-};
/* Free the memory space back to heap */
void rte_free(void *addr)
}
/*
- * Allocate memory on default heap.
+ * Allocate memory on specified heap.
*/
void *
-rte_malloc(const char *type, size_t size, unsigned align)
+rte_malloc_socket(const char *type, size_t size, unsigned align, int socket)
{
- unsigned malloc_socket = malloc_get_numa_socket();
+ struct rte_mem_config *mcfg = rte_eal_get_configuration()->mem_config;
+
/* return NULL if size is 0 or alignment is not power-of-2 */
if (size == 0 || !rte_is_power_of_2(align))
return NULL;
- return malloc_heap_alloc(&malloc_heap[malloc_socket], type,
+
+ if (socket == SOCKET_ID_ANY)
+ socket = malloc_get_numa_socket();
+
+ /* Check socket parameter */
+ if (socket >= RTE_MAX_NUMA_NODES)
+ return NULL;
+
+ return malloc_heap_alloc(&mcfg->malloc_heaps[socket], type,
size, align == 0 ? 1 : align);
}
/*
- * Allocate zero'd memory on default heap.
+ * Allocate memory on default heap.
*/
void *
-rte_zmalloc(const char *type, size_t size, unsigned align)
+rte_malloc(const char *type, size_t size, unsigned align)
{
- void *ptr = rte_malloc(type, size, align);
+ return rte_malloc_socket(type, size, align, SOCKET_ID_ANY);
+}
+
+/*
+ * Allocate zero'd memory on specified heap.
+ */
+void *
+rte_zmalloc_socket(const char *type, size_t size, unsigned align, int socket)
+{
+ void *ptr = rte_malloc_socket(type, size, align, socket);
if (ptr != NULL)
memset(ptr, 0, size);
return ptr;
}
+/*
+ * Allocate zero'd memory on default heap.
+ */
+void *
+rte_zmalloc(const char *type, size_t size, unsigned align)
+{
+ return rte_zmalloc_socket(type, size, align, SOCKET_ID_ANY);
+}
+
+/*
+ * Allocate zero'd memory on specified heap.
+ */
+void *
+rte_calloc_socket(const char *type, size_t num, size_t size, unsigned align, int socket)
+{
+ return rte_zmalloc_socket(type, num * size, align, socket);
+}
+
/*
* Allocate zero'd memory on default heap.
*/