1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2010-2014 Intel Corporation
12 #include <sys/queue.h>
14 #include <rte_memory.h>
16 #include <rte_eal_memconfig.h>
19 #include "eal_private.h"
20 #include "eal_internal_cfg.h"
23 * Return a pointer to a read-only table of struct rte_physmem_desc
24 * elements, containing the layout of all addressable physical
25 * memory. The last element of the table contains a NULL address.
27 const struct rte_memseg *
28 rte_eal_get_physmem_layout(void)
30 return rte_eal_get_configuration()->mem_config->memseg;
34 /* get the total size of memory */
36 rte_eal_get_physmem_size(void)
38 const struct rte_mem_config *mcfg;
40 uint64_t total_len = 0;
42 /* get pointer to global configuration */
43 mcfg = rte_eal_get_configuration()->mem_config;
45 for (i = 0; i < RTE_MAX_MEMSEG; i++) {
46 if (mcfg->memseg[i].addr == NULL)
49 total_len += mcfg->memseg[i].len;
55 /* Dump the physical memory layout on console */
57 rte_dump_physmem_layout(FILE *f)
59 const struct rte_mem_config *mcfg;
62 /* get pointer to global configuration */
63 mcfg = rte_eal_get_configuration()->mem_config;
65 for (i = 0; i < RTE_MAX_MEMSEG; i++) {
66 if (mcfg->memseg[i].addr == NULL)
69 fprintf(f, "Segment %u: IOVA:0x%"PRIx64", len:%zu, "
70 "virt:%p, socket_id:%"PRId32", "
71 "hugepage_sz:%"PRIu64", nchannel:%"PRIx32", "
72 "nrank:%"PRIx32"\n", i,
76 mcfg->memseg[i].socket_id,
77 mcfg->memseg[i].hugepage_sz,
78 mcfg->memseg[i].nchannel,
79 mcfg->memseg[i].nrank);
83 /* return the number of memory channels */
84 unsigned rte_memory_get_nchannel(void)
86 return rte_eal_get_configuration()->mem_config->nchannel;
89 /* return the number of memory rank */
90 unsigned rte_memory_get_nrank(void)
92 return rte_eal_get_configuration()->mem_config->nrank;
96 rte_eal_memdevice_init(void)
98 struct rte_config *config;
100 if (rte_eal_process_type() == RTE_PROC_SECONDARY)
103 config = rte_eal_get_configuration();
104 config->mem_config->nchannel = internal_config.force_nchannel;
105 config->mem_config->nrank = internal_config.force_nrank;
110 /* Lock page in physical memory and prevent from swapping. */
112 rte_mem_lock_page(const void *virt)
114 unsigned long virtual = (unsigned long)virt;
115 int page_size = getpagesize();
116 unsigned long aligned = (virtual & ~(page_size - 1));
117 return mlock((void *)aligned, page_size);
120 /* init memory subsystem */
122 rte_eal_memory_init(void)
124 RTE_LOG(DEBUG, EAL, "Setting up physically contiguous memory...\n");
126 const int retval = rte_eal_process_type() == RTE_PROC_PRIMARY ?
127 rte_eal_hugepage_init() :
128 rte_eal_hugepage_attach();
132 if (internal_config.no_shconf == 0 && rte_eal_memdevice_init() < 0)