1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2010-2014 Intel Corporation.
3 * Copyright(c) 2013 6WIND S.A.
16 #include <sys/types.h>
18 #include <sys/queue.h>
20 #include <sys/resource.h>
23 #include <sys/ioctl.h>
27 #ifdef F_ADD_SEALS /* if file sealing is supported, so is memfd */
28 #include <linux/memfd.h>
29 #define MEMFD_SUPPORTED
31 #ifdef RTE_EAL_NUMA_AWARE_HUGEPAGES
36 #include <rte_errno.h>
38 #include <rte_memory.h>
39 #include <rte_launch.h>
41 #include <rte_per_lcore.h>
42 #include <rte_lcore.h>
43 #include <rte_common.h>
44 #include <rte_string_fns.h>
46 #include "eal_private.h"
47 #include "eal_memalloc.h"
48 #include "eal_memcfg.h"
49 #include "eal_internal_cfg.h"
50 #include "eal_filesystem.h"
51 #include "eal_hugepages.h"
52 #include "eal_options.h"
54 #define PFN_MASK_SIZE 8
58 * Huge page mapping under linux
60 * To reserve a big contiguous amount of memory, we use the hugepage
61 * feature of linux. For that, we need to have hugetlbfs mounted. This
62 * code will create many files in this directory (one per page) and
63 * map them in virtual memory. For each page, we will retrieve its
64 * physical address and remap it in order to have a virtual contiguous
65 * zone as well as a physical contiguous zone.
68 static int phys_addrs_available = -1;
70 #define RANDOMIZE_VA_SPACE_FILE "/proc/sys/kernel/randomize_va_space"
72 uint64_t eal_get_baseaddr(void)
75 * Linux kernel uses a really high address as starting address for
76 * serving mmaps calls. If there exists addressing limitations and IOVA
77 * mode is VA, this starting address is likely too high for those
78 * devices. However, it is possible to use a lower address in the
79 * process virtual address space as with 64 bits there is a lot of
82 * Current known limitations are 39 or 40 bits. Setting the starting
83 * address at 4GB implies there are 508GB or 1020GB for mapping the
84 * available hugepages. This is likely enough for most systems, although
85 * a device with addressing limitations should call
86 * rte_mem_check_dma_mask for ensuring all memory is within supported
89 return 0x100000000ULL;
93 * Get physical address of any mapped virtual address in the current process.
96 rte_mem_virt2phy(const void *virtaddr)
99 uint64_t page, physaddr;
100 unsigned long virt_pfn;
104 if (phys_addrs_available == 0)
107 /* standard page size */
108 page_size = getpagesize();
110 fd = open("/proc/self/pagemap", O_RDONLY);
112 RTE_LOG(INFO, EAL, "%s(): cannot open /proc/self/pagemap: %s\n",
113 __func__, strerror(errno));
117 virt_pfn = (unsigned long)virtaddr / page_size;
118 offset = sizeof(uint64_t) * virt_pfn;
119 if (lseek(fd, offset, SEEK_SET) == (off_t) -1) {
120 RTE_LOG(INFO, EAL, "%s(): seek error in /proc/self/pagemap: %s\n",
121 __func__, strerror(errno));
126 retval = read(fd, &page, PFN_MASK_SIZE);
129 RTE_LOG(INFO, EAL, "%s(): cannot read /proc/self/pagemap: %s\n",
130 __func__, strerror(errno));
132 } else if (retval != PFN_MASK_SIZE) {
133 RTE_LOG(INFO, EAL, "%s(): read %d bytes from /proc/self/pagemap "
134 "but expected %d:\n",
135 __func__, retval, PFN_MASK_SIZE);
140 * the pfn (page frame number) are bits 0-54 (see
141 * pagemap.txt in linux Documentation)
143 if ((page & 0x7fffffffffffffULL) == 0)
146 physaddr = ((page & 0x7fffffffffffffULL) * page_size)
147 + ((unsigned long)virtaddr % page_size);
153 rte_mem_virt2iova(const void *virtaddr)
155 if (rte_eal_iova_mode() == RTE_IOVA_VA)
156 return (uintptr_t)virtaddr;
157 return rte_mem_virt2phy(virtaddr);
161 * For each hugepage in hugepg_tbl, fill the physaddr value. We find
162 * it by browsing the /proc/self/pagemap special file.
165 find_physaddrs(struct hugepage_file *hugepg_tbl, struct hugepage_info *hpi)
170 for (i = 0; i < hpi->num_pages[0]; i++) {
171 addr = rte_mem_virt2phy(hugepg_tbl[i].orig_va);
172 if (addr == RTE_BAD_PHYS_ADDR)
174 hugepg_tbl[i].physaddr = addr;
180 * For each hugepage in hugepg_tbl, fill the physaddr value sequentially.
183 set_physaddrs(struct hugepage_file *hugepg_tbl, struct hugepage_info *hpi)
186 static phys_addr_t addr;
188 for (i = 0; i < hpi->num_pages[0]; i++) {
189 hugepg_tbl[i].physaddr = addr;
190 addr += hugepg_tbl[i].size;
196 * Check whether address-space layout randomization is enabled in
197 * the kernel. This is important for multi-process as it can prevent
198 * two processes mapping data to the same virtual address
200 * 0 - address space randomization disabled
201 * 1/2 - address space randomization enabled
202 * negative error code on error
208 int retval, fd = open(RANDOMIZE_VA_SPACE_FILE, O_RDONLY);
211 retval = read(fd, &c, 1);
221 default: return -EINVAL;
225 static sigjmp_buf huge_jmpenv;
227 static void huge_sigbus_handler(int signo __rte_unused)
229 siglongjmp(huge_jmpenv, 1);
232 /* Put setjmp into a wrap method to avoid compiling error. Any non-volatile,
233 * non-static local variable in the stack frame calling sigsetjmp might be
234 * clobbered by a call to longjmp.
236 static int huge_wrap_sigsetjmp(void)
238 return sigsetjmp(huge_jmpenv, 1);
241 #ifdef RTE_EAL_NUMA_AWARE_HUGEPAGES
242 /* Callback for numa library. */
243 void numa_error(char *where)
245 RTE_LOG(ERR, EAL, "%s failed: %s\n", where, strerror(errno));
250 * Mmap all hugepages of hugepage table: it first open a file in
251 * hugetlbfs, then mmap() hugepage_sz data in it. If orig is set, the
252 * virtual address is stored in hugepg_tbl[i].orig_va, else it is stored
253 * in hugepg_tbl[i].final_va. The second mapping (when orig is 0) tries to
254 * map contiguous physical blocks in contiguous virtual blocks.
257 map_all_hugepages(struct hugepage_file *hugepg_tbl, struct hugepage_info *hpi,
258 uint64_t *essential_memory __rte_unused)
263 #ifdef RTE_EAL_NUMA_AWARE_HUGEPAGES
265 int essential_prev = 0;
267 struct bitmask *oldmask = NULL;
268 bool have_numa = true;
269 unsigned long maxnode = 0;
271 /* Check if kernel supports NUMA. */
272 if (numa_available() != 0) {
273 RTE_LOG(DEBUG, EAL, "NUMA is not supported.\n");
278 RTE_LOG(DEBUG, EAL, "Trying to obtain current memory policy.\n");
279 oldmask = numa_allocate_nodemask();
280 if (get_mempolicy(&oldpolicy, oldmask->maskp,
281 oldmask->size + 1, 0, 0) < 0) {
283 "Failed to get current mempolicy: %s. "
284 "Assuming MPOL_DEFAULT.\n", strerror(errno));
285 oldpolicy = MPOL_DEFAULT;
287 for (i = 0; i < RTE_MAX_NUMA_NODES; i++)
288 if (internal_config.socket_mem[i])
293 for (i = 0; i < hpi->num_pages[0]; i++) {
294 struct hugepage_file *hf = &hugepg_tbl[i];
295 uint64_t hugepage_sz = hpi->hugepage_sz;
297 #ifdef RTE_EAL_NUMA_AWARE_HUGEPAGES
301 for (j = 0; j < maxnode; j++)
302 if (essential_memory[j])
306 node_id = (node_id + 1) % maxnode;
307 while (!internal_config.socket_mem[node_id]) {
314 essential_prev = essential_memory[j];
316 if (essential_memory[j] < hugepage_sz)
317 essential_memory[j] = 0;
319 essential_memory[j] -= hugepage_sz;
323 "Setting policy MPOL_PREFERRED for socket %d\n",
325 numa_set_preferred(node_id);
330 hf->size = hugepage_sz;
331 eal_get_hugefile_path(hf->filepath, sizeof(hf->filepath),
332 hpi->hugedir, hf->file_id);
333 hf->filepath[sizeof(hf->filepath) - 1] = '\0';
335 /* try to create hugepage file */
336 fd = open(hf->filepath, O_CREAT | O_RDWR, 0600);
338 RTE_LOG(DEBUG, EAL, "%s(): open failed: %s\n", __func__,
343 /* map the segment, and populate page tables,
344 * the kernel fills this segment with zeros. we don't care where
345 * this gets mapped - we already have contiguous memory areas
346 * ready for us to map into.
348 virtaddr = mmap(NULL, hugepage_sz, PROT_READ | PROT_WRITE,
349 MAP_SHARED | MAP_POPULATE, fd, 0);
350 if (virtaddr == MAP_FAILED) {
351 RTE_LOG(DEBUG, EAL, "%s(): mmap failed: %s\n", __func__,
357 hf->orig_va = virtaddr;
359 /* In linux, hugetlb limitations, like cgroup, are
360 * enforced at fault time instead of mmap(), even
361 * with the option of MAP_POPULATE. Kernel will send
362 * a SIGBUS signal. To avoid to be killed, save stack
363 * environment here, if SIGBUS happens, we can jump
366 if (huge_wrap_sigsetjmp()) {
367 RTE_LOG(DEBUG, EAL, "SIGBUS: Cannot mmap more "
368 "hugepages of size %u MB\n",
369 (unsigned int)(hugepage_sz / 0x100000));
370 munmap(virtaddr, hugepage_sz);
372 unlink(hugepg_tbl[i].filepath);
373 #ifdef RTE_EAL_NUMA_AWARE_HUGEPAGES
375 essential_memory[node_id] =
380 *(int *)virtaddr = 0;
382 /* set shared lock on the file. */
383 if (flock(fd, LOCK_SH) < 0) {
384 RTE_LOG(DEBUG, EAL, "%s(): Locking file failed:%s \n",
385 __func__, strerror(errno));
394 #ifdef RTE_EAL_NUMA_AWARE_HUGEPAGES
397 "Restoring previous memory policy: %d\n", oldpolicy);
398 if (oldpolicy == MPOL_DEFAULT) {
399 numa_set_localalloc();
400 } else if (set_mempolicy(oldpolicy, oldmask->maskp,
401 oldmask->size + 1) < 0) {
402 RTE_LOG(ERR, EAL, "Failed to restore mempolicy: %s\n",
404 numa_set_localalloc();
408 numa_free_cpumask(oldmask);
414 * Parse /proc/self/numa_maps to get the NUMA socket ID for each huge
418 find_numasocket(struct hugepage_file *hugepg_tbl, struct hugepage_info *hpi)
422 unsigned i, hp_count = 0;
425 char hugedir_str[PATH_MAX];
428 f = fopen("/proc/self/numa_maps", "r");
430 RTE_LOG(NOTICE, EAL, "NUMA support not available"
431 " consider that all memory is in socket_id 0\n");
435 snprintf(hugedir_str, sizeof(hugedir_str),
436 "%s/%s", hpi->hugedir, eal_get_hugefile_prefix());
439 while (fgets(buf, sizeof(buf), f) != NULL) {
441 /* ignore non huge page */
442 if (strstr(buf, " huge ") == NULL &&
443 strstr(buf, hugedir_str) == NULL)
447 virt_addr = strtoull(buf, &end, 16);
448 if (virt_addr == 0 || end == buf) {
449 RTE_LOG(ERR, EAL, "%s(): error in numa_maps parsing\n", __func__);
453 /* get node id (socket id) */
454 nodestr = strstr(buf, " N");
455 if (nodestr == NULL) {
456 RTE_LOG(ERR, EAL, "%s(): error in numa_maps parsing\n", __func__);
460 end = strstr(nodestr, "=");
462 RTE_LOG(ERR, EAL, "%s(): error in numa_maps parsing\n", __func__);
468 socket_id = strtoul(nodestr, &end, 0);
469 if ((nodestr[0] == '\0') || (end == NULL) || (*end != '\0')) {
470 RTE_LOG(ERR, EAL, "%s(): error in numa_maps parsing\n", __func__);
474 /* if we find this page in our mappings, set socket_id */
475 for (i = 0; i < hpi->num_pages[0]; i++) {
476 void *va = (void *)(unsigned long)virt_addr;
477 if (hugepg_tbl[i].orig_va == va) {
478 hugepg_tbl[i].socket_id = socket_id;
480 #ifdef RTE_EAL_NUMA_AWARE_HUGEPAGES
482 "Hugepage %s is on socket %d\n",
483 hugepg_tbl[i].filepath, socket_id);
489 if (hp_count < hpi->num_pages[0])
501 cmp_physaddr(const void *a, const void *b)
503 #ifndef RTE_ARCH_PPC_64
504 const struct hugepage_file *p1 = a;
505 const struct hugepage_file *p2 = b;
507 /* PowerPC needs memory sorted in reverse order from x86 */
508 const struct hugepage_file *p1 = b;
509 const struct hugepage_file *p2 = a;
511 if (p1->physaddr < p2->physaddr)
513 else if (p1->physaddr > p2->physaddr)
520 * Uses mmap to create a shared memory area for storage of data
521 * Used in this file to store the hugepage file map on disk
524 create_shared_memory(const char *filename, const size_t mem_size)
529 /* if no shared files mode is used, create anonymous memory instead */
530 if (internal_config.no_shconf) {
531 retval = mmap(NULL, mem_size, PROT_READ | PROT_WRITE,
532 MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
533 if (retval == MAP_FAILED)
538 fd = open(filename, O_CREAT | O_RDWR, 0600);
541 if (ftruncate(fd, mem_size) < 0) {
545 retval = mmap(NULL, mem_size, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
547 if (retval == MAP_FAILED)
553 * this copies *active* hugepages from one hugepage table to another.
554 * destination is typically the shared memory.
557 copy_hugepages_to_shared_mem(struct hugepage_file * dst, int dest_size,
558 const struct hugepage_file * src, int src_size)
560 int src_pos, dst_pos = 0;
562 for (src_pos = 0; src_pos < src_size; src_pos++) {
563 if (src[src_pos].orig_va != NULL) {
564 /* error on overflow attempt */
565 if (dst_pos == dest_size)
567 memcpy(&dst[dst_pos], &src[src_pos], sizeof(struct hugepage_file));
575 unlink_hugepage_files(struct hugepage_file *hugepg_tbl,
576 unsigned num_hp_info)
578 unsigned socket, size;
579 int page, nrpages = 0;
581 /* get total number of hugepages */
582 for (size = 0; size < num_hp_info; size++)
583 for (socket = 0; socket < RTE_MAX_NUMA_NODES; socket++)
585 internal_config.hugepage_info[size].num_pages[socket];
587 for (page = 0; page < nrpages; page++) {
588 struct hugepage_file *hp = &hugepg_tbl[page];
590 if (hp->orig_va != NULL && unlink(hp->filepath)) {
591 RTE_LOG(WARNING, EAL, "%s(): Removing %s failed: %s\n",
592 __func__, hp->filepath, strerror(errno));
599 * unmaps hugepages that are not going to be used. since we originally allocate
600 * ALL hugepages (not just those we need), additional unmapping needs to be done.
603 unmap_unneeded_hugepages(struct hugepage_file *hugepg_tbl,
604 struct hugepage_info *hpi,
605 unsigned num_hp_info)
607 unsigned socket, size;
608 int page, nrpages = 0;
610 /* get total number of hugepages */
611 for (size = 0; size < num_hp_info; size++)
612 for (socket = 0; socket < RTE_MAX_NUMA_NODES; socket++)
613 nrpages += internal_config.hugepage_info[size].num_pages[socket];
615 for (size = 0; size < num_hp_info; size++) {
616 for (socket = 0; socket < RTE_MAX_NUMA_NODES; socket++) {
617 unsigned pages_found = 0;
619 /* traverse until we have unmapped all the unused pages */
620 for (page = 0; page < nrpages; page++) {
621 struct hugepage_file *hp = &hugepg_tbl[page];
623 /* find a page that matches the criteria */
624 if ((hp->size == hpi[size].hugepage_sz) &&
625 (hp->socket_id == (int) socket)) {
627 /* if we skipped enough pages, unmap the rest */
628 if (pages_found == hpi[size].num_pages[socket]) {
631 unmap_len = hp->size;
633 /* get start addr and len of the remaining segment */
638 if (unlink(hp->filepath) == -1) {
639 RTE_LOG(ERR, EAL, "%s(): Removing %s failed: %s\n",
640 __func__, hp->filepath, strerror(errno));
644 /* lock the page and skip */
650 } /* foreach socket */
651 } /* foreach pagesize */
657 remap_segment(struct hugepage_file *hugepages, int seg_start, int seg_end)
659 struct rte_mem_config *mcfg = rte_eal_get_configuration()->mem_config;
660 struct rte_memseg_list *msl;
661 struct rte_fbarray *arr;
662 int cur_page, seg_len;
663 unsigned int msl_idx;
669 page_sz = hugepages[seg_start].size;
670 socket_id = hugepages[seg_start].socket_id;
671 seg_len = seg_end - seg_start;
673 RTE_LOG(DEBUG, EAL, "Attempting to map %" PRIu64 "M on socket %i\n",
674 (seg_len * page_sz) >> 20ULL, socket_id);
676 /* find free space in memseg lists */
677 for (msl_idx = 0; msl_idx < RTE_MAX_MEMSEG_LISTS; msl_idx++) {
679 msl = &mcfg->memsegs[msl_idx];
680 arr = &msl->memseg_arr;
682 if (msl->page_sz != page_sz)
684 if (msl->socket_id != socket_id)
687 /* leave space for a hole if array is not empty */
688 empty = arr->count == 0;
689 ms_idx = rte_fbarray_find_next_n_free(arr, 0,
690 seg_len + (empty ? 0 : 1));
692 /* memseg list is full? */
696 /* leave some space between memsegs, they are not IOVA
697 * contiguous, so they shouldn't be VA contiguous either.
703 if (msl_idx == RTE_MAX_MEMSEG_LISTS) {
704 RTE_LOG(ERR, EAL, "Could not find space for memseg. Please increase %s and/or %s in configuration.\n",
705 RTE_STR(CONFIG_RTE_MAX_MEMSEG_PER_TYPE),
706 RTE_STR(CONFIG_RTE_MAX_MEM_PER_TYPE));
710 #ifdef RTE_ARCH_PPC_64
711 /* for PPC64 we go through the list backwards */
712 for (cur_page = seg_end - 1; cur_page >= seg_start;
713 cur_page--, ms_idx++) {
715 for (cur_page = seg_start; cur_page < seg_end; cur_page++, ms_idx++) {
717 struct hugepage_file *hfile = &hugepages[cur_page];
718 struct rte_memseg *ms = rte_fbarray_get(arr, ms_idx);
722 fd = open(hfile->filepath, O_RDWR);
724 RTE_LOG(ERR, EAL, "Could not open '%s': %s\n",
725 hfile->filepath, strerror(errno));
728 /* set shared lock on the file. */
729 if (flock(fd, LOCK_SH) < 0) {
730 RTE_LOG(DEBUG, EAL, "Could not lock '%s': %s\n",
731 hfile->filepath, strerror(errno));
735 memseg_len = (size_t)page_sz;
736 addr = RTE_PTR_ADD(msl->base_va, ms_idx * memseg_len);
738 /* we know this address is already mmapped by memseg list, so
739 * using MAP_FIXED here is safe
741 addr = mmap(addr, page_sz, PROT_READ | PROT_WRITE,
742 MAP_SHARED | MAP_POPULATE | MAP_FIXED, fd, 0);
743 if (addr == MAP_FAILED) {
744 RTE_LOG(ERR, EAL, "Couldn't remap '%s': %s\n",
745 hfile->filepath, strerror(errno));
750 /* we have a new address, so unmap previous one */
752 /* in 32-bit legacy mode, we have already unmapped the page */
753 if (!internal_config.legacy_mem)
754 munmap(hfile->orig_va, page_sz);
756 munmap(hfile->orig_va, page_sz);
759 hfile->orig_va = NULL;
760 hfile->final_va = addr;
762 /* rewrite physical addresses in IOVA as VA mode */
763 if (rte_eal_iova_mode() == RTE_IOVA_VA)
764 hfile->physaddr = (uintptr_t)addr;
766 /* set up memseg data */
768 ms->hugepage_sz = page_sz;
769 ms->len = memseg_len;
770 ms->iova = hfile->physaddr;
771 ms->socket_id = hfile->socket_id;
772 ms->nchannel = rte_memory_get_nchannel();
773 ms->nrank = rte_memory_get_nrank();
775 rte_fbarray_set_used(arr, ms_idx);
777 /* store segment fd internally */
778 if (eal_memalloc_set_seg_fd(msl_idx, ms_idx, fd) < 0)
779 RTE_LOG(ERR, EAL, "Could not store segment fd: %s\n",
780 rte_strerror(rte_errno));
782 RTE_LOG(DEBUG, EAL, "Allocated %" PRIu64 "M on socket %i\n",
783 (seg_len * page_sz) >> 20, socket_id);
788 get_mem_amount(uint64_t page_sz, uint64_t max_mem)
790 uint64_t area_sz, max_pages;
792 /* limit to RTE_MAX_MEMSEG_PER_LIST pages or RTE_MAX_MEM_MB_PER_LIST */
793 max_pages = RTE_MAX_MEMSEG_PER_LIST;
794 max_mem = RTE_MIN((uint64_t)RTE_MAX_MEM_MB_PER_LIST << 20, max_mem);
796 area_sz = RTE_MIN(page_sz * max_pages, max_mem);
798 /* make sure the list isn't smaller than the page size */
799 area_sz = RTE_MAX(area_sz, page_sz);
801 return RTE_ALIGN(area_sz, page_sz);
805 free_memseg_list(struct rte_memseg_list *msl)
807 if (rte_fbarray_destroy(&msl->memseg_arr)) {
808 RTE_LOG(ERR, EAL, "Cannot destroy memseg list\n");
811 memset(msl, 0, sizeof(*msl));
815 #define MEMSEG_LIST_FMT "memseg-%" PRIu64 "k-%i-%i"
817 alloc_memseg_list(struct rte_memseg_list *msl, uint64_t page_sz,
818 int n_segs, int socket_id, int type_msl_idx)
820 char name[RTE_FBARRAY_NAME_LEN];
822 snprintf(name, sizeof(name), MEMSEG_LIST_FMT, page_sz >> 10, socket_id,
824 if (rte_fbarray_init(&msl->memseg_arr, name, n_segs,
825 sizeof(struct rte_memseg))) {
826 RTE_LOG(ERR, EAL, "Cannot allocate memseg list: %s\n",
827 rte_strerror(rte_errno));
831 msl->page_sz = page_sz;
832 msl->socket_id = socket_id;
834 msl->heap = 1; /* mark it as a heap segment */
836 RTE_LOG(DEBUG, EAL, "Memseg list allocated: 0x%zxkB at socket %i\n",
837 (size_t)page_sz >> 10, socket_id);
843 alloc_va_space(struct rte_memseg_list *msl)
850 page_sz = msl->page_sz;
851 mem_sz = page_sz * msl->memseg_arr.len;
853 addr = eal_get_virtual_area(msl->base_va, &mem_sz, page_sz, 0, flags);
855 if (rte_errno == EADDRNOTAVAIL)
856 RTE_LOG(ERR, EAL, "Could not mmap %llu bytes at [%p] - "
857 "please use '--" OPT_BASE_VIRTADDR "' option\n",
858 (unsigned long long)mem_sz, msl->base_va);
860 RTE_LOG(ERR, EAL, "Cannot reserve memory\n");
870 * Our VA space is not preallocated yet, so preallocate it here. We need to know
871 * how many segments there are in order to map all pages into one address space,
872 * and leave appropriate holes between segments so that rte_malloc does not
873 * concatenate them into one big segment.
875 * we also need to unmap original pages to free up address space.
877 static int __rte_unused
878 prealloc_segments(struct hugepage_file *hugepages, int n_pages)
880 struct rte_mem_config *mcfg = rte_eal_get_configuration()->mem_config;
881 int cur_page, seg_start_page, end_seg, new_memseg;
882 unsigned int hpi_idx, socket, i;
883 int n_contig_segs, n_segs;
886 /* before we preallocate segments, we need to free up our VA space.
887 * we're not removing files, and we already have information about
888 * PA-contiguousness, so it is safe to unmap everything.
890 for (cur_page = 0; cur_page < n_pages; cur_page++) {
891 struct hugepage_file *hpi = &hugepages[cur_page];
892 munmap(hpi->orig_va, hpi->size);
896 /* we cannot know how many page sizes and sockets we have discovered, so
897 * loop over all of them
899 for (hpi_idx = 0; hpi_idx < internal_config.num_hugepage_sizes;
902 internal_config.hugepage_info[hpi_idx].hugepage_sz;
904 for (i = 0; i < rte_socket_count(); i++) {
905 struct rte_memseg_list *msl;
907 socket = rte_socket_id_by_idx(i);
912 for (cur_page = 0; cur_page < n_pages; cur_page++) {
913 struct hugepage_file *prev, *cur;
914 int prev_seg_start_page = -1;
916 cur = &hugepages[cur_page];
917 prev = cur_page == 0 ? NULL :
918 &hugepages[cur_page - 1];
925 else if (cur->socket_id != (int) socket)
927 else if (cur->size != page_sz)
929 else if (cur_page == 0)
931 #ifdef RTE_ARCH_PPC_64
932 /* On PPC64 architecture, the mmap always start
933 * from higher address to lower address. Here,
934 * physical addresses are in descending order.
936 else if ((prev->physaddr - cur->physaddr) !=
940 else if ((cur->physaddr - prev->physaddr) !=
945 /* if we're already inside a segment,
946 * new segment means end of current one
948 if (seg_start_page != -1) {
950 prev_seg_start_page =
953 seg_start_page = cur_page;
957 if (prev_seg_start_page != -1) {
958 /* we've found a new segment */
962 } else if (seg_start_page != -1) {
963 /* we didn't find new segment,
964 * but did end current one
972 /* we're skipping this page */
976 /* segment continues */
978 /* check if we missed last segment */
979 if (seg_start_page != -1) {
981 n_segs += cur_page - seg_start_page;
984 /* if no segments were found, do not preallocate */
988 /* we now have total number of pages that we will
989 * allocate for this segment list. add separator pages
990 * to the total count, and preallocate VA space.
992 n_segs += n_contig_segs - 1;
994 /* now, preallocate VA space for these segments */
996 /* first, find suitable memseg list for this */
997 for (msl_idx = 0; msl_idx < RTE_MAX_MEMSEG_LISTS;
999 msl = &mcfg->memsegs[msl_idx];
1001 if (msl->base_va != NULL)
1005 if (msl_idx == RTE_MAX_MEMSEG_LISTS) {
1006 RTE_LOG(ERR, EAL, "Not enough space in memseg lists, please increase %s\n",
1007 RTE_STR(CONFIG_RTE_MAX_MEMSEG_LISTS));
1011 /* now, allocate fbarray itself */
1012 if (alloc_memseg_list(msl, page_sz, n_segs, socket,
1016 /* finally, allocate VA space */
1017 if (alloc_va_space(msl) < 0)
1025 * We cannot reallocate memseg lists on the fly because PPC64 stores pages
1026 * backwards, therefore we have to process the entire memseg first before
1027 * remapping it into memseg list VA space.
1030 remap_needed_hugepages(struct hugepage_file *hugepages, int n_pages)
1032 int cur_page, seg_start_page, new_memseg, ret;
1035 for (cur_page = 0; cur_page < n_pages; cur_page++) {
1036 struct hugepage_file *prev, *cur;
1040 cur = &hugepages[cur_page];
1041 prev = cur_page == 0 ? NULL : &hugepages[cur_page - 1];
1043 /* if size is zero, no more pages left */
1049 else if (cur->socket_id != prev->socket_id)
1051 else if (cur->size != prev->size)
1053 #ifdef RTE_ARCH_PPC_64
1054 /* On PPC64 architecture, the mmap always start from higher
1055 * address to lower address. Here, physical addresses are in
1058 else if ((prev->physaddr - cur->physaddr) != cur->size)
1061 else if ((cur->physaddr - prev->physaddr) != cur->size)
1066 /* if this isn't the first time, remap segment */
1067 if (cur_page != 0) {
1068 ret = remap_segment(hugepages, seg_start_page,
1073 /* remember where we started */
1074 seg_start_page = cur_page;
1076 /* continuation of previous memseg */
1078 /* we were stopped, but we didn't remap the last segment, do it now */
1079 if (cur_page != 0) {
1080 ret = remap_segment(hugepages, seg_start_page,
1088 __rte_unused /* function is unused on 32-bit builds */
1089 static inline uint64_t
1090 get_socket_mem_size(int socket)
1095 for (i = 0; i < internal_config.num_hugepage_sizes; i++){
1096 struct hugepage_info *hpi = &internal_config.hugepage_info[i];
1097 size += hpi->hugepage_sz * hpi->num_pages[socket];
1104 * This function is a NUMA-aware equivalent of calc_num_pages.
1105 * It takes in the list of hugepage sizes and the
1106 * number of pages thereof, and calculates the best number of
1107 * pages of each size to fulfill the request for <memory> ram
1110 calc_num_pages_per_socket(uint64_t * memory,
1111 struct hugepage_info *hp_info,
1112 struct hugepage_info *hp_used,
1113 unsigned num_hp_info)
1115 unsigned socket, j, i = 0;
1116 unsigned requested, available;
1117 int total_num_pages = 0;
1118 uint64_t remaining_mem, cur_mem;
1119 uint64_t total_mem = internal_config.memory;
1121 if (num_hp_info == 0)
1124 /* if specific memory amounts per socket weren't requested */
1125 if (internal_config.force_sockets == 0) {
1128 int cpu_per_socket[RTE_MAX_NUMA_NODES];
1129 size_t default_size;
1132 /* Compute number of cores per socket */
1133 memset(cpu_per_socket, 0, sizeof(cpu_per_socket));
1134 RTE_LCORE_FOREACH(lcore_id) {
1135 cpu_per_socket[rte_lcore_to_socket_id(lcore_id)]++;
1139 * Automatically spread requested memory amongst detected sockets according
1140 * to number of cores from cpu mask present on each socket
1142 total_size = internal_config.memory;
1143 for (socket = 0; socket < RTE_MAX_NUMA_NODES && total_size != 0; socket++) {
1145 /* Set memory amount per socket */
1146 default_size = (internal_config.memory * cpu_per_socket[socket])
1147 / rte_lcore_count();
1149 /* Limit to maximum available memory on socket */
1150 default_size = RTE_MIN(default_size, get_socket_mem_size(socket));
1153 memory[socket] = default_size;
1154 total_size -= default_size;
1158 * If some memory is remaining, try to allocate it by getting all
1159 * available memory from sockets, one after the other
1161 for (socket = 0; socket < RTE_MAX_NUMA_NODES && total_size != 0; socket++) {
1162 /* take whatever is available */
1163 default_size = RTE_MIN(get_socket_mem_size(socket) - memory[socket],
1167 memory[socket] += default_size;
1168 total_size -= default_size;
1171 /* in 32-bit mode, allocate all of the memory only on master
1174 total_size = internal_config.memory;
1175 for (socket = 0; socket < RTE_MAX_NUMA_NODES && total_size != 0;
1177 struct rte_config *cfg = rte_eal_get_configuration();
1178 unsigned int master_lcore_socket;
1180 master_lcore_socket =
1181 rte_lcore_to_socket_id(cfg->master_lcore);
1183 if (master_lcore_socket != socket)
1187 memory[socket] = total_size;
1193 for (socket = 0; socket < RTE_MAX_NUMA_NODES && total_mem != 0; socket++) {
1194 /* skips if the memory on specific socket wasn't requested */
1195 for (i = 0; i < num_hp_info && memory[socket] != 0; i++){
1196 strlcpy(hp_used[i].hugedir, hp_info[i].hugedir,
1197 sizeof(hp_used[i].hugedir));
1198 hp_used[i].num_pages[socket] = RTE_MIN(
1199 memory[socket] / hp_info[i].hugepage_sz,
1200 hp_info[i].num_pages[socket]);
1202 cur_mem = hp_used[i].num_pages[socket] *
1203 hp_used[i].hugepage_sz;
1205 memory[socket] -= cur_mem;
1206 total_mem -= cur_mem;
1208 total_num_pages += hp_used[i].num_pages[socket];
1210 /* check if we have met all memory requests */
1211 if (memory[socket] == 0)
1214 /* check if we have any more pages left at this size, if so
1215 * move on to next size */
1216 if (hp_used[i].num_pages[socket] == hp_info[i].num_pages[socket])
1218 /* At this point we know that there are more pages available that are
1219 * bigger than the memory we want, so lets see if we can get enough
1220 * from other page sizes.
1223 for (j = i+1; j < num_hp_info; j++)
1224 remaining_mem += hp_info[j].hugepage_sz *
1225 hp_info[j].num_pages[socket];
1227 /* is there enough other memory, if not allocate another page and quit */
1228 if (remaining_mem < memory[socket]){
1229 cur_mem = RTE_MIN(memory[socket],
1230 hp_info[i].hugepage_sz);
1231 memory[socket] -= cur_mem;
1232 total_mem -= cur_mem;
1233 hp_used[i].num_pages[socket]++;
1235 break; /* we are done with this socket*/
1238 /* if we didn't satisfy all memory requirements per socket */
1239 if (memory[socket] > 0 &&
1240 internal_config.socket_mem[socket] != 0) {
1241 /* to prevent icc errors */
1242 requested = (unsigned) (internal_config.socket_mem[socket] /
1244 available = requested -
1245 ((unsigned) (memory[socket] / 0x100000));
1246 RTE_LOG(ERR, EAL, "Not enough memory available on socket %u! "
1247 "Requested: %uMB, available: %uMB\n", socket,
1248 requested, available);
1253 /* if we didn't satisfy total memory requirements */
1254 if (total_mem > 0) {
1255 requested = (unsigned) (internal_config.memory / 0x100000);
1256 available = requested - (unsigned) (total_mem / 0x100000);
1257 RTE_LOG(ERR, EAL, "Not enough memory available! Requested: %uMB,"
1258 " available: %uMB\n", requested, available);
1261 return total_num_pages;
1264 static inline size_t
1265 eal_get_hugepage_mem_size(void)
1270 for (i = 0; i < internal_config.num_hugepage_sizes; i++) {
1271 struct hugepage_info *hpi = &internal_config.hugepage_info[i];
1272 if (strnlen(hpi->hugedir, sizeof(hpi->hugedir)) != 0) {
1273 for (j = 0; j < RTE_MAX_NUMA_NODES; j++) {
1274 size += hpi->hugepage_sz * hpi->num_pages[j];
1279 return (size < SIZE_MAX) ? (size_t)(size) : SIZE_MAX;
1282 static struct sigaction huge_action_old;
1283 static int huge_need_recover;
1286 huge_register_sigbus(void)
1289 struct sigaction action;
1292 sigaddset(&mask, SIGBUS);
1293 action.sa_flags = 0;
1294 action.sa_mask = mask;
1295 action.sa_handler = huge_sigbus_handler;
1297 huge_need_recover = !sigaction(SIGBUS, &action, &huge_action_old);
1301 huge_recover_sigbus(void)
1303 if (huge_need_recover) {
1304 sigaction(SIGBUS, &huge_action_old, NULL);
1305 huge_need_recover = 0;
1310 * Prepare physical memory mapping: fill configuration structure with
1311 * these infos, return 0 on success.
1312 * 1. map N huge pages in separate files in hugetlbfs
1313 * 2. find associated physical addr
1314 * 3. find associated NUMA socket ID
1315 * 4. sort all huge pages by physical address
1316 * 5. remap these N huge pages in the correct order
1317 * 6. unmap the first mapping
1318 * 7. fill memsegs in configuration with contiguous zones
1321 eal_legacy_hugepage_init(void)
1323 struct rte_mem_config *mcfg;
1324 struct hugepage_file *hugepage = NULL, *tmp_hp = NULL;
1325 struct hugepage_info used_hp[MAX_HUGEPAGE_SIZES];
1326 struct rte_fbarray *arr;
1327 struct rte_memseg *ms;
1329 uint64_t memory[RTE_MAX_NUMA_NODES];
1333 int nr_hugefiles, nr_hugepages = 0;
1336 memset(used_hp, 0, sizeof(used_hp));
1338 /* get pointer to global configuration */
1339 mcfg = rte_eal_get_configuration()->mem_config;
1341 /* hugetlbfs can be disabled */
1342 if (internal_config.no_hugetlbfs) {
1343 void *prealloc_addr;
1345 struct rte_memseg_list *msl;
1346 int n_segs, cur_seg, fd, flags;
1347 #ifdef MEMFD_SUPPORTED
1352 /* nohuge mode is legacy mode */
1353 internal_config.legacy_mem = 1;
1355 /* nohuge mode is single-file segments mode */
1356 internal_config.single_file_segments = 1;
1358 /* create a memseg list */
1359 msl = &mcfg->memsegs[0];
1361 page_sz = RTE_PGSIZE_4K;
1362 n_segs = internal_config.memory / page_sz;
1364 if (rte_fbarray_init(&msl->memseg_arr, "nohugemem", n_segs,
1365 sizeof(struct rte_memseg))) {
1366 RTE_LOG(ERR, EAL, "Cannot allocate memseg list\n");
1370 /* set up parameters for anonymous mmap */
1372 flags = MAP_PRIVATE | MAP_ANONYMOUS;
1374 #ifdef MEMFD_SUPPORTED
1375 /* create a memfd and store it in the segment fd table */
1376 memfd = memfd_create("nohuge", 0);
1378 RTE_LOG(DEBUG, EAL, "Cannot create memfd: %s\n",
1380 RTE_LOG(DEBUG, EAL, "Falling back to anonymous map\n");
1382 /* we got an fd - now resize it */
1383 if (ftruncate(memfd, internal_config.memory) < 0) {
1384 RTE_LOG(ERR, EAL, "Cannot resize memfd: %s\n",
1386 RTE_LOG(ERR, EAL, "Falling back to anonymous map\n");
1389 /* creating memfd-backed file was successful.
1390 * we want changes to memfd to be visible to
1391 * other processes (such as vhost backend), so
1392 * map it as shared memory.
1394 RTE_LOG(DEBUG, EAL, "Using memfd for anonymous memory\n");
1400 /* preallocate address space for the memory, so that it can be
1401 * fit into the DMA mask.
1403 mem_sz = internal_config.memory;
1404 prealloc_addr = eal_get_virtual_area(
1405 NULL, &mem_sz, page_sz, 0, 0);
1406 if (prealloc_addr == NULL) {
1408 "%s: reserving memory area failed: "
1410 __func__, strerror(errno));
1413 addr = mmap(prealloc_addr, mem_sz, PROT_READ | PROT_WRITE,
1414 flags | MAP_FIXED, fd, 0);
1415 if (addr == MAP_FAILED || addr != prealloc_addr) {
1416 RTE_LOG(ERR, EAL, "%s: mmap() failed: %s\n", __func__,
1418 munmap(prealloc_addr, mem_sz);
1421 msl->base_va = addr;
1422 msl->page_sz = page_sz;
1427 /* we're in single-file segments mode, so only the segment list
1428 * fd needs to be set up.
1431 if (eal_memalloc_set_seg_list_fd(0, fd) < 0) {
1432 RTE_LOG(ERR, EAL, "Cannot set up segment list fd\n");
1433 /* not a serious error, proceed */
1437 /* populate memsegs. each memseg is one page long */
1438 for (cur_seg = 0; cur_seg < n_segs; cur_seg++) {
1439 arr = &msl->memseg_arr;
1441 ms = rte_fbarray_get(arr, cur_seg);
1442 if (rte_eal_iova_mode() == RTE_IOVA_VA)
1443 ms->iova = (uintptr_t)addr;
1445 ms->iova = RTE_BAD_IOVA;
1447 ms->hugepage_sz = page_sz;
1451 rte_fbarray_set_used(arr, cur_seg);
1453 addr = RTE_PTR_ADD(addr, (size_t)page_sz);
1455 if (mcfg->dma_maskbits &&
1456 rte_mem_check_dma_mask_thread_unsafe(mcfg->dma_maskbits)) {
1458 "%s(): couldn't allocate memory due to IOVA exceeding limits of current DMA mask.\n",
1460 if (rte_eal_iova_mode() == RTE_IOVA_VA &&
1461 rte_eal_using_phys_addrs())
1463 "%s(): Please try initializing EAL with --iova-mode=pa parameter.\n",
1470 /* calculate total number of hugepages available. at this point we haven't
1471 * yet started sorting them so they all are on socket 0 */
1472 for (i = 0; i < (int) internal_config.num_hugepage_sizes; i++) {
1473 /* meanwhile, also initialize used_hp hugepage sizes in used_hp */
1474 used_hp[i].hugepage_sz = internal_config.hugepage_info[i].hugepage_sz;
1476 nr_hugepages += internal_config.hugepage_info[i].num_pages[0];
1480 * allocate a memory area for hugepage table.
1481 * this isn't shared memory yet. due to the fact that we need some
1482 * processing done on these pages, shared memory will be created
1485 tmp_hp = malloc(nr_hugepages * sizeof(struct hugepage_file));
1489 memset(tmp_hp, 0, nr_hugepages * sizeof(struct hugepage_file));
1491 hp_offset = 0; /* where we start the current page size entries */
1493 huge_register_sigbus();
1495 /* make a copy of socket_mem, needed for balanced allocation. */
1496 for (i = 0; i < RTE_MAX_NUMA_NODES; i++)
1497 memory[i] = internal_config.socket_mem[i];
1499 /* map all hugepages and sort them */
1500 for (i = 0; i < (int)internal_config.num_hugepage_sizes; i ++){
1501 unsigned pages_old, pages_new;
1502 struct hugepage_info *hpi;
1505 * we don't yet mark hugepages as used at this stage, so
1506 * we just map all hugepages available to the system
1507 * all hugepages are still located on socket 0
1509 hpi = &internal_config.hugepage_info[i];
1511 if (hpi->num_pages[0] == 0)
1514 /* map all hugepages available */
1515 pages_old = hpi->num_pages[0];
1516 pages_new = map_all_hugepages(&tmp_hp[hp_offset], hpi, memory);
1517 if (pages_new < pages_old) {
1519 "%d not %d hugepages of size %u MB allocated\n",
1520 pages_new, pages_old,
1521 (unsigned)(hpi->hugepage_sz / 0x100000));
1523 int pages = pages_old - pages_new;
1525 nr_hugepages -= pages;
1526 hpi->num_pages[0] = pages_new;
1531 if (rte_eal_using_phys_addrs() &&
1532 rte_eal_iova_mode() != RTE_IOVA_VA) {
1533 /* find physical addresses for each hugepage */
1534 if (find_physaddrs(&tmp_hp[hp_offset], hpi) < 0) {
1535 RTE_LOG(DEBUG, EAL, "Failed to find phys addr "
1536 "for %u MB pages\n",
1537 (unsigned int)(hpi->hugepage_sz / 0x100000));
1541 /* set physical addresses for each hugepage */
1542 if (set_physaddrs(&tmp_hp[hp_offset], hpi) < 0) {
1543 RTE_LOG(DEBUG, EAL, "Failed to set phys addr "
1544 "for %u MB pages\n",
1545 (unsigned int)(hpi->hugepage_sz / 0x100000));
1550 if (find_numasocket(&tmp_hp[hp_offset], hpi) < 0){
1551 RTE_LOG(DEBUG, EAL, "Failed to find NUMA socket for %u MB pages\n",
1552 (unsigned)(hpi->hugepage_sz / 0x100000));
1556 qsort(&tmp_hp[hp_offset], hpi->num_pages[0],
1557 sizeof(struct hugepage_file), cmp_physaddr);
1559 /* we have processed a num of hugepages of this size, so inc offset */
1560 hp_offset += hpi->num_pages[0];
1563 huge_recover_sigbus();
1565 if (internal_config.memory == 0 && internal_config.force_sockets == 0)
1566 internal_config.memory = eal_get_hugepage_mem_size();
1568 nr_hugefiles = nr_hugepages;
1571 /* clean out the numbers of pages */
1572 for (i = 0; i < (int) internal_config.num_hugepage_sizes; i++)
1573 for (j = 0; j < RTE_MAX_NUMA_NODES; j++)
1574 internal_config.hugepage_info[i].num_pages[j] = 0;
1576 /* get hugepages for each socket */
1577 for (i = 0; i < nr_hugefiles; i++) {
1578 int socket = tmp_hp[i].socket_id;
1580 /* find a hugepage info with right size and increment num_pages */
1581 const int nb_hpsizes = RTE_MIN(MAX_HUGEPAGE_SIZES,
1582 (int)internal_config.num_hugepage_sizes);
1583 for (j = 0; j < nb_hpsizes; j++) {
1584 if (tmp_hp[i].size ==
1585 internal_config.hugepage_info[j].hugepage_sz) {
1586 internal_config.hugepage_info[j].num_pages[socket]++;
1591 /* make a copy of socket_mem, needed for number of pages calculation */
1592 for (i = 0; i < RTE_MAX_NUMA_NODES; i++)
1593 memory[i] = internal_config.socket_mem[i];
1595 /* calculate final number of pages */
1596 nr_hugepages = calc_num_pages_per_socket(memory,
1597 internal_config.hugepage_info, used_hp,
1598 internal_config.num_hugepage_sizes);
1600 /* error if not enough memory available */
1601 if (nr_hugepages < 0)
1605 for (i = 0; i < (int) internal_config.num_hugepage_sizes; i++) {
1606 for (j = 0; j < RTE_MAX_NUMA_NODES; j++) {
1607 if (used_hp[i].num_pages[j] > 0) {
1609 "Requesting %u pages of size %uMB"
1610 " from socket %i\n",
1611 used_hp[i].num_pages[j],
1613 (used_hp[i].hugepage_sz / 0x100000),
1619 /* create shared memory */
1620 hugepage = create_shared_memory(eal_hugepage_data_path(),
1621 nr_hugefiles * sizeof(struct hugepage_file));
1623 if (hugepage == NULL) {
1624 RTE_LOG(ERR, EAL, "Failed to create shared memory!\n");
1627 memset(hugepage, 0, nr_hugefiles * sizeof(struct hugepage_file));
1630 * unmap pages that we won't need (looks at used_hp).
1631 * also, sets final_va to NULL on pages that were unmapped.
1633 if (unmap_unneeded_hugepages(tmp_hp, used_hp,
1634 internal_config.num_hugepage_sizes) < 0) {
1635 RTE_LOG(ERR, EAL, "Unmapping and locking hugepages failed!\n");
1640 * copy stuff from malloc'd hugepage* to the actual shared memory.
1641 * this procedure only copies those hugepages that have orig_va
1642 * not NULL. has overflow protection.
1644 if (copy_hugepages_to_shared_mem(hugepage, nr_hugefiles,
1645 tmp_hp, nr_hugefiles) < 0) {
1646 RTE_LOG(ERR, EAL, "Copying tables to shared memory failed!\n");
1651 /* for legacy 32-bit mode, we did not preallocate VA space, so do it */
1652 if (internal_config.legacy_mem &&
1653 prealloc_segments(hugepage, nr_hugefiles)) {
1654 RTE_LOG(ERR, EAL, "Could not preallocate VA space for hugepages\n");
1659 /* remap all pages we do need into memseg list VA space, so that those
1660 * pages become first-class citizens in DPDK memory subsystem
1662 if (remap_needed_hugepages(hugepage, nr_hugefiles)) {
1663 RTE_LOG(ERR, EAL, "Couldn't remap hugepage files into memseg lists\n");
1667 /* free the hugepage backing files */
1668 if (internal_config.hugepage_unlink &&
1669 unlink_hugepage_files(tmp_hp, internal_config.num_hugepage_sizes) < 0) {
1670 RTE_LOG(ERR, EAL, "Unlinking hugepage files failed!\n");
1674 /* free the temporary hugepage table */
1678 munmap(hugepage, nr_hugefiles * sizeof(struct hugepage_file));
1681 /* we're not going to allocate more pages, so release VA space for
1682 * unused memseg lists
1684 for (i = 0; i < RTE_MAX_MEMSEG_LISTS; i++) {
1685 struct rte_memseg_list *msl = &mcfg->memsegs[i];
1688 /* skip inactive lists */
1689 if (msl->base_va == NULL)
1691 /* skip lists where there is at least one page allocated */
1692 if (msl->memseg_arr.count > 0)
1694 /* this is an unused list, deallocate it */
1696 munmap(msl->base_va, mem_sz);
1697 msl->base_va = NULL;
1700 /* destroy backing fbarray */
1701 rte_fbarray_destroy(&msl->memseg_arr);
1704 if (mcfg->dma_maskbits &&
1705 rte_mem_check_dma_mask_thread_unsafe(mcfg->dma_maskbits)) {
1707 "%s(): couldn't allocate memory due to IOVA exceeding limits of current DMA mask.\n",
1715 huge_recover_sigbus();
1717 if (hugepage != NULL)
1718 munmap(hugepage, nr_hugefiles * sizeof(struct hugepage_file));
1723 static int __rte_unused
1724 hugepage_count_walk(const struct rte_memseg_list *msl, void *arg)
1726 struct hugepage_info *hpi = arg;
1728 if (msl->page_sz != hpi->hugepage_sz)
1731 hpi->num_pages[msl->socket_id] += msl->memseg_arr.len;
1736 limits_callback(int socket_id, size_t cur_limit, size_t new_len)
1738 RTE_SET_USED(socket_id);
1739 RTE_SET_USED(cur_limit);
1740 RTE_SET_USED(new_len);
1745 eal_hugepage_init(void)
1747 struct hugepage_info used_hp[MAX_HUGEPAGE_SIZES];
1748 uint64_t memory[RTE_MAX_NUMA_NODES];
1749 int hp_sz_idx, socket_id;
1751 memset(used_hp, 0, sizeof(used_hp));
1754 hp_sz_idx < (int) internal_config.num_hugepage_sizes;
1757 struct hugepage_info dummy;
1760 /* also initialize used_hp hugepage sizes in used_hp */
1761 struct hugepage_info *hpi;
1762 hpi = &internal_config.hugepage_info[hp_sz_idx];
1763 used_hp[hp_sz_idx].hugepage_sz = hpi->hugepage_sz;
1766 /* for 32-bit, limit number of pages on socket to whatever we've
1767 * preallocated, as we cannot allocate more.
1769 memset(&dummy, 0, sizeof(dummy));
1770 dummy.hugepage_sz = hpi->hugepage_sz;
1771 if (rte_memseg_list_walk(hugepage_count_walk, &dummy) < 0)
1774 for (i = 0; i < RTE_DIM(dummy.num_pages); i++) {
1775 hpi->num_pages[i] = RTE_MIN(hpi->num_pages[i],
1776 dummy.num_pages[i]);
1781 /* make a copy of socket_mem, needed for balanced allocation. */
1782 for (hp_sz_idx = 0; hp_sz_idx < RTE_MAX_NUMA_NODES; hp_sz_idx++)
1783 memory[hp_sz_idx] = internal_config.socket_mem[hp_sz_idx];
1785 /* calculate final number of pages */
1786 if (calc_num_pages_per_socket(memory,
1787 internal_config.hugepage_info, used_hp,
1788 internal_config.num_hugepage_sizes) < 0)
1792 hp_sz_idx < (int)internal_config.num_hugepage_sizes;
1794 for (socket_id = 0; socket_id < RTE_MAX_NUMA_NODES;
1796 struct rte_memseg **pages;
1797 struct hugepage_info *hpi = &used_hp[hp_sz_idx];
1798 unsigned int num_pages = hpi->num_pages[socket_id];
1799 unsigned int num_pages_alloc;
1804 RTE_LOG(DEBUG, EAL, "Allocating %u pages of size %" PRIu64 "M on socket %i\n",
1805 num_pages, hpi->hugepage_sz >> 20, socket_id);
1807 /* we may not be able to allocate all pages in one go,
1808 * because we break up our memory map into multiple
1809 * memseg lists. therefore, try allocating multiple
1810 * times and see if we can get the desired number of
1811 * pages from multiple allocations.
1814 num_pages_alloc = 0;
1816 int i, cur_pages, needed;
1818 needed = num_pages - num_pages_alloc;
1820 pages = malloc(sizeof(*pages) * needed);
1822 /* do not request exact number of pages */
1823 cur_pages = eal_memalloc_alloc_seg_bulk(pages,
1824 needed, hpi->hugepage_sz,
1826 if (cur_pages <= 0) {
1831 /* mark preallocated pages as unfreeable */
1832 for (i = 0; i < cur_pages; i++) {
1833 struct rte_memseg *ms = pages[i];
1834 ms->flags |= RTE_MEMSEG_FLAG_DO_NOT_FREE;
1838 num_pages_alloc += cur_pages;
1839 } while (num_pages_alloc != num_pages);
1842 /* if socket limits were specified, set them */
1843 if (internal_config.force_socket_limits) {
1845 for (i = 0; i < RTE_MAX_NUMA_NODES; i++) {
1846 uint64_t limit = internal_config.socket_limit[i];
1849 if (rte_mem_alloc_validator_register("socket-limit",
1850 limits_callback, i, limit))
1851 RTE_LOG(ERR, EAL, "Failed to register socket limits validator callback\n");
1858 * uses fstat to report the size of a file on disk
1864 if (fstat(fd, &st) < 0)
1870 * This creates the memory mappings in the secondary process to match that of
1871 * the server process. It goes through each memory segment in the DPDK runtime
1872 * configuration and finds the hugepages which form that segment, mapping them
1873 * in order to form a contiguous block in the virtual memory space
1876 eal_legacy_hugepage_attach(void)
1878 struct rte_mem_config *mcfg = rte_eal_get_configuration()->mem_config;
1879 struct hugepage_file *hp = NULL;
1880 unsigned int num_hp = 0;
1882 unsigned int cur_seg;
1884 int fd, fd_hugepage = -1;
1886 if (aslr_enabled() > 0) {
1887 RTE_LOG(WARNING, EAL, "WARNING: Address Space Layout Randomization "
1888 "(ASLR) is enabled in the kernel.\n");
1889 RTE_LOG(WARNING, EAL, " This may cause issues with mapping memory "
1890 "into secondary processes\n");
1893 fd_hugepage = open(eal_hugepage_data_path(), O_RDONLY);
1894 if (fd_hugepage < 0) {
1895 RTE_LOG(ERR, EAL, "Could not open %s\n",
1896 eal_hugepage_data_path());
1900 size = getFileSize(fd_hugepage);
1901 hp = mmap(NULL, size, PROT_READ, MAP_PRIVATE, fd_hugepage, 0);
1902 if (hp == MAP_FAILED) {
1903 RTE_LOG(ERR, EAL, "Could not mmap %s\n",
1904 eal_hugepage_data_path());
1908 num_hp = size / sizeof(struct hugepage_file);
1909 RTE_LOG(DEBUG, EAL, "Analysing %u files\n", num_hp);
1911 /* map all segments into memory to make sure we get the addrs. the
1912 * segments themselves are already in memseg list (which is shared and
1913 * has its VA space already preallocated), so we just need to map
1914 * everything into correct addresses.
1916 for (i = 0; i < num_hp; i++) {
1917 struct hugepage_file *hf = &hp[i];
1918 size_t map_sz = hf->size;
1919 void *map_addr = hf->final_va;
1920 int msl_idx, ms_idx;
1921 struct rte_memseg_list *msl;
1922 struct rte_memseg *ms;
1924 /* if size is zero, no more pages left */
1928 fd = open(hf->filepath, O_RDWR);
1930 RTE_LOG(ERR, EAL, "Could not open %s: %s\n",
1931 hf->filepath, strerror(errno));
1935 map_addr = mmap(map_addr, map_sz, PROT_READ | PROT_WRITE,
1936 MAP_SHARED | MAP_FIXED, fd, 0);
1937 if (map_addr == MAP_FAILED) {
1938 RTE_LOG(ERR, EAL, "Could not map %s: %s\n",
1939 hf->filepath, strerror(errno));
1943 /* set shared lock on the file. */
1944 if (flock(fd, LOCK_SH) < 0) {
1945 RTE_LOG(DEBUG, EAL, "%s(): Locking file failed: %s\n",
1946 __func__, strerror(errno));
1950 /* find segment data */
1951 msl = rte_mem_virt2memseg_list(map_addr);
1953 RTE_LOG(DEBUG, EAL, "%s(): Cannot find memseg list\n",
1957 ms = rte_mem_virt2memseg(map_addr, msl);
1959 RTE_LOG(DEBUG, EAL, "%s(): Cannot find memseg\n",
1964 msl_idx = msl - mcfg->memsegs;
1965 ms_idx = rte_fbarray_find_idx(&msl->memseg_arr, ms);
1967 RTE_LOG(DEBUG, EAL, "%s(): Cannot find memseg idx\n",
1972 /* store segment fd internally */
1973 if (eal_memalloc_set_seg_fd(msl_idx, ms_idx, fd) < 0)
1974 RTE_LOG(ERR, EAL, "Could not store segment fd: %s\n",
1975 rte_strerror(rte_errno));
1977 /* unmap the hugepage config file, since we are done using it */
1983 munmap(hp[i].final_va, hp[i].size);
1987 /* unwind mmap's done so far */
1988 for (cur_seg = 0; cur_seg < i; cur_seg++)
1989 munmap(hp[cur_seg].final_va, hp[cur_seg].size);
1991 if (hp != NULL && hp != MAP_FAILED)
1993 if (fd_hugepage >= 0)
1999 eal_hugepage_attach(void)
2001 if (eal_memalloc_sync_with_primary()) {
2002 RTE_LOG(ERR, EAL, "Could not map memory from primary process\n");
2003 if (aslr_enabled() > 0)
2004 RTE_LOG(ERR, EAL, "It is recommended to disable ASLR in the kernel and retry running both primary and secondary processes\n");
2011 rte_eal_hugepage_init(void)
2013 return internal_config.legacy_mem ?
2014 eal_legacy_hugepage_init() :
2015 eal_hugepage_init();
2019 rte_eal_hugepage_attach(void)
2021 return internal_config.legacy_mem ?
2022 eal_legacy_hugepage_attach() :
2023 eal_hugepage_attach();
2027 rte_eal_using_phys_addrs(void)
2029 if (phys_addrs_available == -1) {
2032 if (rte_eal_has_hugepages() != 0 &&
2033 rte_mem_virt2phy(&tmp) != RTE_BAD_PHYS_ADDR)
2034 phys_addrs_available = 1;
2036 phys_addrs_available = 0;
2038 return phys_addrs_available;
2041 static int __rte_unused
2042 memseg_primary_init_32(void)
2044 struct rte_mem_config *mcfg = rte_eal_get_configuration()->mem_config;
2045 int active_sockets, hpi_idx, msl_idx = 0;
2046 unsigned int socket_id, i;
2047 struct rte_memseg_list *msl;
2048 uint64_t extra_mem_per_socket, total_extra_mem, total_requested_mem;
2051 /* no-huge does not need this at all */
2052 if (internal_config.no_hugetlbfs)
2055 /* this is a giant hack, but desperate times call for desperate
2056 * measures. in legacy 32-bit mode, we cannot preallocate VA space,
2057 * because having upwards of 2 gigabytes of VA space already mapped will
2058 * interfere with our ability to map and sort hugepages.
2060 * therefore, in legacy 32-bit mode, we will be initializing memseg
2061 * lists much later - in eal_memory.c, right after we unmap all the
2062 * unneeded pages. this will not affect secondary processes, as those
2063 * should be able to mmap the space without (too many) problems.
2065 if (internal_config.legacy_mem)
2068 /* 32-bit mode is a very special case. we cannot know in advance where
2069 * the user will want to allocate their memory, so we have to do some
2073 total_requested_mem = 0;
2074 if (internal_config.force_sockets)
2075 for (i = 0; i < rte_socket_count(); i++) {
2078 socket_id = rte_socket_id_by_idx(i);
2079 mem = internal_config.socket_mem[socket_id];
2085 total_requested_mem += mem;
2088 total_requested_mem = internal_config.memory;
2090 max_mem = (uint64_t)RTE_MAX_MEM_MB << 20;
2091 if (total_requested_mem > max_mem) {
2092 RTE_LOG(ERR, EAL, "Invalid parameters: 32-bit process can at most use %uM of memory\n",
2093 (unsigned int)(max_mem >> 20));
2096 total_extra_mem = max_mem - total_requested_mem;
2097 extra_mem_per_socket = active_sockets == 0 ? total_extra_mem :
2098 total_extra_mem / active_sockets;
2100 /* the allocation logic is a little bit convoluted, but here's how it
2101 * works, in a nutshell:
2102 * - if user hasn't specified on which sockets to allocate memory via
2103 * --socket-mem, we allocate all of our memory on master core socket.
2104 * - if user has specified sockets to allocate memory on, there may be
2105 * some "unused" memory left (e.g. if user has specified --socket-mem
2106 * such that not all memory adds up to 2 gigabytes), so add it to all
2107 * sockets that are in use equally.
2109 * page sizes are sorted by size in descending order, so we can safely
2110 * assume that we dispense with bigger page sizes first.
2113 /* create memseg lists */
2114 for (i = 0; i < rte_socket_count(); i++) {
2115 int hp_sizes = (int) internal_config.num_hugepage_sizes;
2116 uint64_t max_socket_mem, cur_socket_mem;
2117 unsigned int master_lcore_socket;
2118 struct rte_config *cfg = rte_eal_get_configuration();
2121 socket_id = rte_socket_id_by_idx(i);
2123 #ifndef RTE_EAL_NUMA_AWARE_HUGEPAGES
2124 /* we can still sort pages by socket in legacy mode */
2125 if (!internal_config.legacy_mem && socket_id > 0)
2129 /* if we didn't specifically request memory on this socket */
2130 skip = active_sockets != 0 &&
2131 internal_config.socket_mem[socket_id] == 0;
2132 /* ...or if we didn't specifically request memory on *any*
2133 * socket, and this is not master lcore
2135 master_lcore_socket = rte_lcore_to_socket_id(cfg->master_lcore);
2136 skip |= active_sockets == 0 && socket_id != master_lcore_socket;
2139 RTE_LOG(DEBUG, EAL, "Will not preallocate memory on socket %u\n",
2144 /* max amount of memory on this socket */
2145 max_socket_mem = (active_sockets != 0 ?
2146 internal_config.socket_mem[socket_id] :
2147 internal_config.memory) +
2148 extra_mem_per_socket;
2151 for (hpi_idx = 0; hpi_idx < hp_sizes; hpi_idx++) {
2152 uint64_t max_pagesz_mem, cur_pagesz_mem = 0;
2153 uint64_t hugepage_sz;
2154 struct hugepage_info *hpi;
2155 int type_msl_idx, max_segs, total_segs = 0;
2157 hpi = &internal_config.hugepage_info[hpi_idx];
2158 hugepage_sz = hpi->hugepage_sz;
2160 /* check if pages are actually available */
2161 if (hpi->num_pages[socket_id] == 0)
2164 max_segs = RTE_MAX_MEMSEG_PER_TYPE;
2165 max_pagesz_mem = max_socket_mem - cur_socket_mem;
2167 /* make it multiple of page size */
2168 max_pagesz_mem = RTE_ALIGN_FLOOR(max_pagesz_mem,
2171 RTE_LOG(DEBUG, EAL, "Attempting to preallocate "
2172 "%" PRIu64 "M on socket %i\n",
2173 max_pagesz_mem >> 20, socket_id);
2176 while (cur_pagesz_mem < max_pagesz_mem &&
2177 total_segs < max_segs) {
2179 unsigned int n_segs;
2181 if (msl_idx >= RTE_MAX_MEMSEG_LISTS) {
2183 "No more space in memseg lists, please increase %s\n",
2184 RTE_STR(CONFIG_RTE_MAX_MEMSEG_LISTS));
2188 msl = &mcfg->memsegs[msl_idx];
2190 cur_mem = get_mem_amount(hugepage_sz,
2192 n_segs = cur_mem / hugepage_sz;
2194 if (alloc_memseg_list(msl, hugepage_sz, n_segs,
2195 socket_id, type_msl_idx)) {
2196 /* failing to allocate a memseg list is
2199 RTE_LOG(ERR, EAL, "Cannot allocate memseg list\n");
2203 if (alloc_va_space(msl)) {
2204 /* if we couldn't allocate VA space, we
2205 * can try with smaller page sizes.
2207 RTE_LOG(ERR, EAL, "Cannot allocate VA space for memseg list, retrying with different page size\n");
2208 /* deallocate memseg list */
2209 if (free_memseg_list(msl))
2214 total_segs += msl->memseg_arr.len;
2215 cur_pagesz_mem = total_segs * hugepage_sz;
2219 cur_socket_mem += cur_pagesz_mem;
2221 if (cur_socket_mem == 0) {
2222 RTE_LOG(ERR, EAL, "Cannot allocate VA space on socket %u\n",
2231 static int __rte_unused
2232 memseg_primary_init(void)
2234 struct rte_mem_config *mcfg = rte_eal_get_configuration()->mem_config;
2239 int i, hpi_idx, msl_idx, ret = -1; /* fail unless told to succeed */
2240 struct rte_memseg_list *msl;
2241 uint64_t max_mem, max_mem_per_type;
2242 unsigned int max_seglists_per_type;
2243 unsigned int n_memtypes, cur_type;
2245 /* no-huge does not need this at all */
2246 if (internal_config.no_hugetlbfs)
2250 * figuring out amount of memory we're going to have is a long and very
2251 * involved process. the basic element we're operating with is a memory
2252 * type, defined as a combination of NUMA node ID and page size (so that
2253 * e.g. 2 sockets with 2 page sizes yield 4 memory types in total).
2255 * deciding amount of memory going towards each memory type is a
2256 * balancing act between maximum segments per type, maximum memory per
2257 * type, and number of detected NUMA nodes. the goal is to make sure
2258 * each memory type gets at least one memseg list.
2260 * the total amount of memory is limited by RTE_MAX_MEM_MB value.
2262 * the total amount of memory per type is limited by either
2263 * RTE_MAX_MEM_MB_PER_TYPE, or by RTE_MAX_MEM_MB divided by the number
2264 * of detected NUMA nodes. additionally, maximum number of segments per
2265 * type is also limited by RTE_MAX_MEMSEG_PER_TYPE. this is because for
2266 * smaller page sizes, it can take hundreds of thousands of segments to
2267 * reach the above specified per-type memory limits.
2269 * additionally, each type may have multiple memseg lists associated
2270 * with it, each limited by either RTE_MAX_MEM_MB_PER_LIST for bigger
2271 * page sizes, or RTE_MAX_MEMSEG_PER_LIST segments for smaller ones.
2273 * the number of memseg lists per type is decided based on the above
2274 * limits, and also taking number of detected NUMA nodes, to make sure
2275 * that we don't run out of memseg lists before we populate all NUMA
2276 * nodes with memory.
2278 * we do this in three stages. first, we collect the number of types.
2279 * then, we figure out memory constraints and populate the list of
2280 * would-be memseg lists. then, we go ahead and allocate the memseg
2284 /* create space for mem types */
2285 n_memtypes = internal_config.num_hugepage_sizes * rte_socket_count();
2286 memtypes = calloc(n_memtypes, sizeof(*memtypes));
2287 if (memtypes == NULL) {
2288 RTE_LOG(ERR, EAL, "Cannot allocate space for memory types\n");
2292 /* populate mem types */
2294 for (hpi_idx = 0; hpi_idx < (int) internal_config.num_hugepage_sizes;
2296 struct hugepage_info *hpi;
2297 uint64_t hugepage_sz;
2299 hpi = &internal_config.hugepage_info[hpi_idx];
2300 hugepage_sz = hpi->hugepage_sz;
2302 for (i = 0; i < (int) rte_socket_count(); i++, cur_type++) {
2303 int socket_id = rte_socket_id_by_idx(i);
2305 #ifndef RTE_EAL_NUMA_AWARE_HUGEPAGES
2306 /* we can still sort pages by socket in legacy mode */
2307 if (!internal_config.legacy_mem && socket_id > 0)
2310 memtypes[cur_type].page_sz = hugepage_sz;
2311 memtypes[cur_type].socket_id = socket_id;
2313 RTE_LOG(DEBUG, EAL, "Detected memory type: "
2314 "socket_id:%u hugepage_sz:%" PRIu64 "\n",
2315 socket_id, hugepage_sz);
2318 /* number of memtypes could have been lower due to no NUMA support */
2319 n_memtypes = cur_type;
2321 /* set up limits for types */
2322 max_mem = (uint64_t)RTE_MAX_MEM_MB << 20;
2323 max_mem_per_type = RTE_MIN((uint64_t)RTE_MAX_MEM_MB_PER_TYPE << 20,
2324 max_mem / n_memtypes);
2326 * limit maximum number of segment lists per type to ensure there's
2327 * space for memseg lists for all NUMA nodes with all page sizes
2329 max_seglists_per_type = RTE_MAX_MEMSEG_LISTS / n_memtypes;
2331 if (max_seglists_per_type == 0) {
2332 RTE_LOG(ERR, EAL, "Cannot accommodate all memory types, please increase %s\n",
2333 RTE_STR(CONFIG_RTE_MAX_MEMSEG_LISTS));
2337 /* go through all mem types and create segment lists */
2339 for (cur_type = 0; cur_type < n_memtypes; cur_type++) {
2340 unsigned int cur_seglist, n_seglists, n_segs;
2341 unsigned int max_segs_per_type, max_segs_per_list;
2342 struct memtype *type = &memtypes[cur_type];
2343 uint64_t max_mem_per_list, pagesz;
2346 pagesz = type->page_sz;
2347 socket_id = type->socket_id;
2350 * we need to create segment lists for this type. we must take
2351 * into account the following things:
2353 * 1. total amount of memory we can use for this memory type
2354 * 2. total amount of memory per memseg list allowed
2355 * 3. number of segments needed to fit the amount of memory
2356 * 4. number of segments allowed per type
2357 * 5. number of segments allowed per memseg list
2358 * 6. number of memseg lists we are allowed to take up
2361 /* calculate how much segments we will need in total */
2362 max_segs_per_type = max_mem_per_type / pagesz;
2363 /* limit number of segments to maximum allowed per type */
2364 max_segs_per_type = RTE_MIN(max_segs_per_type,
2365 (unsigned int)RTE_MAX_MEMSEG_PER_TYPE);
2366 /* limit number of segments to maximum allowed per list */
2367 max_segs_per_list = RTE_MIN(max_segs_per_type,
2368 (unsigned int)RTE_MAX_MEMSEG_PER_LIST);
2370 /* calculate how much memory we can have per segment list */
2371 max_mem_per_list = RTE_MIN(max_segs_per_list * pagesz,
2372 (uint64_t)RTE_MAX_MEM_MB_PER_LIST << 20);
2374 /* calculate how many segments each segment list will have */
2375 n_segs = RTE_MIN(max_segs_per_list, max_mem_per_list / pagesz);
2377 /* calculate how many segment lists we can have */
2378 n_seglists = RTE_MIN(max_segs_per_type / n_segs,
2379 max_mem_per_type / max_mem_per_list);
2381 /* limit number of segment lists according to our maximum */
2382 n_seglists = RTE_MIN(n_seglists, max_seglists_per_type);
2384 RTE_LOG(DEBUG, EAL, "Creating %i segment lists: "
2385 "n_segs:%i socket_id:%i hugepage_sz:%" PRIu64 "\n",
2386 n_seglists, n_segs, socket_id, pagesz);
2388 /* create all segment lists */
2389 for (cur_seglist = 0; cur_seglist < n_seglists; cur_seglist++) {
2390 if (msl_idx >= RTE_MAX_MEMSEG_LISTS) {
2392 "No more space in memseg lists, please increase %s\n",
2393 RTE_STR(CONFIG_RTE_MAX_MEMSEG_LISTS));
2396 msl = &mcfg->memsegs[msl_idx++];
2398 if (alloc_memseg_list(msl, pagesz, n_segs,
2399 socket_id, cur_seglist))
2402 if (alloc_va_space(msl)) {
2403 RTE_LOG(ERR, EAL, "Cannot allocate VA space for memseg list\n");
2408 /* we're successful */
2416 memseg_secondary_init(void)
2418 struct rte_mem_config *mcfg = rte_eal_get_configuration()->mem_config;
2420 struct rte_memseg_list *msl;
2422 for (msl_idx = 0; msl_idx < RTE_MAX_MEMSEG_LISTS; msl_idx++) {
2424 msl = &mcfg->memsegs[msl_idx];
2426 /* skip empty memseg lists */
2427 if (msl->memseg_arr.len == 0)
2430 if (rte_fbarray_attach(&msl->memseg_arr)) {
2431 RTE_LOG(ERR, EAL, "Cannot attach to primary process memseg lists\n");
2435 /* preallocate VA space */
2436 if (alloc_va_space(msl)) {
2437 RTE_LOG(ERR, EAL, "Cannot preallocate VA space for hugepage memory\n");
2446 rte_eal_memseg_init(void)
2448 /* increase rlimit to maximum */
2451 if (getrlimit(RLIMIT_NOFILE, &lim) == 0) {
2452 /* set limit to maximum */
2453 lim.rlim_cur = lim.rlim_max;
2455 if (setrlimit(RLIMIT_NOFILE, &lim) < 0) {
2456 RTE_LOG(DEBUG, EAL, "Setting maximum number of open files failed: %s\n",
2459 RTE_LOG(DEBUG, EAL, "Setting maximum number of open files to %"
2461 (uint64_t)lim.rlim_cur);
2464 RTE_LOG(ERR, EAL, "Cannot get current resource limits\n");
2466 #ifndef RTE_EAL_NUMA_AWARE_HUGEPAGES
2467 if (!internal_config.legacy_mem && rte_socket_count() > 1) {
2468 RTE_LOG(WARNING, EAL, "DPDK is running on a NUMA system, but is compiled without NUMA support.\n");
2469 RTE_LOG(WARNING, EAL, "This will have adverse consequences for performance and usability.\n");
2470 RTE_LOG(WARNING, EAL, "Please use --"OPT_LEGACY_MEM" option, or recompile with NUMA support.\n");
2474 return rte_eal_process_type() == RTE_PROC_PRIMARY ?
2476 memseg_primary_init_32() :
2478 memseg_primary_init() :
2480 memseg_secondary_init();