From: Sinan Kaya <ok...@kernel.org>

Initialize heap area just once.

Signed-off-by: Sinan Kaya <ok...@kernel.org>
---
 lib/eal/common/eal_common_memory.c | 5 +++++
 lib/eal/common/malloc_heap.c       | 6 ++++++
 2 files changed, 11 insertions(+)

diff --git a/lib/eal/common/eal_common_memory.c 
b/lib/eal/common/eal_common_memory.c
index 688dc615d7..e342eeb806 100644
--- a/lib/eal/common/eal_common_memory.c
+++ b/lib/eal/common/eal_common_memory.c
@@ -1084,10 +1084,14 @@ rte_eal_memory_init(void)
 
        int retval;
        RTE_LOG(DEBUG, EAL, "Setting up physically contiguous memory...\n");
+       static int initialized = 0;
 
        if (!mcfg)
                return -1;
 
+       if (initialized)
+               return 0;
+
        /* lock mem hotplug here, to prevent races while we init */
        rte_mcfg_mem_read_lock();
 
@@ -1106,6 +1110,7 @@ rte_eal_memory_init(void)
        if (internal_conf->no_shconf == 0 && rte_eal_memdevice_init() < 0)
                goto fail;
 
+       initialized = true;
        return 0;
 fail:
        rte_mcfg_mem_read_unlock();
diff --git a/lib/eal/common/malloc_heap.c b/lib/eal/common/malloc_heap.c
index 6eb6fcda5e..4c5f8aed0b 100644
--- a/lib/eal/common/malloc_heap.c
+++ b/lib/eal/common/malloc_heap.c
@@ -1405,6 +1405,10 @@ rte_eal_malloc_heap_init(void)
        unsigned int i;
        const struct internal_config *internal_conf =
                eal_get_internal_configuration();
+       static int initialized = 0;
+
+       if (initialized)
+               return 0;
 
        if (internal_conf->match_allocations)
                RTE_LOG(DEBUG, EAL, "Hugepages will be freed exactly as 
allocated.\n");
@@ -1443,6 +1447,8 @@ rte_eal_malloc_heap_init(void)
        if (rte_eal_process_type() != RTE_PROC_PRIMARY)
                return 0;
 
+       initialized = true;
+
        /* add all IOVA-contiguous areas to the heap */
        return rte_memseg_contig_walk(malloc_add_seg, NULL);
 }
-- 
2.25.1

Reply via email to