[v2,5/7] common/mlx5: convert data path objects to unified malloc
diff mbox series

Message ID 1594891216-11778-6-git-send-email-suanmingm@mellanox.com
State Superseded
Delegated to: Raslan Darawsheh
Headers show
Series
  • net/mlx5: add sys_mem_en devarg
Related show

Checks

Context Check Description
ci/Intel-compilation success Compilation OK
ci/checkpatch success coding style OK

Commit Message

Suanming Mou July 16, 2020, 9:20 a.m. UTC
This commit allocates the data path object page and B-tree table memory
from unified malloc function with explicit flag MLX5_MEM_RTE.

Signed-off-by: Suanming Mou <suanmingm@mellanox.com>
Acked-by: Matan Azrad <matan@mellanox.com>
---
 drivers/common/mlx5/mlx5_common.c    | 10 ++++++----
 drivers/common/mlx5/mlx5_common_mr.c | 31 +++++++++++++++----------------
 2 files changed, 21 insertions(+), 20 deletions(-)

Patch
diff mbox series

diff --git a/drivers/common/mlx5/mlx5_common.c b/drivers/common/mlx5/mlx5_common.c
index 693e2c6..17168e6 100644
--- a/drivers/common/mlx5/mlx5_common.c
+++ b/drivers/common/mlx5/mlx5_common.c
@@ -13,6 +13,7 @@ 
 #include "mlx5_common.h"
 #include "mlx5_common_os.h"
 #include "mlx5_common_utils.h"
+#include "mlx5_malloc.h"
 
 int mlx5_common_logtype;
 
