[dpdk-dev] [PATCH v2 06/10] eal: introduce memory management wrappers

Tal Shnaiderman talshn at mellanox.com
Mon Apr 13 09:50:30 CEST 2020


> Subject: [PATCH v2 06/10] eal: introduce memory management wrappers
> 
> System meory management is implemented differently for POSIX and
> Windows. Introduce wrapper functions for operations used across DPDK:
> 
> * rte_mem_map()
>   Create memory mapping for a regular file or a page file (swap).
>   This supports mapping to a reserved memory region even on Windows.
> 
> * rte_mem_unmap()
>   Remove mapping created with rte_mem_map().
> 
> * rte_get_page_size()
>   Obtain default system page size.
> 
> * rte_mem_lock()
>   Make arbitrary-sized memory region non-swappable.
> 
> Wrappers follow POSIX semantics limited to DPDK tasks, but their signatures
> deliberately differ from POSIX ones to be more safe and expressive.
> 
> Signed-off-by: Dmitry Kozlyuk <dmitry.kozliuk at gmail.com>
> ---

<Snip!>

> +void *
> +rte_mem_map(void *requested_addr, size_t size, enum rte_mem_prot
> prot,
> +	enum rte_map_flags flags, int fd, size_t offset) {
> +	int sys_prot = 0;
> +	int sys_flags = 0;
> +
> +	sys_prot = mem_rte_to_sys_prot(prot);
> +
> +	if (flags & RTE_MAP_SHARED)
> +		sys_flags |= MAP_SHARED;
> +	if (flags & RTE_MAP_ANONYMOUS)
> +		sys_flags |= MAP_ANONYMOUS;
> +	if (flags & RTE_MAP_PRIVATE)
> +		sys_flags |= MAP_PRIVATE;
> +	if (flags & RTE_MAP_FIXED)
> +		sys_flags |= MAP_FIXED;
> +
> +	return mem_map(requested_addr, size, sys_prot, sys_flags, fd,
> offset);
> +}

Looks like there is a different behavior in the Windows and Unix implementation of rte_mem_map in case of memory mapping failure, in Windows the function returns NULL however in Unix the return value is the MAP_FAILED value of mmap which is ((void *)-1)


More information about the dev mailing list