memory: malloc now supports multi process
Signed-off-by: Intel
This commit is contained in:
parent
dec5e73d78
commit
766b12e538
@ -38,6 +38,7 @@
|
||||
#include <rte_tailq.h>
|
||||
#include <rte_memory.h>
|
||||
#include <rte_memzone.h>
|
||||
#include <rte_malloc_heap.h>
|
||||
#include <rte_rwlock.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
@ -86,6 +87,9 @@ struct rte_mem_config {
|
||||
struct rte_memseg free_memseg[RTE_MAX_MEMSEG];
|
||||
|
||||
struct rte_tailq_head tailq_head[RTE_MAX_TAILQ]; /**< Tailqs for objects */
|
||||
|
||||
/* Heaps of Malloc per socket */
|
||||
struct malloc_heap malloc_heaps[RTE_MAX_NUMA_NODES];
|
||||
} __attribute__((__packed__));
|
||||
|
||||
|
||||
|
@ -36,9 +36,11 @@
|
||||
#define _RTE_MALLOC_HEAP_H_
|
||||
|
||||
#include <stddef.h>
|
||||
#include <rte_spinlock.h>
|
||||
|
||||
enum heap_state {
|
||||
NOT_INITIALISED = 0,
|
||||
INITIALISING,
|
||||
INITIALISED
|
||||
};
|
||||
|
||||
|
@ -68,6 +68,7 @@
|
||||
#include <rte_common.h>
|
||||
#include <rte_version.h>
|
||||
#include <rte_atomic.h>
|
||||
#include <malloc_heap.h>
|
||||
|
||||
#include "eal_private.h"
|
||||
#include "eal_thread.h"
|
||||
|
@ -43,12 +43,15 @@
|
||||
#include <rte_memzone.h>
|
||||
#include <rte_tailq.h>
|
||||
#include <rte_eal.h>
|
||||
#include <rte_eal_memconfig.h>
|
||||
#include <rte_launch.h>
|
||||
#include <rte_per_lcore.h>
|
||||
#include <rte_lcore.h>
|
||||
#include <rte_common.h>
|
||||
#include <rte_string_fns.h>
|
||||
#include <rte_spinlock.h>
|
||||
#include <rte_memcpy.h>
|
||||
#include <rte_atomic.h>
|
||||
|
||||
#include "malloc_elem.h"
|
||||
#include "malloc_heap.h"
|
||||
@ -114,16 +117,25 @@ malloc_heap_add_memzone(struct malloc_heap *heap, size_t size, unsigned align)
|
||||
static void
|
||||
malloc_heap_init(struct malloc_heap *heap)
|
||||
{
|
||||
static rte_spinlock_t init_lock = RTE_SPINLOCK_INITIALIZER;
|
||||
rte_spinlock_lock(&init_lock);
|
||||
if (!heap->initialised) {
|
||||
heap->free_head = NULL;
|
||||
heap->mz_count = 0;
|
||||
heap->numa_socket = malloc_get_numa_socket();
|
||||
rte_spinlock_init(&heap->lock);
|
||||
heap->initialised = INITIALISED;
|
||||
struct rte_mem_config *mcfg = rte_eal_get_configuration()->mem_config;
|
||||
|
||||
rte_eal_mcfg_wait_complete(mcfg);
|
||||
while (heap->initialised != INITIALISED) {
|
||||
if (rte_atomic32_cmpset(
|
||||
(volatile uint32_t*)&heap->initialised,
|
||||
NOT_INITIALISED, INITIALISING)) {
|
||||
|
||||
heap->free_head = NULL;
|
||||
heap->mz_count = 0;
|
||||
/*
|
||||
* Find NUMA socket of heap that is being initialised, so that
|
||||
* malloc_heaps[n].numa_socket == n
|
||||
*/
|
||||
heap->numa_socket = heap - mcfg->malloc_heaps;
|
||||
rte_spinlock_init(&heap->lock);
|
||||
heap->initialised = INITIALISED;
|
||||
}
|
||||
}
|
||||
rte_spinlock_unlock(&init_lock);
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -54,10 +54,8 @@
|
||||
#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)
|
||||
@ -73,6 +71,8 @@ void rte_free(void *addr)
|
||||
void *
|
||||
rte_malloc_socket(const char *type, size_t size, unsigned align, int 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;
|
||||
@ -84,7 +84,7 @@ rte_malloc_socket(const char *type, size_t size, unsigned align, int socket)
|
||||
if (socket >= RTE_MAX_NUMA_NODES)
|
||||
return NULL;
|
||||
|
||||
return malloc_heap_alloc(&malloc_heaps[socket], type,
|
||||
return malloc_heap_alloc(&mcfg->malloc_heaps[socket], type,
|
||||
size, align == 0 ? 1 : align);
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user