From: Raslan Darawsheh <rasland@nvidia.com>
To: Ophir Munk <ophirmu@nvidia.com>, "dev@dpdk.org" <dev@dpdk.org>
Cc: Ophir Munk <ophirmu@nvidia.com>, Matan Azrad <matan@nvidia.com>,
"stable@dpdk.org" <stable@dpdk.org>
Subject: Re: [dpdk-stable] [PATCH v1] common/mlx5: fix mlx5 aligned malloc
Date: Tue, 15 Sep 2020 10:06:00 +0000 [thread overview]
Message-ID: <DM6PR12MB2748A7F1E4EDEF5C1291FDC5CF200@DM6PR12MB2748.namprd12.prod.outlook.com> (raw)
In-Reply-To: <20200909084317.21569-1-ophirmu@nvidia.com>
Hi,
> -----Original Message-----
> From: Ophir Munk <ophirmu@nvidia.com>
> Sent: Wednesday, September 9, 2020 11:43 AM
> To: dev@dpdk.org
> Cc: Raslan Darawsheh <rasland@nvidia.com>; Ophir Munk
> <ophirmu@nvidia.com>; Matan Azrad <matan@nvidia.com>;
> stable@dpdk.org
> Subject: [PATCH v1] common/mlx5: fix mlx5 aligned malloc
>
> Before this commit system call memalign was used for aligned
> allocations, however memalign is deprecated.
>
> Based on (1) - POSIX requires that memory aligned allocations can be
> freed using free. Some systems provide no way to reclaim memory
> allocated with memalign (because one can only pass to free a pointer
> gotten from malloc, while, memalign would call malloc and then align the
> obtained value).
> Another issue is that 64/32 bits architectures use a minimal alignment
> size. So any requested alignment below the minimal system size can be
> simplified by calling malloc.
>
> The glibc implementation allows memory obtained from posix_memalign to
> be reclaimed with free. This commit replaces system call memalign with
> system call posix_memalign. It also calls malloc in case the requested
> alignment is below the minimal system size.
>
> (1)
> https://nam11.safelinks.protection.outlook.com/?url=https%3A%2F%2Flinux
> .die.net%2Fman%2F3%2Fmemalign&data=02%7C01%7Crasland%40nvid
> ia.com%7C28fa36f0f5544ee01f4a08d8549c7c57%7C43083d15727340c1b7db39
> efd9ccc17a%7C0%7C0%7C637352378361232944&sdata=T73x%2FmnZHK
> 3Yl9fI17Orar%2FpCoXtHpQzZvdy47OckxA%3D&reserved=0
>
> Fixes: d38e3d526657 ("common/mlx5: add memory management functions")
> Cc: stable@dpdk.org
>
> Signed-off-by: Ophir Munk <ophirmu@nvidia.com>
> Acked-by: Matan Azrad <matan@mellanox.com>
> ---
> drivers/common/mlx5/mlx5_malloc.c | 13 +++++++++----
> drivers/common/mlx5/mlx5_malloc.h | 8 ++++++++
> 2 files changed, 17 insertions(+), 4 deletions(-)
>
> diff --git a/drivers/common/mlx5/mlx5_malloc.c
> b/drivers/common/mlx5/mlx5_malloc.c
> index 316305d..4489971 100644
> --- a/drivers/common/mlx5/mlx5_malloc.c
> +++ b/drivers/common/mlx5/mlx5_malloc.c
> @@ -151,9 +151,14 @@ static void *
> mlx5_alloc_align(size_t size, unsigned int align, unsigned int zero)
> {
> void *buf;
> - buf = memalign(align, size);
> - if (!buf) {
> - DRV_LOG(ERR, "Couldn't allocate buf.\n");
> + int ret;
> +
> + ret = posix_memalign(&buf, align, size);
> + if (ret) {
> + DRV_LOG(ERR,
> + "Couldn't allocate buf size=%zu align=%u. Err=%d\n",
> + size, align, ret);
> +
> return NULL;
> }
> if (zero)
> @@ -190,7 +195,7 @@ mlx5_malloc(uint32_t flags, size_t size, unsigned int
> align, int socket)
> return addr;
> }
> /* The memory will be allocated from system. */
> - if (align)
> + if (align > MLX5_MALLOC_ALIGNMENT)
> addr = mlx5_alloc_align(size, align, !!(flags &
> MLX5_MEM_ZERO));
> else if (flags & MLX5_MEM_ZERO)
> addr = calloc(1, size);
> diff --git a/drivers/common/mlx5/mlx5_malloc.h
> b/drivers/common/mlx5/mlx5_malloc.h
> index d3e5f5b..8aea414 100644
> --- a/drivers/common/mlx5/mlx5_malloc.h
> +++ b/drivers/common/mlx5/mlx5_malloc.h
> @@ -9,6 +9,14 @@
> extern "C" {
> #endif
>
> +#ifndef MLX5_MALLOC_ALIGNMENT
> +#ifndef RTE_ARCH_64
> +#define MLX5_MALLOC_ALIGNMENT 8
> +#else
> +#define MLX5_MALLOC_ALIGNMENT 16
> +#endif
> +#endif
> +
> enum mlx5_mem_flags {
> MLX5_MEM_ANY = 0,
> /* Memory will be allocated dpends on sys_mem_en. */
> --
> 2.8.4
Patch applied to next-net-mlx,
Kindest regards,
Raslan Darawsheh
prev parent reply other threads:[~2020-09-15 10:06 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-09-09 8:43 Ophir Munk
2020-09-15 10:06 ` Raslan Darawsheh [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=DM6PR12MB2748A7F1E4EDEF5C1291FDC5CF200@DM6PR12MB2748.namprd12.prod.outlook.com \
--to=rasland@nvidia.com \
--cc=dev@dpdk.org \
--cc=matan@nvidia.com \
--cc=ophirmu@nvidia.com \
--cc=stable@dpdk.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).