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;
78 if (map_sz > SIZE_MAX) {
79 RTE_LOG(ERR, EAL, "Map size too big\n");
84 mapped_addr = mmap(requested_addr, (size_t)map_sz, PROT_READ,
86 if (mapped_addr == MAP_FAILED && allow_shrink)
88 } while (allow_shrink && mapped_addr == MAP_FAILED && *size > 0);
90 /* align resulting address - if map failed, we will ignore the value
91 * anyway, so no need to add additional checks.
93 aligned_addr = no_align ? mapped_addr :
94 RTE_PTR_ALIGN(mapped_addr, page_sz);
97 RTE_LOG(ERR, EAL, "Cannot get a virtual area of any size: %s\n",
101 } else if (mapped_addr == MAP_FAILED) {
102 RTE_LOG(ERR, EAL, "Cannot get a virtual area: %s\n",
104 /* pass errno up the call chain */
107 } else if (requested_addr != NULL && !addr_is_hint &&
108 aligned_addr != requested_addr) {
109 RTE_LOG(ERR, EAL, "Cannot get a virtual area at requested address: %p (got %p)\n",
110 requested_addr, aligned_addr);
111 munmap(mapped_addr, map_sz);
112 rte_errno = EADDRNOTAVAIL;
114 } else if (requested_addr != NULL && addr_is_hint &&
115 aligned_addr != requested_addr) {
116 RTE_LOG(WARNING, EAL, "WARNING! Base virtual address hint (%p != %p) not respected!\n",
117 requested_addr, aligned_addr);
118 RTE_LOG(WARNING, EAL, " This may cause issues with mapping memory into secondary processes\n");
121 RTE_LOG(DEBUG, EAL, "Virtual area found at %p (size = 0x%zx)\n",
122 aligned_addr, *size);
125 munmap(mapped_addr, map_sz);
127 baseaddr_offset += *size;
133 get_mem_amount(uint64_t page_sz, uint64_t max_mem)
135 uint64_t area_sz, max_pages;
137 /* limit to RTE_MAX_MEMSEG_PER_LIST pages or RTE_MAX_MEM_MB_PER_LIST */
138 max_pages = RTE_MAX_MEMSEG_PER_LIST;
139 max_mem = RTE_MIN((uint64_t)RTE_MAX_MEM_MB_PER_LIST << 20, max_mem);
141 area_sz = RTE_MIN(page_sz * max_pages, max_mem);
143 /* make sure the list isn't smaller than the page size */
144 area_sz = RTE_MAX(area_sz, page_sz);
146 return RTE_ALIGN(area_sz, page_sz);
150 free_memseg_list(struct rte_memseg_list *msl)
152 if (rte_fbarray_destroy(&msl->memseg_arr)) {
153 RTE_LOG(ERR, EAL, "Cannot destroy memseg list\n");
156 memset(msl, 0, sizeof(*msl));
161 alloc_memseg_list(struct rte_memseg_list *msl, uint64_t page_sz,
162 uint64_t max_mem, int socket_id, int type_msl_idx)
164 char name[RTE_FBARRAY_NAME_LEN];
168 mem_amount = get_mem_amount(page_sz, max_mem);
169 max_segs = mem_amount / page_sz;
171 snprintf(name, sizeof(name), MEMSEG_LIST_FMT, page_sz >> 10, socket_id,
173 if (rte_fbarray_init(&msl->memseg_arr, name, max_segs,
174 sizeof(struct rte_memseg))) {
175 RTE_LOG(ERR, EAL, "Cannot allocate memseg list: %s\n",
176 rte_strerror(rte_errno));
180 msl->page_sz = page_sz;
181 msl->socket_id = socket_id;
184 RTE_LOG(DEBUG, EAL, "Memseg list allocated: 0x%zxkB at socket %i\n",
185 (size_t)page_sz >> 10, socket_id);
191 alloc_va_space(struct rte_memseg_list *msl)
198 #ifdef RTE_ARCH_PPC_64
199 flags |= MAP_HUGETLB;
202 page_sz = msl->page_sz;
203 mem_sz = page_sz * msl->memseg_arr.len;
205 addr = eal_get_virtual_area(msl->base_va, &mem_sz, page_sz, 0, flags);
207 if (rte_errno == EADDRNOTAVAIL)
208 RTE_LOG(ERR, EAL, "Could not mmap %llu bytes at [%p] - please use '--base-virtaddr' option\n",
209 (unsigned long long)mem_sz, msl->base_va);
211 RTE_LOG(ERR, EAL, "Cannot reserve memory\n");
219 static int __rte_unused
220 memseg_primary_init_32(void)
222 struct rte_mem_config *mcfg = rte_eal_get_configuration()->mem_config;
223 int active_sockets, hpi_idx, msl_idx = 0;
224 unsigned int socket_id, i;
225 struct rte_memseg_list *msl;
226 uint64_t extra_mem_per_socket, total_extra_mem, total_requested_mem;
229 /* no-huge does not need this at all */
230 if (internal_config.no_hugetlbfs)
233 /* this is a giant hack, but desperate times call for desperate
234 * measures. in legacy 32-bit mode, we cannot preallocate VA space,
235 * because having upwards of 2 gigabytes of VA space already mapped will
236 * interfere with our ability to map and sort hugepages.
238 * therefore, in legacy 32-bit mode, we will be initializing memseg
239 * lists much later - in eal_memory.c, right after we unmap all the
240 * unneeded pages. this will not affect secondary processes, as those
241 * should be able to mmap the space without (too many) problems.
243 if (internal_config.legacy_mem)
246 /* 32-bit mode is a very special case. we cannot know in advance where
247 * the user will want to allocate their memory, so we have to do some
251 total_requested_mem = 0;
252 if (internal_config.force_sockets)
253 for (i = 0; i < rte_socket_count(); i++) {
256 socket_id = rte_socket_id_by_idx(i);
257 mem = internal_config.socket_mem[socket_id];
263 total_requested_mem += mem;
266 total_requested_mem = internal_config.memory;
268 max_mem = (uint64_t)RTE_MAX_MEM_MB << 20;
269 if (total_requested_mem > max_mem) {
270 RTE_LOG(ERR, EAL, "Invalid parameters: 32-bit process can at most use %uM of memory\n",
271 (unsigned int)(max_mem >> 20));
274 total_extra_mem = max_mem - total_requested_mem;
275 extra_mem_per_socket = active_sockets == 0 ? total_extra_mem :
276 total_extra_mem / active_sockets;
278 /* the allocation logic is a little bit convoluted, but here's how it
279 * works, in a nutshell:
280 * - if user hasn't specified on which sockets to allocate memory via
281 * --socket-mem, we allocate all of our memory on master core socket.
282 * - if user has specified sockets to allocate memory on, there may be
283 * some "unused" memory left (e.g. if user has specified --socket-mem
284 * such that not all memory adds up to 2 gigabytes), so add it to all
285 * sockets that are in use equally.
287 * page sizes are sorted by size in descending order, so we can safely
288 * assume that we dispense with bigger page sizes first.
291 /* create memseg lists */
292 for (i = 0; i < rte_socket_count(); i++) {
293 int hp_sizes = (int) internal_config.num_hugepage_sizes;
294 uint64_t max_socket_mem, cur_socket_mem;
295 unsigned int master_lcore_socket;
296 struct rte_config *cfg = rte_eal_get_configuration();
299 socket_id = rte_socket_id_by_idx(i);
301 #ifndef RTE_EAL_NUMA_AWARE_HUGEPAGES
306 /* if we didn't specifically request memory on this socket */
307 skip = active_sockets != 0 &&
308 internal_config.socket_mem[socket_id] == 0;
309 /* ...or if we didn't specifically request memory on *any*
310 * socket, and this is not master lcore
312 master_lcore_socket = rte_lcore_to_socket_id(cfg->master_lcore);
313 skip |= active_sockets == 0 && socket_id != master_lcore_socket;
316 RTE_LOG(DEBUG, EAL, "Will not preallocate memory on socket %u\n",
321 /* max amount of memory on this socket */
322 max_socket_mem = (active_sockets != 0 ?
323 internal_config.socket_mem[socket_id] :
324 internal_config.memory) +
325 extra_mem_per_socket;
328 for (hpi_idx = 0; hpi_idx < hp_sizes; hpi_idx++) {
329 uint64_t max_pagesz_mem, cur_pagesz_mem = 0;
330 uint64_t hugepage_sz;
331 struct hugepage_info *hpi;
332 int type_msl_idx, max_segs, total_segs = 0;
334 hpi = &internal_config.hugepage_info[hpi_idx];
335 hugepage_sz = hpi->hugepage_sz;
337 /* check if pages are actually available */
338 if (hpi->num_pages[socket_id] == 0)
341 max_segs = RTE_MAX_MEMSEG_PER_TYPE;
342 max_pagesz_mem = max_socket_mem - cur_socket_mem;
344 /* make it multiple of page size */
345 max_pagesz_mem = RTE_ALIGN_FLOOR(max_pagesz_mem,
348 RTE_LOG(DEBUG, EAL, "Attempting to preallocate "
349 "%" PRIu64 "M on socket %i\n",
350 max_pagesz_mem >> 20, socket_id);
353 while (cur_pagesz_mem < max_pagesz_mem &&
354 total_segs < max_segs) {
355 if (msl_idx >= RTE_MAX_MEMSEG_LISTS) {
357 "No more space in memseg lists, please increase %s\n",
358 RTE_STR(CONFIG_RTE_MAX_MEMSEG_LISTS));
362 msl = &mcfg->memsegs[msl_idx];
364 if (alloc_memseg_list(msl, hugepage_sz,
365 max_pagesz_mem, socket_id,
367 /* failing to allocate a memseg list is
370 RTE_LOG(ERR, EAL, "Cannot allocate memseg list\n");
374 if (alloc_va_space(msl)) {
375 /* if we couldn't allocate VA space, we
376 * can try with smaller page sizes.
378 RTE_LOG(ERR, EAL, "Cannot allocate VA space for memseg list, retrying with different page size\n");
379 /* deallocate memseg list */
380 if (free_memseg_list(msl))
385 total_segs += msl->memseg_arr.len;
386 cur_pagesz_mem = total_segs * hugepage_sz;
390 cur_socket_mem += cur_pagesz_mem;
392 if (cur_socket_mem == 0) {
393 RTE_LOG(ERR, EAL, "Cannot allocate VA space on socket %u\n",
402 static int __rte_unused
403 memseg_primary_init(void)
405 struct rte_mem_config *mcfg = rte_eal_get_configuration()->mem_config;
406 int i, socket_id, hpi_idx, msl_idx = 0;
407 struct rte_memseg_list *msl;
408 uint64_t max_mem, total_mem;
410 /* no-huge does not need this at all */
411 if (internal_config.no_hugetlbfs)
414 max_mem = (uint64_t)RTE_MAX_MEM_MB << 20;
417 /* create memseg lists */
418 for (hpi_idx = 0; hpi_idx < (int) internal_config.num_hugepage_sizes;
420 struct hugepage_info *hpi;
421 uint64_t hugepage_sz;
423 hpi = &internal_config.hugepage_info[hpi_idx];
424 hugepage_sz = hpi->hugepage_sz;
426 for (i = 0; i < (int) rte_socket_count(); i++) {
427 uint64_t max_type_mem, total_type_mem = 0;
428 int type_msl_idx, max_segs, total_segs = 0;
430 socket_id = rte_socket_id_by_idx(i);
432 #ifndef RTE_EAL_NUMA_AWARE_HUGEPAGES
437 max_type_mem = RTE_MIN(max_mem - total_mem,
438 (uint64_t)RTE_MAX_MEM_MB_PER_TYPE << 20);
439 max_segs = RTE_MAX_MEMSEG_PER_TYPE;
442 while (total_type_mem < max_type_mem &&
443 total_segs < max_segs) {
444 uint64_t cur_max_mem;
445 if (msl_idx >= RTE_MAX_MEMSEG_LISTS) {
447 "No more space in memseg lists, please increase %s\n",
448 RTE_STR(CONFIG_RTE_MAX_MEMSEG_LISTS));
452 msl = &mcfg->memsegs[msl_idx++];
454 cur_max_mem = max_type_mem - total_type_mem;
455 if (alloc_memseg_list(msl, hugepage_sz,
456 cur_max_mem, socket_id,
460 total_segs += msl->memseg_arr.len;
461 total_type_mem = total_segs * hugepage_sz;
464 if (alloc_va_space(msl)) {
465 RTE_LOG(ERR, EAL, "Cannot allocate VA space for memseg list\n");
469 total_mem += total_type_mem;
476 memseg_secondary_init(void)
478 struct rte_mem_config *mcfg = rte_eal_get_configuration()->mem_config;
480 struct rte_memseg_list *msl;
482 for (msl_idx = 0; msl_idx < RTE_MAX_MEMSEG_LISTS; msl_idx++) {
484 msl = &mcfg->memsegs[msl_idx];
486 /* skip empty memseg lists */
487 if (msl->memseg_arr.len == 0)
490 if (rte_fbarray_attach(&msl->memseg_arr)) {
491 RTE_LOG(ERR, EAL, "Cannot attach to primary process memseg lists\n");
495 /* preallocate VA space */
496 if (alloc_va_space(msl)) {
497 RTE_LOG(ERR, EAL, "Cannot preallocate VA space for hugepage memory\n");
505 static struct rte_memseg *
506 virt2memseg(const void *addr, const struct rte_memseg_list *msl)
508 const struct rte_fbarray *arr;
512 /* a memseg list was specified, check if it's the right one */
513 start = msl->base_va;
514 end = RTE_PTR_ADD(start, (size_t)msl->page_sz * msl->memseg_arr.len);
516 if (addr < start || addr >= end)
519 /* now, calculate index */
520 arr = &msl->memseg_arr;
521 ms_idx = RTE_PTR_DIFF(addr, msl->base_va) / msl->page_sz;
522 return rte_fbarray_get(arr, ms_idx);
525 static struct rte_memseg_list *
526 virt2memseg_list(const void *addr)
528 struct rte_mem_config *mcfg = rte_eal_get_configuration()->mem_config;
529 struct rte_memseg_list *msl;
532 for (msl_idx = 0; msl_idx < RTE_MAX_MEMSEG_LISTS; msl_idx++) {
534 msl = &mcfg->memsegs[msl_idx];
536 start = msl->base_va;
537 end = RTE_PTR_ADD(start,
538 (size_t)msl->page_sz * msl->memseg_arr.len);
539 if (addr >= start && addr < end)
542 /* if we didn't find our memseg list */
543 if (msl_idx == RTE_MAX_MEMSEG_LISTS)
548 __rte_experimental struct rte_memseg_list *
549 rte_mem_virt2memseg_list(const void *addr)
551 return virt2memseg_list(addr);
559 find_virt(const struct rte_memseg_list *msl __rte_unused,
560 const struct rte_memseg *ms, void *arg)
562 struct virtiova *vi = arg;
563 if (vi->iova >= ms->iova && vi->iova < (ms->iova + ms->len)) {
564 size_t offset = vi->iova - ms->iova;
565 vi->virt = RTE_PTR_ADD(ms->addr, offset);
572 find_virt_legacy(const struct rte_memseg_list *msl __rte_unused,
573 const struct rte_memseg *ms, size_t len, void *arg)
575 struct virtiova *vi = arg;
576 if (vi->iova >= ms->iova && vi->iova < (ms->iova + len)) {
577 size_t offset = vi->iova - ms->iova;
578 vi->virt = RTE_PTR_ADD(ms->addr, offset);
585 __rte_experimental void *
586 rte_mem_iova2virt(rte_iova_t iova)
590 memset(&vi, 0, sizeof(vi));
593 /* for legacy mem, we can get away with scanning VA-contiguous segments,
594 * as we know they are PA-contiguous as well
596 if (internal_config.legacy_mem)
597 rte_memseg_contig_walk(find_virt_legacy, &vi);
599 rte_memseg_walk(find_virt, &vi);
604 __rte_experimental struct rte_memseg *
605 rte_mem_virt2memseg(const void *addr, const struct rte_memseg_list *msl)
607 return virt2memseg(addr, msl != NULL ? msl :
608 rte_mem_virt2memseg_list(addr));
612 physmem_size(const struct rte_memseg_list *msl, void *arg)
614 uint64_t *total_len = arg;
616 *total_len += msl->memseg_arr.count * msl->page_sz;
621 /* get the total size of memory */
623 rte_eal_get_physmem_size(void)
625 uint64_t total_len = 0;
627 rte_memseg_list_walk(physmem_size, &total_len);
633 dump_memseg(const struct rte_memseg_list *msl, const struct rte_memseg *ms,
636 struct rte_mem_config *mcfg = rte_eal_get_configuration()->mem_config;
640 msl_idx = msl - mcfg->memsegs;
641 if (msl_idx < 0 || msl_idx >= RTE_MAX_MEMSEG_LISTS)
644 ms_idx = rte_fbarray_find_idx(&msl->memseg_arr, ms);
648 fprintf(f, "Segment %i-%i: IOVA:0x%"PRIx64", len:%zu, "
649 "virt:%p, socket_id:%"PRId32", "
650 "hugepage_sz:%"PRIu64", nchannel:%"PRIx32", "
665 * Defining here because declared in rte_memory.h, but the actual implementation
666 * is in eal_common_memalloc.c, like all other memalloc internals.
668 int __rte_experimental
669 rte_mem_event_callback_register(const char *name, rte_mem_event_callback_t clb,
672 /* FreeBSD boots with legacy mem enabled by default */
673 if (internal_config.legacy_mem) {
674 RTE_LOG(DEBUG, EAL, "Registering mem event callbacks not supported\n");
678 return eal_memalloc_mem_event_callback_register(name, clb, arg);
681 int __rte_experimental
682 rte_mem_event_callback_unregister(const char *name, void *arg)
684 /* FreeBSD boots with legacy mem enabled by default */
685 if (internal_config.legacy_mem) {
686 RTE_LOG(DEBUG, EAL, "Registering mem event callbacks not supported\n");
690 return eal_memalloc_mem_event_callback_unregister(name, arg);
693 int __rte_experimental
694 rte_mem_alloc_validator_register(const char *name,
695 rte_mem_alloc_validator_t clb, int socket_id, size_t limit)
697 /* FreeBSD boots with legacy mem enabled by default */
698 if (internal_config.legacy_mem) {
699 RTE_LOG(DEBUG, EAL, "Registering mem alloc validators not supported\n");
703 return eal_memalloc_mem_alloc_validator_register(name, clb, socket_id,
707 int __rte_experimental
708 rte_mem_alloc_validator_unregister(const char *name, int socket_id)
710 /* FreeBSD boots with legacy mem enabled by default */
711 if (internal_config.legacy_mem) {
712 RTE_LOG(DEBUG, EAL, "Registering mem alloc validators not supported\n");
716 return eal_memalloc_mem_alloc_validator_unregister(name, socket_id);
719 /* Dump the physical memory layout on console */
721 rte_dump_physmem_layout(FILE *f)
723 rte_memseg_walk(dump_memseg, f);
726 /* return the number of memory channels */
727 unsigned rte_memory_get_nchannel(void)
729 return rte_eal_get_configuration()->mem_config->nchannel;
732 /* return the number of memory rank */
733 unsigned rte_memory_get_nrank(void)
735 return rte_eal_get_configuration()->mem_config->nrank;
739 rte_eal_memdevice_init(void)
741 struct rte_config *config;
743 if (rte_eal_process_type() == RTE_PROC_SECONDARY)
746 config = rte_eal_get_configuration();
747 config->mem_config->nchannel = internal_config.force_nchannel;
748 config->mem_config->nrank = internal_config.force_nrank;
753 /* Lock page in physical memory and prevent from swapping. */
755 rte_mem_lock_page(const void *virt)
757 unsigned long virtual = (unsigned long)virt;
758 int page_size = getpagesize();
759 unsigned long aligned = (virtual & ~(page_size - 1));
760 return mlock((void *)aligned, page_size);
763 int __rte_experimental
764 rte_memseg_contig_walk(rte_memseg_contig_walk_t func, void *arg)
766 struct rte_mem_config *mcfg = rte_eal_get_configuration()->mem_config;
767 int i, ms_idx, ret = 0;
769 /* do not allow allocations/frees/init while we iterate */
770 rte_rwlock_read_lock(&mcfg->memory_hotplug_lock);
772 for (i = 0; i < RTE_MAX_MEMSEG_LISTS; i++) {
773 struct rte_memseg_list *msl = &mcfg->memsegs[i];
774 const struct rte_memseg *ms;
775 struct rte_fbarray *arr;
777 if (msl->memseg_arr.count == 0)
780 arr = &msl->memseg_arr;
782 ms_idx = rte_fbarray_find_next_used(arr, 0);
783 while (ms_idx >= 0) {
787 ms = rte_fbarray_get(arr, ms_idx);
789 /* find how many more segments there are, starting with
792 n_segs = rte_fbarray_find_contig_used(arr, ms_idx);
793 len = n_segs * msl->page_sz;
795 ret = func(msl, ms, len, arg);
799 } else if (ret > 0) {
803 ms_idx = rte_fbarray_find_next_used(arr,
808 rte_rwlock_read_unlock(&mcfg->memory_hotplug_lock);
812 int __rte_experimental
813 rte_memseg_walk(rte_memseg_walk_t func, void *arg)
815 struct rte_mem_config *mcfg = rte_eal_get_configuration()->mem_config;
816 int i, ms_idx, ret = 0;
818 /* do not allow allocations/frees/init while we iterate */
819 rte_rwlock_read_lock(&mcfg->memory_hotplug_lock);
821 for (i = 0; i < RTE_MAX_MEMSEG_LISTS; i++) {
822 struct rte_memseg_list *msl = &mcfg->memsegs[i];
823 const struct rte_memseg *ms;
824 struct rte_fbarray *arr;
826 if (msl->memseg_arr.count == 0)
829 arr = &msl->memseg_arr;
831 ms_idx = rte_fbarray_find_next_used(arr, 0);
832 while (ms_idx >= 0) {
833 ms = rte_fbarray_get(arr, ms_idx);
834 ret = func(msl, ms, arg);
838 } else if (ret > 0) {
842 ms_idx = rte_fbarray_find_next_used(arr, ms_idx + 1);
846 rte_rwlock_read_unlock(&mcfg->memory_hotplug_lock);
850 int __rte_experimental
851 rte_memseg_list_walk(rte_memseg_list_walk_t func, void *arg)
853 struct rte_mem_config *mcfg = rte_eal_get_configuration()->mem_config;
856 /* do not allow allocations/frees/init while we iterate */
857 rte_rwlock_read_lock(&mcfg->memory_hotplug_lock);
859 for (i = 0; i < RTE_MAX_MEMSEG_LISTS; i++) {
860 struct rte_memseg_list *msl = &mcfg->memsegs[i];
862 if (msl->base_va == NULL)
865 ret = func(msl, arg);
876 rte_rwlock_read_unlock(&mcfg->memory_hotplug_lock);
880 /* init memory subsystem */
882 rte_eal_memory_init(void)
884 struct rte_mem_config *mcfg = rte_eal_get_configuration()->mem_config;
886 RTE_LOG(DEBUG, EAL, "Setting up physically contiguous memory...\n");
891 /* lock mem hotplug here, to prevent races while we init */
892 rte_rwlock_read_lock(&mcfg->memory_hotplug_lock);
894 retval = rte_eal_process_type() == RTE_PROC_PRIMARY ?
896 memseg_primary_init_32() :
898 memseg_primary_init() :
900 memseg_secondary_init();
905 if (eal_memalloc_init() < 0)
908 retval = rte_eal_process_type() == RTE_PROC_PRIMARY ?
909 rte_eal_hugepage_init() :
910 rte_eal_hugepage_attach();
914 if (internal_config.no_shconf == 0 && rte_eal_memdevice_init() < 0)
919 rte_rwlock_read_unlock(&mcfg->memory_hotplug_lock);