common/mlx5: fix non-expandable global MR cache
PATCH 1/1 common/mlx5: fix non-expandable global MR cache
The number of memory regions (MR) that MLX5 PMD can use was limited by 512 per IB device, the size of the global MR cache that was fixed at compile time.
The cache allows to search MR LKey by address efficiently, therefore it is the last place searched on data path (skipped is the global MR database which would be slow). If the application logic caused the PMD to create more than 512 MRs, which can be the case with external memory,
those MRs would never be found on data path
and later cause a HW failure.
The cache size was fixed because at the time of overflow the EAL memory hotplug lock may be held,
prohibiting to allocate a larger cache
(it must reside in DPDK memory for multi-process support). This patch adds logic to release the necessary locks, extend the cache, and repeat the attempt to insert new entries.
mlx5_mr_btree structure had overflow field
that was set when a cache (not only the global one)
could not accept new entries.
However, it was only checked for the global cache,
because caches of upper layers were dynamically expandable. With the global cache size limitation removed, this field is not needed. Cache size was previously limited by 16-bit indices.
Use the space in the structure previously fileld by overflow field to extend indices to 32 bits.
With this patch, it is the HW and RAM that limit the number of MRs.
--- drivers/common/mlx5/mlx5_common.c | 30 +++++ drivers/common/mlx5/mlx5_common_mr.c | 158 ++++++++++++++++++++------- drivers/common/mlx5/mlx5_common_mr.h | 7 +- 3 files changed, 150 insertions(+), 45 deletions(-)
drivers/common/mlx5/mlx5_common.c +30 -0
@@ -1082,6 +1082,7 @@ mlx5_common_dev_dma_map(struct rte_device *rte_dev, void *addr, uint64_t iova __rte_unused, size_t len) {struct mlx5_common_device *dev; +struct mlx5_mr_btree *bt;struct mlx5_mr *mr; dev =to_mlx5_device (rte_dev);
@@ -1099,7 +1100,36 @@ mlx5_common_dev_dma_map(struct rte_device *rte_dev, void *addr, rte_errno =EINVAL ;return -1 ; } +try_insert:rte_rwlock_write_lock (&dev->mr_scache.rwlock); + bt = &dev->mr_scache.cache; +if (bt->len == bt->size) { +uint32_t size; +int ret; + + size = bt->size +1 ; +MLX5_ASSERT (size > bt->size); +/* +* Avoid deadlock (numbers show the sequence of events): +* mlx5_mr_create_primary(): +* 1) take EAL memory lock +* 3) take MR lock +* this function: +* 2) take MR lock +* 4) take EAL memory lock while allocating the new cache +* Releasing the MR lock before step 4 +* allows another thread to execute step 3. +*/ +rte_rwlock_write_unlock (&dev->mr_scache.rwlock); + ret =mlx5_mr_expand_cache (&dev->mr_scache, size, + rte_dev->numa_node); +if (ret <0 ) { +mlx5_mr_free (mr, dev->mr_scache.dereg_mr_cb); + rte_errno = ret; +return -1 ; + } + goto try_insert; + }LIST_INSERT_HEAD (&dev->mr_scache.mr_list, mr, mr);/* Insert to the global cache table. */ mlx5_mr_insert_cache (&dev->mr_scache, mr);
drivers/common/mlx5/mlx5_common_mr.c +116 -42
270 lines not on this page · raw message
drivers/common/mlx5/mlx5_common_mr.h +4 -3
@@ -56,9 +56,8 @@ struct mr_cache_entry {/* MR Cache table for Binary search. */ struct mlx5_mr_btree { -uint16_t len;/* Number of entries. */ -uint16_t size;/* Total number of entries. */ -int overflow;/* Mark failure of table expansion. */ +uint32_t len;/* Number of entries. */ +uint32_t size;/* Total number of entries. */ struct mr_cache_entry (*table)[]; } __rte_packed;
@@ -218,6 +217,8 @@ void mlx5_mr_btree_dump(struct mlx5_mr_btree *bt __rte_unused);__rte_internal uint32_t mlx5_mr_mempool2mr_bh(struct mlx5_mr_ctrl *mr_ctrl,struct rte_mempool *mp,uintptr_t addr); +int mlx5_mr_expand_cache (struct mlx5_mr_share_cache *share_cache, +uint32_t new_size,int socket);void mlx5_mr_release_cache (struct mlx5_mr_share_cache *mr_cache);int mlx5_mr_create_cache (struct mlx5_mr_share_cache *share_cache,int socket); void mlx5_mr_dump_cache(struct mlx5_mr_share_cache *share_cache __rte_unused);
Signature · 1 line
2.25.1
PATCH v2 1/1 common/mlx5: fix non-expandable global MR cache
The number of memory regions (MR) that MLX5 PMD can use was limited by 512 per IB device, the size of the global MR cache that was fixed at compile time.
The cache allows to search MR LKey by address efficiently, therefore it is the last place searched on data path (skipped is the global MR database which would be slow). If the application logic caused the PMD to create more than 512 MRs, which can be the case with external memory,
those MRs would never be found on data path
and later cause a HW failure.
The cache size was fixed because at the time of overflow the EAL memory hotplug lock may be held,
prohibiting to allocate a larger cache
(it must reside in DPDK memory for multi-process support). This patch adds logic to release the necessary locks, extend the cache, and repeat the attempt to insert new entries.
mlx5_mr_btree structure had overflow field
that was set when a cache (not only the global one)
could not accept new entries.
However, it was only checked for the global cache,
because caches of upper layers were dynamically expandable. With the global cache size limitation removed, this field is not needed. Cache size was previously limited by 16-bit indices.
Use the space in the structure previously fileld by overflow field to extend indices to 32 bits.
With this patch, it is the HW and RAM that limit the number of MRs.
---
v2: fix warnings in debug mode and with assertions enabled (Raslan).
drivers/common/mlx5/mlx5_common.c | 30 +++++ drivers/common/mlx5/mlx5_common_mr.c | 160 ++++++++++++++++++++------- drivers/common/mlx5/mlx5_common_mr.h | 7 +- 3 files changed, 151 insertions(+), 46 deletions(-)
drivers/common/mlx5/mlx5_common.c +30 -0
@@ -1082,6 +1082,7 @@ mlx5_common_dev_dma_map(struct rte_device *rte_dev, void *addr, uint64_t iova __rte_unused, size_t len) {struct mlx5_common_device *dev; +struct mlx5_mr_btree *bt;struct mlx5_mr *mr; dev =to_mlx5_device (rte_dev);
@@ -1099,7 +1100,36 @@ mlx5_common_dev_dma_map(struct rte_device *rte_dev, void *addr, rte_errno =EINVAL ;return -1 ; } +try_insert:rte_rwlock_write_lock (&dev->mr_scache.rwlock); + bt = &dev->mr_scache.cache; +if (bt->len == bt->size) { +uint32_t size; +int ret; + + size = bt->size +1 ; +MLX5_ASSERT (size > bt->size); +/* +* Avoid deadlock (numbers show the sequence of events): +* mlx5_mr_create_primary(): +* 1) take EAL memory lock +* 3) take MR lock +* this function: +* 2) take MR lock +* 4) take EAL memory lock while allocating the new cache +* Releasing the MR lock before step 4 +* allows another thread to execute step 3. +*/ +rte_rwlock_write_unlock (&dev->mr_scache.rwlock); + ret =mlx5_mr_expand_cache (&dev->mr_scache, size, + rte_dev->numa_node); +if (ret <0 ) { +mlx5_mr_free (mr, dev->mr_scache.dereg_mr_cb); + rte_errno = ret; +return -1 ; + } + goto try_insert; + }LIST_INSERT_HEAD (&dev->mr_scache.mr_list, mr, mr);/* Insert to the global cache table. */ mlx5_mr_insert_cache (&dev->mr_scache, mr);
drivers/common/mlx5/mlx5_common_mr.c +117 -43
278 lines not on this page · raw message
drivers/common/mlx5/mlx5_common_mr.h +4 -3
@@ -56,9 +56,8 @@ struct mr_cache_entry {/* MR Cache table for Binary search. */ struct mlx5_mr_btree { -uint16_t len;/* Number of entries. */ -uint16_t size;/* Total number of entries. */ -int overflow;/* Mark failure of table expansion. */ +uint32_t len;/* Number of entries. */ +uint32_t size;/* Total number of entries. */ struct mr_cache_entry (*table)[]; } __rte_packed;
@@ -218,6 +217,8 @@ void mlx5_mr_btree_dump(struct mlx5_mr_btree *bt __rte_unused);__rte_internal uint32_t mlx5_mr_mempool2mr_bh(struct mlx5_mr_ctrl *mr_ctrl,struct rte_mempool *mp,uintptr_t addr); +int mlx5_mr_expand_cache (struct mlx5_mr_share_cache *share_cache, +uint32_t new_size,int socket);void mlx5_mr_release_cache (struct mlx5_mr_share_cache *mr_cache);int mlx5_mr_create_cache (struct mlx5_mr_share_cache *share_cache,int socket); void mlx5_mr_dump_cache(struct mlx5_mr_share_cache *share_cache __rte_unused);
Signature · 1 line
2.25.1
From: Dmitry Kozlyuk
Quoted 32 lines
Sent: Thursday, June 30, 2022 1:08 AM
To: [email protected]
Cc: Raslan Darawsheh <[email protected]>; [email protected]; Matan Azrad <[email protected]>; Slava Ovsiienko <[email protected]>
Subject: [PATCH v2] common/mlx5: fix non-expandable global MR cacheThe number of memory regions (MR) that MLX5 PMD can use was limited by 512 per IB device, the size of the global MR cache that was fixed at compile time.
The cache allows to search MR LKey by address efficiently, therefore it is the last place searched on data path (skipped is the global MR database which would be slow).
If the application logic caused the PMD to create more than 512 MRs, which can be the case with external memory, those MRs would never be found on data path and later cause a HW failure.The cache size was fixed because at the time of overflow the EAL memory hotplug lock may be held, prohibiting to allocate a larger cache (it must reside in DPDK memory for multi-process support).
This patch adds logic to release the necessary locks, extend the cache, and repeat the attempt to insert new entries.
mlx5_mr_btreestructure hadoverflowfield that was set when a cache (not only the global one) could not accept new entries.
However, it was only checked for the global cache, because caches of upper layers were dynamically expandable.
With the global cache size limitation removed, this field is not needed. Cache size was previously limited by 16-bit indices.
Use the space in the structure previously fileld byoverflowfield to extend indices to 32 bits.
With this patch, it is the HW and RAM that limit the number of MRs.
Quoted 4 lines
Fixes 974f1e7ef146 ("net/mlx5: add new memory region support")Signed-off-by Dmitry Kozlyuk <[email protected]>
Hi,
Quoted 37 lines
-----Original Message-----
From: Dmitry Kozlyuk <[email protected]>
Sent: Thursday, June 30, 2022 1:08 AM
To: [email protected]
Cc: Raslan Darawsheh <[email protected]>; [email protected]; Matan Azrad <[email protected]>; Slava Ovsiienko <[email protected]>
Subject: [PATCH v2] common/mlx5: fix non-expandable global MR cacheThe number of memory regions (MR) that MLX5 PMD can use was limited by 512 per IB device, the size of the global MR cache that was fixed at compile time.
The cache allows to search MR LKey by address efficiently, therefore it is the last place searched on data path (skipped is the global MR database which would be slow). If the application logic caused the PMD to create more than 512 MRs, which can be the case with external memory,
those MRs would never be found on data path
and later cause a HW failure.The cache size was fixed because at the time of overflow the EAL memory hotplug lock may be held,
prohibiting to allocate a larger cache
(it must reside in DPDK memory for multi-process support). This patch adds logic to release the necessary locks, extend the cache, and repeat the attempt to insert new entries.
mlx5_mr_btreestructure hadoverflowfield
that was set when a cache (not only the global one)
could not accept new entries.
However, it was only checked for the global cache,
because caches of upper layers were dynamically expandable. With the global cache size limitation removed, this field is not needed. Cache size was previously limited by 16-bit indices.
Use the space in the structure previously fileld byoverflowfield to extend indices to 32 bits.
With this patch, it is the HW and RAM that limit the number of MRs.
Quoted 7 lines
Fixes 974f1e7ef146 ("net/mlx5: add new memory region support")Signed-off-by Dmitry Kozlyuk <[email protected]>---
v2: fix warnings in debug mode and with assertions enabled (Raslan).
Patch applied to next-net-mlx,
Kindest regards,
Raslan Darawsheh