@@ -169,8 +170,9 @@  static inline void mlx5_cpu_id(unsigned int level,
 	struct mlx5_devx_dbr_page *page;
 
 	/* Allocate space for door-bell page and management data. */
-	page = rte_calloc_socket(__func__, 1, sizeof(struct mlx5_devx_dbr_page),
-				 RTE_CACHE_LINE_SIZE, SOCKET_ID_ANY);
+	page = mlx5_malloc(MLX5_MEM_RTE | MLX5_MEM_ZERO,
+			   sizeof(struct mlx5_devx_dbr_page),
+			   RTE_CACHE_LINE_SIZE, SOCKET_ID_ANY);
 	if (!page) {
 		DRV_LOG(ERR, "cannot allocate dbr page");
 		return NULL;
@@ -180,7 +182,7 @@  static inline void mlx5_cpu_id(unsigned int level,
 					      MLX5_DBR_PAGE_SIZE, 0);
 	if (!page->umem) {
 		DRV_LOG(ERR, "cannot umem reg dbr page");
-		rte_free(page);
+		mlx5_free(page);
 		return NULL;
 	}
 	return page;
@@ -261,7 +263,7 @@  static inline void mlx5_cpu_id(unsigned int level,
 		LIST_REMOVE(page, next);
 		if (page->umem)
 			ret = -mlx5_glue->devx_umem_dereg(page->umem);
-		rte_free(page);
+		mlx5_free(page);
 	} else {
 		/* Mark in bitmap that this door-bell is not in use. */
 		offset /= MLX5_DBR_SIZE;
diff --git a/drivers/common/mlx5/mlx5_common_mr.c b/drivers/common/mlx5/mlx5_common_mr.c
index 564d618..23324c0 100644
--- a/drivers/common/mlx5/mlx5_common_mr.c
+++ b/drivers/common/mlx5/mlx5_common_mr.c
@@ -12,6 +12,7 @@ 
 #include "mlx5_common_mp.h"
 #include "mlx5_common_mr.h"
 #include "mlx5_common_utils.h"
+#include "mlx5_malloc.h"
 
 struct mr_find_contig_memsegs_data {
 	uintptr_t addr;
@@ -47,7 +48,8 @@  struct mr_find_contig_memsegs_data {
 	 * Initially cache_bh[] will be given practically enough space and once
 	 * it is expanded, expansion wouldn't be needed again ever.
 	 */
-	mem = rte_realloc(bt->table, n * sizeof(struct mr_cache_entry), 0);
+	mem = mlx5_realloc(bt->table, MLX5_MEM_RTE | MLX5_MEM_ZERO,
+			   n * sizeof(struct mr_cache_entry), 0, SOCKET_ID_ANY);
 	if (mem == NULL) {
 		/* Not an error, B-tree search will be skipped. */
 		DRV_LOG(WARNING, "failed to expand MR B-tree (%p) table",
@@ -180,9 +182,9 @@  struct mr_find_contig_memsegs_data {
 	}
 	MLX5_ASSERT(!bt->table && !bt->size);
 	memset(bt, 0, sizeof(*bt));
-	bt->table = rte_calloc_socket("B-tree table",
-				      n, sizeof(struct mr_cache_entry),
-				      0, socket);
+	bt->table = mlx5_malloc(MLX5_MEM_RTE | MLX5_MEM_ZERO,
+				sizeof(struct mr_cache_entry) * n,
+				0, socket);
 	if (bt->table == NULL) {
 		rte_errno = ENOMEM;
 		DEBUG("failed to allocate memory for btree cache on socket %d",
@@ -212,7 +214,7 @@  struct mr_find_contig_memsegs_data {
 		return;
 	DEBUG("freeing B-tree %p with table %p",
 	      (void *)bt, (void *)bt->table);
-	rte_free(bt->table);
+	mlx5_free(bt->table);
 	memset(bt, 0, sizeof(*bt));
 }
 
@@ -443,7 +445,7 @@  struct mlx5_mr *
 	dereg_mr_cb(&mr->pmd_mr);
 	if (mr->ms_bmp != NULL)
 		rte_bitmap_free(mr->ms_bmp);
-	rte_free(mr);
+	mlx5_free(mr);
 }
 
 void
@@ -650,11 +652,9 @@  struct mlx5_mr *
 	      (void *)addr, data.start, data.end, msl->page_sz, ms_n);
 	/* Size of memory for bitmap. */
 	bmp_size = rte_bitmap_get_memory_footprint(ms_n);
-	mr = rte_zmalloc_socket(NULL,
-				RTE_ALIGN_CEIL(sizeof(*mr),
-					       RTE_CACHE_LINE_SIZE) +
-				bmp_size,
-				RTE_CACHE_LINE_SIZE, msl->socket_id);
+	mr = mlx5_malloc(MLX5_MEM_RTE |  MLX5_MEM_ZERO,
+			 RTE_ALIGN_CEIL(sizeof(*mr), RTE_CACHE_LINE_SIZE) +
+			 bmp_size, RTE_CACHE_LINE_SIZE, msl->socket_id);
 	if (mr == NULL) {
 		DEBUG("Unable to allocate memory for a new MR of"
 		      " address (%p).", (void *)addr);
@@ -1033,10 +1033,9 @@  struct mlx5_mr *
 {
 	struct mlx5_mr *mr = NULL;
 
-	mr = rte_zmalloc_socket(NULL,
-				RTE_ALIGN_CEIL(sizeof(*mr),
-					       RTE_CACHE_LINE_SIZE),
-				RTE_CACHE_LINE_SIZE, socket_id);
+	mr = mlx5_malloc(MLX5_MEM_RTE | MLX5_MEM_ZERO,
+			 RTE_ALIGN_CEIL(sizeof(*mr), RTE_CACHE_LINE_SIZE),
+			 RTE_CACHE_LINE_SIZE, socket_id);
 	if (mr == NULL)
 		return NULL;
 	reg_mr_cb(pd, (void *)addr, len, &mr->pmd_mr);
@@ -1044,7 +1043,7 @@  struct mlx5_mr *
 		DRV_LOG(WARNING,
 			"Fail to create MR for address (%p)",
 			(void *)addr);
-		rte_free(mr);
+		mlx5_free(mr);
 		return NULL;
 	}
 	mr->msl = NULL; /* Mark it is external memory. */