Skip to contentSkip to conversation

common/mlx5: free MR resource while device DMA unmap

PATCH Superseded Jiawei Wang 3 participants 4 messages Oct 28, 2020 – Nov 5, 2020 Network drivers

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 common/mlx5: free MR resource while device DMA unmap

mlx5 PMD created the MR (Memory Region) resource on the mlx5_dma_map call to make the memory available for DMA operations. On the mlx5_dma_unmap call the MR resource was not freed but inserted to MR Free list for further garbage collection.
Actual MR resource destroying happened on device stop call. That caused the runtime out of memory in case of application performed multiple DMA map/unmap calls.

The fix immediately frees the MR resource on mlx5_dma_unmap call not engaging the list. The export for mlx5_mr_free function from common PMD part is added as well.

Redmine: 2330226

Fixes 989e999d9305 ("net/mlx5: support PCI device DMA map and unmap")
---
 drivers/common/mlx5/mlx5_common_mr.c | 12 ++++++------
 drivers/common/mlx5/mlx5_common_mr.h |  4 ++++
 drivers/common/mlx5/version.map      |  1 +
 drivers/net/mlx5/mlx5_mr.c           |  2 +-
 4 files changed, 12 insertions(+), 7 deletions(-)
drivers/common/mlx5/mlx5_common_mr.c +6 -6
index 23324c0..7c25541 100644
@@ -436,8 +436,8 @@ struct mlx5_mr *
  * @param mr
  *   Pointer to MR to free.
  */
-static void
-mr_free(struct mlx5_mr *mr, mlx5_dereg_mr_t dereg_mr_cb)
+void
+mlx5_mr_free(struct mlx5_mr *mr, mlx5_dereg_mr_t dereg_mr_cb)
 {
 	if (mr == NULL)
 		return;
@@ -492,7 +492,7 @@ struct mlx5_mr *
 		struct mlx5_mr *mr = mr_next;
 
 		mr_next = LIST_NEXT(mr, mr);
-		mr_free(mr, share_cache->dereg_mr_cb);
+		mlx5_mr_free(mr, share_cache->dereg_mr_cb);
 	}
 }
 
@@ -702,7 +702,7 @@ struct mlx5_mr *
 		data.start = RTE_ALIGN_FLOOR(addr, msl->page_sz);
 		data.end = data.start + msl->page_sz;
 		rte_mcfg_mem_read_unlock();
-		mr_free(mr, share_cache->dereg_mr_cb);
+		mlx5_mr_free(mr, share_cache->dereg_mr_cb);
 		goto alloc_resources;
 	}
 	MLX5_ASSERT(data.msl == data_re.msl);
@@ -725,7 +725,7 @@ struct mlx5_mr *
 		 * Must be unlocked before calling rte_free() because
 		 * mlx5_mr_mem_event_free_cb() can be called inside.
 		 */
-		mr_free(mr, share_cache->dereg_mr_cb);
+		mlx5_mr_free(mr, share_cache->dereg_mr_cb);
 		return entry->lkey;
 	}
 	/*
@@ -801,7 +801,7 @@ struct mlx5_mr *
 	 * calling rte_free() because mlx5_mr_mem_event_free_cb() can be called
 	 * inside.
 	 */
-	mr_free(mr, share_cache->dereg_mr_cb);
+	mlx5_mr_free(mr, share_cache->dereg_mr_cb);
 	return UINT32_MAX;
 }
 
drivers/common/mlx5/mlx5_common_mr.h +4 -0
index a2c426d..da0a0f0 100644
@@ -171,4 +171,8 @@ struct mlx5_mr *
 __rte_internal
 void
 mlx5_common_verbs_dereg_mr(struct mlx5_pmd_mr *pmd_mr);
+
+__rte_internal
+void
+mlx5_mr_free(struct mlx5_mr *mr, mlx5_dereg_mr_t dereg_mr_cb);
 #endif /* RTE_PMD_MLX5_COMMON_MR_H_ */
