Memory Hotplug for DPDK
Subsystems (4)
PATCH v6 45/70 memzone: use walk instead of iteration for dumping
In reply to Anatoly BurakovSimplify memzone dump code to use memzone walk, to not maintain the same memzone iteration code twice.
--- lib/librte_eal/common/eal_common_memzone.c | 42 +++++++++++++++--------------- 1 file changed, 21 insertions(+), 21 deletions(-)
lib/librte_eal/common/eal_common_memzone.c +21 -21
@@ -360,31 +360,31 @@ rte_memzone_lookup(const char *name)return memzone; } +static void +dump_memzone (const struct rte_memzone *mz,void *arg) +{ +struct rte_mem_config *mcfg =rte_eal_get_configuration ()->mem_config; +FILE *f = arg; +int mz_idx; + + mz_idx = mz - mcfg->memzone; + +fprintf (f,"Zone %u: name:<%s>, IO:0x%" PRIx64", len:0x%zx, virt:%p, " +"socket_id:%" PRId32", flags:%" PRIx32"\n" , + mz_idx, + mz->name, + mz->iova, + mz->len, + mz->addr, + mz->socket_id, + mz->flags); +} +/* Dump all reserved memory zones on console */ void rte_memzone_dump (FILE *f) { -struct rte_mem_config *mcfg; -unsigned i =0 ; - -/* get pointer to global configuration */ - mcfg =rte_eal_get_configuration ()->mem_config; - -rte_rwlock_read_lock (&mcfg->mlock); -/* dump all zones */ -for (i=0 ; i<RTE_MAX_MEMZONE ; i++) { -if (mcfg->memzone[i].addr ==NULL ) -break ; -fprintf (f,"Zone %u: name:<%s>, IO:0x%" PRIx64", len:0x%zx" -", virt:%p, socket_id:%" PRId32", flags:%" PRIx32"\n" , i, - mcfg->memzone[i].name, - mcfg->memzone[i].iova, - mcfg->memzone[i].len, - mcfg->memzone[i].addr, - mcfg->memzone[i].socket_id, - mcfg->memzone[i].flags); - } -rte_rwlock_read_unlock (&mcfg->mlock); +rte_memzone_walk (dump_memzone, f); }/*
Signature · 1 line
2.7.4
PATCH v6 46/70 vfio: allow to map other memory regions
In reply to Anatoly BurakovCurrently it is not possible to use memory that is not owned by DPDK to perform DMA. This scenarion might be used in vhost applications (like SPDK) where guest send its own memory table. To fill this gap provide API to allow registering arbitrary address in VFIO container.
--- lib/librte_eal/bsdapp/eal/eal.c | 16 + lib/librte_eal/common/include/rte_vfio.h | 41 ++ lib/librte_eal/linuxapp/eal/eal_vfio.c | 708 +++++++++++++++++++++++++++---- lib/librte_eal/linuxapp/eal/eal_vfio.h | 12 + lib/librte_eal/rte_eal_version.map | 2 + 5 files changed, 705 insertions(+), 74 deletions(-)
lib/librte_eal/bsdapp/eal/eal.c +16 -0
@@ -749,6 +749,8 @@ int rte_vfio_enable(const char *modname);int rte_vfio_is_enabled (const char *modname);int rte_vfio_noiommu_is_enabled (void );int rte_vfio_clear_group (int vfio_group_fd); +int rte_vfio_dma_map (uint64_t vaddr,uint64_t iova,uint64_t len); +int rte_vfio_dma_unmap (uint64_t vaddr,uint64_t iova,uint64_t len); int rte_vfio_setup_device(__rte_unused const char *sysfs_base, __rte_unused const char *dev_addr,
@@ -784,3 +786,17 @@ int rte_vfio_clear_group(__rte_unused int vfio_group_fd) {return 0 ; } + +int __rte_experimental +rte_vfio_dma_map(uint64_t __rte_unused vaddr, __rte_unused uint64_t iova, + __rte_unused uint64_t len) +{ +return -1 ; +} + +int __rte_experimental +rte_vfio_dma_unmap(uint64_t __rte_unused vaddr, uint64_t __rte_unused iova, + __rte_unused uint64_t len) +{ +return -1 ; +}
lib/librte_eal/common/include/rte_vfio.h +41 -0
47 lines not on this page · raw message
lib/librte_eal/linuxapp/eal/eal_vfio.c +634 -74
831 lines not on this page · raw message
lib/librte_eal/linuxapp/eal/eal_vfio.h +12 -0
@@ -19,6 +19,7 @@#ifdef VFIO_PRESENT +#include <stdint.h> #include <linux/vfio.h> #define RTE_VFIO_TYPE1 VFIO_TYPE1_IOMMU
@@ -26,6 +27,7 @@#ifndef VFIO_SPAPR_TCE_v2_IOMMU#define RTE_VFIO_SPAPR 7#define VFIO_IOMMU_SPAPR_REGISTER_MEMORY _IO(VFIO_TYPE, VFIO_BASE + 17) +#define VFIO_IOMMU_SPAPR_UNREGISTER_MEMORY _IO(VFIO_TYPE, VFIO_BASE + 18)#define VFIO_IOMMU_SPAPR_TCE_CREATE _IO(VFIO_TYPE, VFIO_BASE + 19)#define VFIO_IOMMU_SPAPR_TCE_REMOVE _IO(VFIO_TYPE, VFIO_BASE + 20)
@@ -110,6 +112,7 @@ struct vfio_config {int vfio_enabled;int vfio_container_fd;int vfio_active_groups; +const struct vfio_iommu_type *vfio_iommu_type;struct vfio_group vfio_groups[VFIO_MAX_GROUPS ]; };
@@ -119,9 +122,18 @@ struct vfio_config {* */ typedef int (*vfio_dma_func_t )(int ); +/* Custom memory region DMA mapping function prototype. +* Takes VFIO container fd, virtual address, phisical address, length and +* operation type (0 to unmap 1 for map) as a parameters. +* Returns 0 on success, -1 on error. +**/ +typedef int (*vfio_dma_user_func_t )(int fd,uint64_t vaddr,uint64_t iova, +uint64_t len,int do_map); +struct vfio_iommu_type {int type_id;const char *name; +vfio_dma_user_func_t dma_user_map_func;vfio_dma_func_t dma_map_func; };
lib/librte_eal/rte_eal_version.map +2 -0
@@ -263,5 +263,7 @@ EXPERIMENTAL { rte_service_start_with_defaults; rte_socket_count; rte_socket_id_by_idx; + rte_vfio_dma_map; + rte_vfio_dma_unmap; } DPDK_18.02;
Signature · 1 line
2.7.4
PATCH v6 47/70 eal: add legacy memory option
In reply to Anatoly BurakovThis adds a "--legacy-mem" command-line switch. It will be used to go back to the old memory behavior, one where we can't dynamically allocate/free memory (the downside), but one where the user can get physically contiguous memory, like before (the upside).
For now, nothing but the legacy behavior exists, non-legacy memory init sequence will be added later. For FreeBSD, non-legacy memory init will never be enabled, while for Linux, it is disabled in this patch to avoid breaking bisect, but will be enabled once non-legacy mode will be fully operational.
--- lib/librte_eal/bsdapp/eal/eal.c | 3 +++ lib/librte_eal/common/eal_common_options.c | 6 ++++++ lib/librte_eal/common/eal_internal_cfg.h | 4 ++++ lib/librte_eal/common/eal_options.h | 2 ++ lib/librte_eal/linuxapp/eal/eal.c | 3 +++ lib/librte_eal/linuxapp/eal/eal_memory.c | 24 ++++++++++++++++++++---- 6 files changed, 38 insertions(+), 4 deletions(-)
lib/librte_eal/bsdapp/eal/eal.c +3 -0
@@ -534,6 +534,9 @@ rte_eal_init(int argc, char **argv)return -1 ; } +/* FreeBSD always uses legacy memory model */ + internal_config.legacy_mem = true; +if (eal_plugins_init () <0 ) {rte_eal_init_alert ("Cannot init plugins\n" ); rte_errno =EINVAL ;
lib/librte_eal/common/eal_common_options.c +6 -0
@@ -73,6 +73,7 @@ eal_long_options[] = { {OPT_VDEV, 1, NULL, OPT_VDEV_NUM }, {OPT_VFIO_INTR, 1, NULL, OPT_VFIO_INTR_NUM }, {OPT_VMWARE_TSC_MAP, 0, NULL, OPT_VMWARE_TSC_MAP_NUM }, + {OPT_LEGACY_MEM, 0, NULL, OPT_LEGACY_MEM_NUM }, {0, 0, NULL, 0 } };
@@ -1113,6 +1114,8 @@ eal_parse_common_option(int opt, const char *optarg,case OPT_NO_HUGE_NUM : conf->no_hugetlbfs =1 ; +/* no-huge is legacy mem */ + conf->legacy_mem =1 ;break ;case OPT_NO_PCI_NUM :
@@ -1184,6 +1187,9 @@ eal_parse_common_option(int opt, const char *optarg, core_parsed =LCORE_OPT_MAP ;break ; +case OPT_LEGACY_MEM_NUM : + conf->legacy_mem =1 ; +break ;/* don't know what to do, leave this to caller */ default :
lib/librte_eal/common/eal_internal_cfg.h +4 -0
@@ -47,6 +47,10 @@ struct internal_config {volatile unsigned force_sockets;volatile uint64_t socket_mem[RTE_MAX_NUMA_NODES ];/**< amount of memory per socket */ uintptr_t base_virtaddr;/**< base address to try and reserve memory from */ +volatile unsigned legacy_mem; +/**< true to enable legacy memory behavior (no dynamic allocation, +* IOVA-contiguous segments). +*/ volatile int syslog_facility;/**< facility passed to openlog() */ /** default interrupt mode for VFIO */ volatile enum rte_intr_mode vfio_intr_mode;
lib/librte_eal/common/eal_options.h +2 -0
@@ -55,6 +55,8 @@ enum {OPT_VFIO_INTR_NUM , #define OPT_VMWARE_TSC_MAP "vmware-tsc-map"OPT_VMWARE_TSC_MAP_NUM , +#define OPT_LEGACY_MEM "legacy-mem" +OPT_LEGACY_MEM_NUM , OPT_LONG_MAX_NUM };
lib/librte_eal/linuxapp/eal/eal.c +3 -0
@@ -348,6 +348,7 @@ eal_usage(const char *prgname)" --" OPT_BASE_VIRTADDR " Base virtual address\n" " --" OPT_CREATE_UIO_DEV " Create /dev/uioX (usually done by hotplug)\n" " --" OPT_VFIO_INTR " Interrupt mode for VFIO (legacy|msi|msix)\n" +" --" OPT_LEGACY_MEM " Legacy memory mode (no dynamic allocation, contiguous segments)\n" "\n");/* Allow the application to print its usage message too if hook is set */ if ( rte_application_usage_hook ) {
@@ -767,6 +768,8 @@ rte_eal_init(int argc, char **argv)rte_atomic32_clear (&run_once);return -1 ; } +/* for now, always set legacy mem */ + internal_config.legacy_mem =1 ;if (eal_plugins_init () <0 ) {rte_eal_init_alert ("Cannot init plugins\n" );
lib/librte_eal/linuxapp/eal/eal_memory.c +20 -4
@@ -922,8 +922,8 @@ huge_recover_sigbus(void)* 6. unmap the first mapping * 7. fill memsegs in configuration with contiguous zones */ -int -rte_eal_hugepage_init (void ) +static int +eal_legacy_hugepage_init (void ) {struct rte_mem_config *mcfg;struct hugepage_file *hugepage =NULL , *tmp_hp =NULL ;
@@ -1266,8 +1266,8 @@ getFileSize(int fd)* configuration and finds the hugepages which form that segment, mapping them * in order to form a contiguous block in the virtual memory space */ -int -rte_eal_hugepage_attach (void ) +static int +eal_legacy_hugepage_attach (void ) {const struct rte_mem_config *mcfg =rte_eal_get_configuration ()->mem_config;struct hugepage_file *hp =NULL ;
@@ -1403,6 +1403,22 @@ rte_eal_hugepage_attach(void) }int +rte_eal_hugepage_init (void ) +{ +if (internal_config.legacy_mem) +return eal_legacy_hugepage_init (); +return -1 ; +} + +int +rte_eal_hugepage_attach (void ) +{ +if (internal_config.legacy_mem) +return eal_legacy_hugepage_attach (); +return -1 ; +} + +int rte_eal_using_phys_addrs (void ) {return phys_addrs_available;
Signature · 1 line
2.7.4
PATCH v6 48/70 eal: add shared indexed file-backed array
In reply to Anatoly Burakovrte_fbarray is a simple indexed array stored in shared memory via mapping files into memory. Rationale for its existence is the
following: since we are going to map memory page-by-page, there could be quite a lot of memory segments to keep track of (for smaller page sizes, page count can easily reach thousands). We can't really make page lists truly dynamic and infinitely expandable, because that involves reallocating memory (which is a big no-no in multiprocess). What we can do instead is have a maximum capacity as something really, really large, and decide at allocation time how big the array is going to be. We map the entire file into memory, which makes it possible to use fbarray as shared memory, provided the structure itself is allocated in shared memory. Per-fbarray locking is also used to avoid index data races (but not contents data races - that is up to user application to synchronize).
In addition, in understanding that we will frequently need to scan this array for free space and iterating over array linearly can become slow, rte_fbarray provides facilities to index array's usage. The following use cases are covered:
- find next free/used slot (useful either for adding new elements to fbarray, or walking the list)
- find starting index for next N free/used slots (useful for when we want to allocate chunk of VA-contiguous memory composed of several pages)
- find how many contiguous free/used slots there are, starting from specified index (useful for when we want to figure out how many pages we have until next hole in allocated memory, to speed up some bulk operations where we would otherwise have to walk the array and add pages one by one)
This is accomplished by storing a usage mask in-memory, right after the data section of the array, and using some bit-level magic to figure out the info we need.
--- lib/librte_eal/bsdapp/eal/Makefile | 1 + lib/librte_eal/common/Makefile | 2 +- lib/librte_eal/common/eal_common_fbarray.c | 859 ++++++++++++++++++++++++++++ lib/librte_eal/common/eal_filesystem.h | 13 + lib/librte_eal/common/include/rte_fbarray.h | 353 ++++++++++++ lib/librte_eal/common/meson.build | 2 + lib/librte_eal/linuxapp/eal/Makefile | 1 + lib/librte_eal/rte_eal_version.map | 16 + 8 files changed, 1246 insertions(+), 1 deletion(-) create mode 100644 lib/librte_eal/common/eal_common_fbarray.c create mode 100644 lib/librte_eal/common/include/rte_fbarray.h
lib/librte_eal/bsdapp/eal/Makefile +1 -0
@@ -53,6 +53,7 @@ SRCS-$(CONFIG_RTE_EXEC_ENV_BSDAPP) += eal_common_dev.c SRCS-$(CONFIG_RTE_EXEC_ENV_BSDAPP) += eal_common_options.c SRCS-$(CONFIG_RTE_EXEC_ENV_BSDAPP) += eal_common_thread.c SRCS-$(CONFIG_RTE_EXEC_ENV_BSDAPP) += eal_common_proc.c +SRCS-$(CONFIG_RTE_EXEC_ENV_BSDAPP) += eal_common_fbarray.c SRCS-$(CONFIG_RTE_EXEC_ENV_BSDAPP) += rte_malloc.c SRCS-$(CONFIG_RTE_EXEC_ENV_BSDAPP) += malloc_elem.c SRCS-$(CONFIG_RTE_EXEC_ENV_BSDAPP) += malloc_heap.c
lib/librte_eal/common/Makefile +1 -1
@@ -16,7 +16,7 @@ INC += rte_pci_dev_feature_defs.h rte_pci_dev_features.h INC += rte_malloc.h rte_keepalive.h rte_time.h INC += rte_service.h rte_service_component.h INC += rte_bitmap.h rte_vfio.h rte_hypervisor.h rte_test.h -INC += rte_reciprocal.h +INC += rte_reciprocal.h rte_fbarray.h GENERIC_INC := rte_atomic.h rte_byteorder.h rte_cycles.h rte_prefetch.h GENERIC_INC += rte_spinlock.h rte_memcpy.h rte_cpuflags.h rte_rwlock.h
lib/librte_eal/common/eal_common_fbarray.c new file +859 -0
859 lines not on this page · raw message
lib/librte_eal/common/eal_filesystem.h +13 -0
@@ -13,6 +13,7 @@/** Path of rte config file. */ #define RUNTIME_CONFIG_FMT "%s/.%s_config" +#define FBARRAY_FMT "%s/%s_%s"#include <stdint.h> #include <limits.h>
@@ -55,6 +56,18 @@ eal_mp_socket_path(void)return buffer; } +static inline const char * +eal_get_fbarray_path (char *buffer,size_t buflen,const char *name) { +const char *directory ="/tmp" ; +const char *home_dir =getenv ("HOME" ); + +if (getuid () !=0 && home_dir !=NULL ) + directory = home_dir; +snprintf (buffer, buflen -1 ,FBARRAY_FMT , directory, + internal_config.hugefile_prefix, name); +return buffer; +} +/** Path of hugepage info file. */ #define HUGEPAGE_INFO_FMT "%s/.%s_hugepage_info"
lib/librte_eal/common/include/rte_fbarray.h new file +353 -0
353 lines not on this page · raw message
lib/librte_eal/common/meson.build +2 -0
@@ -11,6 +11,7 @@ common_sources = files( 'eal_common_devargs.c', 'eal_common_dev.c', 'eal_common_errno.c', + 'eal_common_fbarray.c', 'eal_common_hexdump.c', 'eal_common_launch.c', 'eal_common_lcore.c',
@@ -51,6 +52,7 @@ common_headers = files( 'include/rte_eal_memconfig.h', 'include/rte_eal_interrupts.h', 'include/rte_errno.h', + 'include/rte_fbarray.h', 'include/rte_hexdump.h', 'include/rte_interrupts.h', 'include/rte_keepalive.h',
lib/librte_eal/linuxapp/eal/Makefile +1 -0
@@ -61,6 +61,7 @@ SRCS-$(CONFIG_RTE_EXEC_ENV_LINUXAPP) += eal_common_dev.c SRCS-$(CONFIG_RTE_EXEC_ENV_LINUXAPP) += eal_common_options.c SRCS-$(CONFIG_RTE_EXEC_ENV_LINUXAPP) += eal_common_thread.c SRCS-$(CONFIG_RTE_EXEC_ENV_LINUXAPP) += eal_common_proc.c +SRCS-$(CONFIG_RTE_EXEC_ENV_LINUXAPP) += eal_common_fbarray.c SRCS-$(CONFIG_RTE_EXEC_ENV_LINUXAPP) += rte_malloc.c SRCS-$(CONFIG_RTE_EXEC_ENV_LINUXAPP) += malloc_elem.c SRCS-$(CONFIG_RTE_EXEC_ENV_LINUXAPP) += malloc_heap.c
lib/librte_eal/rte_eal_version.map +16 -0
@@ -221,6 +221,22 @@ EXPERIMENTAL { rte_eal_hotplug_add; rte_eal_hotplug_remove; rte_eal_mbuf_user_pool_ops; + rte_fbarray_attach; + rte_fbarray_destroy; + rte_fbarray_detach; + rte_fbarray_dump_metadata; + rte_fbarray_find_idx; + rte_fbarray_find_next_free; + rte_fbarray_find_next_used; + rte_fbarray_find_next_n_free; + rte_fbarray_find_next_n_used; + rte_fbarray_find_contig_free; + rte_fbarray_find_contig_used; + rte_fbarray_get; + rte_fbarray_init; + rte_fbarray_is_used; + rte_fbarray_set_free; + rte_fbarray_set_used; rte_log_register_type_and_pick_level; rte_malloc_dump_heaps; rte_mem_iova2virt;
Signature · 1 line
2.7.4
PATCH v6 49/70 eal: replace memseg with memseg lists
In reply to Anatoly BurakovBefore, we were aggregating multiple pages into one memseg, so the number of memsegs was small. Now, each page gets its own memseg, so the list of memsegs is huge. To accommodate the new memseg list size and to keep the under-the-hood workings sane, the memseg list is now not just a single list, but multiple lists. To be precise, each hugepage size available on the system gets one or more memseg lists, per socket.
In order to support dynamic memory allocation, we reserve all memory in advance (unless we're in 32-bit legacy mode, in which case we do not preallocate memory). As in, we do an anonymous mmap() of the entire maximum size of memory per hugepage size, per socket (which is limited to either RTE_MAX_MEMSEG_PER_TYPE pages or RTE_MAX_MEM_MB_PER_TYPE megabytes worth of memory, whichever is the smaller one), split over multiple lists (which are limited to either RTE_MAX_MEMSEG_PER_LIST memsegs or RTE_MAX_MEM_MB_PER_LIST megabytes per list, whichever is the smaller one). There is also a global limit of CONFIG_RTE_MAX_MEM_MB megabytes, which is mainly used for 32-bit targets to limit amounts of preallocated memory, but can be used to place an upper limit on total amount of VA memory that can be allocated by DPDK application.
So, for each hugepage size, we get (by default) up to 128G worth of memory, per socket, split into chunks of up to 32G in size. The address space is claimed at the start, in eal_common_memory.c. The actual page allocation code is in eal_memalloc.c (Linux-only), and largely consists of copied EAL memory init code.
Pages in the list are also indexed by address. That is, in order to figure out where the page belongs, one can simply look at base address for a memseg list. Similarly, figuring out IOVA address of a memzone is a matter of finding the right memseg list, getting offset and dividing by page size to get the appropriate memseg.
This commit also removes rte_eal_dump_physmem_layout() call, according to deprecation notice [1], and removes that deprecation notice as well.
On 32-bit targets due to limited VA space, DPDK will no longer spread memory to different sockets like before. Instead, it will (by default) allocate all of the memory on socket where master lcore is. To override this behavior, --socket-mem must be used.
The rest of the changes are really ripple effects from the memseg change - heap changes, compile fixes, and rewrites to support fbarray-backed memseg lists. Due to earlier switch to _walk() functions, most of the changes are simple fixes, however some of the _walk() calls were switched to memseg list walk, where it made sense to do so.
Additionally, we are also switching locks from flock() to fcntl(). Down the line, we will be introducing single-file segments option, and we cannot use flock() locks to lock parts of the file. Therefore, we will use fcntl() locks for legacy mem as well, in case someone is unfortunate enough to accidentally start legacy mem primary process alongside an already working non-legacy mem-based primary process.
[1] http://dpdk.org/dev/patchwork/patch/34002/
--- config/common_base | 15 +- config/defconfig_i686-native-linuxapp-gcc | 3 + config/defconfig_i686-native-linuxapp-icc | 3 + config/defconfig_x86_x32-native-linuxapp-gcc | 3 + config/rte_config.h | 7 +- doc/guides/rel_notes/deprecation.rst | 9 - drivers/bus/fslmc/fslmc_vfio.c | 10 +- drivers/bus/fslmc/portal/dpaa2_hw_pvt.h | 2 +- drivers/bus/pci/linux/pci.c | 8 +- drivers/crypto/dpaa_sec/dpaa_sec.c | 2 +- drivers/net/mlx4/mlx4_mr.c | 4 +- drivers/net/mlx5/mlx5.c | 3 +- drivers/net/mlx5/mlx5_mr.c | 4 +- drivers/net/virtio/virtio_user/vhost_kernel.c | 4 +- lib/librte_eal/bsdapp/eal/eal.c | 12 +- lib/librte_eal/bsdapp/eal/eal_hugepage_info.c | 17 +- lib/librte_eal/bsdapp/eal/eal_memory.c | 209 ++++- lib/librte_eal/common/eal_common_memory.c | 603 ++++++++++++-- lib/librte_eal/common/eal_common_memzone.c | 48 +- lib/librte_eal/common/eal_hugepages.h | 1 - lib/librte_eal/common/eal_internal_cfg.h | 2 +- lib/librte_eal/common/include/rte_eal_memconfig.h | 22 +- lib/librte_eal/common/include/rte_memory.h | 56 +- lib/librte_eal/common/include/rte_memzone.h | 1 - lib/librte_eal/common/malloc_elem.c | 12 +- lib/librte_eal/common/malloc_elem.h | 6 +- lib/librte_eal/common/malloc_heap.c | 62 +- lib/librte_eal/common/rte_malloc.c | 22 +- lib/librte_eal/linuxapp/eal/eal.c | 15 +- lib/librte_eal/linuxapp/eal/eal_hugepage_info.c | 25 +- lib/librte_eal/linuxapp/eal/eal_memory.c | 914 +++++++++++++++------- lib/librte_eal/linuxapp/eal/eal_vfio.c | 9 +- lib/librte_eal/rte_eal_version.map | 3 +- lib/librte_mempool/rte_mempool.c | 9 +- test/test/test_malloc.c | 30 +- test/test/test_memory.c | 10 +- test/test/test_memzone.c | 12 +- 37 files changed, 1587 insertions(+), 590 deletions(-)
config/common_base +14 -1
@@ -61,7 +61,20 @@ CONFIG_RTE_CACHE_LINE_SIZE=64 CONFIG_RTE_LIBRTE_EAL=y CONFIG_RTE_MAX_LCORE=128 CONFIG_RTE_MAX_NUMA_NODES=8 -CONFIG_RTE_MAX_MEMSEG=256 +CONFIG_RTE_MAX_MEMSEG_LISTS=64 +# each memseg list will be limited to either RTE_MAX_MEMSEG_PER_LIST pages +# or RTE_MAX_MEM_MB_PER_LIST megabytes worth of memory, whichever is smaller +CONFIG_RTE_MAX_MEMSEG_PER_LIST=8192 +CONFIG_RTE_MAX_MEM_MB_PER_LIST=32768 +# a "type" is a combination of page size and NUMA node. total number of memseg +# lists per type will be limited to either RTE_MAX_MEMSEG_PER_TYPE pages (split +# over multiple lists of RTE_MAX_MEMSEG_PER_LIST pages), or +# RTE_MAX_MEM_MB_PER_TYPE megabytes of memory (split over multiple lists of +# RTE_MAX_MEM_MB_PER_LIST), whichever is smaller +CONFIG_RTE_MAX_MEMSEG_PER_TYPE=32768 +CONFIG_RTE_MAX_MEM_MB_PER_TYPE=131072 +# global maximum usable amount of VA, in megabytes +CONFIG_RTE_MAX_MEM_MB=524288 CONFIG_RTE_MAX_MEMZONE=2560 CONFIG_RTE_MAX_TAILQ=32 CONFIG_RTE_ENABLE_ASSERT=n
config/defconfig_i686-native-linuxapp-gcc +3 -0
@@ -46,3 +46,6 @@ CONFIG_RTE_LIBRTE_PMD_ZUC=n # AVP PMD is not supported on 32-bit # CONFIG_RTE_LIBRTE_AVP_PMD=n + +# 32-bit doesn't break up memory in lists, but does have VA allocation limit +CONFIG_RTE_MAX_MEM_MB=2048
config/defconfig_i686-native-linuxapp-icc +3 -0
@@ -51,3 +51,6 @@ CONFIG_RTE_LIBRTE_PMD_ZUC=n # AVP PMD is not supported on 32-bit # CONFIG_RTE_LIBRTE_AVP_PMD=n + +# 32-bit doesn't break up memory in lists, but does have VA allocation limit +CONFIG_RTE_MAX_MEM_MB=2048
config/defconfig_x86_x32-native-linuxapp-gcc +3 -0
@@ -26,3 +26,6 @@ CONFIG_RTE_LIBRTE_SFC_EFX_PMD=n # AVP PMD is not supported on 32-bit # CONFIG_RTE_LIBRTE_AVP_PMD=n + +# 32-bit doesn't break up memory in lists, but does have VA allocation limit +CONFIG_RTE_MAX_MEM_MB=2048
config/rte_config.h +6 -1
@@ -21,7 +21,12 @@/****** library defines ********/ /* EAL defines */ -#define RTE_MAX_MEMSEG 512 +#define RTE_MAX_MEMSEG_LISTS 128 +#define RTE_MAX_MEMSEG_PER_LIST 8192 +#define RTE_MAX_MEM_MB_PER_LIST 32768 +#define RTE_MAX_MEMSEG_PER_TYPE 32768 +#define RTE_MAX_MEM_MB_PER_TYPE 65536 +#define RTE_MAX_MEM_MB 524288#define RTE_MAX_MEMZONE 2560#define RTE_MAX_TAILQ 32#define RTE_LOG_DP_LEVEL RTE_LOG_INFO
doc/guides/rel_notes/deprecation.rst +0 -9
@@ -38,15 +38,6 @@ Deprecation Notices success and failure, respectively. This will change to 1 and 0 for true and false, respectively, to make use of the function more intuitive. -* eal: due to internal data layout reorganization, there will be changes to - several structures and functions as a result of coming changes to support - memory hotplug in v18.05. - ``rte_eal_get_physmem_layout`` will be deprecated and removed in subsequent - releases. - ``rte_mem_config`` contents will change due to switch to memseg lists. - ``rte_memzone`` member ``memseg_id`` will no longer serve any useful purpose - and will be removed. - * eal: a new set of mbuf mempool ops name APIs for user, platform and best mempool names have been defined in ``rte_mbuf`` in v18.02. The uses of ``rte_eal_mbuf_default_mempool_ops`` shall be replaced by
drivers/bus/fslmc/fslmc_vfio.c +2 -8
@@ -190,7 +190,8 @@ static int vfio_map_irq_region(struct fslmc_vfio_group *group) }static int -fslmc_vfio_map (const struct rte_memseg *ms,void *arg) +fslmc_vfio_map(const struct rte_memseg_list *msl __rte_unused, +const struct rte_memseg *ms,void *arg) {int *n_segs = arg;struct fslmc_vfio_group *group;
@@ -232,18 +233,11 @@ fslmc_vfio_map(const struct rte_memseg *ms, void *arg)int rte_fslmc_vfio_dmamap (void ) { -const struct rte_memseg *memseg;int i =0 ;if (is_dma_done)return 0 ; - memseg =rte_eal_get_physmem_layout (); -if (memseg ==NULL ) { -DPAA2_BUS_ERR ("Cannot get physical layout" ); -return -ENODEV ; - } -if (rte_memseg_walk (fslmc_vfio_map, &i) <0 )return -1 ;
drivers/bus/fslmc/portal/dpaa2_hw_pvt.h +1 -1
@@ -274,7 +274,7 @@ static phys_addr_t dpaa2_mem_vtop(uint64_t vaddr)if (dpaa2_virt_mode)return vaddr; - memseg =rte_mem_virt2memseg ((void *)(uintptr_t )vaddr); + memseg =rte_mem_virt2memseg ((void *)(uintptr_t )vaddr,NULL );if (memseg)return memseg->phys_addr +RTE_PTR_DIFF (vaddr, memseg->addr);return (size_t )NULL ;
drivers/bus/pci/linux/pci.c +5 -3
@@ -117,9 +117,10 @@ rte_pci_unmap_device(struct rte_pci_device *dev) }static int -find_max_end_va (const struct rte_memseg *ms,void *arg) +find_max_end_va (const struct rte_memseg_list *msl,void *arg) { -void *end_va =RTE_PTR_ADD (ms->addr, ms->len); +size_t sz = msl->memseg_arr.len * msl->page_sz; +void *end_va =RTE_PTR_ADD (msl->base_va, sz);void **max_va = arg;if (*max_va < end_va)
@@ -132,10 +133,11 @@ pci_find_max_end_va(void) {void *va =NULL ; -rte_memseg_walk (find_max_end_va, &va); +rte_memseg_list_walk (find_max_end_va, &va);return va; } +/* parse one line of the "resource" sysfs file (note that the 'line' * string is modified) */
drivers/crypto/dpaa_sec/dpaa_sec.c +1 -1
@@ -95,7 +95,7 @@ dpaa_mem_vtop(void *vaddr) {const struct rte_memseg *ms; - ms =rte_mem_virt2memseg (vaddr); + ms =rte_mem_virt2memseg (vaddr,NULL );if (ms)return ms->iova +RTE_PTR_DIFF (vaddr, ms->addr);return (size_t )NULL ;
drivers/net/mlx4/mlx4_mr.c +2 -2
@@ -141,10 +141,10 @@ mlx4_mr_get(struct priv *priv, struct rte_mempool *mp) (void *)mp, (void *)start, (void *)end, (size_t)(end - start));/* Round start and end to page boundary if found in memory segments. */ - ms =rte_mem_virt2memseg ((void *)start); + ms =rte_mem_virt2memseg ((void *)start,NULL );if (ms !=NULL ) start =RTE_ALIGN_FLOOR (start, ms->hugepage_sz); - ms =rte_mem_virt2memseg ((void *)end); + ms =rte_mem_virt2memseg ((void *)end,NULL );if (ms !=NULL ) end =RTE_ALIGN_CEIL (end, ms->hugepage_sz);
drivers/net/mlx5/mlx5.c +2 -1
@@ -478,7 +478,8 @@ static struct rte_pci_driver mlx5_driver;static void *uar_base;static int -find_lower_va_bound (const struct rte_memseg *ms,void *arg) +find_lower_va_bound(const struct rte_memseg_list *msl __rte_unused, +const struct rte_memseg *ms,void *arg) {void **addr = arg;
drivers/net/mlx5/mlx5_mr.c +2 -2
@@ -262,10 +262,10 @@ mlx5_mr_new(struct rte_eth_dev *dev, struct rte_mempool *mp) mr->end = end;/* Round start and end to page boundary if found in memory segments. */ - ms =rte_mem_virt2memseg ((void *)start); + ms =rte_mem_virt2memseg ((void *)start,NULL );if (ms !=NULL ) start =RTE_ALIGN_FLOOR (start, ms->hugepage_sz); - ms =rte_mem_virt2memseg ((void *)end); + ms =rte_mem_virt2memseg ((void *)end,NULL );if (ms !=NULL ) end =RTE_ALIGN_CEIL (end, ms->hugepage_sz);
drivers/net/virtio/virtio_user/vhost_kernel.c +2 -2
@@ -75,7 +75,8 @@ struct walk_arg {uint32_t region_nr; };static int -add_memory_region (const struct rte_memseg *ms,size_t len,void *arg) +add_memory_region(const struct rte_memseg_list *msl __rte_unused, +const struct rte_memseg *ms,size_t len,void *arg) {struct walk_arg *wa = arg;struct vhost_memory_region *mr;
@@ -95,7 +96,6 @@ add_memory_region(const struct rte_memseg *ms, size_t len, void *arg)return 0 ; } -/* By default, vhost kernel module allows 64 regions, but DPDK allows * 256 segments. As a relief, below function merges those virtually * adjacent memsegs into one region.
lib/librte_eal/bsdapp/eal/eal.c +6 -6
@@ -64,8 +64,8 @@ static int mem_cfg_fd = -1;static struct flock wr_lock = { .l_type =F_WRLCK , .l_whence =SEEK_SET , - .l_start = offsetof(struct rte_mem_config , memseg), - .l_len =sizeof (early_mem_config.memseg), + .l_start = offsetof(struct rte_mem_config , memsegs), + .l_len =sizeof (early_mem_config.memsegs), };/* Address of global and public configuration */
@@ -430,11 +430,11 @@ eal_parse_args(int argc, char **argv) }static int -check_socket (const struct rte_memseg *ms,void *arg) +check_socket (const struct rte_memseg_list *msl,void *arg) {int *socket_id = arg; -if (ms->socket_id == *socket_id) +if (msl->socket_id == *socket_id && msl->memseg_arr.count !=0 )return 1 ;return 0 ;
@@ -447,10 +447,11 @@ eal_check_mem_on_local_socket(void) socket_id =rte_lcore_to_socket_id (rte_config.master_lcore); -if (rte_memseg_walk (check_socket, &socket_id) ==0 ) +if (rte_memseg_list_walk (check_socket, &socket_id) ==0 )RTE_LOG (WARNING ,EAL ,"WARNING: Master core has no memory on local socket!\n" ); } +static int sync_func (__attribute__((unused))void *arg) {
@@ -561,7 +562,6 @@ rte_eal_init(int argc, char **argv)rte_eal_get_configuration ()->iova_mode =rte_bus_get_iommu_class ();if (internal_config.no_hugetlbfs ==0 && - internal_config.process_type !=RTE_PROC_SECONDARY &&eal_hugepage_info_init () <0 ) {rte_eal_init_alert ("Cannot get hugepage information." ); rte_errno =EACCES ;
lib/librte_eal/bsdapp/eal/eal_hugepage_info.c +11 -6
@@ -47,12 +47,18 @@ eal_hugepage_info_init(void)struct hugepage_info *hpi = &internal_config.hugepage_info[0 ];struct hugepage_info *tmp_hpi; + internal_config.num_hugepage_sizes =1 ; + +/* nothing more to be done for secondary */ +if (rte_eal_process_type () ==RTE_PROC_SECONDARY ) +return 0 ; + sysctl_size =sizeof (num_buffers); error =sysctlbyname ("hw.contigmem.num_buffers" , &num_buffers, &sysctl_size,NULL ,0 );if (error !=0 ) { -RTE_LOG (ERR ,EAL ,"could not read sysctl hw.contigmem.num_buffers" ); +RTE_LOG (ERR ,EAL ,"could not read sysctl hw.contigmem.num_buffers\n" );return -1 ; }
@@ -61,7 +67,7 @@ eal_hugepage_info_init(void) &sysctl_size, NULL, 0);if (error !=0 ) { -RTE_LOG (ERR ,EAL ,"could not read sysctl hw.contigmem.buffer_size" ); +RTE_LOG (ERR ,EAL ,"could not read sysctl hw.contigmem.buffer_size\n" );return -1 ; }
@@ -81,22 +87,21 @@ eal_hugepage_info_init(void)RTE_LOG (INFO ,EAL ,"Contigmem driver has %d buffers, each of size %dKB\n" , num_buffers, (int )(buffer_size>>10 )); - internal_config.num_hugepage_sizes =1 ; hpi->hugedir =CONTIGMEM_DEV ; hpi->hugepage_sz = buffer_size; hpi->num_pages[0 ] = num_buffers; hpi->lock_descriptor = fd; tmp_hpi =create_shared_memory (eal_hugepage_info_path (), -sizeof (struct hugepage_info )); +sizeof (internal_config.hugepage_info));if (tmp_hpi ==NULL ) {RTE_LOG (ERR ,EAL ,"Failed to create shared memory!\n" );return -1 ; } -memcpy (tmp_hpi, hpi,sizeof (struct hugepage_info )); +memcpy (tmp_hpi, hpi,sizeof (internal_config.hugepage_info)); -if (munmap (tmp_hpi,sizeof (struct hugepage_info )) <0 ) { +if (munmap (tmp_hpi,sizeof (internal_config.hugepage_info)) <0 ) {RTE_LOG (ERR ,EAL ,"Failed to unmap shared memory!\n" );return -1 ; }
lib/librte_eal/bsdapp/eal/eal_memory.c +170 -39
287 lines not on this page · raw message
lib/librte_eal/common/eal_common_memory.c +516 -87
706 lines not on this page · raw message
lib/librte_eal/common/eal_common_memzone.c +35 -13
84 lines not on this page · raw message
lib/librte_eal/common/eal_hugepages.h +0 -1
@@ -22,7 +22,6 @@ struct hugepage_file {size_t size;/**< the page size */ int socket_id;/**< NUMA socket ID */ int file_id;/**< the '%d' in HUGEFILE_FMT */ -int memseg_id;/**< the memory segment to which page belongs */ char filepath[MAX_HUGEPAGE_PATH ];/**< path to backing file on filesystem */ };
lib/librte_eal/common/eal_internal_cfg.h +1 -1
@@ -23,7 +23,7 @@ struct hugepage_info {uint64_t hugepage_sz;/**< size of a huge page */ const char *hugedir;/**< dir where hugetlbfs is mounted */ uint32_t num_pages[RTE_MAX_NUMA_NODES ]; -/**< number of hugepages of that size on each socket */ +/**< number of hugepages of that size on each socket */ int lock_descriptor;/**< file descriptor for hugepage dir */ };
lib/librte_eal/common/include/rte_eal_memconfig.h +21 -1
@@ -12,12 +12,30 @@#include <rte_malloc_heap.h> #include <rte_rwlock.h> #include <rte_pause.h> +#include <rte_fbarray.h> #ifdef __cplusplus extern "C" { #endif /** + * memseg list is a special case as we need to store a bunch of other data + * together with the array itself. + */ +struct rte_memseg_list { + RTE_STD_C11 + union { + void *base_va; + /**< Base virtual address for this memseg list. */ + uint64_t addr_64; + /**< Makes sure addr is always 64-bits */ + }; + int socket_id; /**< Socket ID for all memsegs in this list. */ + uint64_t page_sz; /**< Page size for all memsegs in this list. */ + struct rte_fbarray memseg_arr; +}; + +/** * the structure for the memory configuration for the RTE. * Used by the rte_config structure. It is separated out, as for multi-process * support, the memory details should be shared across instances
@@ -43,9 +61,11 @@ struct rte_mem_config {uint32_t memzone_cnt;/**< Number of allocated memzones */ /* memory segments and zones */ -struct rte_memseg memseg[RTE_MAX_MEMSEG ];/**< Physmem descriptors. */ struct rte_memzone memzone[RTE_MAX_MEMZONE ];/**< Memzone descriptors. */ +struct rte_memseg_list memsegs[RTE_MAX_MEMSEG_LISTS ]; +/**< list of dynamic arrays holding memsegs */ +struct rte_tailq_head tailq_head[RTE_MAX_TAILQ ];/**< Tailqs for objects */ /* Heaps of Malloc per socket */
lib/librte_eal/common/include/rte_memory.h +40 -16
89 lines not on this page · raw message
lib/librte_eal/common/include/rte_memzone.h +0 -1
@@ -68,7 +68,6 @@ struct rte_memzone {int32_t socket_id;/**< NUMA socket ID. */ uint32_t flags;/**< Characteristics of this memzone. */ -uint32_t memseg_id;/**< Memseg it belongs. */ } __attribute__((__packed__));/**
lib/librte_eal/common/malloc_elem.c +6 -6
@@ -27,11 +27,11 @@* Initialize a general malloc_elem header structure */ void -malloc_elem_init (struct malloc_elem *elem, -struct malloc_heap *heap,const struct rte_memseg *ms,size_t size) +malloc_elem_init (struct malloc_elem *elem,struct malloc_heap *heap, +struct rte_memseg_list *msl,size_t size) { elem->heap = heap; - elem->ms = ms; + elem->msl = msl; elem->prev =NULL ; elem->next =NULL ;memset (&elem->free_list,0 ,sizeof (elem->free_list));
@@ -100,7 +100,7 @@ malloc_elem_insert(struct malloc_elem *elem)* so we just check the page addresses. */ static bool -elem_check_phys_contig(const struct rte_memseg *ms __rte_unused, +elem_check_phys_contig(const struct rte_memseg_list *msl __rte_unused,void *start,size_t size) {rte_iova_t cur, expected;
@@ -191,7 +191,7 @@ elem_start_pt(struct malloc_elem *elem, size_t size, unsigned align,* couldn't fit all data into one physically contiguous * block, try again with lower addresses. */ -if (!elem_check_phys_contig (elem->ms, +if (!elem_check_phys_contig (elem->msl, (void *)new_data_start, new_data_size)) { elem_size -= align;
@@ -225,7 +225,7 @@ split_elem(struct malloc_elem *elem, struct malloc_elem *split_pt)const size_t old_elem_size = (uintptr_t )split_pt - (uintptr_t )elem;const size_t new_elem_size = elem->size - old_elem_size; -malloc_elem_init (split_pt, elem->heap, elem->ms, new_elem_size); +malloc_elem_init (split_pt, elem->heap, elem->msl, new_elem_size); split_pt->prev = elem; split_pt->next = next_elem;if (next_elem)
lib/librte_eal/common/malloc_elem.h +3 -3
@@ -7,7 +7,7 @@#include <stdbool.h> -#include <rte_memory.h> +#include <rte_eal_memconfig.h> /* dummy definition of struct so we can use pointers to it in malloc_elem struct */ struct malloc_heap ;
@@ -26,7 +26,7 @@ struct malloc_elem {/**< points to next elem in memseg */ LIST_ENTRY (malloc_elem) free_list;/**< list of free elements in heap */ -const struct rte_memseg *ms; +struct rte_memseg_list *msl;volatile enum elem_state state;uint32_t pad;size_t size;
@@ -113,7 +113,7 @@ malloc_elem_from_data(const void *data)void malloc_elem_init (struct malloc_elem *elem,struct malloc_heap *heap, -const struct rte_memseg *ms, +struct rte_memseg_list *msl,size_t size);void
lib/librte_eal/common/malloc_heap.c +38 -24
94 lines not on this page · raw message
lib/librte_eal/common/rte_malloc.c +13 -9
@@ -242,17 +242,21 @@ rte_malloc_set_limit(__rte_unused const char *type,rte_iova_t rte_malloc_virt2iova (const void *addr) { -rte_iova_t iova; -const struct malloc_elem *elem =malloc_elem_from_data (addr); +const struct rte_memseg *ms; +struct malloc_elem *elem =malloc_elem_from_data (addr); +if (elem ==NULL )return RTE_BAD_IOVA ; -if (elem->ms->iova ==RTE_BAD_IOVA ) -return RTE_BAD_IOVA ;if (rte_eal_iova_mode () ==RTE_IOVA_VA ) - iova = (uintptr_t )addr; -else - iova = elem->ms->iova + -RTE_PTR_DIFF (addr, elem->ms->addr); -return iova; +return (uintptr_t ) addr; + + ms =rte_mem_virt2memseg (addr, elem->msl); +if (ms ==NULL ) +return RTE_BAD_IOVA ; + +if (ms->iova ==RTE_BAD_IOVA ) +return RTE_BAD_IOVA ; + +return ms->iova +RTE_PTR_DIFF (addr, ms->addr); }
lib/librte_eal/linuxapp/eal/eal.c +9 -6
@@ -74,8 +74,8 @@ static int mem_cfg_fd = -1;static struct flock wr_lock = { .l_type =F_WRLCK , .l_whence =SEEK_SET , - .l_start = offsetof(struct rte_mem_config , memseg), - .l_len =sizeof (early_mem_config.memseg), + .l_start = offsetof(struct rte_mem_config , memsegs), + .l_len =sizeof (early_mem_config.memsegs), };/* Address of global and public configuration */
@@ -640,11 +640,14 @@ eal_parse_args(int argc, char **argv) }static int -check_mem (const struct rte_memseg *ms,void *arg) +check_socket (const struct rte_memseg_list *msl,void *arg) { -int *socket = arg; +int *socket_id = arg; -return ms->socket_id == *socket; +if (msl->socket_id == *socket_id && msl->memseg_arr.count !=0 ) +return 1 ; + +return 0 ; } static void
@@ -654,7 +657,7 @@ eal_check_mem_on_local_socket(void) socket_id =rte_lcore_to_socket_id (rte_config.master_lcore); -if (rte_memseg_walk (check_mem, &socket_id) ==0 ) +if (rte_memseg_list_walk (check_socket, &socket_id) ==0 )RTE_LOG (WARNING ,EAL ,"WARNING: Master core has no memory on local socket!\n" ); }
lib/librte_eal/linuxapp/eal/eal_hugepage_info.c +23 -2
@@ -15,6 +15,7 @@#include <unistd.h> #include <errno.h> #include <sys/queue.h> +#include <sys/stat.h> #include <rte_memory.h> #include <rte_eal.h>
@@ -160,6 +161,18 @@ get_hugepage_dir(uint64_t hugepage_sz) }/* +* uses fstat to report the size of a file on disk +*/ +static off_t +get_file_size (int fd) +{ +struct stat st; +if (fstat (fd, &st) <0 ) +return 0 ; +return st.st_size; +} + +/* * Clear the hugepage directory of whatever hugepage files * there are. Checks if the file is locked (i.e. * if it's in use by another DPDK process).
@@ -189,6 +202,8 @@ clear_hugedir(const char * hugedir) }while (dirent !=NULL ){ +struct flock lck = {0 }; +/* skip files that don't match the hugepage pattern */ if (fnmatch (filter, dirent->d_name,0 ) >0 ) { dirent =readdir (dir);
@@ -205,11 +220,17 @@ clear_hugedir(const char * hugedir) }/* non-blocking lock */ - lck_result =flock (fd,LOCK_EX |LOCK_NB ); + lck.l_type =F_RDLCK ; + lck.l_whence =SEEK_SET ; + lck.l_start =0 ; + lck.l_len =get_file_size (fd); + + lck_result =fcntl (fd,F_SETLK , &lck);/* if lock succeeds, unlock and remove the file */ if (lck_result !=-1 ) { -flock (fd,LOCK_UN ); + lck.l_type =F_UNLCK ; +fcntl (fd,F_SETLK , &lck);unlinkat (dir_fd, dirent->d_name,0 ); }close (fd);
lib/librte_eal/linuxapp/eal/eal_memory.c +616 -298
1,112 lines not on this page · raw message
lib/librte_eal/linuxapp/eal/eal_vfio.c +6 -3
@@ -908,7 +908,8 @@ vfio_get_group_no(const char *sysfs_base, }static int -type1_map (const struct rte_memseg *ms,void *arg) +type1_map(const struct rte_memseg_list *msl __rte_unused, +const struct rte_memseg *ms,void *arg) {int *vfio_container_fd = arg;
@@ -1021,7 +1022,8 @@ vfio_spapr_dma_do_map(int vfio_container_fd, uint64_t vaddr, uint64_t iova, }static int -vfio_spapr_map_walk (const struct rte_memseg *ms,void *arg) +vfio_spapr_map_walk(const struct rte_memseg_list *msl __rte_unused, +const struct rte_memseg *ms,void *arg) {int *vfio_container_fd = arg;
@@ -1034,7 +1036,8 @@ struct spapr_walk_param {uint64_t hugepage_sz; };static int -vfio_spapr_window_size_walk (const struct rte_memseg *ms,void *arg) +vfio_spapr_window_size_walk(const struct rte_memseg_list *msl __rte_unused, +const struct rte_memseg *ms,void *arg) {struct spapr_walk_param *param = arg;uint64_t max = ms->iova + ms->len;
lib/librte_eal/rte_eal_version.map +2 -1
@@ -25,7 +25,6 @@ DPDK_2.0 { rte_eal_devargs_type_count; rte_eal_get_configuration; rte_eal_get_lcore_state; - rte_eal_get_physmem_layout; rte_eal_get_physmem_size; rte_eal_has_hugepages; rte_eal_hpet_init;
@@ -241,7 +240,9 @@ EXPERIMENTAL { rte_malloc_dump_heaps; rte_mem_iova2virt; rte_mem_virt2memseg; + rte_mem_virt2memseg_list; rte_memseg_contig_walk; + rte_memseg_list_walk; rte_memseg_walk; rte_mp_action_register; rte_mp_action_unregister;
lib/librte_mempool/rte_mempool.c +5 -4
@@ -100,12 +100,12 @@ static unsigned optimize_object_size(unsigned obj_size) }static int -find_min_pagesz (const struct rte_memseg *ms,void *arg) +find_min_pagesz (const struct rte_memseg_list *msl,void *arg) {size_t *min = arg; -if (ms->hugepage_sz < *min) - *min = ms->hugepage_sz; +if (msl->page_sz < *min) + *min = msl->page_sz;return 0 ; }
@@ -115,11 +115,12 @@ get_min_page_size(void) {size_t min_pagesz =SIZE_MAX ; -rte_memseg_walk (find_min_pagesz, &min_pagesz); +rte_memseg_list_walk (find_min_pagesz, &min_pagesz);return min_pagesz ==SIZE_MAX ? (size_t )getpagesize () : min_pagesz; } +static void mempool_add_elem (struct rte_mempool *mp,void *obj,rte_iova_t iova) {
test/test/test_malloc.c +7 -23
@@ -12,6 +12,7 @@#include <rte_common.h> #include <rte_memory.h> +#include <rte_eal_memconfig.h> #include <rte_per_lcore.h> #include <rte_launch.h> #include <rte_eal.h>
@@ -706,36 +707,20 @@ test_malloc_bad_params(void) }static int -check_socket_mem (const struct rte_memseg *ms,void *arg) +check_socket_mem (const struct rte_memseg_list *msl,void *arg) {int32_t *socket = arg; -return *socket == ms->socket_id; +return *socket == msl->socket_id; }/* Check if memory is available on a specific socket */ static int is_mem_on_socket (int32_t socket) { -return rte_memseg_walk (check_socket_mem, &socket); +return rte_memseg_list_walk (check_socket_mem, &socket); } -struct walk_param { -void *addr; -int32_t socket; -}; -static int -find_socket (const struct rte_memseg *ms,void *arg) -{ -struct walk_param *param = arg; - - if (param->addr >= ms->addr &&
Lines of this file are not shown. View the raw message.
The rest of this diff is not shown. View the raw message.
Signature · 1 line
2.7.4
Part of the diff is not shown here. View the raw message.
PATCH v6 50/70 eal: replace memzone array with fbarray
In reply to Anatoly BurakovIt's there, so we might as well use it. Some operations will be sped up by that.
Since we have to allocate an fbarray for memzones, we have to do it before we initialize memory subsystem, because that, in secondary processes, will (later) allocate more fbarrays than the primary process, which will result in inability to attach to memzone fbarray if we do it after the fact.
--- drivers/net/ena/Makefile | 3 + drivers/net/ena/ena_ethdev.c | 10 +- lib/librte_eal/bsdapp/eal/eal.c | 14 ++- lib/librte_eal/common/eal_common_memzone.c | 113 ++++++++++++---------- lib/librte_eal/common/include/rte_eal_memconfig.h | 4 +- lib/librte_eal/common/malloc_heap.c | 4 + lib/librte_eal/linuxapp/eal/eal.c | 13 ++- test/test/test_memzone.c | 9 +- 8 files changed, 103 insertions(+), 67 deletions(-)
drivers/net/ena/Makefile +3 -0
@@ -43,6 +43,9 @@ INCLUDES :=-I$(SRCDIR) -I$(SRCDIR)/base/ena_defs -I$(SRCDIR)/base EXPORT_MAP := rte_pmd_ena_version.map LIBABIVER := 1 +# rte_fbarray is not yet part of stable API +CFLAGS += -DALLOW_EXPERIMENTAL_API + VPATH += $(SRCDIR)/base # # all source are stored in SRCS-y
drivers/net/ena/ena_ethdev.c +7 -3
@@ -264,11 +264,15 @@ static const struct eth_dev_ops ena_dev_ops = {static inline int ena_cpu_to_node (int cpu) {struct rte_config *config =rte_eal_get_configuration (); +struct rte_fbarray *arr = &config->mem_config->memzones; +const struct rte_memzone *mz; -if (likely (cpu <RTE_MAX_MEMZONE )) -return config->mem_config->memzone[cpu].socket_id; +if (unlikely (cpu >=RTE_MAX_MEMZONE )) +return NUMA_NO_NODE ; -return NUMA_NO_NODE ; + mz =rte_fbarray_get (arr, cpu); + +return mz->socket_id; } static inline void ena_rx_mbuf_prepare(struct rte_mbuf *mbuf,
lib/librte_eal/bsdapp/eal/eal.c +12 -2
@@ -599,14 +599,24 @@ rte_eal_init(int argc, char **argv) } } +/* in secondary processes, memory init may allocate additional fbarrays +* not present in primary processes, so to avoid any potential issues, +* initialize memzones first. +*/ +if (rte_eal_memzone_init () <0 ) { +rte_eal_init_alert ("Cannot init memzone\n" ); + rte_errno =ENODEV ; +return -1 ; + } +if (rte_eal_memory_init () <0 ) {rte_eal_init_alert ("Cannot init memory\n" ); rte_errno =ENOMEM ;return -1 ; } -if (rte_eal_memzone_init () <0 ) { -rte_eal_init_alert ("Cannot init memzone\n" ); +if (rte_eal_malloc_heap_init () <0 ) { +rte_eal_init_alert ("Cannot init malloc heap\n" ); rte_errno =ENODEV ;return -1 ; }
lib/librte_eal/common/eal_common_memzone.c +60 -53
208 lines not on this page · raw message
lib/librte_eal/common/include/rte_eal_memconfig.h +1 -3
@@ -58,10 +58,8 @@ struct rte_mem_config {rte_rwlock_t qlock;/**< used for tailq operation for thread safe. */ rte_rwlock_t mplock;/**< only used by mempool LIB for thread-safe. */ -uint32_t memzone_cnt;/**< Number of allocated memzones */ -/* memory segments and zones */ -struct rte_memzone memzone[RTE_MAX_MEMZONE ];/**< Memzone descriptors. */ +struct rte_fbarray memzones;/**< Memzone descriptors. */ struct rte_memseg_list memsegs[RTE_MAX_MEMSEG_LISTS ];/**< list of dynamic arrays holding memsegs */
lib/librte_eal/common/malloc_heap.c +4 -0
@@ -278,6 +278,10 @@ rte_eal_malloc_heap_init(void)if (mcfg ==NULL )return -1 ; +/* secondary process does not need to initialize anything */ +if (rte_eal_process_type () !=RTE_PROC_PRIMARY ) +return 0 ; +/* add all IOVA-contiguous areas to the heap */ return rte_memseg_contig_walk (malloc_add_seg,NULL ); }
lib/librte_eal/linuxapp/eal/eal.c +11 -2
@@ -858,6 +858,15 @@ rte_eal_init(int argc, char **argv) return -1; }#endif +/* in secondary processes, memory init may allocate additional fbarrays +* not present in primary processes, so to avoid any potential issues, +* initialize memzones first. +*/ +if (rte_eal_memzone_init () <0 ) { +rte_eal_init_alert ("Cannot init memzone\n" ); + rte_errno =ENODEV ; +return -1 ; + }if (rte_eal_memory_init () <0 ) {rte_eal_init_alert ("Cannot init memory\n" );
@@ -868,8 +877,8 @@ rte_eal_init(int argc, char **argv)/* the directories are locked during eal_hugepage_info_init */ eal_hugedirs_unlock (); -if (rte_eal_memzone_init () <0 ) { -rte_eal_init_alert ("Cannot init memzone\n" ); +if (rte_eal_malloc_heap_init () <0 ) { +rte_eal_init_alert ("Cannot init malloc heap\n" ); rte_errno =ENODEV ;return -1 ; }
test/test/test_memzone.c +5 -4
@@ -909,7 +909,7 @@ test_memzone_basic(void)const struct rte_memzone *mz;int memzone_cnt_after, memzone_cnt_expected;int memzone_cnt_before = -rte_eal_get_configuration ()->mem_config->memzone_cnt; +rte_eal_get_configuration ()->mem_config->memzones.count; memzone1 =rte_memzone_reserve (TEST_MEMZONE_NAME ("testzone1" ),100 ,SOCKET_ID_ANY ,0 );
@@ -933,7 +933,7 @@ test_memzone_basic(void) (memzone3 !=NULL ) + (memzone4 !=NULL ); memzone_cnt_after = -rte_eal_get_configuration ()->mem_config->memzone_cnt; +rte_eal_get_configuration ()->mem_config->memzones.count;if (memzone_cnt_after != memzone_cnt_expected)return -1 ;
@@ -1012,7 +1012,7 @@ test_memzone_basic(void) } memzone_cnt_after = -rte_eal_get_configuration ()->mem_config->memzone_cnt; +rte_eal_get_configuration ()->mem_config->memzones.count;if (memzone_cnt_after != memzone_cnt_before)return -1 ;
@@ -1033,7 +1033,8 @@ static inttest_memzone (void) {/* take note of how many memzones were allocated before running */ -int memzone_cnt =rte_eal_get_configuration ()->mem_config->memzone_cnt; +int memzone_cnt = +rte_eal_get_configuration ()->mem_config->memzones.count;printf ("test basic memzone API\n" );if (test_memzone_basic () <0 )
Signature · 1 line
2.7.4
PATCH v6 51/70 mem: add support for mapping hugepages at runtime
In reply to Anatoly BurakovNothing uses this code yet. The bulk of it is copied from old memory allocation code (linuxapp eal_memory.c). We provide an EAL-internal API to allocate either one page or multiple pages, guaranteeing that we'll get contiguous VA for all of the pages that we requested.
Not supported on FreeBSD.
Locking is done via fcntl() because that way, when it comes to taking out write locks or unlocking on deallocation, we don't have to keep original fd's around. Plus, using fcntl() gives us ability to lock parts of a file, which is useful for single-file segments, which are coming down the line.
--- lib/librte_eal/bsdapp/eal/Makefile | 1 + lib/librte_eal/bsdapp/eal/eal_memalloc.c | 26 ++ lib/librte_eal/bsdapp/eal/meson.build | 1 + lib/librte_eal/common/eal_memalloc.h | 31 +++ lib/librte_eal/linuxapp/eal/Makefile | 2 + lib/librte_eal/linuxapp/eal/eal_memalloc.c | 429 +++++++++++++++++++++++++++++ lib/librte_eal/linuxapp/eal/meson.build | 1 + 7 files changed, 491 insertions(+) create mode 100644 lib/librte_eal/bsdapp/eal/eal_memalloc.c create mode 100644 lib/librte_eal/common/eal_memalloc.h create mode 100644 lib/librte_eal/linuxapp/eal/eal_memalloc.c
lib/librte_eal/bsdapp/eal/Makefile +1 -0
@@ -29,6 +29,7 @@ SRCS-$(CONFIG_RTE_EXEC_ENV_BSDAPP) += eal_memory.c SRCS-$(CONFIG_RTE_EXEC_ENV_BSDAPP) += eal_hugepage_info.c SRCS-$(CONFIG_RTE_EXEC_ENV_BSDAPP) += eal_thread.c SRCS-$(CONFIG_RTE_EXEC_ENV_BSDAPP) += eal_debug.c +SRCS-$(CONFIG_RTE_EXEC_ENV_BSDAPP) += eal_memalloc.c SRCS-$(CONFIG_RTE_EXEC_ENV_BSDAPP) += eal_lcore.c SRCS-$(CONFIG_RTE_EXEC_ENV_BSDAPP) += eal_timer.c SRCS-$(CONFIG_RTE_EXEC_ENV_BSDAPP) += eal_interrupts.c
lib/librte_eal/bsdapp/eal/eal_memalloc.c new file +26 -0
@@ -0,0 +1,26 @@ +/* SPDX-License-Identifier: BSD-3-Clause +* Copyright(c) 2017-2018 Intel Corporation +*/ + +#include <inttypes.h> + +#include <rte_log.h> +#include <rte_memory.h> + +#include "eal_memalloc.h" + +int +eal_memalloc_alloc_seg_bulk(struct rte_memseg **ms __rte_unused, + int __rte_unused n_segs, size_t __rte_unused page_sz, + int __rte_unused socket, bool __rte_unused exact) +{ +RTE_LOG (ERR ,EAL ,"Memory hotplug not supported on FreeBSD\n" ); +return -1 ; +} + +struct rte_memseg * +eal_memalloc_alloc_seg(size_t __rte_unused page_sz, int __rte_unused socket) +{ +RTE_LOG (ERR ,EAL ,"Memory hotplug not supported on FreeBSD\n" ); +return NULL ; +}
lib/librte_eal/bsdapp/eal/meson.build +1 -0
@@ -8,6 +8,7 @@ env_sources = files('eal_alarm.c', 'eal_hugepage_info.c', 'eal_interrupts.c', 'eal_lcore.c', + 'eal_memalloc.c', 'eal_thread.c', 'eal_timer.c', 'eal.c',
lib/librte_eal/common/eal_memalloc.h new file +31 -0
@@ -0,0 +1,31 @@ +/* SPDX-License-Identifier: BSD-3-Clause +* Copyright(c) 2017-2018 Intel Corporation +*/ + +#ifndef EAL_MEMALLOC_H +#define EAL_MEMALLOC_H + +#include <stdbool.h> + +#include <rte_memory.h> + +/* +* Allocate segment of specified page size. +*/ +struct rte_memseg * +eal_memalloc_alloc_seg (size_t page_sz,int socket); + +/* +* Allocate `n_segs` segments. +* +* Note: `ms` can be NULL. +* +* Note: it is possible to request best-effort allocation by setting `exact` to +* `false`, in which case allocator will return however many pages it managed to +* allocate successfully. +*/ +int +eal_memalloc_alloc_seg_bulk (struct rte_memseg **ms,int n_segs,size_t page_sz, +int socket,bool exact); + +#endif /* EAL_MEMALLOC_H */
lib/librte_eal/linuxapp/eal/Makefile +2 -0
@@ -36,6 +36,7 @@ SRCS-$(CONFIG_RTE_EXEC_ENV_LINUXAPP) += eal_thread.c SRCS-$(CONFIG_RTE_EXEC_ENV_LINUXAPP) += eal_log.c SRCS-$(CONFIG_RTE_EXEC_ENV_LINUXAPP) += eal_vfio.c SRCS-$(CONFIG_RTE_EXEC_ENV_LINUXAPP) += eal_vfio_mp_sync.c +SRCS-$(CONFIG_RTE_EXEC_ENV_LINUXAPP) += eal_memalloc.c SRCS-$(CONFIG_RTE_EXEC_ENV_LINUXAPP) += eal_debug.c SRCS-$(CONFIG_RTE_EXEC_ENV_LINUXAPP) += eal_lcore.c SRCS-$(CONFIG_RTE_EXEC_ENV_LINUXAPP) += eal_timer.c
@@ -82,6 +83,7 @@ CFLAGS_eal_interrupts.o := -D_GNU_SOURCE CFLAGS_eal_vfio_mp_sync.o := -D_GNU_SOURCE CFLAGS_eal_timer.o := -D_GNU_SOURCE CFLAGS_eal_lcore.o := -D_GNU_SOURCE +CFLAGS_eal_memalloc.o := -D_GNU_SOURCE CFLAGS_eal_thread.o := -D_GNU_SOURCE CFLAGS_eal_log.o := -D_GNU_SOURCE CFLAGS_eal_common_log.o := -D_GNU_SOURCE
lib/librte_eal/linuxapp/eal/eal_memalloc.c new file +429 -0
429 lines not on this page · raw message
lib/librte_eal/linuxapp/eal/meson.build +1 -0
@@ -10,6 +10,7 @@ env_sources = files('eal_alarm.c', 'eal_debug.c', 'eal_hugepage_info.c', 'eal_interrupts.c', + 'eal_memalloc.c', 'eal_lcore.c', 'eal_log.c', 'eal_thread.c',
Signature · 1 line
2.7.4
Re: [PATCH v6 51/70] mem: add support for mapping hugepages at runtime
Quoted 22 lines · Anatoly Burakov
Nothing uses this code yet. The bulk of it is copied from old memory allocation code (linuxapp
eal_memory.c). We provide an EAL-internal API to allocate either one page or multiple pages, guaranteeing that we'll get contiguous VA for all of the pages that we requested.Not supported on FreeBSD.
Locking is done via
fcntl()because that way, when it comes to taking out write locks or unlocking on deallocation, we don't have to keep original fd's around. Plus, usingfcntl()gives us ability to lock parts of a file, which is useful for single-file segments, which are coming down the line.Signed-off-by Anatoly Burakov <[email protected]>Tested-by Santosh Shukla <[email protected]>Tested-by Hemant Agrawal <[email protected]>---
[...]
Quoted 17 lines
lib/librte_eal/linuxapp/eal/eal_memalloc.c new file +11
-0@@ -0,0 +1,429 @@ +/* SPDX-License-Identifier: BSD-3-Clause +* Copyright(c) 2017-2018 Intel Corporation +*/ + +#define _FILE_OFFSET_BITS 64 +#include <errno.h> +#include <stdarg.h> +#include <stdbool.h> +#include <stdlib.h> +#include <stdio.h> +#include <stdint.h>
lib/librte_eal/linuxapp/eal/eal_memalloc.c line 21
Quoted 10 lines
lib/librte_eal/linuxapp/eal/eal_memalloc.c new file +10
-0+#include <inttypes.h> +#include <string.h> +#include <sys/mman.h> +#include <sys/types.h> +#include <sys/stat.h> +#include <sys/queue.h> +#include <sys/file.h> +#include <unistd.h> +#include <limits.h> +#include <fcntl.h>
There's a bug in the old RedHat release:
Bug 1476120 - glibc headers don't include linux/falloc.h, and therefore doesn't include fallocate() flags [1]
How about adding "#include <linux/falloc.h>" ahead of fcntl.h? I'm quite lazy to update my host and using CentOS 7.2.1511, then it failed to compile due to this bug.
[1] https://bugzilla.redhat.com/show_bug.cgi?id=1476120
Thanks,
Yongseok
Re: [PATCH v6 51/70] mem: add support for mapping hugepages at runtime
17/04/2018 04:06, Yongseok Koh:
Quoted 6 lines
There's a bug in the old RedHat release:
Bug 1476120 - glibc headers don't includelinux/falloc.h, and therefore doesn't includefallocate()flags [1]How about adding "#include <
linux/falloc.h>" ahead offcntl.h? I'm quite lazy to update my host and using CentOS 7.2.1511, then it failed to compile due to this bug.
It's strange, it is already fixed (at least in master). Please can you double check what's wrong?
Quoted 1 line
Re: [PATCH v6 51/70] mem: add support for mapping hugepages at runtime
Quoted 8 lines · Thomas Monjalon
17/04/2018 04:06, Yongseok Koh:
Quoted 3 lines
There's a bug in the old RedHat release:
Bug 1476120 - glibc headers don't includelinux/falloc.h, and therefore doesn't includefallocate()flags [1]
Quoted 6 lines
Quoted 3 lines
How about adding "#include <
linux/falloc.h>" ahead offcntl.h? I'm quite lazy to update my host and using CentOS 7.2.1511, then it failed to compile due to this bug.It's strange, it is already fixed (at least in master). Please can you double check what's wrong?
My bad, I was still following Anatoly's GitHub.
I didn't notice it's been merged.
I'm seeing it's been fixed.
Thanks,
Yongseok
PATCH v6 52/70 mem: add support for unmapping pages at runtime
In reply to Anatoly BurakovThis isn't used anywhere yet, but the support is now there. Also, adding cleanup to allocation procedures, so that if we fail to allocate everything we asked for, we can free all of it back.
--- lib/librte_eal/bsdapp/eal/eal_memalloc.c | 15 +++ lib/librte_eal/common/eal_memalloc.h | 14 +++ lib/librte_eal/linuxapp/eal/eal_memalloc.c | 148 ++++++++++++++++++++++++++++- 3 files changed, 176 insertions(+), 1 deletion(-)
lib/librte_eal/bsdapp/eal/eal_memalloc.c +15 -0
@@ -24,3 +24,18 @@ eal_memalloc_alloc_seg(size_t __rte_unused page_sz, int __rte_unused socket)RTE_LOG (ERR ,EAL ,"Memory hotplug not supported on FreeBSD\n" );return NULL ; } + +int +eal_memalloc_free_seg(struct rte_memseg *ms __rte_unused) +{ +RTE_LOG (ERR ,EAL ,"Memory hotplug not supported on FreeBSD\n" ); +return -1 ; +} + +int +eal_memalloc_free_seg_bulk(struct rte_memseg **ms __rte_unused, + int n_segs __rte_unused) +{ +RTE_LOG (ERR ,EAL ,"Memory hotplug not supported on FreeBSD\n" ); +return -1 ; +}
lib/librte_eal/common/eal_memalloc.h +14 -0
@@ -28,4 +28,18 @@ int eal_memalloc_alloc_seg_bulk(struct rte_memseg **ms, int n_segs, size_t page_sz, int socket, bool exact); +/* +* Deallocate segment +*/ +int +eal_memalloc_free_seg (struct rte_memseg *ms); + +/* +* Deallocate `n_segs` segments. Returns 0 on successful deallocation of all +* segments, returns -1 on error. Any segments that could have been deallocated, +* will be deallocated even in case of error. +*/ +int +eal_memalloc_free_seg_bulk (struct rte_memseg **ms,int n_segs); +#endif /* EAL_MEMALLOC_H */
lib/librte_eal/linuxapp/eal/eal_memalloc.c +147 -1
182 lines not on this page · raw message
Signature · 1 line
2.7.4
PATCH v6 53/70 eal: add single file segments command-line option
In reply to Anatoly BurakovCurrently, DPDK stores all pages as separate files in hugetlbfs. This option will allow storing all pages in one file (one file per memseg list).
We do this by using fallocate() calls on FreeBSD, however this is only supported on fairly recent (4.3+) kernels, so ftruncate() fallback is provided to grow (but not shrink) hugepage files. Naming scheme is deterministic, so both primary and secondary processes will be able to easily map needed files and offsets.
For multi-file segments, we can close fd's right away. For single-file segments, we can reuse the same fd and reduce the amount of fd's needed to map/use hugepages. However, we need to store the fd's somewhere, so we add a tailq.
--- lib/librte_eal/common/eal_common_options.c | 4 + lib/librte_eal/common/eal_internal_cfg.h | 4 + lib/librte_eal/common/eal_options.h | 2 + lib/librte_eal/linuxapp/eal/eal.c | 1 + lib/librte_eal/linuxapp/eal/eal_memalloc.c | 337 ++++++++++++++++++++++++----- 5 files changed, 297 insertions(+), 51 deletions(-)
lib/librte_eal/common/eal_common_options.c +4 -0
@@ -74,6 +74,7 @@ eal_long_options[] = { {OPT_VFIO_INTR, 1, NULL, OPT_VFIO_INTR_NUM }, {OPT_VMWARE_TSC_MAP, 0, NULL, OPT_VMWARE_TSC_MAP_NUM }, {OPT_LEGACY_MEM, 0, NULL, OPT_LEGACY_MEM_NUM }, + {OPT_SINGLE_FILE_SEGMENTS, 0, NULL, OPT_SINGLE_FILE_SEGMENTS_NUM}, {0, 0, NULL, 0 } };
@@ -1190,6 +1191,9 @@ eal_parse_common_option(int opt, const char *optarg,case OPT_LEGACY_MEM_NUM : conf->legacy_mem =1 ;break ; +case OPT_SINGLE_FILE_SEGMENTS_NUM : + conf->single_file_segments =1 ; +break ;/* don't know what to do, leave this to caller */ default :
lib/librte_eal/common/eal_internal_cfg.h +4 -0
@@ -51,6 +51,10 @@ struct internal_config {/**< true to enable legacy memory behavior (no dynamic allocation, * IOVA-contiguous segments). */ +volatile unsigned single_file_segments; +/**< true if storing all pages within single files (per-page-size, +* per-node) non-legacy mode only. +*/ volatile int syslog_facility;/**< facility passed to openlog() */ /** default interrupt mode for VFIO */ volatile enum rte_intr_mode vfio_intr_mode;
lib/librte_eal/common/eal_options.h +2 -0
@@ -57,6 +57,8 @@ enum {OPT_VMWARE_TSC_MAP_NUM , #define OPT_LEGACY_MEM "legacy-mem"OPT_LEGACY_MEM_NUM , +#define OPT_SINGLE_FILE_SEGMENTS "single-file-segments" +OPT_SINGLE_FILE_SEGMENTS_NUM , OPT_LONG_MAX_NUM };
lib/librte_eal/linuxapp/eal/eal.c +1 -0
@@ -349,6 +349,7 @@ eal_usage(const char *prgname)" --" OPT_CREATE_UIO_DEV " Create /dev/uioX (usually done by hotplug)\n" " --" OPT_VFIO_INTR " Interrupt mode for VFIO (legacy|msi|msix)\n" " --" OPT_LEGACY_MEM " Legacy memory mode (no dynamic allocation, contiguous segments)\n" +" --" OPT_SINGLE_FILE_SEGMENTS " Put all hugepage memory in single files\n" "\n");/* Allow the application to print its usage message too if hook is set */ if ( rte_application_usage_hook ) {
lib/librte_eal/linuxapp/eal/eal_memalloc.c +286 -51
392 lines not on this page · raw message
Signature · 1 line
2.7.4
PATCH v6 54/70 mem: add internal API to check if memory is contiguous
In reply to Anatoly BurakovFor now, memory is always contiguous because legacy mem mode is enabled unconditionally, but this function will be helpful down the line when we implement support for allocating physically non-contiguous memory. We can no longer guarantee physically contiguous memory unless we're in legacy or IOVA_AS_VA mode, but we can certainly try and see if we succeed.
In addition, this would be useful for e.g. PMD's who may allocate chunks that are smaller than the pagesize, but they must not cross the page boundary, in which case we will be able to accommodate that request. This function will also support non-hugepage memory.
--- lib/librte_eal/bsdapp/eal/Makefile | 1 + lib/librte_eal/common/eal_common_memalloc.c | 90 +++++++++++++++++++++++++++++ lib/librte_eal/common/eal_memalloc.h | 9 +++ lib/librte_eal/common/malloc_elem.c | 40 +------------ lib/librte_eal/common/meson.build | 1 + lib/librte_eal/linuxapp/eal/Makefile | 1 + 6 files changed, 105 insertions(+), 37 deletions(-) create mode 100644 lib/librte_eal/common/eal_common_memalloc.c
lib/librte_eal/bsdapp/eal/Makefile +1 -0
@@ -41,6 +41,7 @@ SRCS-$(CONFIG_RTE_EXEC_ENV_BSDAPP) += eal_common_timer.c SRCS-$(CONFIG_RTE_EXEC_ENV_BSDAPP) += eal_common_memzone.c SRCS-$(CONFIG_RTE_EXEC_ENV_BSDAPP) += eal_common_log.c SRCS-$(CONFIG_RTE_EXEC_ENV_BSDAPP) += eal_common_launch.c +SRCS-$(CONFIG_RTE_EXEC_ENV_BSDAPP) += eal_common_memalloc.c SRCS-$(CONFIG_RTE_EXEC_ENV_BSDAPP) += eal_common_memory.c SRCS-$(CONFIG_RTE_EXEC_ENV_BSDAPP) += eal_common_tailqs.c SRCS-$(CONFIG_RTE_EXEC_ENV_BSDAPP) += eal_common_errno.c
lib/librte_eal/common/eal_common_memalloc.c new file +90 -0
90 lines not on this page · raw message
lib/librte_eal/common/eal_memalloc.h +9 -0
@@ -8,6 +8,7 @@#include <stdbool.h> #include <rte_memory.h> +#include <rte_eal_memconfig.h> /* * Allocate segment of specified page size.
@@ -42,4 +43,12 @@ eal_memalloc_free_seg(struct rte_memseg *ms);int eal_memalloc_free_seg_bulk (struct rte_memseg **ms,int n_segs); +/* +* Check if memory pointed to by `start` and of `length` that resides in +* memseg list `msl` is IOVA-contiguous. +*/ +bool +eal_memalloc_is_contig (const struct rte_memseg_list *msl,void *start, +size_t len); +#endif /* EAL_MEMALLOC_H */
lib/librte_eal/common/malloc_elem.c +3 -37
@@ -18,6 +18,7 @@#include <rte_common.h> #include <rte_spinlock.h> +#include "eal_memalloc.h" #include "malloc_elem.h" #include "malloc_heap.h"
@@ -100,45 +101,10 @@ malloc_elem_insert(struct malloc_elem *elem)* so we just check the page addresses. */ static bool -elem_check_phys_contig(const struct rte_memseg_list *msl __rte_unused, +elem_check_phys_contig (const struct rte_memseg_list *msl,void *start,size_t size) { -rte_iova_t cur, expected; -void *start_page, *end_page, *cur_page; -size_t pagesz; - -/* for hugepage memory or IOVA as VA, it's always contiguous */ -if (rte_eal_has_hugepages () ||rte_eal_iova_mode () ==RTE_IOVA_VA ) -return true; - -/* otherwise, check if start and end are within the same page */ - pagesz =getpagesize (); - - start_page =RTE_PTR_ALIGN_FLOOR (start, pagesz); - end_page =RTE_PTR_ALIGN_FLOOR (RTE_PTR_ADD (start, size -1 ), pagesz); - -if (start_page == end_page) -return true; - -/* if they are from different pages, check if they are contiguous */ - -/* if we can't access physical addresses, assume non-contiguous */ -if (!rte_eal_using_phys_addrs ()) -return false; - -/* skip first iteration */ - cur =rte_mem_virt2iova (start_page); - expected = cur + pagesz; - cur_page =RTE_PTR_ADD (start_page, pagesz); - -while (cur_page <= end_page) { - cur =rte_mem_virt2iova (cur_page); -if (cur != expected) -return false; - cur_page =RTE_PTR_ADD (cur_page, pagesz); - expected += pagesz; - } -return true; +return eal_memalloc_is_contig (msl, start, size); }/*
lib/librte_eal/common/meson.build +1 -0
@@ -16,6 +16,7 @@ common_sources = files( 'eal_common_launch.c', 'eal_common_lcore.c', 'eal_common_log.c', + 'eal_common_memalloc.c', 'eal_common_memory.c', 'eal_common_memzone.c', 'eal_common_options.c',
lib/librte_eal/linuxapp/eal/Makefile +1 -0
@@ -49,6 +49,7 @@ SRCS-$(CONFIG_RTE_EXEC_ENV_LINUXAPP) += eal_common_timer.c SRCS-$(CONFIG_RTE_EXEC_ENV_LINUXAPP) += eal_common_memzone.c SRCS-$(CONFIG_RTE_EXEC_ENV_LINUXAPP) += eal_common_log.c SRCS-$(CONFIG_RTE_EXEC_ENV_LINUXAPP) += eal_common_launch.c +SRCS-$(CONFIG_RTE_EXEC_ENV_LINUXAPP) += eal_common_memalloc.c SRCS-$(CONFIG_RTE_EXEC_ENV_LINUXAPP) += eal_common_memory.c SRCS-$(CONFIG_RTE_EXEC_ENV_LINUXAPP) += eal_common_tailqs.c SRCS-$(CONFIG_RTE_EXEC_ENV_LINUXAPP) += eal_common_errno.c
Signature · 1 line
2.7.4
PATCH v6 55/70 mem: prepare memseg lists for multiprocess sync
In reply to Anatoly BurakovIn preparation for implementing multiprocess support, we are adding a version number to memseg lists. We will not need any locks, because memory hotplug will have a global lock (so any time memory map and thus version number might change, we will already be holding a lock).
There are two ways of implementing multiprocess support for memory
hotplug: either all information about mapped memory is shared between processes, and secondary processes simply attempt to map/unmap memory based on requests from the primary, or secondary processes store their own maps and only check if they are in sync with the primary process' maps.
This implementation will opt for the latter option: primary process shared mappings will be authoritative, and each secondary process will use its own interal view of mapped memory, and will attempt to synchronize on these mappings using versioning.
Under this model, only primary process will decide which pages get mapped, and secondary processes will only copy primary's page maps and get notified of the changes via IPC mechanism (coming in later commits).
--- lib/librte_eal/bsdapp/eal/eal_memalloc.c | 7 + lib/librte_eal/common/eal_memalloc.h | 4 + lib/librte_eal/common/include/rte_eal_memconfig.h | 1 + lib/librte_eal/linuxapp/eal/eal_memalloc.c | 250 ++++++++++++++++++++++ 4 files changed, 262 insertions(+)
lib/librte_eal/bsdapp/eal/eal_memalloc.c +7 -0
@@ -39,3 +39,10 @@ eal_memalloc_free_seg_bulk(struct rte_memseg **ms __rte_unused,RTE_LOG (ERR ,EAL ,"Memory hotplug not supported on FreeBSD\n" );return -1 ; } + +int +eal_memalloc_sync_with_primary (void ) +{ +RTE_LOG (ERR ,EAL ,"Memory hotplug not supported on FreeBSD\n" ); +return -1 ; +}
lib/librte_eal/common/eal_memalloc.h +4 -0
@@ -51,4 +51,8 @@ bool eal_memalloc_is_contig(const struct rte_memseg_list *msl, void *start, size_t len); +/* synchronize local memory map to primary process */ +int +eal_memalloc_sync_with_primary (void ); +#endif /* EAL_MEMALLOC_H */
lib/librte_eal/common/include/rte_eal_memconfig.h +1 -0
@@ -32,6 +32,7 @@ struct rte_memseg_list { };int socket_id;/**< Socket ID for all memsegs in this list. */ uint64_t page_sz;/**< Page size for all memsegs in this list. */ +volatile uint32_t version;/**< version number for multiprocess sync. */ struct rte_fbarray memseg_arr; };
lib/librte_eal/linuxapp/eal/eal_memalloc.c +250 -0
272 lines not on this page · raw message
Signature · 1 line
2.7.4
PATCH v6 56/70 eal: read hugepage counts from node-specific sysfs path
In reply to Anatoly BurakovFor non-legacy memory init mode, instead of looking at generic sysfs path, look at sysfs paths pertaining to each NUMA node for hugepage counts. Note that per-NUMA node path does not provide information regarding reserved pages, so we might not get the best info from these paths, but this saves us from the whole mapping/remapping business before we're actually able to tell which page is on which socket, because we no longer require our memory to be physically contiguous.
Legacy memory init will not use this.
--- lib/librte_eal/linuxapp/eal/eal_hugepage_info.c | 80 +++++++++++++++++++++++-- 1 file changed, 74 insertions(+), 6 deletions(-)
lib/librte_eal/linuxapp/eal/eal_hugepage_info.c +74 -6
@@ -31,6 +31,7 @@#include "eal_filesystem.h" static const char sys_dir_path[] ="/sys/kernel/mm/hugepages" ; +static const char sys_pages_numa_dir_path[] ="/sys/devices/system/node" ;/* this function is only called from eal_hugepage_info_init which itself * is only called from a primary process */
@@ -71,6 +72,45 @@ get_num_hugepages(const char *subdir)return num_pages; } +static uint32_t +get_num_hugepages_on_node (const char *subdir,unsigned int socket) +{ +char path[PATH_MAX ], socketpath[PATH_MAX ]; +DIR *socketdir; +unsigned long num_pages =0 ; +const char *nr_hp_file ="free_hugepages" ; + +snprintf (socketpath,sizeof (socketpath),"%s/node%u/hugepages" , + sys_pages_numa_dir_path, socket); + + socketdir =opendir (socketpath); +if (socketdir) { +/* Keep calm and carry on */ +closedir (socketdir); + }else { +/* Can't find socket dir, so ignore it */ +return 0 ; + } + +snprintf (path,sizeof (path),"%s/%s/%s" , + socketpath, subdir, nr_hp_file); +if (eal_parse_sysfs_value (path, &num_pages) <0 ) +return 0 ; + +if (num_pages ==0 ) +RTE_LOG (WARNING ,EAL ,"No free hugepages reported in %s\n" , + subdir); + +/* +* we want to return a uint32_t and more than this looks suspicious +* anyway ... +*/ +if (num_pages >UINT32_MAX ) + num_pages =UINT32_MAX ; + +return num_pages; +} +static uint64_t get_default_hp_size (void ) {
@@ -269,7 +309,7 @@ eal_hugepage_info_init(void) {const char dirent_start_text[] ="hugepages-" ;const size_t dirent_start_len =sizeof (dirent_start_text) -1 ; -unsigned i, num_sizes =0 ; +unsigned int i, total_pages, num_sizes =0 ;DIR *dir;struct dirent *dirent;
@@ -323,9 +363,28 @@ eal_hugepage_info_init(void)if (clear_hugedir (hpi->hugedir) ==-1 )break ; -/* for now, put all pages into socket 0, -* later they will be sorted */ - hpi->num_pages[0 ] =get_num_hugepages (dirent->d_name); +/* +* first, try to put all hugepages into relevant sockets, but +* if first attempts fails, fall back to collecting all pages +* in one socket and sorting them later +*/ + total_pages =0 ; +/* we also don't want to do this for legacy init */ +if (!internal_config.legacy_mem) +for (i =0 ; i <rte_socket_count (); i++) { +int socket =rte_socket_id_by_idx (i); +unsigned int num_pages = +get_num_hugepages_on_node ( + dirent->d_name, socket); + hpi->num_pages[socket] = num_pages; + total_pages += num_pages; + } +/* +* we failed to sort memory from the get go, so fall +* back to old way +*/ +if (total_pages ==0 ) + hpi->num_pages[0 ] =get_num_hugepages (dirent->d_name);#ifndef RTE_ARCH_64 /* for 32-bit systems, limit number of hugepages to
@@ -349,10 +408,19 @@ eal_hugepage_info_init(void) sizeof(internal_config.hugepage_info[0]), compare_hpi);/* now we have all info, check we have at least one valid size */ -for (i =0 ; i < num_sizes; i++) +for (i =0 ; i < num_sizes; i++) { +/* pages may no longer all be on socket 0, so check all */ +unsigned int j, num_pages =0 ; + +for (j =0 ; j <RTE_MAX_NUMA_NODES ; j++) { +struct hugepage_info *hpi = + &internal_config.hugepage_info[i]; + num_pages += hpi->num_pages[j]; + }if (internal_config.hugepage_info[i].hugedir !=NULL && - internal_config.hugepage_info[i].num_pages[0 ] >0 ) + num_pages >0 )return 0 ; + }/* no valid hugepage mounts available, return error */ return -1 ;
Signature · 1 line
2.7.4
PATCH v6 57/70 eal: make use of memory hotplug for init
In reply to Anatoly BurakovAdd a new (non-legacy) memory init path for EAL. It uses the new memory hotplug facilities.
If no -m or --socket-mem switches were specified, the new init will not allocate anything, whereas if those switches were passed, appropriate amounts of pages would be requested, just like for legacy init.
Allocated pages will be physically discontiguous (or rather, they're not guaranteed to be physically contiguous - they may still be so by accident) unless RTE_IOVA_VA mode is used.
--- lib/librte_eal/linuxapp/eal/eal_memory.c | 62 ++++++++++++++++++++++++++++++-- 1 file changed, 59 insertions(+), 3 deletions(-)
lib/librte_eal/linuxapp/eal/eal_memory.c +59 -3
@@ -40,6 +40,7 @@#include <rte_string_fns.h> #include "eal_private.h" +#include "eal_memalloc.h" #include "eal_internal_cfg.h" #include "eal_filesystem.h" #include "eal_hugepages.h"
@@ -1601,6 +1602,61 @@ eal_legacy_hugepage_init(void)return -1 ; } +static int +eal_hugepage_init (void ) +{ +struct hugepage_info used_hp[MAX_HUGEPAGE_SIZES ]; +uint64_t memory[RTE_MAX_NUMA_NODES ]; +int hp_sz_idx, socket_id; + +test_phys_addrs_available (); + +memset (used_hp,0 ,sizeof (used_hp)); + +for (hp_sz_idx =0 ; + hp_sz_idx < (int ) internal_config.num_hugepage_sizes; + hp_sz_idx++) { +/* also initialize used_hp hugepage sizes in used_hp */ +struct hugepage_info *hpi; + hpi = &internal_config.hugepage_info[hp_sz_idx]; + used_hp[hp_sz_idx].hugepage_sz = hpi->hugepage_sz; + } + +/* make a copy of socket_mem, needed for balanced allocation. */ +for (hp_sz_idx =0 ; hp_sz_idx <RTE_MAX_NUMA_NODES ; hp_sz_idx++) + memory[hp_sz_idx] = internal_config.socket_mem[hp_sz_idx]; + +/* calculate final number of pages */ +if (calc_num_pages_per_socket (memory, + internal_config.hugepage_info, used_hp, + internal_config.num_hugepage_sizes) <0 ) +return -1 ; + +for (hp_sz_idx =0 ; + hp_sz_idx < (int )internal_config.num_hugepage_sizes; + hp_sz_idx++) { +for (socket_id =0 ; socket_id <RTE_MAX_NUMA_NODES ; + socket_id++) { +struct hugepage_info *hpi = &used_hp[hp_sz_idx]; +unsigned int num_pages = hpi->num_pages[socket_id]; +int num_pages_alloc; + +if (num_pages ==0 ) +continue ; + +RTE_LOG (DEBUG ,EAL ,"Allocating %u pages of size %" PRIu64"M on socket %i\n" , + num_pages, hpi->hugepage_sz >>20 , socket_id); + + num_pages_alloc =eal_memalloc_alloc_seg_bulk (NULL , + num_pages, hpi->hugepage_sz, + socket_id, true); +if (num_pages_alloc <0 ) +return -1 ; + } + } +return 0 ; +} +/* * uses fstat to report the size of a file on disk */
@@ -1723,9 +1779,9 @@ eal_legacy_hugepage_attach(void)int rte_eal_hugepage_init (void ) { -if (internal_config.legacy_mem) -return eal_legacy_hugepage_init (); -return -1 ; +return internal_config.legacy_mem ? +eal_legacy_hugepage_init () : +eal_hugepage_init (); }int
Signature · 1 line
2.7.4
PATCH v6 58/70 eal: share hugepage info primary and secondary
In reply to Anatoly BurakovSince we are going to need to map hugepages in both primary and secondary processes, we need to know where we should look for hugetlbfs mountpoints. So, share those with secondary processes, and map them on init.
--- lib/librte_eal/bsdapp/eal/eal.c | 19 ++-- lib/librte_eal/bsdapp/eal/eal_hugepage_info.c | 56 +++++++++-- lib/librte_eal/bsdapp/eal/eal_memory.c | 21 +--- lib/librte_eal/common/eal_common_options.c | 5 +- lib/librte_eal/common/eal_filesystem.h | 17 ++++ lib/librte_eal/common/eal_hugepages.h | 10 +- lib/librte_eal/common/eal_internal_cfg.h | 2 +- lib/librte_eal/linuxapp/eal/eal.c | 18 ++-- lib/librte_eal/linuxapp/eal/eal_hugepage_info.c | 121 ++++++++++++++++++++---- lib/librte_eal/linuxapp/eal/eal_memory.c | 15 +-- 10 files changed, 217 insertions(+), 67 deletions(-)
lib/librte_eal/bsdapp/eal/eal.c +12 -7
@@ -289,7 +289,7 @@ eal_get_hugepage_mem_size(void)for (i =0 ; i < internal_config.num_hugepage_sizes; i++) {struct hugepage_info *hpi = &internal_config.hugepage_info[i]; -if (hpi->hugedir !=NULL ) { +if (strnlen (hpi->hugedir,sizeof (hpi->hugedir)) !=0 ) {for (j =0 ; j <RTE_MAX_NUMA_NODES ; j++) { size += hpi->hugepage_sz * hpi->num_pages[j]; }
@@ -561,12 +561,17 @@ rte_eal_init(int argc, char **argv)/* autodetect the iova mapping mode (default is iova_pa) */ rte_eal_get_configuration ()->iova_mode =rte_bus_get_iommu_class (); -if (internal_config.no_hugetlbfs ==0 && -eal_hugepage_info_init () <0 ) { -rte_eal_init_alert ("Cannot get hugepage information." ); - rte_errno =EACCES ; -rte_atomic32_clear (&run_once); -return -1 ; +if (internal_config.no_hugetlbfs ==0 ) { +/* rte_config isn't initialized yet */ + ret = internal_config.process_type ==RTE_PROC_PRIMARY ? +eal_hugepage_info_init () : +eal_hugepage_info_read (); +if (ret <0 ) { +rte_eal_init_alert ("Cannot get hugepage information." ); + rte_errno =EACCES ; +rte_atomic32_clear (&run_once); +return -1 ; + } }if (internal_config.memory ==0 && internal_config.force_sockets ==0 ) {
lib/librte_eal/bsdapp/eal/eal_hugepage_info.c +49 -7
94 lines not on this page · raw message
lib/librte_eal/bsdapp/eal/eal_memory.c +2 -19
@@ -242,23 +242,10 @@ intrte_eal_hugepage_attach (void) {const struct hugepage_info *hpi; -int fd_hugepage_info, fd_hugepage =-1 ; +int fd_hugepage =-1 ;unsigned int i; -/* Obtain a file descriptor for hugepage_info */ - fd_hugepage_info =open (eal_hugepage_info_path (),O_RDONLY ); -if (fd_hugepage_info <0 ) { -RTE_LOG (ERR ,EAL ,"Could not open %s\n" ,eal_hugepage_info_path ()); -return -1 ; - } - -/* Map the shared hugepage_info into the process address spaces */ - hpi =mmap (NULL ,sizeof (internal_config.hugepage_info), -PROT_READ ,MAP_PRIVATE , fd_hugepage_info,0 ); -if (hpi ==MAP_FAILED ) { -RTE_LOG (ERR ,EAL ,"Could not mmap %s\n" ,eal_hugepage_info_path ()); - goto error; - } + hpi = &internal_config.hugepage_info[0 ];for (i =0 ; i < internal_config.num_hugepage_sizes; i++) {const struct hugepage_info *cur_hpi = &hpi[i];
@@ -288,13 +275,9 @@ rte_eal_hugepage_attach(void) }/* hugepage_info is no longer required */ -munmap ((void *)(uintptr_t )hpi,sizeof (internal_config.hugepage_info)); -close (fd_hugepage_info);return 0 ; error: -if (fd_hugepage_info >=0 ) -close (fd_hugepage_info);if (fd_hugepage >=0 )close (fd_hugepage);return -1 ;
lib/librte_eal/common/eal_common_options.c +4 -1
@@ -179,8 +179,11 @@ eal_reset_internal_config(struct internal_config *internal_cfg)for (i =0 ; i <RTE_MAX_NUMA_NODES ; i++) internal_cfg->socket_mem[i] =0 ;/* zero out hugedir descriptors */ -for (i =0 ; i <MAX_HUGEPAGE_SIZES ; i++) +for (i =0 ; i <MAX_HUGEPAGE_SIZES ; i++) { +memset (&internal_cfg->hugepage_info[i],0 , +sizeof (internal_cfg->hugepage_info[0 ])); internal_cfg->hugepage_info[i].lock_descriptor =-1 ; + } internal_cfg->base_virtaddr =0 ; internal_cfg->syslog_facility =LOG_DAEMON ;
lib/librte_eal/common/eal_filesystem.h +17 -0
@@ -85,6 +85,23 @@ eal_hugepage_info_path(void)return buffer; } +/** Path of hugepage info file. */ +#define HUGEPAGE_FILE_FMT "%s/.%s_hugepage_file" + +static inline const char * +eal_hugepage_file_path (void ) +{ +static char buffer[PATH_MAX ];/* static so auto-zeroed */ +const char *directory = default_config_dir; +const char *home_dir =getenv ("HOME" ); + +if (getuid () !=0 && home_dir !=NULL ) + directory = home_dir; +snprintf (buffer,sizeof (buffer) -1 ,HUGEPAGE_FILE_FMT , directory, + internal_config.hugefile_prefix); +return buffer; +} +/** String format for hugepage map files. */ #define HUGEFILE_FMT "%s/%smap_%d"#define TEMP_HUGEFILE_FMT "%s/%smap_temp_%d"
lib/librte_eal/common/eal_hugepages.h +8 -2
@@ -26,9 +26,15 @@ struct hugepage_file { };/** -* Read the information from linux on what hugepages are available -* for the EAL to use +* Read the information on what hugepages are available for the EAL to use, +* clearing out any unused ones. */ int eal_hugepage_info_init (void ); +/** +* Read whatever information primary process has shared about hugepages into +* secondary process. +*/ +int eal_hugepage_info_read (void ); +#endif /* EAL_HUGEPAGES_H */
lib/librte_eal/common/eal_internal_cfg.h +1 -1
@@ -21,7 +21,7 @@*/ struct hugepage_info {uint64_t hugepage_sz;/**< size of a huge page */ -const char *hugedir;/**< dir where hugetlbfs is mounted */ +char hugedir[PATH_MAX ];/**< dir where hugetlbfs is mounted */ uint32_t num_pages[RTE_MAX_NUMA_NODES ];/**< number of hugepages of that size on each socket */ int lock_descriptor;/**< file descriptor for hugepage dir */
lib/librte_eal/linuxapp/eal/eal.c +11 -7
@@ -807,13 +807,17 @@ rte_eal_init(int argc, char **argv) "KNI module inserted\n"); } -if (internal_config.no_hugetlbfs ==0 && - internal_config.process_type !=RTE_PROC_SECONDARY && -eal_hugepage_info_init () <0 ) { -rte_eal_init_alert ("Cannot get hugepage information." ); - rte_errno =EACCES ; -rte_atomic32_clear (&run_once); -return -1 ; +if (internal_config.no_hugetlbfs ==0 ) { +/* rte_config isn't initialized yet */ + ret = internal_config.process_type ==RTE_PROC_PRIMARY ? +eal_hugepage_info_init () : +eal_hugepage_info_read (); +if (ret <0 ) { +rte_eal_init_alert ("Cannot get hugepage information." ); + rte_errno =EACCES ; +rte_atomic32_clear (&run_once); +return -1 ; + } }if (internal_config.memory ==0 && internal_config.force_sockets ==0 ) {
lib/librte_eal/linuxapp/eal/eal_hugepage_info.c +105 -16
170 lines not on this page · raw message
lib/librte_eal/linuxapp/eal/eal_memory.c +8 -7
@@ -1060,7 +1060,7 @@ get_socket_mem_size(int socket)for (i =0 ; i < internal_config.num_hugepage_sizes; i++){struct hugepage_info *hpi = &internal_config.hugepage_info[i]; -if (hpi->hugedir !=NULL ) +if (strnlen (hpi->hugedir,sizeof (hpi->hugedir)) !=0 ) size += hpi->hugepage_sz * hpi->num_pages[socket]; }
@@ -1160,7 +1160,8 @@ calc_num_pages_per_socket(uint64_t * memory,for (socket =0 ; socket <RTE_MAX_NUMA_NODES && total_mem !=0 ; socket++) {/* skips if the memory on specific socket wasn't requested */ for (i =0 ; i < num_hp_info && memory[socket] !=0 ; i++){ - hp_used[i].hugedir = hp_info[i].hugedir; +snprintf (hp_used[i].hugedir,sizeof (hp_used[i].hugedir), +"%s" , hp_info[i].hugedir); hp_used[i].num_pages[socket] =RTE_MIN ( memory[socket] / hp_info[i].hugepage_sz, hp_info[i].num_pages[socket]);
@@ -1235,7 +1236,7 @@ eal_get_hugepage_mem_size(void)for (i =0 ; i < internal_config.num_hugepage_sizes; i++) {struct hugepage_info *hpi = &internal_config.hugepage_info[i]; -if (hpi->hugedir !=NULL ) { +if (strnlen (hpi->hugedir,sizeof (hpi->hugedir)) !=0 ) {for (j =0 ; j <RTE_MAX_NUMA_NODES ; j++) { size += hpi->hugepage_sz * hpi->num_pages[j]; }
@@ -1509,7 +1510,7 @@ eal_legacy_hugepage_init(void) }/* create shared memory */ - hugepage =create_shared_memory (eal_hugepage_info_path (), + hugepage =create_shared_memory (eal_hugepage_file_path (), nr_hugefiles *sizeof (struct hugepage_file ));if (hugepage ==NULL ) {
@@ -1694,16 +1695,16 @@ eal_legacy_hugepage_attach(void)test_phys_addrs_available (); - fd_hugepage =open (eal_hugepage_info_path (),O_RDONLY ); + fd_hugepage =open (eal_hugepage_file_path (),O_RDONLY );if (fd_hugepage <0 ) { -RTE_LOG (ERR ,EAL ,"Could not open %s\n" ,eal_hugepage_info_path ()); +RTE_LOG (ERR ,EAL ,"Could not open %s\n" ,eal_hugepage_file_path ()); goto error; } size =getFileSize (fd_hugepage); hp =mmap (NULL , size,PROT_READ ,MAP_PRIVATE , fd_hugepage,0 );if (hp ==MAP_FAILED ) { -RTE_LOG (ERR ,EAL ,"Could not mmap %s\n" ,eal_hugepage_info_path ()); +RTE_LOG (ERR ,EAL ,"Could not mmap %s\n" ,eal_hugepage_file_path ()); goto error; }
Signature · 1 line
2.7.4
PATCH v6 59/70 eal: add secondary process init with memory hotplug
In reply to Anatoly BurakovSecondary initialization will just sync memory map with primary process.
--- lib/librte_eal/common/eal_common_memory.c | 1 + lib/librte_eal/linuxapp/eal/eal_memory.c | 18 +++++++++++++++--- 2 files changed, 16 insertions(+), 3 deletions(-)
lib/librte_eal/common/eal_common_memory.c +1 -0
@@ -20,6 +20,7 @@#include <rte_errno.h> #include <rte_log.h> +#include "eal_memalloc.h" #include "eal_private.h" #include "eal_internal_cfg.h"
lib/librte_eal/linuxapp/eal/eal_memory.c +15 -3
@@ -1777,6 +1777,18 @@ eal_legacy_hugepage_attach(void)return -1 ; } +static int +eal_hugepage_attach (void ) +{ +if (eal_memalloc_sync_with_primary ()) { +RTE_LOG (ERR ,EAL ,"Could not map memory from primary process\n" ); +if (aslr_enabled () >0 ) +RTE_LOG (ERR ,EAL ,"It is recommended to disable ASLR in the kernel and retry running both primary and secondary processes\n" ); +return -1 ; + } +return 0 ; +} +int rte_eal_hugepage_init (void ) {
@@ -1788,9 +1800,9 @@ rte_eal_hugepage_init(void)int rte_eal_hugepage_attach (void ) { -if (internal_config.legacy_mem) -return eal_legacy_hugepage_attach (); -return -1 ; +return internal_config.legacy_mem ? +eal_legacy_hugepage_attach () : +eal_hugepage_attach (); }int
Signature · 1 line
2.7.4
PATCH v6 60/70 malloc: enable memory hotplug support
In reply to Anatoly BurakovThis set of changes enables rte_malloc to allocate and free memory as needed. Currently, it is disabled because legacy mem mode is enabled unconditionally.
The way it works is, first malloc checks if there is enough memory already allocated to satisfy user's request. If there isn't, we try and allocate more memory. The reverse happens with free - we free an element, check its size (including free element merging due to adjacency) and see if it's bigger than hugepage size and that its start and end span a hugepage or more. Then we remove the area from malloc heap (adjusting element lengths where appropriate), and deallocate the page.
For legacy mode, runtime alloc/free of pages is disabled.
It is worth noting that memseg lists are being sorted by page size, and that we try our best to satisfy user's request. That is, if the user requests an element from a 2MB page memory, we will check if we can satisfy that request from existing memory, if not we try and allocate more 2MB pages. If that fails and user also specified a "size is hint" flag, we then check other page sizes and try to allocate from there. If that fails too, then, depending on flags, we may try allocating from other sockets. In other words, we try our best to give the user what they asked for, but going to other sockets is last resort - first we try to allocate more memory on the same socket.
--- lib/librte_eal/common/eal_common_memzone.c | 26 +-- lib/librte_eal/common/malloc_elem.c | 92 ++++++++ lib/librte_eal/common/malloc_elem.h | 3 + lib/librte_eal/common/malloc_heap.c | 347 ++++++++++++++++++++++++++++- lib/librte_eal/common/malloc_heap.h | 4 +- lib/librte_eal/common/rte_malloc.c | 31 +-- 6 files changed, 439 insertions(+), 64 deletions(-)
lib/librte_eal/common/eal_common_memzone.c +3 -23
@@ -93,7 +93,7 @@ memzone_reserve_aligned_thread_unsafe(const char *name, size_t len,struct rte_mem_config *mcfg;struct rte_fbarray *arr;size_t requested_len; -int socket, i, mz_idx; +int mz_idx;bool contig;/* get pointer to global configuration */
@@ -183,29 +183,9 @@ memzone_reserve_aligned_thread_unsafe(const char *name, size_t len, } } -if (socket_id ==SOCKET_ID_ANY ) - socket =malloc_get_numa_socket (); -else - socket = socket_id; -/* allocate memory on heap */ -void *mz_addr =malloc_heap_alloc (&mcfg->malloc_heaps[socket],NULL , - requested_len, flags, align, bound, contig); - -if ((mz_addr ==NULL ) && (socket_id ==SOCKET_ID_ANY )) { -/* try other heaps */ -for (i =0 ; i <RTE_MAX_NUMA_NODES ; i++) { -if (socket == i) -continue ; - - mz_addr =malloc_heap_alloc (&mcfg->malloc_heaps[i], -NULL , requested_len, flags, align, - bound, contig); -if (mz_addr !=NULL ) -break ; - } - } - +void *mz_addr =malloc_heap_alloc (NULL , requested_len, socket_id, flags, + align, bound, contig);if (mz_addr ==NULL ) { rte_errno =ENOMEM ;return NULL ;
lib/librte_eal/common/malloc_elem.c +92 -0
98 lines not on this page · raw message
lib/librte_eal/common/malloc_elem.h +3 -0
@@ -154,6 +154,9 @@ int malloc_elem_resize(struct malloc_elem *elem, size_t size);void +malloc_elem_hide_region (struct malloc_elem *elem,void *start,size_t len); + +void malloc_elem_free_list_remove (struct malloc_elem *elem);/*
lib/librte_eal/common/malloc_heap.c +336 -11
392 lines not on this page · raw message
lib/librte_eal/common/malloc_heap.h +2 -2
@@ -26,8 +26,8 @@ malloc_get_numa_socket(void) }void * -malloc_heap_alloc (struct malloc_heap *heap,const char *type,size_t size, -unsigned int flags,size_t align,size_t bound,bool contig); +malloc_heap_alloc (const char *type,size_t size,int socket,unsigned int flags, +size_t align,size_t bound,bool contig);int malloc_heap_free (struct malloc_elem *elem);
lib/librte_eal/common/rte_malloc.c +3 -28
@@ -40,10 +40,6 @@ void * rte_malloc_socket(const char *type, size_t size, unsigned int align, int socket_arg) { - struct rte_mem_config *mcfg = rte_eal_get_configuration()->mem_config; -int socket, i; -void *ret; - /* return NULL if size is 0 or alignment is not power-of-2 */ if (size == 0 || (align && !rte_is_power_of_2(align))) return NULL;
@@ -51,33 +47,12 @@ rte_malloc_socket(const char *type, size_t size, unsigned int align,if (!rte_eal_has_hugepages ()) socket_arg =SOCKET_ID_ANY ; -if (socket_arg ==SOCKET_ID_ANY ) - socket =malloc_get_numa_socket (); -else - socket = socket_arg; -/* Check socket parameter */ -if (socket >=RTE_MAX_NUMA_NODES ) +if (socket_arg >=RTE_MAX_NUMA_NODES )return NULL ; - ret =malloc_heap_alloc (&mcfg->malloc_heaps[socket], type, - size,0 , align ==0 ?1 : align,0 , false); -if (ret !=NULL || socket_arg !=SOCKET_ID_ANY ) -return ret; - -/* try other heaps */ -for (i =0 ; i <RTE_MAX_NUMA_NODES ; i++) { -/* we already tried this one */ -if (i == socket) -continue ; - - ret =malloc_heap_alloc (&mcfg->malloc_heaps[i], type, - size,0 , align ==0 ?1 : align,0 , false); -if (ret !=NULL ) -return ret; - } - -return NULL ; +return malloc_heap_alloc (type, size, socket_arg,0 , + align ==0 ?1 : align,0 , false); }/*
Signature · 1 line
2.7.4
PATCH v6 61/70 malloc: add support for multiprocess memory hotplug
In reply to Anatoly BurakovThis enables multiprocess synchronization for memory hotplug requests at runtime (as opposed to initialization).
Basic workflow is the following. Primary process always does initial mapping and unmapping, and secondary processes always follow primary page map. Only one allocation request can be active at any one time.
When primary allocates memory, it ensures that all other processes have allocated the same set of hugepages successfully, otherwise any allocations made are being rolled back, and heap is freed back. Heap is locked throughout the process, and there is also a global memory hotplug lock, so no race conditions can happen.
When primary frees memory, it frees the heap, deallocates affected pages, and notifies other processes of deallocations. Since heap is freed from that memory chunk, the area basically becomes invisible to other processes even if they happen to fail to unmap that specific set of pages, so it's completely safe to ignore results of sync requests.
When secondary allocates memory, it does not do so by itself. Instead, it sends a request to primary process to try and allocate pages of specified size and on specified socket, such that a specified heap allocation request could complete. Primary process then sends all secondaries (including the requestor) a separate notification of allocated pages, and expects all secondary processes to report success before considering pages as "allocated".
Only after primary process ensures that all memory has been successfully allocated in all secondary process, it will respond positively to the initial request, and let secondary proceed with the allocation. Since the heap now has memory that can satisfy allocation request, and it was locked all this time (so no other allocations could take place), secondary process will be able to allocate memory from the heap.
When secondary frees memory, it hides pages to be deallocated from the heap. Then, it sends a deallocation request to primary process, so that it deallocates pages itself, and then sends a separate sync request to all other processes (including the requestor) to unmap the same pages. This way, even if secondary fails to notify other processes of this deallocation, that memory will become invisible to other processes, and will not be allocated from again.
So, to summarize: address space will only become part of the heap if primary process can ensure that all other processes have allocated this memory successfully. If anything goes wrong, the worst thing that could happen is that a page will "leak" and will not be available to neither DPDK nor the system, as some process will still hold onto it. It's not an actual leak, as we can account for the page - it's just that none of the processes will be able to use this page for anything useful, until it gets allocated from by the primary.
Due to underlying DPDK IPC implementation being single-threaded, some asynchronous magic had to be done, as we need to complete several requests before we can definitively allow secondary process to use allocated memory (namely, it has to be present in all other secondary processes before it can be used). Additionally, only one allocation request is allowed to be submitted at once.
Memory allocation requests are only allowed when there are no secondary processes currently initializing. To enforce that, a shared rwlock is used, that is set to read lock on init (so that several secondaries could initialize concurrently), and write lock on making allocation requests (so that either secondary init will have to wait, or allocation request will have to wait until all processes have initialized).
Any other function that wishes to iterate over memory or prevent allocations should be using memory hotplug lock.
--- lib/librte_eal/bsdapp/eal/Makefile | 1 + lib/librte_eal/common/eal_common_memory.c | 67 +- lib/librte_eal/common/include/rte_eal_memconfig.h | 3 + lib/librte_eal/common/malloc_heap.c | 255 ++++++-- lib/librte_eal/common/malloc_mp.c | 744 ++++++++++++++++++++++ lib/librte_eal/common/malloc_mp.h | 86 +++ lib/librte_eal/common/meson.build | 1 + lib/librte_eal/linuxapp/eal/Makefile | 1 + lib/librte_eal/linuxapp/eal/eal_memalloc.c | 32 +- 9 files changed, 1126 insertions(+), 64 deletions(-) create mode 100644 lib/librte_eal/common/malloc_mp.c create mode 100644 lib/librte_eal/common/malloc_mp.h
lib/librte_eal/bsdapp/eal/Makefile +1 -0
@@ -59,6 +59,7 @@ SRCS-$(CONFIG_RTE_EXEC_ENV_BSDAPP) += eal_common_fbarray.c SRCS-$(CONFIG_RTE_EXEC_ENV_BSDAPP) += rte_malloc.c SRCS-$(CONFIG_RTE_EXEC_ENV_BSDAPP) += malloc_elem.c SRCS-$(CONFIG_RTE_EXEC_ENV_BSDAPP) += malloc_heap.c +SRCS-$(CONFIG_RTE_EXEC_ENV_BSDAPP) += malloc_mp.c SRCS-$(CONFIG_RTE_EXEC_ENV_BSDAPP) += rte_keepalive.c SRCS-$(CONFIG_RTE_EXEC_ENV_BSDAPP) += rte_service.c SRCS-$(CONFIG_RTE_EXEC_ENV_BSDAPP) += rte_reciprocal.c
lib/librte_eal/common/eal_common_memory.c +49 -18
130 lines not on this page · raw message
lib/librte_eal/common/include/rte_eal_memconfig.h +3 -0
@@ -59,6 +59,9 @@ struct rte_mem_config {rte_rwlock_t qlock;/**< used for tailq operation for thread safe. */ rte_rwlock_t mplock;/**< only used by mempool LIB for thread-safe. */ +rte_rwlock_t memory_hotplug_lock; +/**< indicates whether memory hotplug request is in progress. */ +/* memory segments and zones */ struct rte_fbarray memzones;/**< Memzone descriptors. */
lib/librte_eal/common/malloc_heap.c +212 -43
371 lines not on this page · raw message
lib/librte_eal/common/malloc_mp.c new file +744 -0
744 lines not on this page · raw message
lib/librte_eal/common/malloc_mp.h new file +86 -0
86 lines not on this page · raw message
lib/librte_eal/common/meson.build +1 -0
@@ -27,6 +27,7 @@ common_sources = files( 'eal_common_timer.c', 'malloc_elem.c', 'malloc_heap.c', + 'malloc_mp.c', 'rte_keepalive.c', 'rte_malloc.c', 'rte_reciprocal.c',
lib/librte_eal/linuxapp/eal/Makefile +1 -0
@@ -67,6 +67,7 @@ SRCS-$(CONFIG_RTE_EXEC_ENV_LINUXAPP) += eal_common_fbarray.c SRCS-$(CONFIG_RTE_EXEC_ENV_LINUXAPP) += rte_malloc.c SRCS-$(CONFIG_RTE_EXEC_ENV_LINUXAPP) += malloc_elem.c SRCS-$(CONFIG_RTE_EXEC_ENV_LINUXAPP) += malloc_heap.c +SRCS-$(CONFIG_RTE_EXEC_ENV_LINUXAPP) += malloc_mp.c SRCS-$(CONFIG_RTE_EXEC_ENV_LINUXAPP) += rte_keepalive.c SRCS-$(CONFIG_RTE_EXEC_ENV_LINUXAPP) += rte_service.c SRCS-$(CONFIG_RTE_EXEC_ENV_LINUXAPP) += rte_reciprocal.c
lib/librte_eal/linuxapp/eal/eal_memalloc.c +29 -3
@@ -211,6 +211,32 @@ is_zero_length(int fd)return st.st_blocks ==0 ; } +/* we cannot use rte_memseg_list_walk() here because we will be holding a +* write lock whenever we enter every function in this file, however copying +* the same iteration code everywhere is not ideal as well. so, use a lockless +* copy of memseg list walk here. +*/ +static int +memseg_list_walk_thread_unsafe (rte_memseg_list_walk_t func,void *arg) +{ +struct rte_mem_config *mcfg =rte_eal_get_configuration ()->mem_config; +int i, ret =0 ; + +for (i =0 ; i <RTE_MAX_MEMSEG_LISTS ; i++) { +struct rte_memseg_list *msl = &mcfg->memsegs[i]; + +if (msl->base_va ==NULL ) +continue ; + + ret =func (msl, arg); +if (ret <0 ) +return -1 ; +if (ret >0 ) +return 1 ; + } +return 0 ; +} +static int get_seg_fd (char *path,int buflen,struct hugepage_info *hi,unsigned int list_idx,unsigned int seg_idx)
@@ -739,7 +765,7 @@ eal_memalloc_alloc_seg_bulk(struct rte_memseg **ms, int n_segs, size_t page_sz, wa.socket = socket; wa.segs_allocated =0 ; - ret =rte_memseg_list_walk (alloc_seg_walk, &wa); + ret =memseg_list_walk_thread_unsafe (alloc_seg_walk, &wa);if (ret ==0 ) {RTE_LOG (ERR ,EAL ,"%s(): couldn't find suitable memseg_list\n" , __func__);
@@ -797,7 +823,7 @@ eal_memalloc_free_seg_bulk(struct rte_memseg **ms, int n_segs) wa.ms = cur; wa.hi = hi; - walk_res =rte_memseg_list_walk (free_seg_walk, &wa); + walk_res =memseg_list_walk_thread_unsafe (free_seg_walk, &wa);if (walk_res ==1 )continue ;if (walk_res ==0 )
@@ -1054,7 +1080,7 @@ eal_memalloc_sync_with_primary(void)if (rte_eal_process_type () ==RTE_PROC_PRIMARY )return 0 ; -if (rte_memseg_list_walk (sync_walk,NULL )) +if (memseg_list_walk_thread_unsafe (sync_walk,NULL ))return -1 ;return 0 ; }
Signature · 1 line
2.7.4
PATCH v6 62/70 malloc: add support for callbacks on memory events
In reply to Anatoly BurakovEach process will have its own callbacks. Callbacks will indicate whether it's allocation and deallocation that's happened, and will also provide start VA address and length of allocated block.
Since memory hotplug isn't supported on FreeBSD and in legacy mem mode, it will not be possible to register them in either.
Callbacks are called whenever something happens to the memory map of current process, therefore at those times memory hotplug subsystem is write-locked, which leads to deadlocks on attempt to use these functions. Document the limitation.
--- lib/librte_eal/common/eal_common_memalloc.c | 133 ++++++++++++++++++++++++++++ lib/librte_eal/common/eal_common_memory.c | 28 ++++++ lib/librte_eal/common/eal_memalloc.h | 11 +++ lib/librte_eal/common/include/rte_memory.h | 71 +++++++++++++++ lib/librte_eal/rte_eal_version.map | 2 + 5 files changed, 245 insertions(+)
lib/librte_eal/common/eal_common_memalloc.c +133 -0
@@ -2,16 +2,46 @@* Copyright(c) 2017-2018 Intel Corporation */ +#include <string.h> + +#include <rte_errno.h> #include <rte_lcore.h> #include <rte_fbarray.h> #include <rte_memzone.h> #include <rte_memory.h> #include <rte_eal_memconfig.h> +#include <rte_rwlock.h> #include "eal_private.h" #include "eal_internal_cfg.h" #include "eal_memalloc.h" +struct mem_event_callback_entry { +TAILQ_ENTRY (mem_event_callback_entry) next; +char name[RTE_MEM_EVENT_CALLBACK_NAME_LEN ]; +rte_mem_event_callback_t clb; +}; + +/** Double linked list of actions. */ +TAILQ_HEAD (mem_event_callback_entry_list, mem_event_callback_entry); + +static struct mem_event_callback_entry_list mem_event_callback_list = +TAILQ_HEAD_INITIALIZER (mem_event_callback_list); + +static rte_rwlock_t mem_event_rwlock =RTE_RWLOCK_INITIALIZER ; + +static struct mem_event_callback_entry * +find_mem_event_callback (const char *name) +{ +struct mem_event_callback_entry *r; + + TAILQ_FOREACH(r, &mem_event_callback_list, next) { +if (!strcmp (r->name, name)) +break ; + } +return r; +} +bool eal_memalloc_is_contig (const struct rte_memseg_list *msl,void *start,size_t len)
@@ -88,3 +118,106 @@ eal_memalloc_is_contig(const struct rte_memseg_list *msl, void *start, }return true; } + +int +eal_memalloc_mem_event_callback_register (const char *name, +rte_mem_event_callback_t clb) +{ +struct mem_event_callback_entry *entry; +int ret, len; +if (name ==NULL || clb ==NULL ) { + rte_errno =EINVAL ; +return -1 ; + } + len =strnlen (name,RTE_MEM_EVENT_CALLBACK_NAME_LEN ); +if (len ==0 ) { + rte_errno =EINVAL ; +return -1 ; + }else if (len ==RTE_MEM_EVENT_CALLBACK_NAME_LEN ) { + rte_errno =ENAMETOOLONG ; +return -1 ; + } +rte_rwlock_write_lock (&mem_event_rwlock); + + entry =find_mem_event_callback (name); +if (entry !=NULL ) { + rte_errno =EEXIST ; + ret =-1 ; + goto unlock; + } + + entry =malloc (sizeof (*entry)); +if (entry ==NULL ) { + rte_errno =ENOMEM ; + ret =-1 ; + goto unlock; + } + +/* callback successfully created and is valid, add it to the list */ + entry->clb = clb; +snprintf (entry->name,RTE_MEM_EVENT_CALLBACK_NAME_LEN ,"%s" , name); +TAILQ_INSERT_TAIL (&mem_event_callback_list, entry, next); + + ret =0 ; + +RTE_LOG (DEBUG ,EAL ,"Mem event callback '%s' registered\n" , name); + +unlock: +rte_rwlock_write_unlock (&mem_event_rwlock); +return ret; +} + +int +eal_memalloc_mem_event_callback_unregister (const char *name) +{ +struct mem_event_callback_entry *entry; +int ret, len; + +if (name ==NULL ) { + rte_errno =EINVAL ; +return -1 ; + } + len =strnlen (name,RTE_MEM_EVENT_CALLBACK_NAME_LEN ); +if (len ==0 ) { + rte_errno =EINVAL ; +return -1 ; + }else if (len ==RTE_MEM_EVENT_CALLBACK_NAME_LEN ) { + rte_errno =ENAMETOOLONG ; +return -1 ; + } +rte_rwlock_write_lock (&mem_event_rwlock); + + entry =find_mem_event_callback (name); +if (entry ==NULL ) { + rte_errno =ENOENT ; + ret =-1 ; + goto unlock; + } +TAILQ_REMOVE (&mem_event_callback_list, entry, next); +free (entry); + + ret =0 ; + +RTE_LOG (DEBUG ,EAL ,"Mem event callback '%s' unregistered\n" , name); + +unlock: +rte_rwlock_write_unlock (&mem_event_rwlock); +return ret; +} + +void +eal_memalloc_mem_event_notify (enum rte_mem_event event,const void *start, +size_t len) +{ +struct mem_event_callback_entry *entry; + +rte_rwlock_read_lock (&mem_event_rwlock); + + TAILQ_FOREACH(entry, &mem_event_callback_list, next) { +RTE_LOG (DEBUG ,EAL ,"Calling mem event callback %s" , + entry->name); + entry->clb (event, start, len); + } + +rte_rwlock_read_unlock (&mem_event_rwlock); +}
lib/librte_eal/common/eal_common_memory.c +28 -0
@@ -624,6 +624,34 @@ dump_memseg(const struct rte_memseg_list *msl, const struct rte_memseg *ms,return 0 ; } +/* +* Defining here because declared in rte_memory.h, but the actual implementation +* is in eal_common_memalloc.c, like all other memalloc internals. +*/ +int __rte_experimental +rte_mem_event_callback_register (const char *name,rte_mem_event_callback_t clb) +{ +/* FreeBSD boots with legacy mem enabled by default */ +if (internal_config.legacy_mem) { +RTE_LOG (DEBUG ,EAL ,"Registering mem event callbacks not supported\n" ); + rte_errno =ENOTSUP ; +return -1 ; + } +return eal_memalloc_mem_event_callback_register (name, clb); +} + +int __rte_experimental +rte_mem_event_callback_unregister (const char *name) +{ +/* FreeBSD boots with legacy mem enabled by default */ +if (internal_config.legacy_mem) { +RTE_LOG (DEBUG ,EAL ,"Registering mem event callbacks not supported\n" ); + rte_errno =ENOTSUP ; +return -1 ; + } +return eal_memalloc_mem_event_callback_unregister (name); +} +/* Dump the physical memory layout on console */ void rte_dump_physmem_layout (FILE *f)
lib/librte_eal/common/eal_memalloc.h +11 -0
@@ -55,4 +55,15 @@ eal_memalloc_is_contig(const struct rte_memseg_list *msl, void *start,int eal_memalloc_sync_with_primary (void ); +int +eal_memalloc_mem_event_callback_register (const char *name, +rte_mem_event_callback_t clb); + +int +eal_memalloc_mem_event_callback_unregister (const char *name); + +void +eal_memalloc_mem_event_notify (enum rte_mem_event event,const void *start, +size_t len); +#endif /* EAL_MEMALLOC_H */
lib/librte_eal/common/include/rte_memory.h +71 -0
113 lines not on this page · raw message
lib/librte_eal/rte_eal_version.map +2 -0
@@ -238,6 +238,8 @@ EXPERIMENTAL { rte_fbarray_set_used; rte_log_register_type_and_pick_level; rte_malloc_dump_heaps; + rte_mem_event_callback_register; + rte_mem_event_callback_unregister; rte_mem_iova2virt; rte_mem_virt2memseg; rte_mem_virt2memseg_list;
Signature · 1 line
2.7.4
PATCH v6 63/70 malloc: enable callbacks on alloc/free and mp sync
In reply to Anatoly BurakovCallbacks will be triggered just after allocation and just before deallocation, to ensure that memory address space referenced in the callback is always valid by the time callback is called.
--- lib/librte_eal/common/malloc_heap.c | 21 +++++++++++++++++++++ lib/librte_eal/linuxapp/eal/eal_memalloc.c | 30 ++++++++++++++++++++++++++++++ lib/librte_eal/linuxapp/eal/eal_vfio.c | 15 +++++++++++++-- 3 files changed, 64 insertions(+), 2 deletions(-)
lib/librte_eal/common/malloc_heap.c +21 -0
@@ -241,6 +241,7 @@ try_expand_heap_primary(struct malloc_heap *heap, uint64_t pg_sz,void *map_addr;size_t alloc_sz;int n_segs; +bool callback_triggered = false; alloc_sz =RTE_ALIGN_CEIL (align + elt_size +MALLOC_ELEM_TRAILER_LEN , pg_sz);
@@ -262,12 +263,22 @@ try_expand_heap_primary(struct malloc_heap *heap, uint64_t pg_sz, map_addr = ms[0 ]->addr; +/* notify user about changes in memory map */ +eal_memalloc_mem_event_notify (RTE_MEM_EVENT_ALLOC , map_addr, alloc_sz); +/* notify other processes that this has happened */ if (request_sync ()) {/* we couldn't ensure all processes have mapped memory, * so free it back and notify everyone that it's been * freed back. +* +* technically, we could've avoided adding memory addresses to +* the map, but that would've led to inconsistent behavior +* between primary and secondary processes, as those get +* callbacks during sync. therefore, force primary process to +* do alloc-and-rollback syncs as well. */ + callback_triggered = true; goto free_elem; } heap->total_size += alloc_sz;
@@ -280,6 +291,10 @@ try_expand_heap_primary(struct malloc_heap *heap, uint64_t pg_sz,return 0 ; free_elem: +if (callback_triggered) +eal_memalloc_mem_event_notify (RTE_MEM_EVENT_FREE , + map_addr, alloc_sz); +rollback_expand_heap (ms, n_segs, elem, map_addr, alloc_sz);request_sync ();
@@ -642,6 +657,10 @@ malloc_heap_free(struct malloc_elem *elem) heap->total_size -= aligned_len;if (rte_eal_process_type () ==RTE_PROC_PRIMARY ) { +/* notify user about changes in memory map */ +eal_memalloc_mem_event_notify (RTE_MEM_EVENT_FREE , + aligned_start, aligned_len); +/* don't care if any of this fails */ malloc_heap_free_pages (aligned_start, aligned_len);
@@ -666,6 +685,8 @@ malloc_heap_free(struct malloc_elem *elem)* already removed from the heap, so it is, for all intents and * purposes, hidden from the rest of DPDK even if some other * process (including this one) may have these pages mapped. +* +* notifications about deallocated memory happen during sync. */ request_to_primary (&req); }
lib/librte_eal/linuxapp/eal/eal_memalloc.c +30 -0
@@ -876,6 +876,21 @@ sync_chunk(struct rte_memseg_list *primary_msl, diff_len =RTE_MIN (chunk_len, diff_len); +/* if we are freeing memory, notify the application */ +if (!used) { +struct rte_memseg *ms; +void *start_va; +size_t len, page_sz; + + ms =rte_fbarray_get (l_arr, start); + start_va = ms->addr; + page_sz = (size_t )primary_msl->page_sz; + len = page_sz * diff_len; + +eal_memalloc_mem_event_notify (RTE_MEM_EVENT_FREE , + start_va, len); + } +for (i =0 ; i < diff_len; i++) {struct rte_memseg *p_ms, *l_ms;int seg_idx = start + i;
@@ -901,6 +916,21 @@ sync_chunk(struct rte_memseg_list *primary_msl, } } +/* if we just allocated memory, notify the application */ +if (used) { +struct rte_memseg *ms; +void *start_va; +size_t len, page_sz; + + ms =rte_fbarray_get (l_arr, start); + start_va = ms->addr; + page_sz = (size_t )primary_msl->page_sz; + len = page_sz * diff_len; + +eal_memalloc_mem_event_notify (RTE_MEM_EVENT_ALLOC , + start_va, len); + } +/* calculate how much we can advance until next chunk */ diff_len = used ? rte_fbarray_find_contig_used(l_arr, start) :
lib/librte_eal/linuxapp/eal/eal_vfio.c +13 -2
@@ -1128,6 +1128,7 @@ vfio_spapr_dma_mem_map(int vfio_container_fd, uint64_t vaddr, uint64_t iova, create.levels =1 ;if (do_map) { +void *addr;/* re-create window and remap the entire memory */ if (iova > create.window_size) { if (vfio_spapr_create_new_dma_window(vfio_container_fd,
@@ -1158,9 +1159,19 @@ vfio_spapr_dma_mem_map(int vfio_container_fd, uint64_t vaddr, uint64_t iova,/* now that we've remapped all of the memory that was present * before, map the segment that we were requested to map. +* +* however, if we were called by the callback, the memory we +* were called with was already in the memseg list, so previous +* mapping should've mapped that segment already. +* +* virt2memseg_list is a relatively cheap check, so use that. if +* memory is within any memseg list, it's a memseg, so it's +* already mapped. */ -if (vfio_spapr_dma_do_map (vfio_container_fd, - vaddr, iova, len,1 ) <0 ) { + addr = (void *)(uintptr_t )vaddr; +if (rte_mem_virt2memseg_list (addr) ==NULL && +vfio_spapr_dma_do_map (vfio_container_fd, + vaddr, iova, len,1 ) <0 ) {RTE_LOG (ERR ,EAL ,"Could not map segment\n" ); ret =-1 ; goto out;
Signature · 1 line
2.7.4
PATCH v6 64/70 vfio: enable support for mem event callbacks
In reply to Anatoly BurakovEnable callbacks on first device attach, disable callbacks on last device attach.
PPC64 IOMMU does memseg walk, which will cause a deadlock on trying to do it inside a callback, so provide a local, thread-unsafe copy of memseg walk.
PPC64 IOMMU also may remap the entire memory map for DMA while adding new elements to it, so change user map list lock to a recursive lock. That way, we can safely enter rte_vfio_dma_map(), lock the user map list, enter DMA mapping function and lock the list again (for reading previously existing maps).
--- lib/librte_eal/linuxapp/eal/eal_vfio.c | 157 +++++++++++++++++++++++++++++---- 1 file changed, 138 insertions(+), 19 deletions(-)
lib/librte_eal/linuxapp/eal/eal_vfio.c +138 -19
@@ -20,6 +20,8 @@#ifdef VFIO_PRESENT +#define VFIO_MEM_EVENT_CLB_NAME "vfio_mem_event_clb" +/* per-process VFIO config */ static struct vfio_config vfio_cfg;
@@ -69,13 +71,49 @@ struct user_mem_map {uint64_t len; };static struct { -rte_spinlock_t lock; +rte_spinlock_recursive_t lock;int n_maps;struct user_mem_map maps[VFIO_MAX_USER_MEM_MAPS ]; } user_mem_maps = { - .lock =RTE_SPINLOCK_INITIALIZER + .lock =RTE_SPINLOCK_RECURSIVE_INITIALIZER }; +/* for sPAPR IOMMU, we will need to walk memseg list, but we cannot use +* rte_memseg_walk() because by the time we enter callback we will be holding a +* write lock, so regular rte-memseg_walk will deadlock. copying the same +* iteration code everywhere is not ideal as well. so, use a lockless copy of +* memseg walk here. +*/ +static int +memseg_walk_thread_unsafe (rte_memseg_walk_t func,void *arg) +{ +struct rte_mem_config *mcfg =rte_eal_get_configuration ()->mem_config; +int i, ms_idx, ret =0 ; + +for (i =0 ; i <RTE_MAX_MEMSEG_LISTS ; i++) { +struct rte_memseg_list *msl = &mcfg->memsegs[i]; +const struct rte_memseg *ms; +struct rte_fbarray *arr; + +if (msl->memseg_arr.count ==0 ) +continue ; + + arr = &msl->memseg_arr; + + ms_idx =rte_fbarray_find_next_used (arr,0 ); +while (ms_idx >=0 ) { + ms =rte_fbarray_get (arr, ms_idx); + ret =func (msl, ms, arg); +if (ret <0 ) +return -1 ; +if (ret >0 ) +return 1 ; + ms_idx =rte_fbarray_find_next_used (arr, ms_idx +1 ); + } + } +return 0 ; +} +static int is_null_map (const struct user_mem_map *map) {
@@ -406,6 +444,38 @@ vfio_group_device_count(int vfio_group_fd)return vfio_cfg.vfio_groups[i].devices; } +static void +vfio_mem_event_callback (enum rte_mem_event type,const void *addr,size_t len) +{ +struct rte_memseg_list *msl; +struct rte_memseg *ms; +size_t cur_len =0 ; + + msl =rte_mem_virt2memseg_list (addr); + +/* for IOVA as VA mode, no need to care for IOVA addresses */ +if (rte_eal_iova_mode () ==RTE_IOVA_VA ) { +uint64_t vfio_va = (uint64_t )(uintptr_t )addr; +if (type ==RTE_MEM_EVENT_ALLOC ) +vfio_dma_mem_map (vfio_va, vfio_va, len,1 ); +else +vfio_dma_mem_map (vfio_va, vfio_va, len,0 ); +return ; + } + +/* memsegs are contiguous in memory */ + ms =rte_mem_virt2memseg (addr, msl); +while (cur_len < len) { +if (type ==RTE_MEM_EVENT_ALLOC ) +vfio_dma_mem_map (ms->addr_64, ms->iova, ms->len,1 ); +else +vfio_dma_mem_map (ms->addr_64, ms->iova, ms->len,0 ); + + cur_len += ms->len; + ++ms; + } +} +int rte_vfio_clear_group (int vfio_group_fd) {
@@ -468,6 +538,8 @@ int rte_vfio_setup_device(const char *sysfs_base, const char *dev_addr, int *vfio_dev_fd, struct vfio_device_info *device_info) { + struct rte_mem_config *mcfg = rte_eal_get_configuration()->mem_config; +rte_rwlock_t *mem_lock = &mcfg->memory_hotplug_lock;struct vfio_group_status group_status = { .argsz =sizeof (group_status) };
@@ -555,6 +627,10 @@ rte_vfio_setup_device(const char *sysfs_base, const char *dev_addr,rte_vfio_clear_group (vfio_group_fd);return -1 ; } +/* lock memory hotplug before mapping and release it +* after registering callback, to prevent races +*/ +rte_rwlock_read_lock (mem_lock); ret = t->dma_map_func (vfio_cfg.vfio_container_fd);if (ret) { RTE_LOG(ERR, EAL,
@@ -562,13 +638,14 @@ rte_vfio_setup_device(const char *sysfs_base, const char *dev_addr, dev_addr, errno, strerror(errno));close (vfio_group_fd);rte_vfio_clear_group (vfio_group_fd); +rte_rwlock_read_unlock (mem_lock);return -1 ; } vfio_cfg.vfio_iommu_type = t;/* re-map all user-mapped segments */ -rte_spinlock_lock (&user_mem_maps.lock); +rte_spinlock_recursive_lock (&user_mem_maps.lock);/* this IOMMU type may not support DMA mapping, but * if we have mappings in the list - that means we have
@@ -590,12 +667,29 @@ rte_vfio_setup_device(const char *sysfs_base, const char *dev_addr,"len: 0x%" PRIu64"\n" , map->addr, map->iova, map->len); -rte_spinlock_unlock ( +rte_spinlock_recursive_unlock ( &user_mem_maps.lock); +rte_rwlock_read_unlock (mem_lock);return -1 ; } } -rte_spinlock_unlock (&user_mem_maps.lock); +rte_spinlock_recursive_unlock (&user_mem_maps.lock); + +/* register callback for mem events */ + ret =rte_mem_event_callback_register ( +VFIO_MEM_EVENT_CLB_NAME , + vfio_mem_event_callback); +/* unlock memory hotplug */ +rte_rwlock_read_unlock (mem_lock); + +if (ret && rte_errno !=ENOTSUP ) { +RTE_LOG (ERR ,EAL ,"Could not install memory event callback for VFIO\n" ); +return -1 ; + } +if (ret) +RTE_LOG (DEBUG ,EAL ,"Memory event callbacks not supported\n" ); +else +RTE_LOG (DEBUG ,EAL ,"Installed memory event callback for VFIO\n" ); } }
@@ -633,6 +727,8 @@ int rte_vfio_release_device(const char *sysfs_base, const char *dev_addr, int vfio_dev_fd) { + struct rte_mem_config *mcfg = rte_eal_get_configuration()->mem_config; +rte_rwlock_t *mem_lock = &mcfg->memory_hotplug_lock;struct vfio_group_status group_status = { .argsz =sizeof (group_status) };
@@ -640,13 +736,20 @@ rte_vfio_release_device(const char *sysfs_base, const char *dev_addr,int iommu_group_no;int ret; +/* we don't want any DMA mapping messages to come while we're detaching +* VFIO device, because this might be the last device and we might need +* to unregister the callback. +*/ +rte_rwlock_read_lock (mem_lock); +/* get group number */ ret =vfio_get_group_no (sysfs_base, dev_addr, &iommu_group_no);if (ret <=0 ) {RTE_LOG (WARNING ,EAL ," %s not managed by VFIO driver\n" , dev_addr);/* This is an error at this point. */ -return -1 ; + ret =-1 ; + goto out; }/* get the actual group fd */
@@ -654,7 +757,8 @@ rte_vfio_release_device(const char *sysfs_base, const char *dev_addr,if (vfio_group_fd <=0 ) {RTE_LOG (INFO ,EAL ,"vfio_get_group_fd failed for %s\n" , dev_addr); -return -1 ; + ret =-1 ; + goto out; }/* At this point we got an active group. Closing it will make the
@@ -666,7 +770,8 @@ rte_vfio_release_device(const char *sysfs_base, const char *dev_addr,if (close (vfio_dev_fd) <0 ) {RTE_LOG (INFO ,EAL ,"Error when closing vfio_dev_fd for %s\n" , dev_addr); -return -1 ; + ret =-1 ; + goto out; }/* An VFIO group can have several devices attached. Just when there is
@@ -678,17 +783,30 @@ rte_vfio_release_device(const char *sysfs_base, const char *dev_addr,if (close (vfio_group_fd) <0 ) {RTE_LOG (INFO ,EAL ,"Error when closing vfio_group_fd for %s\n" , dev_addr); -return -1 ; + ret =-1 ; + goto out; }if (rte_vfio_clear_group (vfio_group_fd) <0 ) {RTE_LOG (INFO ,EAL ,"Error when clearing group for %s\n" , dev_addr); -return -1 ; + ret =-1 ; + goto out; } } -return 0 ; +/* if there are no active device groups, unregister the callback to +* avoid spurious attempts to map/unmap memory from VFIO. +*/ +if (vfio_cfg.vfio_active_groups ==0 ) +rte_mem_event_callback_unregister (VFIO_MEM_EVENT_CLB_NAME ); + +/* success */ + ret =0 ; + +out: +rte_rwlock_read_unlock (mem_lock); +return ret; }int
@@ -1104,12 +1222,13 @@ vfio_spapr_dma_mem_map(int vfio_container_fd, uint64_t vaddr, uint64_t iova, };int i, ret =0 ; -rte_spinlock_lock (&user_mem_maps.lock); +rte_spinlock_recursive_lock (&user_mem_maps.lock);/* check if window size needs to be adjusted */ memset (¶m,0 ,sizeof (param)); -if (rte_memseg_walk (vfio_spapr_window_size_walk, ¶m) <0 ) { +if (memseg_walk_thread_unsafe (vfio_spapr_window_size_walk, + ¶m) <0 ) {RTE_LOG (ERR ,EAL ,"Could not get window size\n" ); ret =-1 ; goto out;
@@ -1137,7 +1256,7 @@ vfio_spapr_dma_mem_map(int vfio_container_fd, uint64_t vaddr, uint64_t iova, ret =-1 ; goto out; } -if (rte_memseg_walk (vfio_spapr_map_walk, +if (memseg_walk_thread_unsafe (vfio_spapr_map_walk, &vfio_container_fd) <0 ) {RTE_LOG (ERR ,EAL ,"Could not recreate DMA maps\n" ); ret =-1 ;
@@ -1187,7 +1306,7 @@ vfio_spapr_dma_mem_map(int vfio_container_fd, uint64_t vaddr, uint64_t iova,vfio_spapr_dma_do_map (vfio_container_fd, vaddr, iova, len,0 ); } out: -rte_spinlock_unlock (&user_mem_maps.lock); +rte_spinlock_recursive_unlock (&user_mem_maps.lock);return ret; }
@@ -1272,7 +1391,7 @@ rte_vfio_dma_map(uint64_t vaddr, uint64_t iova, uint64_t len)return -1 ; } -rte_spinlock_lock (&user_mem_maps.lock); +rte_spinlock_recursive_lock (&user_mem_maps.lock);if (user_mem_maps.n_maps ==VFIO_MAX_USER_MEM_MAPS ) {RTE_LOG (ERR ,EAL ,"No more space for user mem maps\n" ); rte_errno =ENOMEM ;
@@ -1300,7 +1419,7 @@ rte_vfio_dma_map(uint64_t vaddr, uint64_t iova, uint64_t len)compact_user_maps (); out: -rte_spinlock_unlock (&user_mem_maps.lock); +rte_spinlock_recursive_unlock (&user_mem_maps.lock);return ret; }
@@ -1315,7 +1434,7 @@ rte_vfio_dma_unmap(uint64_t vaddr, uint64_t iova, uint64_t len)return -1 ; } -rte_spinlock_lock (&user_mem_maps.lock); +rte_spinlock_recursive_lock (&user_mem_maps.lock);/* find our mapping */ map =find_user_mem_map (vaddr, iova, len);
@@ -1374,7 +1493,7 @@ rte_vfio_dma_unmap(uint64_t vaddr, uint64_t iova, uint64_t len) } out: -rte_spinlock_unlock (&user_mem_maps.lock); +rte_spinlock_recursive_unlock (&user_mem_maps.lock);return ret; }
Signature · 1 line
2.7.4
PATCH v6 65/70 bus/fslmc: move vfio DMA map into bus probe
In reply to Anatoly Burakovfslmc bus needs to map all allocated memory for VFIO before device probe. This bus doesn't support hotplug, so at the time of this call, all possible device that could be present, are present. This will also be the place where we install VFIO callback, although this change will come in the next patch.
Since rte_fslmc_vfio_dmamap() is now only called at bus probe, there is no longer any need to check if DMA mappings have been already done.
--- drivers/bus/fslmc/fslmc_bus.c | 11 +++++++++++ drivers/bus/fslmc/fslmc_vfio.c | 6 ------ drivers/net/dpaa2/dpaa2_ethdev.c | 1 - 3 files changed, 11 insertions(+), 7 deletions(-)
drivers/bus/fslmc/fslmc_bus.c +11 -0
@@ -286,6 +286,17 @@ rte_fslmc_probe(void)return 0 ; } +/* Map existing segments as well as, in case of hotpluggable memory, +* install callback handler. +*/ + ret =rte_fslmc_vfio_dmamap (); +if (ret) { +DPAA2_BUS_ERR ("Unable to DMA map existing VAs: (%d)" , ret); +/* Not continuing ahead */ +DPAA2_BUS_ERR ("FSLMC VFIO Mapping failed" ); +return 0 ; + } + ret =fslmc_vfio_process_group ();if (ret) {DPAA2_BUS_ERR ("Unable to setup devices %d" , ret);
drivers/bus/fslmc/fslmc_vfio.c +0 -6
@@ -51,7 +51,6 @@ static int container_device_fd;static char *g_container;static uint32_t *msi_intr_vaddr;void *(*rte_mcp_ptr_list); -static int is_dma_done;static struct rte_dpaa2_object_list dpaa2_obj_list =TAILQ_HEAD_INITIALIZER (dpaa2_obj_list);
@@ -235,9 +234,6 @@ int rte_fslmc_vfio_dmamap(void) {int i =0 ; -if (is_dma_done) -return 0 ; -if (rte_memseg_walk (fslmc_vfio_map, &i) <0 )return -1 ;
@@ -254,8 +250,6 @@ int rte_fslmc_vfio_dmamap(void)*/ vfio_map_irq_region (&vfio_group); - is_dma_done =1 ; -return 0 ; }
drivers/net/dpaa2/dpaa2_ethdev.c +0 -1
@@ -1845,7 +1845,6 @@ dpaa2_dev_init(struct rte_eth_dev *eth_dev) eth_dev->rx_pkt_burst = dpaa2_dev_prefetch_rx; eth_dev->tx_pkt_burst = dpaa2_dev_tx; -rte_fslmc_vfio_dmamap ();DPAA2_PMD_INFO ("%s: netdev created" , eth_dev->data->name);return 0 ;
Signature · 1 line
2.7.4
PATCH v6 66/70 bus/fslmc: enable support for mem event callbacks for vfio
In reply to Anatoly BurakovVFIO needs to map and unmap segments for DMA whenever they become available or unavailable, so register a callback for memory events, and provide map/unmap functions.
Remove unneeded check for number of segments, as in non-legacy mode this now becomes a valid scenario.
--- drivers/bus/fslmc/fslmc_vfio.c | 153 ++++++++++++++++++++++++++++++++++++----- 1 file changed, 135 insertions(+), 18 deletions(-)
drivers/bus/fslmc/fslmc_vfio.c +135 -18
@@ -30,6 +30,7 @@#include <rte_kvargs.h> #include <rte_dev.h> #include <rte_bus.h> +#include <rte_eal_memconfig.h> #include "rte_fslmc.h" #include "fslmc_vfio.h"
@@ -188,11 +189,62 @@ static int vfio_map_irq_region(struct fslmc_vfio_group *group)return -errno; } +static int fslmc_map_dma (uint64_t vaddr,rte_iova_t iovaddr,size_t len); +static int fslmc_unmap_dma (uint64_t vaddr,rte_iova_t iovaddr,size_t len); + +static void +fslmc_memevent_cb (enum rte_mem_event type,const void *addr,size_t len) +{ +struct rte_memseg_list *msl; +struct rte_memseg *ms; +size_t cur_len =0 , map_len =0 ; +uint64_t virt_addr; +rte_iova_t iova_addr; +int ret; + + msl =rte_mem_virt2memseg_list (addr); + +while (cur_len < len) { +const void *va =RTE_PTR_ADD (addr, cur_len); + + ms =rte_mem_virt2memseg (va, msl); + iova_addr = ms->iova; + virt_addr = ms->addr_64; + map_len = ms->len; + +DPAA2_BUS_DEBUG ("Request for %s, va=%p, " +"virt_addr=0x%" PRIx64", " +"iova=0x%" PRIx64", map_len=%zu" , + type ==RTE_MEM_EVENT_ALLOC ? +"alloc" :"dealloc" , + va, virt_addr, iova_addr, map_len); + +if (type ==RTE_MEM_EVENT_ALLOC ) + ret =fslmc_map_dma (virt_addr, iova_addr, map_len); +else + ret =fslmc_unmap_dma (virt_addr, iova_addr, map_len); + +if (ret !=0 ) { +DPAA2_BUS_ERR ("DMA Mapping/Unmapping failed. " +"Map=%d, addr=%p, len=%zu, err:(%d)" , + type, va, map_len, ret); +return ; + } + + cur_len += map_len; + } + +if (type ==RTE_MEM_EVENT_ALLOC ) +DPAA2_BUS_DEBUG ("Total Mapped: addr=%p, len=%zu" , + addr, len); +else +DPAA2_BUS_DEBUG ("Total Unmapped: addr=%p, len=%zu" , + addr, len); +} +static int -fslmc_vfio_map(const struct rte_memseg_list *msl __rte_unused, -const struct rte_memseg *ms,void *arg) +fslmc_map_dma(uint64_t vaddr, rte_iova_t iovaddr __rte_unused, size_t len) { -int *n_segs = arg;struct fslmc_vfio_group *group;struct vfio_iommu_type1_dma_map dma_map = { .argsz =sizeof (struct vfio_iommu_type1_dma_map ),
@@ -200,10 +252,11 @@ fslmc_vfio_map(const struct rte_memseg_list *msl __rte_unused, };int ret; - dma_map.size = ms->len; - dma_map.vaddr = ms->addr_64; + dma_map.size = len; + dma_map.vaddr = vaddr; +#ifdef RTE_LIBRTE_DPAA2_USE_PHYS_IOVA - dma_map.iova = ms->iova; + dma_map.iova = iovaddr;#else dma_map.iova = dma_map.vaddr;#endif
@@ -216,32 +269,91 @@ fslmc_vfio_map(const struct rte_memseg_list *msl __rte_unused,return -1 ; } -DPAA2_BUS_DEBUG ("-->Initial SHM Virtual ADDR %llX" , - dma_map.vaddr); -DPAA2_BUS_DEBUG ("-----> DMA size 0x%llX" , dma_map.size); - ret =ioctl (group->container->fd,VFIO_IOMMU_MAP_DMA , - &dma_map); +DPAA2_BUS_DEBUG ("--> Map address: %llX, size: 0x%llX" , + dma_map.vaddr, dma_map.size); + ret =ioctl (group->container->fd,VFIO_IOMMU_MAP_DMA , &dma_map);if (ret) {DPAA2_BUS_ERR ("VFIO_IOMMU_MAP_DMA API(errno = %d)" , errno);return -1 ; } - (*n_segs)++; +return 0 ; } -int rte_fslmc_vfio_dmamap (void ) +static int +fslmc_unmap_dma(uint64_t vaddr, uint64_t iovaddr __rte_unused, size_t len) { -int i =0 ; +struct fslmc_vfio_group *group; +struct vfio_iommu_type1_dma_unmap dma_unmap = { + .argsz =sizeof (struct vfio_iommu_type1_dma_unmap ), + .flags =0 , + }; +int ret; + + dma_unmap.size = len; + dma_unmap.iova = vaddr; -if (rte_memseg_walk (fslmc_vfio_map, &i) <0 ) +/* SET DMA MAP for IOMMU */ + group = &vfio_group; + +if (!group->container) { +DPAA2_BUS_ERR ("Container is not connected " );return -1 ; + } -/* Verifying that at least single segment is available */ -if (i <=0 ) { -DPAA2_BUS_ERR ("No Segments found for VFIO Mapping" ); +DPAA2_BUS_DEBUG ("--> Unmap address: %llX, size: 0x%llX" , + dma_unmap.iova, dma_unmap.size); + ret =ioctl (group->container->fd,VFIO_IOMMU_UNMAP_DMA , &dma_unmap); +if (ret) { +DPAA2_BUS_ERR ("VFIO_IOMMU_UNMAP_DMA API(errno = %d)" , + errno);return -1 ; } + +return 0 ; +} + +static int +fslmc_dmamap_seg(const struct rte_memseg_list *msl __rte_unused, +const struct rte_memseg *ms,void *arg) +{ +int *n_segs = arg; +int ret; + + ret =fslmc_map_dma (ms->addr_64, ms->iova, ms->len); +if (ret) +DPAA2_BUS_ERR ("Unable to VFIO map (addr=%p, len=%zu)" , + ms->addr, ms->len); +else + (*n_segs)++; + +return ret; +} + +int rte_fslmc_vfio_dmamap (void ) +{ +int i =0 , ret; +struct rte_mem_config *mcfg =rte_eal_get_configuration ()->mem_config; +rte_rwlock_t *mem_lock = &mcfg->memory_hotplug_lock; + +/* Lock before parsing and registering callback to memory subsystem */ +rte_rwlock_read_lock (mem_lock); + +if (rte_memseg_walk (fslmc_dmamap_seg, &i) <0 ) { +rte_rwlock_read_unlock (mem_lock); +return -1 ; + } + + ret =rte_mem_event_callback_register ("fslmc_memevent_clb" , + fslmc_memevent_cb); +if (ret && rte_errno ==ENOTSUP ) +DPAA2_BUS_DEBUG ("Memory event callbacks not supported" ); +else if (ret) +DPAA2_BUS_DEBUG ("Unable to install memory handler" ); +else +DPAA2_BUS_DEBUG ("Installed memory callback handler" ); +DPAA2_BUS_DEBUG ("Total %d segments found." , i);/* TODO - This is a W.A. as VFIO currently does not add the mapping of
@@ -250,6 +362,11 @@ int rte_fslmc_vfio_dmamap(void)*/ vfio_map_irq_region (&vfio_group); +/* Existing segments have been mapped and memory callback for hotplug +* has been installed. +*/ +rte_rwlock_read_unlock (mem_lock); +return 0 ; }
Signature · 1 line
2.7.4
PATCH v6 67/70 eal: enable non-legacy memory mode
In reply to Anatoly BurakovNow that every other piece of the puzzle is in place, enable non-legacy init mode.
--- lib/librte_eal/linuxapp/eal/eal.c | 2 -- 1 file changed, 2 deletions(-)
lib/librte_eal/linuxapp/eal/eal.c +0 -2
@@ -772,8 +772,6 @@ rte_eal_init(int argc, char **argv)rte_atomic32_clear (&run_once);return -1 ; } -/* for now, always set legacy mem */ - internal_config.legacy_mem =1 ;if (eal_plugins_init () <0 ) {rte_eal_init_alert ("Cannot init plugins\n" );
Signature · 1 line
2.7.4
PATCH v6 68/70 eal: add memory validator callback
In reply to Anatoly BurakovThis API will enable application to register for notifications on page allocations that are about to happen, giving the application a chance to allow or deny the allocation when total memory utilization as a result would be above specified limit on specified socket.
--- lib/librte_eal/common/eal_common_memalloc.c | 138 +++++++++++++++++++++++++++- lib/librte_eal/common/eal_common_memory.c | 26 ++++++ lib/librte_eal/common/eal_memalloc.h | 10 ++ lib/librte_eal/common/include/rte_memory.h | 63 +++++++++++++ lib/librte_eal/rte_eal_version.map | 2 + 5 files changed, 238 insertions(+), 1 deletion(-)
lib/librte_eal/common/eal_common_memalloc.c +137 -1
@@ -22,14 +22,26 @@ struct mem_event_callback_entry {rte_mem_event_callback_t clb; }; +struct mem_alloc_validator_entry { +TAILQ_ENTRY (mem_alloc_validator_entry) next; +char name[RTE_MEM_ALLOC_VALIDATOR_NAME_LEN ]; +rte_mem_alloc_validator_t clb; +int socket_id; +size_t limit; +}; +/** Double linked list of actions. */ TAILQ_HEAD (mem_event_callback_entry_list, mem_event_callback_entry); +TAILQ_HEAD (mem_alloc_validator_entry_list, mem_alloc_validator_entry);static struct mem_event_callback_entry_list mem_event_callback_list =TAILQ_HEAD_INITIALIZER (mem_event_callback_list); -static rte_rwlock_t mem_event_rwlock =RTE_RWLOCK_INITIALIZER ; +static struct mem_alloc_validator_entry_list mem_alloc_validator_list = +TAILQ_HEAD_INITIALIZER (mem_alloc_validator_list); +static rte_rwlock_t mem_alloc_validator_rwlock =RTE_RWLOCK_INITIALIZER ; +static struct mem_event_callback_entry *find_mem_event_callback (const char *name) {
@@ -42,6 +54,18 @@ find_mem_event_callback(const char *name)return r; } +static struct mem_alloc_validator_entry * +find_mem_alloc_validator (const char *name,int socket_id) +{ +struct mem_alloc_validator_entry *r; + + TAILQ_FOREACH(r, &mem_alloc_validator_list, next) { +if (!strcmp (r->name, name) && r->socket_id == socket_id) +break ; + } +return r; +} +bool eal_memalloc_is_contig (const struct rte_memseg_list *msl,void *start,size_t len)
@@ -221,3 +245,115 @@ eal_memalloc_mem_event_notify(enum rte_mem_event event, const void *start,rte_rwlock_read_unlock (&mem_event_rwlock); } + +int +eal_memalloc_mem_alloc_validator_register (const char *name, +rte_mem_alloc_validator_t clb,int socket_id,size_t limit) +{ +struct mem_alloc_validator_entry *entry; +int ret, len; +if (name ==NULL || clb ==NULL || socket_id <0 ) { + rte_errno =EINVAL ; +return -1 ; + } + len =strnlen (name,RTE_MEM_ALLOC_VALIDATOR_NAME_LEN ); +if (len ==0 ) { + rte_errno =EINVAL ; +return -1 ; + }else if (len ==RTE_MEM_ALLOC_VALIDATOR_NAME_LEN ) { + rte_errno =ENAMETOOLONG ; +return -1 ; + } +rte_rwlock_write_lock (&mem_alloc_validator_rwlock); + + entry =find_mem_alloc_validator (name, socket_id); +if (entry !=NULL ) { + rte_errno =EEXIST ; + ret =-1 ; + goto unlock; + } + + entry =malloc (sizeof (*entry)); +if (entry ==NULL ) { + rte_errno =ENOMEM ; + ret =-1 ; + goto unlock; + } + +/* callback successfully created and is valid, add it to the list */ + entry->clb = clb; + entry->socket_id = socket_id; + entry->limit = limit; +snprintf (entry->name,RTE_MEM_ALLOC_VALIDATOR_NAME_LEN ,"%s" , name); +TAILQ_INSERT_TAIL (&mem_alloc_validator_list, entry, next); + + ret =0 ; + +RTE_LOG (DEBUG ,EAL ,"Mem alloc validator '%s' on socket %i with limit %zu registered\n" , + name, socket_id, limit); + +unlock: +rte_rwlock_write_unlock (&mem_alloc_validator_rwlock); +return ret; +} + +int +eal_memalloc_mem_alloc_validator_unregister (const char *name,int socket_id) +{ +struct mem_alloc_validator_entry *entry; +int ret, len; + +if (name ==NULL || socket_id <0 ) { + rte_errno =EINVAL ; +return -1 ; + } + len =strnlen (name,RTE_MEM_ALLOC_VALIDATOR_NAME_LEN ); +if (len ==0 ) { + rte_errno =EINVAL ; +return -1 ; + }else if (len ==RTE_MEM_ALLOC_VALIDATOR_NAME_LEN ) { + rte_errno =ENAMETOOLONG ; +return -1 ; + } +rte_rwlock_write_lock (&mem_alloc_validator_rwlock); + + entry =find_mem_alloc_validator (name, socket_id); +if (entry ==NULL ) { + rte_errno =ENOENT ; + ret =-1 ; + goto unlock; + } +TAILQ_REMOVE (&mem_alloc_validator_list, entry, next); +free (entry); + + ret =0 ; + +RTE_LOG (DEBUG ,EAL ,"Mem alloc validator '%s' on socket %i unregistered\n" , + name, socket_id); + +unlock: +rte_rwlock_write_unlock (&mem_alloc_validator_rwlock); +return ret; +} + +int +eal_memalloc_mem_alloc_validate (int socket_id,size_t new_len) +{ +struct mem_alloc_validator_entry *entry; +int ret =0 ; + +rte_rwlock_read_lock (&mem_alloc_validator_rwlock); + + TAILQ_FOREACH(entry, &mem_alloc_validator_list, next) { +if (entry->socket_id != socket_id || entry->limit > new_len) +continue ; +RTE_LOG (DEBUG ,EAL ,"Calling mem alloc validator '%s' on socket %i\n" , + entry->name, entry->socket_id); +if (entry->clb (socket_id, entry->limit, new_len) <0 ) + ret =-1 ; + } + +rte_rwlock_read_unlock (&mem_alloc_validator_rwlock); + +return ret; +}
lib/librte_eal/common/eal_common_memory.c +26 -0
@@ -652,6 +652,32 @@ rte_mem_event_callback_unregister(const char *name)return eal_memalloc_mem_event_callback_unregister (name); } +int __rte_experimental +rte_mem_alloc_validator_register (const char *name, +rte_mem_alloc_validator_t clb,int socket_id,size_t limit) +{ +/* FreeBSD boots with legacy mem enabled by default */ +if (internal_config.legacy_mem) { +RTE_LOG (DEBUG ,EAL ,"Registering mem alloc validators not supported\n" ); + rte_errno =ENOTSUP ; +return -1 ; + } +return eal_memalloc_mem_alloc_validator_register (name, clb, socket_id, + limit); +} + +int __rte_experimental +rte_mem_alloc_validator_unregister (const char *name,int socket_id) +{ +/* FreeBSD boots with legacy mem enabled by default */ +if (internal_config.legacy_mem) { +RTE_LOG (DEBUG ,EAL ,"Registering mem alloc validators not supported\n" ); + rte_errno =ENOTSUP ; +return -1 ; + } +return eal_memalloc_mem_alloc_validator_unregister (name, socket_id); +} +/* Dump the physical memory layout on console */ void rte_dump_physmem_layout (FILE *f)
lib/librte_eal/common/eal_memalloc.h +10 -0
@@ -66,4 +66,14 @@ void eal_memalloc_mem_event_notify(enum rte_mem_event event, const void *start, size_t len); +int +eal_memalloc_mem_alloc_validator_register (const char *name, +rte_mem_alloc_validator_t clb,int socket_id,size_t limit); + +int +eal_memalloc_mem_alloc_validator_unregister (const char *name,int socket_id); + +int +eal_memalloc_mem_alloc_validate (int socket_id,size_t new_len); +#endif /* EAL_MEMALLOC_H */
lib/librte_eal/common/include/rte_memory.h +63 -0
69 lines not on this page · raw message
lib/librte_eal/rte_eal_version.map +2 -0
@@ -238,6 +238,8 @@ EXPERIMENTAL { rte_fbarray_set_used; rte_log_register_type_and_pick_level; rte_malloc_dump_heaps; + rte_mem_alloc_validator_register; + rte_mem_alloc_validator_unregister; rte_mem_event_callback_register; rte_mem_event_callback_unregister; rte_mem_iova2virt;
Signature · 1 line
2.7.4
PATCH v6 69/70 malloc: enable validation before new page allocation
In reply to Anatoly BurakovBefore allocating a new page, give a chance to the user to allow or deny allocation via callbacks.
--- lib/librte_eal/common/malloc_heap.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-)
lib/librte_eal/common/malloc_heap.c +9 -1
@@ -196,6 +196,15 @@ alloc_pages_on_heap(struct malloc_heap *heap, uint64_t pg_sz, size_t elt_size,int allocd_pages;void *ret, *map_addr; + alloc_sz = (size_t )pg_sz * n_segs; + +/* first, check if we're allowed to allocate this memory */ +if (eal_memalloc_mem_alloc_validate (socket, + heap->total_size + alloc_sz) <0 ) { +RTE_LOG (DEBUG ,EAL ,"User has disallowed allocation\n" ); +return NULL ; + } + allocd_pages =eal_memalloc_alloc_seg_bulk (ms, n_segs, pg_sz, socket, true);
@@ -205,7 +214,6 @@ alloc_pages_on_heap(struct malloc_heap *heap, uint64_t pg_sz, size_t elt_size, map_addr = ms[0 ]->addr; msl =rte_mem_virt2memseg_list (map_addr); - alloc_sz = (size_t )msl->page_sz * allocd_pages;/* check if we wanted contiguous memory but didn't get it */ if (contig && !eal_memalloc_is_contig (msl, map_addr, alloc_sz)) {
Signature · 1 line
2.7.4
PATCH v6 70/70 mem: prevent preallocated pages from being freed
In reply to Anatoly BurakovIt is common sense to expect for DPDK process to not deallocate any pages that were preallocated by "-m" or "--socket-mem" flags - yet, currently, DPDK memory subsystem will do exactly that once it finds that the pages are unused.
Fix this by marking pages as unfreebale, and preventing malloc from ever trying to free them.
--- lib/librte_eal/common/include/rte_memory.h | 3 +++ lib/librte_eal/common/malloc_heap.c | 23 +++++++++++++++++++++++ lib/librte_eal/linuxapp/eal/eal_memalloc.c | 7 +++++++ lib/librte_eal/linuxapp/eal/eal_memory.c | 18 +++++++++++++++--- 4 files changed, 48 insertions(+), 3 deletions(-)
lib/librte_eal/common/include/rte_memory.h +3 -0
@@ -83,6 +83,8 @@ typedef uint64_t rte_iova_t;/** * Physical memory segment descriptor. */ +#define RTE_MEMSEG_FLAG_DO_NOT_FREE (1 << 0) +/**< Prevent this segment from being freed back to the OS. */ struct rte_memseg { RTE_STD_C11 union {
@@ -99,6 +101,7 @@ struct rte_memseg {int32_t socket_id;/**< NUMA socket ID. */ uint32_t nchannel;/**< Number of channels. */ uint32_t nrank;/**< Number of ranks. */ +uint32_t flags;/**< Memseg-specific flags */ } __rte_packed;/**
lib/librte_eal/common/malloc_heap.c +23 -0
@@ -606,6 +606,7 @@ malloc_heap_free(struct malloc_elem *elem)void *start, *aligned_start, *end, *aligned_end;size_t len, aligned_len, page_sz;struct rte_memseg_list *msl; +unsigned int i, n_segs;int ret;if (!malloc_elem_cookies_ok (elem) || elem->state !=ELEM_BUSY )
@@ -647,6 +648,28 @@ malloc_heap_free(struct malloc_elem *elem)if (aligned_len < page_sz) goto free_unlock; +/* we can free something. however, some of these pages may be marked as +* unfreeable, so also check that as well +*/ + n_segs = aligned_len / page_sz; +for (i =0 ; i < n_segs; i++) { +const struct rte_memseg *tmp = +rte_mem_virt2memseg (aligned_start, msl); + +if (tmp->flags &RTE_MEMSEG_FLAG_DO_NOT_FREE ) { +/* this is an unfreeable segment, so move start */ + aligned_start =RTE_PTR_ADD (tmp->addr, tmp->len); + } + } + +/* recalculate length and number of segments */ + aligned_len =RTE_PTR_DIFF (aligned_end, aligned_start); + n_segs = aligned_len / page_sz; + +/* check if we can still free some pages */ +if (n_segs ==0 ) + goto free_unlock; +rte_rwlock_write_lock (&mcfg->memory_hotplug_lock);/*
lib/librte_eal/linuxapp/eal/eal_memalloc.c +7 -0
@@ -806,6 +806,13 @@ eal_memalloc_free_seg_bulk(struct rte_memseg **ms, int n_segs)struct free_walk_param wa;int i, walk_res; +/* if this page is marked as unfreeable, fail */ +if (cur->flags &RTE_MEMSEG_FLAG_DO_NOT_FREE ) { +RTE_LOG (DEBUG ,EAL ,"Page is not allowed to be freed\n" ); + ret =-1 ; +continue ; + } +memset (&wa,0 ,sizeof (wa)); for (i = 0; i < (int)RTE_DIM(internal_config.hugepage_info);
lib/librte_eal/linuxapp/eal/eal_memory.c +15 -3
@@ -1638,21 +1638,33 @@ eal_hugepage_init(void) hp_sz_idx++) {for (socket_id =0 ; socket_id <RTE_MAX_NUMA_NODES ; socket_id++) { +struct rte_memseg **pages;struct hugepage_info *hpi = &used_hp[hp_sz_idx];unsigned int num_pages = hpi->num_pages[socket_id]; -int num_pages_alloc; +int num_pages_alloc, i;if (num_pages ==0 )continue ; + pages =malloc (sizeof (*pages) * num_pages); +RTE_LOG (DEBUG ,EAL ,"Allocating %u pages of size %" PRIu64"M on socket %i\n" , num_pages, hpi->hugepage_sz >>20 , socket_id); - num_pages_alloc =eal_memalloc_alloc_seg_bulk (NULL , + num_pages_alloc =eal_memalloc_alloc_seg_bulk (pages, num_pages, hpi->hugepage_sz, socket_id, true); -if (num_pages_alloc <0 ) +if (num_pages_alloc <0 ) { +free (pages);return -1 ; + } + +/* mark preallocated pages as unfreeable */ +for (i =0 ; i < num_pages_alloc; i++) { +struct rte_memseg *ms = pages[i]; + ms->flags |=RTE_MEMSEG_FLAG_DO_NOT_FREE ; + } +free (pages); } }return 0 ;
Signature · 1 line
2.7.4
11/04/2018 14:29, Anatoly Burakov:
Quoted 2 lines
This patchset introduces dynamic memory allocation for DPDK (aka memory hotplug). Based upon RFC submitted in December [1].
Applied (with some fixes discussed together), thanks for the huge work!
Now waiting adjustments for some devices or platforms.
Quoted 60 lines · Anatoly Burakov
This patchset introduces dynamic memory allocation for DPDK (aka memory hotplug). Based upon RFC submitted in December [1].
Dependencies (to be applied in specified order):
- IPC bugfixes patchset [2]
- IPC improvements patchset [3]
- IPC asynchronous request API patch [4]
- Function to return number of sockets [5]Deprecation notices relevant to this patchset:
- General outline of memory hotplug changes [6]
- EAL NUMA node count changes [7]The vast majority of changes are in the EAL and malloc, the external API disruption is minimal: a new set of API's are added for contiguous memory allocation for
rte_memzone, and a few API additions inrte_memorydue to switch tomemseg_listsas opposed to memsegs. Every other API change is internal to EAL, and all of the memory allocation/freeing is handled throughrte_malloc, with no externally visible API changes.Quick outline of all changes done as part of this patchset:
* Malloc heap adjusted to handle holes in address space
* Single memseg list replaced by multiple memseg lists
* VA space for hugepages is preallocated in advance
* Added alloc/free for pages happening as needed on rte_malloc/rte_free
* Added contiguous memory allocation API's forrte_memzone
* Integrated Pawel Wodkowski's patch for registering/unregistering memory with VFIO [8]
* Callbacks for registering memory allocations
* Multiprocess support done via DPDK IPC introduced in 18.02The biggest difference is a "memseg" now represents a single page (as opposed to being a big contiguous block of pages). As a consequence, both memzones and malloc elements are no longer guaranteed to be physically contiguous, unless the user asks for it at reserve time. To preserve whatever functionality that was dependent on previous behavior, a legacy memory option is also provided, however it is expected (or perhaps vainly hoped) to be temporary solution.
Why multiple memseg lists instead of one? Since memseg is a single page now, the list of memsegs will get quite big, and we need to locate pages somehow when we allocate and free them. We could of course just walk the list and allocate one contiguous chunk of VA space for memsegs, but this implementation uses separate lists instead in order to speed up many operations with memseg lists.
For v1, the following limitations are present:
- FreeBSD does not even compile, let alone run
- No 32-bit support
- There are some minor quality-of-life improvements planned that aren't ready yet and will be part of v2
- VFIO support is only smoke-tested (but is expected to work), VFIO support with secondary processes is not tested; work is ongoing to validate VFIO for all use cases
- Dynamic mapping/unmapping memory with VFIO is not supported in sPAPR IOMMU mode - help from sPAPR maintainers requestedNevertheless, this patchset should be testable under 64-bit Linux, and should work for all use cases bar those mentioned above.
Quoted 9 lines
[1] http://dpdk.org/dev/patchwork/bundle/aburakov/Memory_RFC/
[2] http://dpdk.org/dev/patchwork/bundle/aburakov/IPC_Fixes/
[3] http://dpdk.org/dev/patchwork/bundle/aburakov/IPC_Improvements/
[4] http://dpdk.org/dev/patchwork/bundle/aburakov/IPC_Async_Request/
[5] http://dpdk.org/dev/patchwork/bundle/aburakov/Num_Sockets/
[6] http://dpdk.org/dev/patchwork/patch/34002/
[7] http://dpdk.org/dev/patchwork/patch/33853/
[8] http://dpdk.org/dev/patchwork/patch/24484/
For those wanting to test this patchset, there is now a github tree with all of the dependent patches applied:
https://github.com/anatolyburakov/dpdk
Signature · 2 lines
Thanks, Anatoly
Hi Anatoly,
Quoted 60 lines · Anatoly Burakov
This patchset introduces dynamic memory allocation for DPDK (aka memory hotplug). Based upon RFC submitted in December [1].
Dependencies (to be applied in specified order):
- IPC bugfixes patchset [2]
- IPC improvements patchset [3]
- IPC asynchronous request API patch [4]
- Function to return number of sockets [5]Deprecation notices relevant to this patchset:
- General outline of memory hotplug changes [6]
- EAL NUMA node count changes [7]The vast majority of changes are in the EAL and malloc, the external API disruption is minimal: a new set of API's are added for contiguous memory allocation for
rte_memzone, and a few API additions inrte_memorydue to switch tomemseg_listsas opposed to memsegs. Every other API change is internal to EAL, and all of the memory allocation/freeing is handled throughrte_malloc, with no externally visible API changes.Quick outline of all changes done as part of this patchset:
* Malloc heap adjusted to handle holes in address space
* Single memseg list replaced by multiple memseg lists
* VA space for hugepages is preallocated in advance
* Added alloc/free for pages happening as needed on rte_malloc/rte_free
* Added contiguous memory allocation API's forrte_memzone
* Integrated Pawel Wodkowski's patch for registering/unregistering memory with VFIO [8]
* Callbacks for registering memory allocations
* Multiprocess support done via DPDK IPC introduced in 18.02The biggest difference is a "memseg" now represents a single page (as opposed to being a big contiguous block of pages). As a consequence, both memzones and malloc elements are no longer guaranteed to be physically contiguous, unless the user asks for it at reserve time. To preserve whatever functionality that was dependent on previous behavior, a legacy memory option is also provided, however it is expected (or perhaps vainly hoped) to be temporary solution.
Why multiple memseg lists instead of one? Since memseg is a single page now, the list of memsegs will get quite big, and we need to locate pages somehow when we allocate and free them. We could of course just walk the list and allocate one contiguous chunk of VA space for memsegs, but this implementation uses separate lists instead in order to speed up many operations with memseg lists.
For v1, the following limitations are present:
- FreeBSD does not even compile, let alone run
- No 32-bit support
- There are some minor quality-of-life improvements planned that aren't ready yet and will be part of v2
- VFIO support is only smoke-tested (but is expected to work), VFIO support with secondary processes is not tested; work is ongoing to validate VFIO for all use cases
- Dynamic mapping/unmapping memory with VFIO is not supported in sPAPR IOMMU mode - help from sPAPR maintainers requestedNevertheless, this patchset should be testable under 64-bit Linux, and should work for all use cases bar those mentioned above.
Quoted 8 lines
[1] http://dpdk.org/dev/patchwork/bundle/aburakov/Memory_RFC/
[2] http://dpdk.org/dev/patchwork/bundle/aburakov/IPC_Fixes/
[3] http://dpdk.org/dev/patchwork/bundle/aburakov/IPC_Improvements/
[4] http://dpdk.org/dev/patchwork/bundle/aburakov/IPC_Async_Request/
[5] http://dpdk.org/dev/patchwork/bundle/aburakov/Num_Sockets/
[6] http://dpdk.org/dev/patchwork/patch/34002/
[7] http://dpdk.org/dev/patchwork/patch/33853/
[8] http://dpdk.org/dev/patchwork/patch/24484/
I did a quick pass on your patches (unfortunately, I don't have the time to really dive in it).
I have few questions/comments:
- This is really a big patchset. Thank you for working on this topic. I'll try to test our application with it as soon as possible.
- I see from patch 17 that it is possible that rte_malloc() expands the heap by requesting more memory to the OS? Did I understand well? Today, a good property of rte_malloc() compared to malloc() is that it won't interrupt the process (the worst case is a spinlock). This is appreciable on a dataplane core. Will it change?
- It's not a big issue, but I have the feeling that the "const" statement is often forgotten in the patchset. I think it is helpful for both optimization, documentation and to detect bugs that modifies/free something that should not.
I'm sending some other dummy comments as replies to patches.
Thanks,
Olivier
Quoted 77 lines · Olivier Matz
Hi Anatoly,
Quoted 60 lines · Anatoly Burakov
This patchset introduces dynamic memory allocation for DPDK (aka memory hotplug). Based upon RFC submitted in December [1].
Dependencies (to be applied in specified order):
- IPC bugfixes patchset [2]
- IPC improvements patchset [3]
- IPC asynchronous request API patch [4]
- Function to return number of sockets [5]Deprecation notices relevant to this patchset:
- General outline of memory hotplug changes [6]
- EAL NUMA node count changes [7]The vast majority of changes are in the EAL and malloc, the external API disruption is minimal: a new set of API's are added for contiguous memory allocation for
rte_memzone, and a few API additions inrte_memorydue to switch tomemseg_listsas opposed to memsegs. Every other API change is internal to EAL, and all of the memory allocation/freeing is handled throughrte_malloc, with no externally visible API changes.Quick outline of all changes done as part of this patchset:
* Malloc heap adjusted to handle holes in address space
* Single memseg list replaced by multiple memseg lists
* VA space for hugepages is preallocated in advance
* Added alloc/free for pages happening as needed on rte_malloc/rte_free
* Added contiguous memory allocation API's forrte_memzone
* Integrated Pawel Wodkowski's patch for registering/unregistering memory with VFIO [8]
* Callbacks for registering memory allocations
* Multiprocess support done via DPDK IPC introduced in 18.02The biggest difference is a "memseg" now represents a single page (as opposed to being a big contiguous block of pages). As a consequence, both memzones and malloc elements are no longer guaranteed to be physically contiguous, unless the user asks for it at reserve time. To preserve whatever functionality that was dependent on previous behavior, a legacy memory option is also provided, however it is expected (or perhaps vainly hoped) to be temporary solution.
Why multiple memseg lists instead of one? Since memseg is a single page now, the list of memsegs will get quite big, and we need to locate pages somehow when we allocate and free them. We could of course just walk the list and allocate one contiguous chunk of VA space for memsegs, but this implementation uses separate lists instead in order to speed up many operations with memseg lists.
For v1, the following limitations are present:
- FreeBSD does not even compile, let alone run
- No 32-bit support
- There are some minor quality-of-life improvements planned that aren't ready yet and will be part of v2
- VFIO support is only smoke-tested (but is expected to work), VFIO support with secondary processes is not tested; work is ongoing to validate VFIO for all use cases
- Dynamic mapping/unmapping memory with VFIO is not supported in sPAPR IOMMU mode - help from sPAPR maintainers requestedNevertheless, this patchset should be testable under 64-bit Linux, and should work for all use cases bar those mentioned above.
Quoted 8 lines
[1] http://dpdk.org/dev/patchwork/bundle/aburakov/Memory_RFC/
[2] http://dpdk.org/dev/patchwork/bundle/aburakov/IPC_Fixes/
[3] http://dpdk.org/dev/patchwork/bundle/aburakov/IPC_Improvements/
[4] http://dpdk.org/dev/patchwork/bundle/aburakov/IPC_Async_Request/
[5] http://dpdk.org/dev/patchwork/bundle/aburakov/Num_Sockets/
[6] http://dpdk.org/dev/patchwork/patch/34002/
[7] http://dpdk.org/dev/patchwork/patch/33853/
[8] http://dpdk.org/dev/patchwork/patch/24484/I did a quick pass on your patches (unfortunately, I don't have the time to really dive in it).
I have few questions/comments:
Quoted 8 lines
- This is really a big patchset. Thank you for working on this topic. I'll try to test our application with it as soon as possible.
- I see from patch 17 that it is possible that
rte_malloc()expands the heap by requesting more memory to the OS? Did I understand well? Today, a good property ofrte_malloc()compared tomalloc()is that it won't interrupt the process (the worst case is a spinlock). This is appreciable on a dataplane core. Will it change?
Hi Olivier,
Not sure what you mean by "interrupt the process". The new rte_malloc will _mostly_ work just like the old one. There are now two levels of locks: the heap lock, and the system allocation lock. If your rte_malloc call requests amount of memory that can be satisfied by already allocated memory, then only the heap lock is engaged - or, to put it in other words, things work as before.
When you *don't* have enough memory allocated, previously rte_malloc would just fail. Now, it instead will lock the second lock and try to allocate more memory from the system. This requires IPC (to ensure all processes have allocated/freed the same memory), so this will take way longer (timeout is set to wait up to 5 seconds, although under normal circumstances it's taking a lot less - depending on how many processes you have running, but generally under 100ms), and will block other system allocations (i.e. if another rte_malloc call on another heap is trying to request more memory from the system).
So, in short - you can't allocate from the same heap in parallel (same as before), and you can't have parallel system memory allocation requests (regardless of from which heap it comes from). The latter *only* applies to system memory allocations - that is, if one heap is allocating system memory while another heap receives allocation request *and is able to satisfy it from already allocated memory*, it will not block, because the second lock is never engaged.
Quoted 5 lines
- It's not a big issue, but I have the feeling that the "const" statement is often forgotten in the patchset. I think it is helpful for both optimization, documentation and to detect bugs that modifies/free something that should not.
Generally, if things aren't const, they aren't for a reason :) I made things const by default and removed constness once i needed to. However, there may have been a few places where i changed the code around but forgot to put constness back. I'll look into it.
Thanks for your reviews!
Quoted 6 lines
I'm sending some other dummy comments as replies to patches.
Thanks,
Olivier
Signature · 2 lines
Thanks, Anatoly
Quoted 106 lines · Anatoly
Quoted 77 lines · Olivier Matz
Hi Anatoly,
Quoted 60 lines · Anatoly Burakov
This patchset introduces dynamic memory allocation for DPDK (aka memory hotplug). Based upon RFC submitted in December [1].
Dependencies (to be applied in specified order):
- IPC bugfixes patchset [2]
- IPC improvements patchset [3]
- IPC asynchronous request API patch [4]
- Function to return number of sockets [5]Deprecation notices relevant to this patchset:
- General outline of memory hotplug changes [6]
- EAL NUMA node count changes [7]The vast majority of changes are in the EAL and malloc, the external API disruption is minimal: a new set of API's are added for contiguous memory allocation for
rte_memzone, and a few API additions inrte_memorydue to switch tomemseg_listsas opposed to memsegs. Every other API change is internal to EAL, and all of the memory allocation/freeing is handled throughrte_malloc, with no externally visible API changes.Quick outline of all changes done as part of this patchset:
* Malloc heap adjusted to handle holes in address space
* Single memseg list replaced by multiple memseg lists
* VA space for hugepages is preallocated in advance
* Added alloc/free for pages happening as needed on rte_malloc/rte_free
* Added contiguous memory allocation API's forrte_memzone
* Integrated Pawel Wodkowski's patch for registering/unregistering memory with VFIO [8]
* Callbacks for registering memory allocations
* Multiprocess support done via DPDK IPC introduced in 18.02The biggest difference is a "memseg" now represents a single page (as opposed to being a big contiguous block of pages). As a consequence, both memzones and malloc elements are no longer guaranteed to be physically contiguous, unless the user asks for it at reserve time. To preserve whatever functionality that was dependent on previous behavior, a legacy memory option is also provided, however it is expected (or perhaps vainly hoped) to be temporary solution.
Why multiple memseg lists instead of one? Since memseg is a single page now, the list of memsegs will get quite big, and we need to locate pages somehow when we allocate and free them. We could of course just walk the list and allocate one contiguous chunk of VA space for memsegs, but this implementation uses separate lists instead in order to speed up many operations with memseg lists.
For v1, the following limitations are present:
- FreeBSD does not even compile, let alone run
- No 32-bit support
- There are some minor quality-of-life improvements planned that aren't ready yet and will be part of v2
- VFIO support is only smoke-tested (but is expected to work), VFIO support with secondary processes is not tested; work is ongoing to validate VFIO for all use cases
- Dynamic mapping/unmapping memory with VFIO is not supported in sPAPR IOMMU mode - help from sPAPR maintainers requestedNevertheless, this patchset should be testable under 64-bit Linux, and should work for all use cases bar those mentioned above.
Quoted 8 lines
[1] http://dpdk.org/dev/patchwork/bundle/aburakov/Memory_RFC/
[2] http://dpdk.org/dev/patchwork/bundle/aburakov/IPC_Fixes/
[3] http://dpdk.org/dev/patchwork/bundle/aburakov/IPC_Improvements/
[4] http://dpdk.org/dev/patchwork/bundle/aburakov/IPC_Async_Request/
[5] http://dpdk.org/dev/patchwork/bundle/aburakov/Num_Sockets/
[6] http://dpdk.org/dev/patchwork/patch/34002/
[7] http://dpdk.org/dev/patchwork/patch/33853/
[8] http://dpdk.org/dev/patchwork/patch/24484/I did a quick pass on your patches (unfortunately, I don't have the time to really dive in it).
I have few questions/comments:
Quoted 8 lines
- This is really a big patchset. Thank you for working on this topic. I'll try to test our application with it as soon as possible.
- I see from patch 17 that it is possible that
rte_malloc()expands the heap by requesting more memory to the OS? Did I understand well? Today, a good property ofrte_malloc()compared tomalloc()is that it won't interrupt the process (the worst case is a spinlock). This is appreciable on a dataplane core. Will it change?Hi Olivier,
Not sure what you mean by "interrupt the process". The new
rte_mallocwill _mostly_ work just like the old one. There are now two levels of locks: the heap lock, and the system allocation lock. If yourrte_malloccall requests amount of memory that can be satisfied by already allocated memory, then only the heap lock is engaged - or, to put it in other words, things work as before.When you *don't* have enough memory allocated, previously
rte_mallocwould just fail. Now, it instead will lock the second lock and try to allocate more memory from the system. This requires IPC (to ensure all processes have allocated/freed the same memory), so this will take way longer (timeout is set to wait up to 5 seconds, although under normal circumstances it's taking a lot less - depending on how many processes you have running, but generally under 100ms), and will block other system allocations (i.e. if anotherrte_malloccall on another heap is trying to request more memory from the system).
Quoted 7 lines
So, in short - you can't allocate from the same heap in parallel (same as before), and you can't have parallel system memory allocation requests (regardless of from which heap it comes from). The latter *only* applies to system memory allocations - that is, if one heap is allocating system memory while another heap receives allocation request *and is able to satisfy it from already allocated memory*, it will not block, because the second lock is never engaged.
OK. Let's imagine you are using rte_malloc() on a dataplane core, and you run out of memory. Previously, the allocation would just fail. Now, if my understanding is correct, it can block for a long time, which can be a problem on a dataplane core, because it will cause packet losses, especially if it also blocks allocations on other cores during that time. In this case, it could be useful to make the dynamic heap resizing feature optional.
I have another question about the patchset. Today, it is not really possible for an application to allocate a page. If you want a full page (ex: 2M), you need to allocate 4M because the rte_malloc layer adds a header before the allocated memory. Therefore, if the memory is fragmented a lot with only 2M pages, you cannot allocate them as pages.
It is possible, with your patchset or in the future, to have an access to a page-based allocator? The use-case is to be able for an application to ask for pages in dpdk memory and remap them in a virtually contiguous memory.
Thanks
Olivier
Quoted 115 lines · Olivier Matz
Quoted 106 lines · Anatoly
Quoted 77 lines · Olivier Matz
Hi Anatoly,
Quoted 60 lines · Anatoly Burakov
This patchset introduces dynamic memory allocation for DPDK (aka memory hotplug). Based upon RFC submitted in December [1].
Dependencies (to be applied in specified order):
- IPC bugfixes patchset [2]
- IPC improvements patchset [3]
- IPC asynchronous request API patch [4]
- Function to return number of sockets [5]Deprecation notices relevant to this patchset:
- General outline of memory hotplug changes [6]
- EAL NUMA node count changes [7]The vast majority of changes are in the EAL and malloc, the external API disruption is minimal: a new set of API's are added for contiguous memory allocation for
rte_memzone, and a few API additions inrte_memorydue to switch tomemseg_listsas opposed to memsegs. Every other API change is internal to EAL, and all of the memory allocation/freeing is handled throughrte_malloc, with no externally visible API changes.Quick outline of all changes done as part of this patchset:
* Malloc heap adjusted to handle holes in address space
* Single memseg list replaced by multiple memseg lists
* VA space for hugepages is preallocated in advance
* Added alloc/free for pages happening as needed on rte_malloc/rte_free
* Added contiguous memory allocation API's forrte_memzone
* Integrated Pawel Wodkowski's patch for registering/unregistering memory with VFIO [8]
* Callbacks for registering memory allocations
* Multiprocess support done via DPDK IPC introduced in 18.02The biggest difference is a "memseg" now represents a single page (as opposed to being a big contiguous block of pages). As a consequence, both memzones and malloc elements are no longer guaranteed to be physically contiguous, unless the user asks for it at reserve time. To preserve whatever functionality that was dependent on previous behavior, a legacy memory option is also provided, however it is expected (or perhaps vainly hoped) to be temporary solution.
Why multiple memseg lists instead of one? Since memseg is a single page now, the list of memsegs will get quite big, and we need to locate pages somehow when we allocate and free them. We could of course just walk the list and allocate one contiguous chunk of VA space for memsegs, but this implementation uses separate lists instead in order to speed up many operations with memseg lists.
For v1, the following limitations are present:
- FreeBSD does not even compile, let alone run
- No 32-bit support
- There are some minor quality-of-life improvements planned that aren't ready yet and will be part of v2
- VFIO support is only smoke-tested (but is expected to work), VFIO support with secondary processes is not tested; work is ongoing to validate VFIO for all use cases
- Dynamic mapping/unmapping memory with VFIO is not supported in sPAPR IOMMU mode - help from sPAPR maintainers requestedNevertheless, this patchset should be testable under 64-bit Linux, and should work for all use cases bar those mentioned above.
Quoted 8 lines
[1] http://dpdk.org/dev/patchwork/bundle/aburakov/Memory_RFC/
[2] http://dpdk.org/dev/patchwork/bundle/aburakov/IPC_Fixes/
[3] http://dpdk.org/dev/patchwork/bundle/aburakov/IPC_Improvements/
[4] http://dpdk.org/dev/patchwork/bundle/aburakov/IPC_Async_Request/
[5] http://dpdk.org/dev/patchwork/bundle/aburakov/Num_Sockets/
[6] http://dpdk.org/dev/patchwork/patch/34002/
[7] http://dpdk.org/dev/patchwork/patch/33853/
[8] http://dpdk.org/dev/patchwork/patch/24484/I did a quick pass on your patches (unfortunately, I don't have the time to really dive in it).
I have few questions/comments:
Quoted 8 lines
- This is really a big patchset. Thank you for working on this topic. I'll try to test our application with it as soon as possible.
- I see from patch 17 that it is possible that
rte_malloc()expands the heap by requesting more memory to the OS? Did I understand well? Today, a good property ofrte_malloc()compared tomalloc()is that it won't interrupt the process (the worst case is a spinlock). This is appreciable on a dataplane core. Will it change?Hi Olivier,
Not sure what you mean by "interrupt the process". The new
rte_mallocwill _mostly_ work just like the old one. There are now two levels of locks: the heap lock, and the system allocation lock. If yourrte_malloccall requests amount of memory that can be satisfied by already allocated memory, then only the heap lock is engaged - or, to put it in other words, things work as before.When you *don't* have enough memory allocated, previously
rte_mallocwould just fail. Now, it instead will lock the second lock and try to allocate more memory from the system. This requires IPC (to ensure all processes have allocated/freed the same memory), so this will take way longer (timeout is set to wait up to 5 seconds, although under normal circumstances it's taking a lot less - depending on how many processes you have running, but generally under 100ms), and will block other system allocations (i.e. if anotherrte_malloccall on another heap is trying to request more memory from the system).Quoted 7 lines
So, in short - you can't allocate from the same heap in parallel (same as before), and you can't have parallel system memory allocation requests (regardless of from which heap it comes from). The latter *only* applies to system memory allocations - that is, if one heap is allocating system memory while another heap receives allocation request *and is able to satisfy it from already allocated memory*, it will not block, because the second lock is never engaged.
Quoted 7 lines
OK. Let's imagine you are using
rte_malloc()on a dataplane core, and you run out of memory. Previously, the allocation would just fail. Now, if my understanding is correct, it can block for a long time, which can be a problem on a dataplane core, because it will cause packet losses, especially if it also blocks allocations on other cores during that time. In this case, it could be useful to make the dynamic heap resizing feature optional.
Why would anyone in their right mind call rte_malloc on fast path? If you're referring to mempool allocations/deallocations, then this is a completely separate subject, as mempool alloc/free is not handled by rte_malloc but is handled by rte_mempool itself - as far as rte_malloc is concerned, that memory is already allocated and it will not touch it.
As for "making heap resizing feature optional", i'm working on functionality that would essentially enable that. Specifically, i'm adding API's to set allocation limits and a callback which will get triggered once allocator tries to allocate beyond said limits, with an option of returning -1 and thus preventing this allocation from completing. While this is kind of a round-about way of doing it, it would have similar effect.
Quoted 11 lines
I have another question about the patchset. Today, it is not really possible for an application to allocate a page. If you want a full page (ex: 2M), you need to allocate 4M because the
rte_malloclayer adds a header before the allocated memory. Therefore, if the memory is fragmented a lot with only 2M pages, you cannot allocate them as pages.It is possible, with your patchset or in the future, to have an access to a page-based allocator? The use-case is to be able for an application to ask for pages in dpdk memory and remap them in a virtually contiguous memory.
Pages returned from our allocator are already virtually contiguous, there is no need to do any remapping. If user specifies proper size and alignment (i.e. reserve a memzone with RTE_MEMZONE_2MB and with 2M size and alignment), it will essentially cause the allocator to return a memzone that's exactly page-size long. Yes, in the background, it will allocate another page to store malloc metadata, and yes, memory will become fragmented if multiple such allocations will occur. It is not possible (neither now nor in the future planned work) to do what you describe unless we store malloc data separately from allocated memory (which can be done, but is a non-trivial amount of work).
Malloc stores its metadata right in the hugepage mostly for multiprocess purposes - so that the entire heap is always shared between all processes. If we want to store malloc metadata separately from allocated memory, a replacement mechanism to shared heap metadata will need to be put in place (which, again, can be done, but is a non-trivial amount of work - arguably for questionable gain).
That said, use case you have described is already possible - just allocate multiple pages from DPDK as a memzone, and overlay your own memory allocator over that memory. This will have the same effect.
Quoted 4 lines
Thanks
Olivier
Signature · 2 lines
Thanks, Anatoly
Hi,
Quoted 130 lines · Anatoly
Quoted 115 lines · Olivier Matz
Quoted 106 lines · Anatoly
Quoted 77 lines · Olivier Matz
Hi Anatoly,
Quoted 60 lines · Anatoly Burakov
This patchset introduces dynamic memory allocation for DPDK (aka memory hotplug). Based upon RFC submitted in December [1].
Dependencies (to be applied in specified order):
- IPC bugfixes patchset [2]
- IPC improvements patchset [3]
- IPC asynchronous request API patch [4]
- Function to return number of sockets [5]Deprecation notices relevant to this patchset:
- General outline of memory hotplug changes [6]
- EAL NUMA node count changes [7]The vast majority of changes are in the EAL and malloc, the external API disruption is minimal: a new set of API's are added for contiguous memory allocation for
rte_memzone, and a few API additions inrte_memorydue to switch tomemseg_listsas opposed to memsegs. Every other API change is internal to EAL, and all of the memory allocation/freeing is handled throughrte_malloc, with no externally visible API changes.Quick outline of all changes done as part of this patchset:
* Malloc heap adjusted to handle holes in address space
* Single memseg list replaced by multiple memseg lists
* VA space for hugepages is preallocated in advance
* Added alloc/free for pages happening as needed on rte_malloc/rte_free
* Added contiguous memory allocation API's forrte_memzone
* Integrated Pawel Wodkowski's patch for registering/unregistering memory with VFIO [8]
* Callbacks for registering memory allocations
* Multiprocess support done via DPDK IPC introduced in 18.02The biggest difference is a "memseg" now represents a single page (as opposed to being a big contiguous block of pages). As a consequence, both memzones and malloc elements are no longer guaranteed to be physically contiguous, unless the user asks for it at reserve time. To preserve whatever functionality that was dependent on previous behavior, a legacy memory option is also provided, however it is expected (or perhaps vainly hoped) to be temporary solution.
Why multiple memseg lists instead of one? Since memseg is a single page now, the list of memsegs will get quite big, and we need to locate pages somehow when we allocate and free them. We could of course just walk the list and allocate one contiguous chunk of VA space for memsegs, but this implementation uses separate lists instead in order to speed up many operations with memseg lists.
For v1, the following limitations are present:
- FreeBSD does not even compile, let alone run
- No 32-bit support
- There are some minor quality-of-life improvements planned that aren't ready yet and will be part of v2
- VFIO support is only smoke-tested (but is expected to work), VFIO support with secondary processes is not tested; work is ongoing to validate VFIO for all use cases
- Dynamic mapping/unmapping memory with VFIO is not supported in sPAPR IOMMU mode - help from sPAPR maintainers requestedNevertheless, this patchset should be testable under 64-bit Linux, and should work for all use cases bar those mentioned above.
Quoted 8 lines
[1] http://dpdk.org/dev/patchwork/bundle/aburakov/Memory_RFC/
[2] http://dpdk.org/dev/patchwork/bundle/aburakov/IPC_Fixes/
[3] http://dpdk.org/dev/patchwork/bundle/aburakov/IPC_Improvements/
[4] http://dpdk.org/dev/patchwork/bundle/aburakov/IPC_Async_Request/
[5] http://dpdk.org/dev/patchwork/bundle/aburakov/Num_Sockets/
[6] http://dpdk.org/dev/patchwork/patch/34002/
[7] http://dpdk.org/dev/patchwork/patch/33853/
[8] http://dpdk.org/dev/patchwork/patch/24484/I did a quick pass on your patches (unfortunately, I don't have the time to really dive in it).
I have few questions/comments:
Quoted 8 lines
- This is really a big patchset. Thank you for working on this topic. I'll try to test our application with it as soon as possible.
- I see from patch 17 that it is possible that
rte_malloc()expands the heap by requesting more memory to the OS? Did I understand well? Today, a good property ofrte_malloc()compared tomalloc()is that it won't interrupt the process (the worst case is a spinlock). This is appreciable on a dataplane core. Will it change?Hi Olivier,
Not sure what you mean by "interrupt the process". The new
rte_mallocwill _mostly_ work just like the old one. There are now two levels of locks: the heap lock, and the system allocation lock. If yourrte_malloccall requests amount of memory that can be satisfied by already allocated memory, then only the heap lock is engaged - or, to put it in other words, things work as before.When you *don't* have enough memory allocated, previously
rte_mallocwould just fail. Now, it instead will lock the second lock and try to allocate more memory from the system. This requires IPC (to ensure all processes have allocated/freed the same memory), so this will take way longer (timeout is set to wait up to 5 seconds, although under normal circumstances it's taking a lot less - depending on how many processes you have running, but generally under 100ms), and will block other system allocations (i.e. if anotherrte_malloccall on another heap is trying to request more memory from the system).Quoted 7 lines
So, in short - you can't allocate from the same heap in parallel (same as before), and you can't have parallel system memory allocation requests (regardless of from which heap it comes from). The latter *only* applies to system memory allocations - that is, if one heap is allocating system memory while another heap receives allocation request *and is able to satisfy it from already allocated memory*, it will not block, because the second lock is never engaged.
Quoted 7 lines
OK. Let's imagine you are using
rte_malloc()on a dataplane core, and you run out of memory. Previously, the allocation would just fail. Now, if my understanding is correct, it can block for a long time, which can be a problem on a dataplane core, because it will cause packet losses, especially if it also blocks allocations on other cores during that time. In this case, it could be useful to make the dynamic heap resizing feature optional.Why would anyone in their right mind call
rte_mallocon fast path? If you're referring to mempool allocations/deallocations, then this is a completely separate subject, as mempool alloc/free is not handled byrte_mallocbut is handled byrte_mempoolitself - as far asrte_mallocis concerned, that memory is already allocated and it will not touch it.
Quoted 6 lines
As for "making heap resizing feature optional", i'm working on functionality that would essentially enable that. Specifically, i'm adding API's to set allocation limits and a callback which will get triggered once allocator tries to allocate beyond said limits, with an option of returning -1 and thus preventing this allocation from completing. While this is kind of a round-about way of doing it, it would have similar effect.
Calling rte_malloc() in the data path may be required in case the application needs to allocate an unknown-sized object. I'm not saying it's a usual or an optimal use case, I just say that it happens.
Waiting for a spinlock is acceptable in datapath, if it is held by another dataplane core.
Waiting for several hundreds of ms is not an option in that case.
If the feature is going to be optional, it's perfectly fine for me.
Quoted 29 lines
Quoted 10 lines
I have another question about the patchset. Today, it is not really possible for an application to allocate a page. If you want a full page (ex: 2M), you need to allocate 4M because the
rte_malloclayer adds a header before the allocated memory. Therefore, if the memory is fragmented a lot with only 2M pages, you cannot allocate them as pages.It is possible, with your patchset or in the future, to have an access to a page-based allocator? The use-case is to be able for an application to ask for pages in dpdk memory and remap them in a virtually contiguous memory.
Pages returned from our allocator are already virtually contiguous, there is no need to do any remapping. If user specifies proper size and alignment (i.e. reserve a memzone with
RTE_MEMZONE_2MBand with 2M size and alignment), it will essentially cause the allocator to return a memzone that's exactly page-size long. Yes, in the background, it will allocate another page to store malloc metadata, and yes, memory will become fragmented if multiple such allocations will occur. It is not possible (neither now nor in the future planned work) to do what you describe unless we store malloc data separately from allocated memory (which can be done, but is a non-trivial amount of work).Malloc stores its metadata right in the hugepage mostly for multiprocess purposes - so that the entire heap is always shared between all processes. If we want to store malloc metadata separately from allocated memory, a replacement mechanism to shared heap metadata will need to be put in place (which, again, can be done, but is a non-trivial amount of work - arguably for questionable gain).
Quoted 3 lines
That said, use case you have described is already possible - just allocate multiple pages from DPDK as a memzone, and overlay your own memory allocator over that memory. This will have the same effect.
Yes, that's currently what I'm doing: to get one 2M page, I'm allocating more 2M with 2M alignement, which actually results in 4M allocation. My problem today is when the huge pages are already fragmented at dpdk start (i.e. only isolated pages). So an allocation of > 2M would fail.
So your patchset mostly solves that issue, because rte_malloc() does not request physically contiguous memory anymore, which means that physically isolated hugepages are now virtually contiguous, right? So rte_malloc(4M) will always be succesful until the memory is virtually fragmented (i.e. after several malloc/free).
Thank you for the clarification.
Quoted 144 lines · Olivier Matz
Hi,
Quoted 130 lines · Anatoly
Quoted 115 lines · Olivier Matz
Quoted 106 lines · Anatoly
Quoted 77 lines · Olivier Matz
Hi Anatoly,
Quoted 60 lines · Anatoly Burakov
This patchset introduces dynamic memory allocation for DPDK (aka memory hotplug). Based upon RFC submitted in December [1].
Dependencies (to be applied in specified order):
- IPC bugfixes patchset [2]
- IPC improvements patchset [3]
- IPC asynchronous request API patch [4]
- Function to return number of sockets [5]Deprecation notices relevant to this patchset:
- General outline of memory hotplug changes [6]
- EAL NUMA node count changes [7]The vast majority of changes are in the EAL and malloc, the external API disruption is minimal: a new set of API's are added for contiguous memory allocation for
rte_memzone, and a few API additions inrte_memorydue to switch tomemseg_listsas opposed to memsegs. Every other API change is internal to EAL, and all of the memory allocation/freeing is handled throughrte_malloc, with no externally visible API changes.Quick outline of all changes done as part of this patchset:
* Malloc heap adjusted to handle holes in address space
* Single memseg list replaced by multiple memseg lists
* VA space for hugepages is preallocated in advance
* Added alloc/free for pages happening as needed on rte_malloc/rte_free
* Added contiguous memory allocation API's forrte_memzone
* Integrated Pawel Wodkowski's patch for registering/unregistering memory with VFIO [8]
* Callbacks for registering memory allocations
* Multiprocess support done via DPDK IPC introduced in 18.02The biggest difference is a "memseg" now represents a single page (as opposed to being a big contiguous block of pages). As a consequence, both memzones and malloc elements are no longer guaranteed to be physically contiguous, unless the user asks for it at reserve time. To preserve whatever functionality that was dependent on previous behavior, a legacy memory option is also provided, however it is expected (or perhaps vainly hoped) to be temporary solution.
Why multiple memseg lists instead of one? Since memseg is a single page now, the list of memsegs will get quite big, and we need to locate pages somehow when we allocate and free them. We could of course just walk the list and allocate one contiguous chunk of VA space for memsegs, but this implementation uses separate lists instead in order to speed up many operations with memseg lists.
For v1, the following limitations are present:
- FreeBSD does not even compile, let alone run
- No 32-bit support
- There are some minor quality-of-life improvements planned that aren't ready yet and will be part of v2
- VFIO support is only smoke-tested (but is expected to work), VFIO support with secondary processes is not tested; work is ongoing to validate VFIO for all use cases
- Dynamic mapping/unmapping memory with VFIO is not supported in sPAPR IOMMU mode - help from sPAPR maintainers requestedNevertheless, this patchset should be testable under 64-bit Linux, and should work for all use cases bar those mentioned above.
Quoted 8 lines
[1] http://dpdk.org/dev/patchwork/bundle/aburakov/Memory_RFC/
[2] http://dpdk.org/dev/patchwork/bundle/aburakov/IPC_Fixes/
[3] http://dpdk.org/dev/patchwork/bundle/aburakov/IPC_Improvements/
[4] http://dpdk.org/dev/patchwork/bundle/aburakov/IPC_Async_Request/
[5] http://dpdk.org/dev/patchwork/bundle/aburakov/Num_Sockets/
[6] http://dpdk.org/dev/patchwork/patch/34002/
[7] http://dpdk.org/dev/patchwork/patch/33853/
[8] http://dpdk.org/dev/patchwork/patch/24484/I did a quick pass on your patches (unfortunately, I don't have the time to really dive in it).
I have few questions/comments:
Quoted 8 lines
- This is really a big patchset. Thank you for working on this topic. I'll try to test our application with it as soon as possible.
- I see from patch 17 that it is possible that
rte_malloc()expands the heap by requesting more memory to the OS? Did I understand well? Today, a good property ofrte_malloc()compared tomalloc()is that it won't interrupt the process (the worst case is a spinlock). This is appreciable on a dataplane core. Will it change?Hi Olivier,
Not sure what you mean by "interrupt the process". The new
rte_mallocwill _mostly_ work just like the old one. There are now two levels of locks: the heap lock, and the system allocation lock. If yourrte_malloccall requests amount of memory that can be satisfied by already allocated memory, then only the heap lock is engaged - or, to put it in other words, things work as before.When you *don't* have enough memory allocated, previously
rte_mallocwould just fail. Now, it instead will lock the second lock and try to allocate more memory from the system. This requires IPC (to ensure all processes have allocated/freed the same memory), so this will take way longer (timeout is set to wait up to 5 seconds, although under normal circumstances it's taking a lot less - depending on how many processes you have running, but generally under 100ms), and will block other system allocations (i.e. if anotherrte_malloccall on another heap is trying to request more memory from the system).Quoted 7 lines
So, in short - you can't allocate from the same heap in parallel (same as before), and you can't have parallel system memory allocation requests (regardless of from which heap it comes from). The latter *only* applies to system memory allocations - that is, if one heap is allocating system memory while another heap receives allocation request *and is able to satisfy it from already allocated memory*, it will not block, because the second lock is never engaged.
Quoted 7 lines
OK. Let's imagine you are using
rte_malloc()on a dataplane core, and you run out of memory. Previously, the allocation would just fail. Now, if my understanding is correct, it can block for a long time, which can be a problem on a dataplane core, because it will cause packet losses, especially if it also blocks allocations on other cores during that time. In this case, it could be useful to make the dynamic heap resizing feature optional.Why would anyone in their right mind call
rte_mallocon fast path? If you're referring to mempool allocations/deallocations, then this is a completely separate subject, as mempool alloc/free is not handled byrte_mallocbut is handled byrte_mempoolitself - as far asrte_mallocis concerned, that memory is already allocated and it will not touch it.Quoted 6 lines
As for "making heap resizing feature optional", i'm working on functionality that would essentially enable that. Specifically, i'm adding API's to set allocation limits and a callback which will get triggered once allocator tries to allocate beyond said limits, with an option of returning -1 and thus preventing this allocation from completing. While this is kind of a round-about way of doing it, it would have similar effect.
Calling
rte_malloc()in the data path may be required in case the application needs to allocate an unknown-sized object. I'm not saying it's a usual or an optimal use case, I just say that it happens.
Quoted 5 lines
Waiting for a spinlock is acceptable in datapath, if it is held by another dataplane core.
Waiting for several hundreds of ms is not an option in that case.If the feature is going to be optional, it's perfectly fine for me.
Well, there's always an option of running in "legacy mem" mode, which disables memory hotplug completely and will essentially behave like it does right now (allocate VA and IOVA-contiguous segments).
But yes, with said allocation limits API you will essentially be able to control which allocations succeed and which don't. It's not exactly "making it optional", but you can have control over system memory allocations that would enable that. For example, at init you allocate all your necessary data structures, and then you set the memory allocation limits in such a way that you can neither allocate nor deallocate any pages whatsoever once you start up your fast-path. This way, regular malloc will still work, but any page allocation/deallocation request will not go through.
Quoted 40 lines
Quoted 31 lines
Quoted 8 lines
I have another question about the patchset. Today, it is not really possible for an application to allocate a page. If you want a full page (ex: 2M), you need to allocate 4M because the
rte_malloclayer adds a header before the allocated memory. Therefore, if the memory is fragmented a lot with only 2M pages, you cannot allocate them as pages.Quoted 4 lines
It is possible, with your patchset or in the future, to have an access to a page-based allocator? The use-case is to be able for an application to ask for pages in dpdk memory and remap them in a virtually contiguous memory.
Pages returned from our allocator are already virtually contiguous, there is no need to do any remapping. If user specifies proper size and alignment (i.e. reserve a memzone with
RTE_MEMZONE_2MBand with 2M size and alignment), it will essentially cause the allocator to return a memzone that's exactly page-size long. Yes, in the background, it will allocate another page to store malloc metadata, and yes, memory will become fragmented if multiple such allocations will occur. It is not possible (neither now nor in the future planned work) to do what you describe unless we store malloc data separately from allocated memory (which can be done, but is a non-trivial amount of work).Malloc stores its metadata right in the hugepage mostly for multiprocess purposes - so that the entire heap is always shared between all processes. If we want to store malloc metadata separately from allocated memory, a replacement mechanism to shared heap metadata will need to be put in place (which, again, can be done, but is a non-trivial amount of work - arguably for questionable gain).
Quoted 3 lines
That said, use case you have described is already possible - just allocate multiple pages from DPDK as a memzone, and overlay your own memory allocator over that memory. This will have the same effect.
Yes, that's currently what I'm doing: to get one 2M page, I'm allocating more 2M with 2M alignement, which actually results in 4M allocation. My problem today is when the huge pages are already fragmented at dpdk start (i.e. only isolated pages). So an allocation of > 2M would fail.
Quoted 5 lines
So your patchset mostly solves that issue, because
rte_malloc()does not request physically contiguous memory anymore, which means that physically isolated hugepages are now virtually contiguous, right? Sorte_malloc(4M)will always be succesful until the memory is virtually fragmented (i.e. after several malloc/free).
Yes, that is correct. We preallocate all VA space in advance, so unless you fragment your VA space by making multiple allocations in this way up to a point where you run out of pages, you should be OK.
As i said, it is possible to rewrite the heap in a way that will do away with storing metadata in-place, and that will solve some of the tricky issues with memory allocator (such as pad elements, which require special handling everywhere), however this metadata still has to be stored somewhere in shared memory in order to be shared across processes, and that poses a problem because at some point we may hit a condition where we have plenty of free space but have exhausted our malloc element list and cannot allocate more (and we can't realloc because, well, multiprocess). So, such a scenario will come with its own set of challenges. Sadly, there's no free lunch :(
Quoted 3 lines
Thank you for the clarification.
Signature · 2 lines
Thanks, Anatoly
Quoted 2 lines · Anatoly Burakov
This patchset introduces dynamic memory allocation for DPDK (aka memory hotplug). Based upon RFC submitted in December [1].
Hi Anatoly,
I am able to bring up pmd with these patches in powerpc. I am continuing to validate more on memory limits that this patch set has (eg pre-allocating anonymous mapping for largest mem possible as per default mem and memseg values). I'll keep posting my observations further.
Thanks for the patches,
Gowrishankar
Quoted 182 lines
Dependencies (to be applied in specified order):
- IPC bugfixes patchset [2]
- IPC improvements patchset [3]
- IPC asynchronous request API patch [4]
- Function to return number of sockets [5]Deprecation notices relevant to this patchset:
- General outline of memory hotplug changes [6]
- EAL NUMA node count changes [7]The vast majority of changes are in the EAL and malloc, the external API disruption is minimal: a new set of API's are added for contiguous memory allocation for
rte_memzone, and a few API additions inrte_memorydue to switch tomemseg_listsas opposed to memsegs. Every other API change is internal to EAL, and all of the memory allocation/freeing is handled throughrte_malloc, with no externally visible API changes.Quick outline of all changes done as part of this patchset:
* Malloc heap adjusted to handle holes in address space
* Single memseg list replaced by multiple memseg lists
* VA space for hugepages is preallocated in advance
* Added alloc/free for pages happening as needed on rte_malloc/rte_free
* Added contiguous memory allocation API's forrte_memzone
* Integrated Pawel Wodkowski's patch for registering/unregistering memory with VFIO [8]
* Callbacks for registering memory allocations
* Multiprocess support done via DPDK IPC introduced in 18.02The biggest difference is a "memseg" now represents a single page (as opposed to being a big contiguous block of pages). As a consequence, both memzones and malloc elements are no longer guaranteed to be physically contiguous, unless the user asks for it at reserve time. To preserve whatever functionality that was dependent on previous behavior, a legacy memory option is also provided, however it is expected (or perhaps vainly hoped) to be temporary solution.
Why multiple memseg lists instead of one? Since memseg is a single page now, the list of memsegs will get quite big, and we need to locate pages somehow when we allocate and free them. We could of course just walk the list and allocate one contiguous chunk of VA space for memsegs, but this implementation uses separate lists instead in order to speed up many operations with memseg lists.
For v1, the following limitations are present:
- FreeBSD does not even compile, let alone run
- No 32-bit support
- There are some minor quality-of-life improvements planned that aren't ready yet and will be part of v2
- VFIO support is only smoke-tested (but is expected to work), VFIO support with secondary processes is not tested; work is ongoing to validate VFIO for all use cases
- Dynamic mapping/unmapping memory with VFIO is not supported in sPAPR IOMMU mode - help from sPAPR maintainers requestedNevertheless, this patchset should be testable under 64-bit Linux, and should work for all use cases bar those mentioned above.
[1] http://dpdk.org/dev/patchwork/bundle/aburakov/Memory_RFC/
[2] http://dpdk.org/dev/patchwork/bundle/aburakov/IPC_Fixes/
[3] http://dpdk.org/dev/patchwork/bundle/aburakov/IPC_Improvements/
[4] http://dpdk.org/dev/patchwork/bundle/aburakov/IPC_Async_Request/
[5] http://dpdk.org/dev/patchwork/bundle/aburakov/Num_Sockets/
[6] http://dpdk.org/dev/patchwork/patch/34002/
[7] http://dpdk.org/dev/patchwork/patch/33853/
[8] http://dpdk.org/dev/patchwork/patch/24484/Anatoly Burakov (41):
eal: moveget_virtual_areaout of linuxappeal_memory.c
eal: move all locking to heap
eal: make malloc heap a doubly-linked list
eal: add function to dump malloc heap contents
test: add command to dump malloc heap contents
eal: makemalloc_elem_join_adjacent_freepublic
eal: make malloc free list remove public
eal: make malloc free return resulting malloc element
eal: addrte_fbarray
eal: add "single file segments" command-line option
eal: add "legacy memory" option
eal: read hugepage counts from node-specific sysfs path
eal: replace memseg with memseg lists
eal: add support for mapping hugepages at runtime
eal: add support for unmapping pages at runtime
eal: make use of memory hotplug for init
eal: enable memory hotplug support inrte_malloc
test: fix malloc autotest to support memory hotplug
eal: add API to check if memory is contiguous
eal: add backend support for contiguous allocation
eal: enable reserving physically contiguous memzones
eal: replace memzone array with fbarray
mempool: add support for the new allocation methods
vfio: allow to map other memory regions
eal: map/unmap memory with VFIO when alloc/free pages
eal: prepare memseg lists for multiprocess sync
eal: add multiprocess init with memory hotplug
eal: add support for multiprocess memory hotplug
eal: add support for callbacks on memory hotplug
eal: enable callbacks on malloc/free and mp sync
ethdev: use contiguous allocation for DMA memorycrypto/qat: use contiguous allocation for DMA memory net/avf: use contiguous allocation for DMA memory net/bnx2x: use contiguous allocation for DMA memory net/cxgbe: use contiguous allocation for DMA memory net/ena: use contiguous allocation for DMA memory net/enic: use contiguous allocation for DMA memory net/i40e: use contiguous allocation for DMA memory net/qede: use contiguous allocation for DMA memory net/virtio: use contiguous allocation for DMA memory net/vmxnet3: use contiguous allocation for DMA memoryconfig/common_base | 15 +- drivers/bus/pci/linux/pci.c | 29 +- drivers/crypto/qat/qat_qp.c | 4 +- drivers/net/avf/avf_ethdev.c | 2 +- drivers/net/bnx2x/bnx2x.c | 2 +- drivers/net/bnx2x/bnx2x_rxtx.c | 3 +- drivers/net/cxgbe/sge.c | 3 +- drivers/net/ena/base/ena_plat_dpdk.h | 7 +- drivers/net/ena/ena_ethdev.c | 10 +- drivers/net/enic/enic_main.c | 4 +- drivers/net/i40e/i40e_ethdev.c | 2 +- drivers/net/i40e/i40e_rxtx.c | 2 +- drivers/net/qede/base/bcm_osal.c | 5 +- drivers/net/virtio/virtio_ethdev.c | 8 +- drivers/net/virtio/virtio_user/vhost_kernel.c | 108 ++- drivers/net/vmxnet3/vmxnet3_ethdev.c | 7 +- lib/librte_eal/bsdapp/eal/Makefile | 4 + lib/librte_eal/bsdapp/eal/eal.c | 25 + lib/librte_eal/bsdapp/eal/eal_hugepage_info.c | 7 + lib/librte_eal/bsdapp/eal/eal_memalloc.c | 33 + lib/librte_eal/bsdapp/eal/meson.build | 1 + lib/librte_eal/common/Makefile | 2 +- lib/librte_eal/common/eal_common_fbarray.c | 859 +++++++++++++++++ lib/librte_eal/common/eal_common_memalloc.c | 181 ++++ lib/librte_eal/common/eal_common_memory.c | 512 +++++++++- lib/librte_eal/common/eal_common_memzone.c | 275 ++++-- lib/librte_eal/common/eal_common_options.c | 8 + lib/librte_eal/common/eal_filesystem.h | 13 + lib/librte_eal/common/eal_hugepages.h | 7 + lib/librte_eal/common/eal_internal_cfg.h | 10 +- lib/librte_eal/common/eal_memalloc.h | 41 + lib/librte_eal/common/eal_options.h | 4 + lib/librte_eal/common/eal_private.h | 33 + lib/librte_eal/common/include/rte_eal_memconfig.h | 29 +- lib/librte_eal/common/include/rte_fbarray.h | 352 +++++++ lib/librte_eal/common/include/rte_malloc.h | 9 + lib/librte_eal/common/include/rte_malloc_heap.h | 6 + lib/librte_eal/common/include/rte_memory.h | 79 +- lib/librte_eal/common/include/rte_memzone.h | 155 ++- lib/librte_eal/common/include/rte_vfio.h | 39 + lib/librte_eal/common/malloc_elem.c | 436 +++++++-- lib/librte_eal/common/malloc_elem.h | 41 +- lib/librte_eal/common/malloc_heap.c | 694 +++++++++++++- lib/librte_eal/common/malloc_heap.h | 15 +- lib/librte_eal/common/malloc_mp.c | 723 ++++++++++++++ lib/librte_eal/common/malloc_mp.h | 86 ++ lib/librte_eal/common/meson.build | 4 + lib/librte_eal/common/rte_malloc.c | 75 +- lib/librte_eal/linuxapp/eal/Makefile | 5 + lib/librte_eal/linuxapp/eal/eal.c | 102 +- lib/librte_eal/linuxapp/eal/eal_hugepage_info.c | 155 ++- lib/librte_eal/linuxapp/eal/eal_memalloc.c | 1049 +++++++++++++++++++++ lib/librte_eal/linuxapp/eal/eal_memory.c | 516 ++++++---- lib/librte_eal/linuxapp/eal/eal_vfio.c | 318 +++++-- lib/librte_eal/linuxapp/eal/eal_vfio.h | 11 + lib/librte_eal/linuxapp/eal/meson.build | 1 + lib/librte_eal/rte_eal_version.map | 23 +- lib/librte_ether/rte_ethdev.c | 3 +- lib/librte_mempool/rte_mempool.c | 87 +- test/test/commands.c | 3 + test/test/test_malloc.c | 71 +- test/test/test_memory.c | 43 +- test/test/test_memzone.c | 26 +- 63 files changed, 6631 insertions(+), 751 deletions(-)create mode 100644
lib/librte_eal/bsdapp/eal/eal_memalloc.ccreate mode 100644lib/librte_eal/common/eal_common_fbarray.ccreate mode 100644lib/librte_eal/common/eal_common_memalloc.ccreate mode 100644lib/librte_eal/common/eal_memalloc.hcreate mode 100644lib/librte_eal/common/include/rte_fbarray.hcreate mode 100644lib/librte_eal/common/malloc_mp.ccreate mode 100644lib/librte_eal/common/malloc_mp.hcreate mode 100644lib/librte_eal/linuxapp/eal/eal_memalloc.c