| 1734 | } |
| 1735 | |
| 1736 | int |
| 1737 | eal_memalloc_init(void) |
| 1738 | { |
| 1739 | const struct internal_config *internal_conf = |
| 1740 | eal_get_internal_configuration(); |
| 1741 | |
| 1742 | if (rte_eal_process_type() == RTE_PROC_SECONDARY) |
| 1743 | /* memory_hotplug_lock is held during initialization, so it's |
| 1744 | * safe to call thread-unsafe version. |
| 1745 | */ |
| 1746 | if (rte_memseg_list_walk_thread_unsafe(secondary_msl_create_walk, NULL) < 0) |
| 1747 | return -1; |
| 1748 | if (rte_eal_process_type() == RTE_PROC_PRIMARY && |
| 1749 | internal_conf->in_memory) { |
| 1750 | int mfd_res = test_memfd_create(); |
| 1751 | |
| 1752 | if (mfd_res < 0) { |
| 1753 | RTE_LOG(ERR, EAL, "Unable to check if memfd is supported\n"); |
| 1754 | return -1; |
| 1755 | } |
| 1756 | if (mfd_res == 1) |
| 1757 | RTE_LOG(DEBUG, EAL, "Using memfd for anonymous memory\n"); |
| 1758 | else |
| 1759 | RTE_LOG(INFO, EAL, "Using memfd is not supported, falling back to anonymous hugepages\n"); |
| 1760 | |
| 1761 | /* we only support single-file segments mode with in-memory mode |
| 1762 | * if we support hugetlbfs with memfd_create. this code will |
| 1763 | * test if we do. |
| 1764 | */ |
| 1765 | if (internal_conf->single_file_segments && |
| 1766 | mfd_res != 1) { |
| 1767 | RTE_LOG(ERR, EAL, "Single-file segments mode cannot be used without memfd support\n"); |
| 1768 | return -1; |
| 1769 | } |
| 1770 | /* this cannot ever happen but better safe than sorry */ |
| 1771 | if (!anonymous_hugepages_supported) { |
| 1772 | RTE_LOG(ERR, EAL, "Using anonymous memory is not supported\n"); |
| 1773 | return -1; |
| 1774 | } |
| 1775 | /* safety net, should be impossible to configure */ |
| 1776 | if (internal_conf->hugepage_file.unlink_before_mapping && |
| 1777 | !internal_conf->hugepage_file.unlink_existing) { |
| 1778 | RTE_LOG(ERR, EAL, "Unlinking existing hugepage files is prohibited, cannot unlink them before mapping.\n"); |
| 1779 | return -1; |
| 1780 | } |
| 1781 | } |
| 1782 | |
| 1783 | /* initialize all of the fd lists */ |
| 1784 | if (rte_memseg_list_walk_thread_unsafe(fd_list_create_walk, NULL)) |
| 1785 | return -1; |
| 1786 | return 0; |
| 1787 | } |
no test coverage detected