drivers/common/mlx5/version.map +1 -0
index 884001c..f0f3ca9 100644
@@ -63,6 +63,7 @@ INTERNAL {
 	mlx5_mr_lookup_list;
 	mlx5_mr_create_primary;
 	mlx5_mr_flush_local_cache;
+	mlx5_mr_free;
 
 	mlx5_nl_allmulti;
 	mlx5_nl_devlink_family_id_get;
drivers/net/mlx5/mlx5_mr.c +1 -1
index c308ecc..8b20ee3 100644
@@ -404,7 +404,7 @@ struct mr_update_mp_data {
 		return -1;
 	}
 	LIST_REMOVE(mr, mr);
-	LIST_INSERT_HEAD(&sh->share_cache.mr_free_list, mr, mr);
+	mlx5_mr_free(mr, sh->share_cache.dereg_mr_cb);
 	DEBUG("port %u remove MR(%p) from list", dev->data->port_id,
 	      (void *)mr);
 	mlx5_mr_rebuild_cache(&sh->share_cache);
Signature · 1 line
1.8.3.1
Acked-by on v1 1/1
#1 lore raw
Quoted 21 lines

-----Original Message-----
From: Jiawei Wang <[email protected]>
Sent: Wednesday, October 28, 2020 15:14
To: Slava Ovsiienko <[email protected]>; Matan Azrad <[email protected]>; Shahaf Shuler <[email protected]>; Ori Kam <[email protected]>
Cc: [email protected]; Raslan Darawsheh <[email protected]>; [email protected]
Subject: [PATCH] common/mlx5: free MR resource while device DMA unmap

mlx5 PMD created the MR (Memory Region) resource on the mlx5_dma_map call to make the memory available for DMA operations. On the mlx5_dma_unmap call the MR resource was not freed but inserted to MR Free list for further garbage collection.
Actual MR resource destroying happened on device stop call. That caused the runtime out of memory in case of application performed multiple DMA map/unmap calls.

The fix immediately frees the MR resource on mlx5_dma_unmap call not engaging the list. The export for mlx5_mr_free function from common PMD part is added as well.

Quoted 5 lines

Redmine: 2330226

Fixes 989e999d9305 ("net/mlx5: support PCI device DMA map and unmap")
#2 lore raw

PATCH v2 1/1 common/mlx5: free MR resource while device DMA unmap

In reply to Jiawei Wang

mlx5 PMD created the MR (Memory Region) resource on the mlx5_dma_map call to make the memory available for DMA operations. On the mlx5_dma_unmap call the MR resource was not freed but inserted to MR Free list for further garbage collection.
Actual MR resource destroying happened on device stop call. That caused the runtime out of memory in case of application performed multiple DMA map/unmap calls.

The fix immediately frees the MR resource on mlx5_dma_unmap call not engaging the list. The export for mlx5_mr_free function from common PMD part is added as well.

Fixes 989e999d9305 ("net/mlx5: support PCI device DMA map and unmap")
---
 drivers/common/mlx5/mlx5_common_mr.c | 12 ++++++------
 drivers/common/mlx5/mlx5_common_mr.h |  4 ++++
 drivers/common/mlx5/version.map      |  1 +
 drivers/net/mlx5/mlx5_mr.c           |  2 +-
 4 files changed, 12 insertions(+), 7 deletions(-)
drivers/common/mlx5/mlx5_common_mr.c +6 -6
index 23324c0..7c25541 100644
@@ -436,8 +436,8 @@ struct mlx5_mr *
  * @param mr
  *   Pointer to MR to free.
  */
-static void
-mr_free(struct mlx5_mr *mr, mlx5_dereg_mr_t dereg_mr_cb)
+void
+mlx5_mr_free(struct mlx5_mr *mr, mlx5_dereg_mr_t dereg_mr_cb)
 {
 	if (mr == NULL)
 		return;
@@ -492,7 +492,7 @@ struct mlx5_mr *
 		struct mlx5_mr *mr = mr_next;
 
 		mr_next = LIST_NEXT(mr, mr);
-		mr_free(mr, share_cache->dereg_mr_cb);
+		mlx5_mr_free(mr, share_cache->dereg_mr_cb);
 	}
 }
 
@@ -702,7 +702,7 @@ struct mlx5_mr *
 		data.start = RTE_ALIGN_FLOOR(addr, msl->page_sz);
 		data.end = data.start + msl->page_sz;
 		rte_mcfg_mem_read_unlock();
