[dpdk-dev] [PATCH v5 03/11] eal: introduce memory management wrappers
Burakov, Anatoly
anatoly.burakov at intel.com
Thu May 28 13:26:35 CEST 2020
On 25-May-20 1:37 AM, Dmitry Kozlyuk wrote:
> Introduce OS-independent wrappers for memory management operations used
> across DPDK and specifically in common code of EAL:
>
> * rte_mem_map()
> * rte_mem_unmap()
> * rte_get_page_size()
> * rte_mem_lock()
>
> Windows uses different APIs for memory mapping and reservation, while
> Unices reserve memory by mapping it. Introduce EAL private functions to
> support memory reservation in common code:
>
> * eal_mem_reserve()
> * eal_mem_free()
> * eal_mem_set_dump()
>
> 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>
> - page_sz = sysconf(_SC_PAGESIZE);
> + page_sz = rte_get_page_size();
> if (page_sz == (size_t)-1) {
> free(ma);
> return -1;
> @@ -754,9 +751,11 @@ rte_fbarray_init(struct rte_fbarray *arr, const char *name, unsigned int len,
>
> if (internal_config.no_shconf) {
> /* remap virtual area as writable */
> - void *new_data = mmap(data, mmap_len, PROT_READ | PROT_WRITE,
> - MAP_FIXED | MAP_PRIVATE | MAP_ANONYMOUS, fd, 0);
> - if (new_data == MAP_FAILED) {
> + static const int flags = RTE_MAP_FORCE_ADDRESS |
> + RTE_MAP_PRIVATE | RTE_MAP_ANONYMOUS;
> + void *new_data = rte_mem_map(data, mmap_len,
> + RTE_PROT_READ | RTE_PROT_WRITE, flags, fd, 0);
> + if (new_data == NULL) {
> RTE_LOG(DEBUG, EAL, "%s(): couldn't remap anonymous memory: %s\n",
> __func__, strerror(errno));
I believe this should be rte_strerror(rte_errno) instead of strerror(errno).
> goto fail;
> @@ -821,7 +820,7 @@ rte_fbarray_init(struct rte_fbarray *arr, const char *name, unsigned int len,
> return 0;
> fail:
> if (data)
> - munmap(data, mmap_len);
> + rte_mem_unmap(data, mmap_len);
> if (fd >= 0)
> close(fd);
> free(ma);
> @@ -859,7 +858,7 @@ rte_fbarray_attach(struct rte_fbarray *arr)
> return -1;
<snip>
>
> +/**
> + * Memory protection flags.
> + */
> +enum rte_mem_prot {
> + RTE_PROT_READ = 1 << 0, /**< Read access. */
> + RTE_PROT_WRITE = 1 << 1, /**< Write access. */
> + RTE_PROT_EXECUTE = 1 << 2 /**< Code execution. */
> +};
> +
> +/**
> + * Additional flags for memory mapping.
> + */
> +enum rte_map_flags {
> + /** Changes to the mapped memory are visible to other processes. */
> + RTE_MAP_SHARED = 1 << 0,
> + /** Mapping is not backed by a regular file. */
> + RTE_MAP_ANONYMOUS = 1 << 1,
> + /** Copy-on-write mapping, changes are invisible to other processes. */
> + RTE_MAP_PRIVATE = 1 << 2,
> + /**
> + * Force mapping to the requested address. This flag should be used
> + * with caution, because to fulfill the request implementation
> + * may remove all other mappings in the requested region. However,
> + * it is not required to do so, thus mapping with this flag may fail.
> + */
> + RTE_MAP_FORCE_ADDRESS = 1 << 3
> +};
I have no strong opinion on this, but it feels like the fact that these
are enums is a relic from the times where you used enum everywhere :) i
have a feeling that DPDK codebase prefers #define's for this usage,
while what you have here is more of a C++ thing.
--
Thanks,
Anatoly
More information about the dev
mailing list