| 512 | } |
| 513 | |
| 514 | static int |
| 515 | alloc_seg(struct rte_memseg *ms, void *addr, int socket_id, |
| 516 | struct hugepage_info *hi, unsigned int list_idx, |
| 517 | unsigned int seg_idx) |
| 518 | { |
| 519 | #ifdef RTE_EAL_NUMA_AWARE_HUGEPAGES |
| 520 | int cur_socket_id = 0; |
| 521 | #endif |
| 522 | uint64_t map_offset; |
| 523 | rte_iova_t iova; |
| 524 | void *va; |
| 525 | char path[PATH_MAX]; |
| 526 | int ret = 0; |
| 527 | int fd; |
| 528 | bool dirty; |
| 529 | size_t alloc_sz; |
| 530 | int flags; |
| 531 | void *new_addr; |
| 532 | const struct internal_config *internal_conf = |
| 533 | eal_get_internal_configuration(); |
| 534 | |
| 535 | alloc_sz = hi->hugepage_sz; |
| 536 | |
| 537 | /* these are checked at init, but code analyzers don't know that */ |
| 538 | if (internal_conf->in_memory && !anonymous_hugepages_supported) { |
| 539 | RTE_LOG(ERR, EAL, "Anonymous hugepages not supported, in-memory mode cannot allocate memory\n"); |
| 540 | return -1; |
| 541 | } |
| 542 | if (internal_conf->in_memory && !memfd_create_supported && |
| 543 | internal_conf->single_file_segments) { |
| 544 | RTE_LOG(ERR, EAL, "Single-file segments are not supported without memfd support\n"); |
| 545 | return -1; |
| 546 | } |
| 547 | |
| 548 | /* in-memory without memfd is a special case */ |
| 549 | int mmap_flags; |
| 550 | |
| 551 | if (internal_conf->in_memory && !memfd_create_supported) { |
| 552 | const int in_memory_flags = MAP_HUGETLB | MAP_FIXED | |
| 553 | MAP_PRIVATE | MAP_ANONYMOUS; |
| 554 | int pagesz_flag; |
| 555 | |
| 556 | pagesz_flag = pagesz_flags(alloc_sz); |
| 557 | fd = -1; |
| 558 | dirty = false; |
| 559 | mmap_flags = in_memory_flags | pagesz_flag; |
| 560 | |
| 561 | /* single-file segments codepath will never be active |
| 562 | * here because in-memory mode is incompatible with the |
| 563 | * fallback path, and it's stopped at EAL initialization |
| 564 | * stage. |
| 565 | */ |
| 566 | map_offset = 0; |
| 567 | } else { |
| 568 | /* takes out a read lock on segment or segment list */ |
| 569 | fd = get_seg_fd(path, sizeof(path), hi, list_idx, seg_idx, |
| 570 | &dirty); |
| 571 | if (fd < 0) { |
no test coverage detected