-		mr_free(mr, share_cache->dereg_mr_cb);
+		mlx5_mr_free(mr, share_cache->dereg_mr_cb);
 		goto alloc_resources;
 	}
 	MLX5_ASSERT(data.msl == data_re.msl);
@@ -725,7 +725,7 @@ struct mlx5_mr *
 		 * Must be unlocked before calling rte_free() because
 		 * mlx5_mr_mem_event_free_cb() can be called inside.
 		 */
-		mr_free(mr, share_cache->dereg_mr_cb);
+		mlx5_mr_free(mr, share_cache->dereg_mr_cb);
 		return entry->lkey;
 	}
 	/*
@@ -801,7 +801,7 @@ struct mlx5_mr *
 	 * calling rte_free() because mlx5_mr_mem_event_free_cb() can be called
 	 * inside.
 	 */
-	mr_free(mr, share_cache->dereg_mr_cb);
+	mlx5_mr_free(mr, share_cache->dereg_mr_cb);
 	return UINT32_MAX;
 }
 
drivers/common/mlx5/mlx5_common_mr.h +4 -0
index a2c426d..da0a0f0 100644
@@ -171,4 +171,8 @@ struct mlx5_mr *
 __rte_internal
 void
 mlx5_common_verbs_dereg_mr(struct mlx5_pmd_mr *pmd_mr);
+
+__rte_internal
+void
+mlx5_mr_free(struct mlx5_mr *mr, mlx5_dereg_mr_t dereg_mr_cb);
 #endif /* RTE_PMD_MLX5_COMMON_MR_H_ */
drivers/common/mlx5/version.map +1 -0
index 884001c..f0f3ca9 100644
@@ -63,6 +63,7 @@ INTERNAL {
 	mlx5_mr_lookup_list;
 	mlx5_mr_create_primary;
 	mlx5_mr_flush_local_cache;
+	mlx5_mr_free;
 
 	mlx5_nl_allmulti;
 	mlx5_nl_devlink_family_id_get;
drivers/net/mlx5/mlx5_mr.c +1 -1
index c308ecc..8b20ee3 100644
@@ -404,7 +404,7 @@ struct mr_update_mp_data {
 		return -1;
 	}
 	LIST_REMOVE(mr, mr);
-	LIST_INSERT_HEAD(&sh->share_cache.mr_free_list, mr, mr);
+	mlx5_mr_free(mr, sh->share_cache.dereg_mr_cb);
 	DEBUG("port %u remove MR(%p) from list", dev->data->port_id,
 	      (void *)mr);
 	mlx5_mr_rebuild_cache(&sh->share_cache);
Signature · 1 line
1.8.3.1
#3 lore raw

Hi,

Quoted 27 lines

-----Original Message-----
From: Jiawei Wang <[email protected]>
Sent: Monday, November 2, 2020 4:22 AM
To: Slava Ovsiienko <[email protected]>; Matan Azrad <[email protected]>; Shahaf Shuler <[email protected]>; Ori Kam <[email protected]>
Cc: [email protected]; Raslan Darawsheh <[email protected]>; [email protected]
Subject: [PATCH v2] common/mlx5: free MR resource while device DMA unmap

mlx5 PMD created the MR (Memory Region) resource on the mlx5_dma_map call to make the memory available for DMA operations. On the mlx5_dma_unmap call the MR resource was not freed but inserted to MR Free list for further garbage collection.
Actual MR resource destroying happened on device stop call. That caused the runtime out of memory in case of application performed multiple DMA map/unmap calls.

The fix immediately frees the MR resource on mlx5_dma_unmap call not engaging the list. The export for mlx5_mr_free function from common PMD part is added as well.

Fixes 989e999d9305 ("net/mlx5: support PCI device DMA map and unmap")
Quoted 9 lines
---
 drivers/common/mlx5/mlx5_common_mr.c | 12 ++++++------
 drivers/common/mlx5/mlx5_common_mr.h |  4 ++++
 drivers/common/mlx5/version.map      |  1 +
 drivers/net/mlx5/mlx5_mr.c           |  2 +-
 4 files changed, 12 insertions(+), 7 deletions(-)

Patch applied to next-net-mlx,

Kindest regards,
Raslan Darawsheh