1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2010-2014 Intel Corporation
14 #include <sys/queue.h>
16 #include <rte_fbarray.h>
17 #include <rte_memory.h>
19 #include <rte_eal_memconfig.h>
20 #include <rte_errno.h>
23 #include "eal_memalloc.h"
24 #include "eal_private.h"
25 #include "eal_internal_cfg.h"
28 * Try to mmap *size bytes in /dev/zero. If it is successful, return the
29 * pointer to the mmap'd area and keep *size unmodified. Else, retry
30 * with a smaller zone: decrease *size by hugepage_sz until it reaches
31 * 0. In this case, return NULL. Note: this function returns an address
32 * which is a multiple of hugepage size.
35 #define MEMSEG_LIST_FMT "memseg-%" PRIu64 "k-%i-%i"
37 static uint64_t baseaddr_offset;
38 static uint64_t system_page_sz;
41 eal_get_virtual_area(void *requested_addr, size_t *size,
42 size_t page_sz, int flags, int mmap_flags)
44 bool addr_is_hint, allow_shrink, unmap, no_align;
46 void *mapped_addr, *aligned_addr;
48 if (system_page_sz == 0)
49 system_page_sz = sysconf(_SC_PAGESIZE);
51 mmap_flags |= MAP_PRIVATE | MAP_ANONYMOUS;
53 RTE_LOG(DEBUG, EAL, "Ask a virtual area of 0x%zx bytes\n", *size);
55 addr_is_hint = (flags & EAL_VIRTUAL_AREA_ADDR_IS_HINT) > 0;
56 allow_shrink = (flags & EAL_VIRTUAL_AREA_ALLOW_SHRINK) > 0;
57 unmap = (flags & EAL_VIRTUAL_AREA_UNMAP) > 0;
59 if (requested_addr == NULL && internal_config.base_virtaddr != 0) {
60 requested_addr = (void *) (internal_config.base_virtaddr +
61 (size_t)baseaddr_offset);
62 requested_addr = RTE_PTR_ALIGN(requested_addr, page_sz);
66 /* if requested address is not aligned by page size, or if requested
67 * address is NULL, add page size to requested length as we may get an
68 * address that's aligned by system page size, which can be smaller than
69 * our requested page size. additionally, we shouldn't try to align if
70 * system page size is the same as requested page size.
72 no_align = (requested_addr != NULL &&
73 ((uintptr_t)requested_addr & (page_sz - 1)) == 0) ||
74 page_sz == system_page_sz;
77 map_sz = no_align ? *size : *size + page_sz;
79 mapped_addr = mmap(requested_addr, map_sz, PROT_READ,
81 if (mapped_addr == MAP_FAILED && allow_shrink)
83 } while (allow_shrink && mapped_addr == MAP_FAILED && *size > 0);
85 /* align resulting address - if map failed, we will ignore the value
86 * anyway, so no need to add additional checks.
88 aligned_addr = no_align ? mapped_addr :
89 RTE_PTR_ALIGN(mapped_addr, page_sz);
92 RTE_LOG(ERR, EAL, "Cannot get a virtual area of any size: %s\n",
96 } else if (mapped_addr == MAP_FAILED) {
97 RTE_LOG(ERR, EAL, "Cannot get a virtual area: %s\n",
99 /* pass errno up the call chain */
102 } else if (requested_addr != NULL && !addr_is_hint &&
103 aligned_addr != requested_addr) {
104 RTE_LOG(ERR, EAL, "Cannot get a virtual area at requested address: %p (got %p)\n",
105 requested_addr, aligned_addr);
106 munmap(mapped_addr, map_sz);
107 rte_errno = EADDRNOTAVAIL;
109 } else if (requested_addr != NULL && addr_is_hint &&
110 aligned_addr != requested_addr) {
111 RTE_LOG(WARNING, EAL, "WARNING! Base virtual address hint (%p != %p) not respected!\n",
112 requested_addr, aligned_addr);
113 RTE_LOG(WARNING, EAL, " This may cause issues with mapping memory into secondary processes\n");
116 RTE_LOG(DEBUG, EAL, "Virtual area found at %p (size = 0x%zx)\n",
117 aligned_addr, *size);
120 munmap(mapped_addr, map_sz);
122 baseaddr_offset += *size;
128 get_mem_amount(uint64_t page_sz, uint64_t max_mem)
130 uint64_t area_sz, max_pages;
132 /* limit to RTE_MAX_MEMSEG_PER_LIST pages or RTE_MAX_MEM_MB_PER_LIST */
133 max_pages = RTE_MAX_MEMSEG_PER_LIST;
134 max_mem = RTE_MIN((uint64_t)RTE_MAX_MEM_MB_PER_LIST << 20, max_mem);
136 area_sz = RTE_MIN(page_sz * max_pages, max_mem);
138 /* make sure the list isn't smaller than the page size */
139 area_sz = RTE_MAX(area_sz, page_sz);
141 return RTE_ALIGN(area_sz, page_sz);
145 free_memseg_list(struct rte_memseg_list *msl)
147 if (rte_fbarray_destroy(&msl->memseg_arr)) {
148 RTE_LOG(ERR, EAL, "Cannot destroy memseg list\n");
151 memset(msl, 0, sizeof(*msl));
156 alloc_memseg_list(struct rte_memseg_list *msl, uint64_t page_sz,
157 uint64_t max_mem, int socket_id, int type_msl_idx)
159 char name[RTE_FBARRAY_NAME_LEN];
163 mem_amount = get_mem_amount(page_sz, max_mem);
164 max_segs = mem_amount / page_sz;
166 snprintf(name, sizeof(name), MEMSEG_LIST_FMT, page_sz >> 10, socket_id,
168 if (rte_fbarray_init(&msl->memseg_arr, name, max_segs,
169 sizeof(struct rte_memseg))) {
170 RTE_LOG(ERR, EAL, "Cannot allocate memseg list: %s\n",
171 rte_strerror(rte_errno));
175 msl->page_sz = page_sz;
176 msl->socket_id = socket_id;
179 RTE_LOG(DEBUG, EAL, "Memseg list allocated: 0x%zxkB at socket %i\n",
180 (size_t)page_sz >> 10, socket_id);
186 alloc_va_space(struct rte_memseg_list *msl)
193 #ifdef RTE_ARCH_PPC_64
194 flags |= MAP_HUGETLB;
197 page_sz = msl->page_sz;
198 mem_sz = page_sz * msl->memseg_arr.len;
200 addr = eal_get_virtual_area(msl->base_va, &mem_sz, page_sz, 0, flags);
202 if (rte_errno == EADDRNOTAVAIL)
203 RTE_LOG(ERR, EAL, "Could not mmap %llu bytes at [%p] - please use '--base-virtaddr' option\n",
204 (unsigned long long)mem_sz, msl->base_va);
206 RTE_LOG(ERR, EAL, "Cannot reserve memory\n");
214 static int __rte_unused
215 memseg_primary_init_32(void)
217 struct rte_mem_config *mcfg = rte_eal_get_configuration()->mem_config;
218 int active_sockets, hpi_idx, msl_idx = 0;
219 unsigned int socket_id, i;
220 struct rte_memseg_list *msl;
221 uint64_t extra_mem_per_socket, total_extra_mem, total_requested_mem;
224 /* no-huge does not need this at all */
225 if (internal_config.no_hugetlbfs)
228 /* this is a giant hack, but desperate times call for desperate
229 * measures. in legacy 32-bit mode, we cannot preallocate VA space,
230 * because having upwards of 2 gigabytes of VA space already mapped will
231 * interfere with our ability to map and sort hugepages.
233 * therefore, in legacy 32-bit mode, we will be initializing memseg
234 * lists much later - in eal_memory.c, right after we unmap all the
235 * unneeded pages. this will not affect secondary processes, as those
236 * should be able to mmap the space without (too many) problems.
238 if (internal_config.legacy_mem)
241 /* 32-bit mode is a very special case. we cannot know in advance where
242 * the user will want to allocate their memory, so we have to do some
246 total_requested_mem = 0;
247 if (internal_config.force_sockets)
248 for (i = 0; i < rte_socket_count(); i++) {
251 socket_id = rte_socket_id_by_idx(i);
252 mem = internal_config.socket_mem[socket_id];
258 total_requested_mem += mem;
261 total_requested_mem = internal_config.memory;
263 max_mem = (uint64_t)RTE_MAX_MEM_MB << 20;
264 if (total_requested_mem > max_mem) {
265 RTE_LOG(ERR, EAL, "Invalid parameters: 32-bit process can at most use %uM of memory\n",
266 (unsigned int)(max_mem >> 20));
269 total_extra_mem = max_mem - total_requested_mem;
270 extra_mem_per_socket = active_sockets == 0 ? total_extra_mem :
271 total_extra_mem / active_sockets;
273 /* the allocation logic is a little bit convoluted, but here's how it
274 * works, in a nutshell:
275 * - if user hasn't specified on which sockets to allocate memory via
276 * --socket-mem, we allocate all of our memory on master core socket.
277 * - if user has specified sockets to allocate memory on, there may be
278 * some "unused" memory left (e.g. if user has specified --socket-mem
279 * such that not all memory adds up to 2 gigabytes), so add it to all
280 * sockets that are in use equally.
282 * page sizes are sorted by size in descending order, so we can safely
283 * assume that we dispense with bigger page sizes first.
286 /* create memseg lists */
287 for (i = 0; i < rte_socket_count(); i++) {
288 int hp_sizes = (int) internal_config.num_hugepage_sizes;
289 uint64_t max_socket_mem, cur_socket_mem;
290 unsigned int master_lcore_socket;
291 struct rte_config *cfg = rte_eal_get_configuration();
294 socket_id = rte_socket_id_by_idx(i);
296 #ifndef RTE_EAL_NUMA_AWARE_HUGEPAGES
301 /* if we didn't specifically request memory on this socket */
302 skip = active_sockets != 0 &&
303 internal_config.socket_mem[socket_id] == 0;
304 /* ...or if we didn't specifically request memory on *any*
305 * socket, and this is not master lcore
307 master_lcore_socket = rte_lcore_to_socket_id(cfg->master_lcore);
308 skip |= active_sockets == 0 && socket_id != master_lcore_socket;
311 RTE_LOG(DEBUG, EAL, "Will not preallocate memory on socket %u\n",
316 /* max amount of memory on this socket */
317 max_socket_mem = (active_sockets != 0 ?
318 internal_config.socket_mem[socket_id] :
319 internal_config.memory) +
320 extra_mem_per_socket;
323 for (hpi_idx = 0; hpi_idx < hp_sizes; hpi_idx++) {
324 uint64_t max_pagesz_mem, cur_pagesz_mem = 0;
325 uint64_t hugepage_sz;
326 struct hugepage_info *hpi;
327 int type_msl_idx, max_segs, total_segs = 0;
329 hpi = &internal_config.hugepage_info[hpi_idx];
330 hugepage_sz = hpi->hugepage_sz;
332 max_segs = RTE_MAX_MEMSEG_PER_TYPE;
333 max_pagesz_mem = max_socket_mem - cur_socket_mem;
335 /* make it multiple of page size */
336 max_pagesz_mem = RTE_ALIGN_FLOOR(max_pagesz_mem,
339 RTE_LOG(DEBUG, EAL, "Attempting to preallocate "
340 "%" PRIu64 "M on socket %i\n",
341 max_pagesz_mem >> 20, socket_id);
344 while (cur_pagesz_mem < max_pagesz_mem &&
345 total_segs < max_segs) {
346 if (msl_idx >= RTE_MAX_MEMSEG_LISTS) {
348 "No more space in memseg lists, please increase %s\n",
349 RTE_STR(CONFIG_RTE_MAX_MEMSEG_LISTS));
353 msl = &mcfg->memsegs[msl_idx];
355 if (alloc_memseg_list(msl, hugepage_sz,
356 max_pagesz_mem, socket_id,
358 /* failing to allocate a memseg list is
361 RTE_LOG(ERR, EAL, "Cannot allocate memseg list\n");
365 if (alloc_va_space(msl)) {
366 /* if we couldn't allocate VA space, we
367 * can try with smaller page sizes.
369 RTE_LOG(ERR, EAL, "Cannot allocate VA space for memseg list, retrying with different page size\n");
370 /* deallocate memseg list */
371 if (free_memseg_list(msl))
376 total_segs += msl->memseg_arr.len;
377 cur_pagesz_mem = total_segs * hugepage_sz;
381 cur_socket_mem += cur_pagesz_mem;
383 if (cur_socket_mem == 0) {
384 RTE_LOG(ERR, EAL, "Cannot allocate VA space on socket %u\n",
393 static int __rte_unused
394 memseg_primary_init(void)
396 struct rte_mem_config *mcfg = rte_eal_get_configuration()->mem_config;
397 int i, socket_id, hpi_idx, msl_idx = 0;
398 struct rte_memseg_list *msl;
399 uint64_t max_mem, total_mem;
401 /* no-huge does not need this at all */
402 if (internal_config.no_hugetlbfs)
405 max_mem = (uint64_t)RTE_MAX_MEM_MB << 20;
408 /* create memseg lists */
409 for (hpi_idx = 0; hpi_idx < (int) internal_config.num_hugepage_sizes;
411 struct hugepage_info *hpi;
412 uint64_t hugepage_sz;
414 hpi = &internal_config.hugepage_info[hpi_idx];
415 hugepage_sz = hpi->hugepage_sz;
417 for (i = 0; i < (int) rte_socket_count(); i++) {
418 uint64_t max_type_mem, total_type_mem = 0;
419 int type_msl_idx, max_segs, total_segs = 0;
421 socket_id = rte_socket_id_by_idx(i);
423 #ifndef RTE_EAL_NUMA_AWARE_HUGEPAGES
428 max_type_mem = RTE_MIN(max_mem - total_mem,
429 (uint64_t)RTE_MAX_MEM_MB_PER_TYPE << 20);
430 max_segs = RTE_MAX_MEMSEG_PER_TYPE;
433 while (total_type_mem < max_type_mem &&
434 total_segs < max_segs) {
435 uint64_t cur_max_mem;
436 if (msl_idx >= RTE_MAX_MEMSEG_LISTS) {
438 "No more space in memseg lists, please increase %s\n",
439 RTE_STR(CONFIG_RTE_MAX_MEMSEG_LISTS));
443 msl = &mcfg->memsegs[msl_idx++];
445 cur_max_mem = max_type_mem - total_type_mem;
446 if (alloc_memseg_list(msl, hugepage_sz,
447 cur_max_mem, socket_id,
451 total_segs += msl->memseg_arr.len;
452 total_type_mem = total_segs * hugepage_sz;
455 if (alloc_va_space(msl)) {
456 RTE_LOG(ERR, EAL, "Cannot allocate VA space for memseg list\n");
460 total_mem += total_type_mem;
467 memseg_secondary_init(void)
469 struct rte_mem_config *mcfg = rte_eal_get_configuration()->mem_config;
471 struct rte_memseg_list *msl;
473 for (msl_idx = 0; msl_idx < RTE_MAX_MEMSEG_LISTS; msl_idx++) {
475 msl = &mcfg->memsegs[msl_idx];
477 /* skip empty memseg lists */
478 if (msl->memseg_arr.len == 0)
481 if (rte_fbarray_attach(&msl->memseg_arr)) {
482 RTE_LOG(ERR, EAL, "Cannot attach to primary process memseg lists\n");
486 /* preallocate VA space */
487 if (alloc_va_space(msl)) {
488 RTE_LOG(ERR, EAL, "Cannot preallocate VA space for hugepage memory\n");
496 static struct rte_memseg *
497 virt2memseg(const void *addr, const struct rte_memseg_list *msl)
499 const struct rte_fbarray *arr;
503 /* a memseg list was specified, check if it's the right one */
504 start = msl->base_va;
505 end = RTE_PTR_ADD(start, (size_t)msl->page_sz * msl->memseg_arr.len);
507 if (addr < start || addr >= end)
510 /* now, calculate index */
511 arr = &msl->memseg_arr;
512 ms_idx = RTE_PTR_DIFF(addr, msl->base_va) / msl->page_sz;
513 return rte_fbarray_get(arr, ms_idx);
516 static struct rte_memseg_list *
517 virt2memseg_list(const void *addr)
519 struct rte_mem_config *mcfg = rte_eal_get_configuration()->mem_config;
520 struct rte_memseg_list *msl;
523 for (msl_idx = 0; msl_idx < RTE_MAX_MEMSEG_LISTS; msl_idx++) {
525 msl = &mcfg->memsegs[msl_idx];
527 start = msl->base_va;
528 end = RTE_PTR_ADD(start,
529 (size_t)msl->page_sz * msl->memseg_arr.len);
530 if (addr >= start && addr < end)
533 /* if we didn't find our memseg list */
534 if (msl_idx == RTE_MAX_MEMSEG_LISTS)
539 __rte_experimental struct rte_memseg_list *
540 rte_mem_virt2memseg_list(const void *addr)
542 return virt2memseg_list(addr);
550 find_virt(const struct rte_memseg_list *msl __rte_unused,
551 const struct rte_memseg *ms, void *arg)
553 struct virtiova *vi = arg;
554 if (vi->iova >= ms->iova && vi->iova < (ms->iova + ms->len)) {
555 size_t offset = vi->iova - ms->iova;
556 vi->virt = RTE_PTR_ADD(ms->addr, offset);
563 find_virt_legacy(const struct rte_memseg_list *msl __rte_unused,
564 const struct rte_memseg *ms, size_t len, void *arg)
566 struct virtiova *vi = arg;
567 if (vi->iova >= ms->iova && vi->iova < (ms->iova + len)) {
568 size_t offset = vi->iova - ms->iova;
569 vi->virt = RTE_PTR_ADD(ms->addr, offset);
576 __rte_experimental void *
577 rte_mem_iova2virt(rte_iova_t iova)
581 memset(&vi, 0, sizeof(vi));
584 /* for legacy mem, we can get away with scanning VA-contiguous segments,
585 * as we know they are PA-contiguous as well
587 if (internal_config.legacy_mem)
588 rte_memseg_contig_walk(find_virt_legacy, &vi);
590 rte_memseg_walk(find_virt, &vi);
595 __rte_experimental struct rte_memseg *
596 rte_mem_virt2memseg(const void *addr, const struct rte_memseg_list *msl)
598 return virt2memseg(addr, msl != NULL ? msl :
599 rte_mem_virt2memseg_list(addr));
603 physmem_size(const struct rte_memseg_list *msl, void *arg)
605 uint64_t *total_len = arg;
607 *total_len += msl->memseg_arr.count * msl->page_sz;
612 /* get the total size of memory */
614 rte_eal_get_physmem_size(void)
616 uint64_t total_len = 0;
618 rte_memseg_list_walk(physmem_size, &total_len);
624 dump_memseg(const struct rte_memseg_list *msl, const struct rte_memseg *ms,
627 struct rte_mem_config *mcfg = rte_eal_get_configuration()->mem_config;
631 msl_idx = msl - mcfg->memsegs;
632 if (msl_idx < 0 || msl_idx >= RTE_MAX_MEMSEG_LISTS)
635 ms_idx = rte_fbarray_find_idx(&msl->memseg_arr, ms);
639 fprintf(f, "Segment %i-%i: IOVA:0x%"PRIx64", len:%zu, "
640 "virt:%p, socket_id:%"PRId32", "
641 "hugepage_sz:%"PRIu64", nchannel:%"PRIx32", "
656 * Defining here because declared in rte_memory.h, but the actual implementation
657 * is in eal_common_memalloc.c, like all other memalloc internals.
659 int __rte_experimental
660 rte_mem_event_callback_register(const char *name, rte_mem_event_callback_t clb)
662 /* FreeBSD boots with legacy mem enabled by default */
663 if (internal_config.legacy_mem) {
664 RTE_LOG(DEBUG, EAL, "Registering mem event callbacks not supported\n");
668 return eal_memalloc_mem_event_callback_register(name, clb);
671 int __rte_experimental
672 rte_mem_event_callback_unregister(const char *name)
674 /* FreeBSD boots with legacy mem enabled by default */
675 if (internal_config.legacy_mem) {
676 RTE_LOG(DEBUG, EAL, "Registering mem event callbacks not supported\n");
680 return eal_memalloc_mem_event_callback_unregister(name);
683 int __rte_experimental
684 rte_mem_alloc_validator_register(const char *name,
685 rte_mem_alloc_validator_t clb, int socket_id, size_t limit)
687 /* FreeBSD boots with legacy mem enabled by default */
688 if (internal_config.legacy_mem) {
689 RTE_LOG(DEBUG, EAL, "Registering mem alloc validators not supported\n");
693 return eal_memalloc_mem_alloc_validator_register(name, clb, socket_id,
697 int __rte_experimental
698 rte_mem_alloc_validator_unregister(const char *name, int socket_id)
700 /* FreeBSD boots with legacy mem enabled by default */
701 if (internal_config.legacy_mem) {
702 RTE_LOG(DEBUG, EAL, "Registering mem alloc validators not supported\n");
706 return eal_memalloc_mem_alloc_validator_unregister(name, socket_id);
709 /* Dump the physical memory layout on console */
711 rte_dump_physmem_layout(FILE *f)
713 rte_memseg_walk(dump_memseg, f);
716 /* return the number of memory channels */
717 unsigned rte_memory_get_nchannel(void)
719 return rte_eal_get_configuration()->mem_config->nchannel;
722 /* return the number of memory rank */
723 unsigned rte_memory_get_nrank(void)
725 return rte_eal_get_configuration()->mem_config->nrank;
729 rte_eal_memdevice_init(void)
731 struct rte_config *config;
733 if (rte_eal_process_type() == RTE_PROC_SECONDARY)
736 config = rte_eal_get_configuration();
737 config->mem_config->nchannel = internal_config.force_nchannel;
738 config->mem_config->nrank = internal_config.force_nrank;
743 /* Lock page in physical memory and prevent from swapping. */
745 rte_mem_lock_page(const void *virt)
747 unsigned long virtual = (unsigned long)virt;
748 int page_size = getpagesize();
749 unsigned long aligned = (virtual & ~(page_size - 1));
750 return mlock((void *)aligned, page_size);
753 int __rte_experimental
754 rte_memseg_contig_walk(rte_memseg_contig_walk_t func, void *arg)
756 struct rte_mem_config *mcfg = rte_eal_get_configuration()->mem_config;
757 int i, ms_idx, ret = 0;
759 /* do not allow allocations/frees/init while we iterate */
760 rte_rwlock_read_lock(&mcfg->memory_hotplug_lock);
762 for (i = 0; i < RTE_MAX_MEMSEG_LISTS; i++) {
763 struct rte_memseg_list *msl = &mcfg->memsegs[i];
764 const struct rte_memseg *ms;
765 struct rte_fbarray *arr;
767 if (msl->memseg_arr.count == 0)
770 arr = &msl->memseg_arr;
772 ms_idx = rte_fbarray_find_next_used(arr, 0);
773 while (ms_idx >= 0) {
777 ms = rte_fbarray_get(arr, ms_idx);
779 /* find how many more segments there are, starting with
782 n_segs = rte_fbarray_find_contig_used(arr, ms_idx);
783 len = n_segs * msl->page_sz;
785 ret = func(msl, ms, len, arg);
789 } else if (ret > 0) {
793 ms_idx = rte_fbarray_find_next_used(arr,
798 rte_rwlock_read_unlock(&mcfg->memory_hotplug_lock);
802 int __rte_experimental
803 rte_memseg_walk(rte_memseg_walk_t func, void *arg)
805 struct rte_mem_config *mcfg = rte_eal_get_configuration()->mem_config;
806 int i, ms_idx, ret = 0;
808 /* do not allow allocations/frees/init while we iterate */
809 rte_rwlock_read_lock(&mcfg->memory_hotplug_lock);
811 for (i = 0; i < RTE_MAX_MEMSEG_LISTS; i++) {
812 struct rte_memseg_list *msl = &mcfg->memsegs[i];
813 const struct rte_memseg *ms;
814 struct rte_fbarray *arr;
816 if (msl->memseg_arr.count == 0)
819 arr = &msl->memseg_arr;
821 ms_idx = rte_fbarray_find_next_used(arr, 0);
822 while (ms_idx >= 0) {
823 ms = rte_fbarray_get(arr, ms_idx);
824 ret = func(msl, ms, arg);
828 } else if (ret > 0) {
832 ms_idx = rte_fbarray_find_next_used(arr, ms_idx + 1);
836 rte_rwlock_read_unlock(&mcfg->memory_hotplug_lock);
840 int __rte_experimental
841 rte_memseg_list_walk(rte_memseg_list_walk_t func, void *arg)
843 struct rte_mem_config *mcfg = rte_eal_get_configuration()->mem_config;
846 /* do not allow allocations/frees/init while we iterate */
847 rte_rwlock_read_lock(&mcfg->memory_hotplug_lock);
849 for (i = 0; i < RTE_MAX_MEMSEG_LISTS; i++) {
850 struct rte_memseg_list *msl = &mcfg->memsegs[i];
852 if (msl->base_va == NULL)
855 ret = func(msl, arg);
866 rte_rwlock_read_unlock(&mcfg->memory_hotplug_lock);
870 /* init memory subsystem */
872 rte_eal_memory_init(void)
874 struct rte_mem_config *mcfg = rte_eal_get_configuration()->mem_config;
876 RTE_LOG(DEBUG, EAL, "Setting up physically contiguous memory...\n");
881 /* lock mem hotplug here, to prevent races while we init */
882 rte_rwlock_read_lock(&mcfg->memory_hotplug_lock);
884 retval = rte_eal_process_type() == RTE_PROC_PRIMARY ?
886 memseg_primary_init_32() :
888 memseg_primary_init() :
890 memseg_secondary_init();
895 retval = rte_eal_process_type() == RTE_PROC_PRIMARY ?
896 rte_eal_hugepage_init() :
897 rte_eal_hugepage_attach();
901 if (internal_config.no_shconf == 0 && rte_eal_memdevice_init() < 0)
906 rte_rwlock_read_unlock(&mcfg->memory_hotplug_lock);