net/mana: use a MR variable on the stack instead of allocating it
PATCH 1/2 net/mana: use a MR variable on the stack instead of allocating it
From: Long Li <[email protected]>
The content of the MR is copied to the cache trees, it's not necessary to allocate a MR to do this. Use a variable on the stack instead.
This also fixes the memory leak in the code where a MR is allocated but never freed.
--- drivers/net/mana/mr.c | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-)
drivers/net/mana/mr.c +7 -8
@@ -40,7 +40,7 @@ mana_new_pmd_mr(struct mana_mr_btree *local_tree, struct mana_priv *priv,struct ibv_mr *ibv_mr;struct mana_range ranges[pool->nb_mem_chunks];uint32_t i; -struct mana_mr_cache *mr; +struct mana_mr_cache mr;int ret;rte_mempool_mem_iter (pool, mana_mempool_chunk_cb, ranges);
@@ -75,14 +75,13 @@ mana_new_pmd_mr(struct mana_mr_btree *local_tree, struct mana_priv *priv,DP_LOG (DEBUG ,"MR lkey %u addr %p len %zu" , ibv_mr->lkey, ibv_mr->addr, ibv_mr->length); - mr =rte_calloc ("MANA MR" ,1 ,sizeof (*mr),0 ); - mr->lkey = ibv_mr->lkey; - mr->addr = (uintptr_t )ibv_mr->addr; - mr->len = ibv_mr->length; - mr->verb_obj = ibv_mr; + mr.lkey = ibv_mr->lkey; + mr.addr = (uintptr_t )ibv_mr->addr; + mr.len = ibv_mr->length; + mr.verb_obj = ibv_mr;rte_spinlock_lock (&priv->mr_btree_lock); - ret =mana_mr_btree_insert (&priv->mr_btree, mr); + ret =mana_mr_btree_insert (&priv->mr_btree, &mr);rte_spinlock_unlock (&priv->mr_btree_lock);if (ret) {ibv_dereg_mr (ibv_mr);
@@ -90,7 +89,7 @@ mana_new_pmd_mr(struct mana_mr_btree *local_tree, struct mana_priv *priv,return ret; } - ret =mana_mr_btree_insert (local_tree, mr); + ret =mana_mr_btree_insert (local_tree, &mr);if (ret) {/* Don't need to clean up MR as it's already * in the global tree
Signature · 1 line
2.17.1
PATCH 2/2 net/mana: properly deal with MR cache expansion failure
From: Long Li <[email protected]>
On MR cache expension failure, the request should fail as there is no path to get a new MR into the tree. Attempting to insert a new MR to the cache tree will result in memory violation.
--- drivers/net/mana/mana.h | 6 +++--- drivers/net/mana/mr.c | 45 ++++++++++++++++++++++++++++------------- 2 files changed, 34 insertions(+), 17 deletions(-)
drivers/net/mana/mana.h +3 -3
@@ -522,9 +522,9 @@ void mana_del_pmd_mr(struct mana_mr_cache *mr);void mana_mempool_chunk_cb (struct rte_mempool *mp,void *opaque,struct rte_mempool_memhdr *memhdr,unsigned int idx); -struct mana_mr_cache *mana_mr_btree_lookup (struct mana_mr_btree *bt, -uint16_t *idx, -uintptr_t addr,size_t len); +int mana_mr_btree_lookup (struct mana_mr_btree *bt,uint16_t *idx, +uintptr_t addr,size_t len, +struct mana_mr_cache **cache);int mana_mr_btree_insert (struct mana_mr_btree *bt,struct mana_mr_cache *entry);int mana_mr_btree_init (struct mana_mr_btree *bt,int n,int socket);void mana_mr_btree_free (struct mana_mr_btree *bt);
drivers/net/mana/mr.c +31 -14
100 lines not on this page · raw message
Signature · 1 line
2.17.1
Re: [PATCH 2/2] net/mana: properly deal with MR cache expansion failure
Quoted 6 lines · On 1/30/2024 1:24 AM, [email protected] wrote:
From: Long Li <[email protected]>
On MR cache expension failure, the request should fail as there is no path to get a new MR into the tree. Attempting to insert a new MR to the cache tree will result in memory violation.
if this patch is fixing memory violation, can you please update commit log as fix commit and add fixes tag?
RE: [PATCH 2/2] net/mana: properly deal with MR cache expansion failure
Quoted 7 lines
Quoted 4 lines
On MR cache expension failure, the request should fail as there is no path to get a new MR into the tree. Attempting to insert a new MR to the cache tree will result in memory violation.
if this patch is fixing memory violation, can you please update commit log as fix commit and add fixes tag?
Will send v2.
PATCH v2 1/2 net/mana: fix memory leak on MR variable allocation
In reply to [email protected]From: Long Li <[email protected]>
Use a MR on the stack instead of allocating it. This fixes the memory leak in the code where a MR is allocated but never freed.
---
Change in v2:
change commit message to indicate this is a fix. added "Fixes" tag.
drivers/net/mana/mr.c | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-)
drivers/net/mana/mr.c +7 -8
@@ -40,7 +40,7 @@ mana_new_pmd_mr(struct mana_mr_btree *local_tree, struct mana_priv *priv,struct ibv_mr *ibv_mr;struct mana_range ranges[pool->nb_mem_chunks];uint32_t i; -struct mana_mr_cache *mr; +struct mana_mr_cache mr;int ret;rte_mempool_mem_iter (pool, mana_mempool_chunk_cb, ranges);
@@ -75,14 +75,13 @@ mana_new_pmd_mr(struct mana_mr_btree *local_tree, struct mana_priv *priv,DP_LOG (DEBUG ,"MR lkey %u addr %p len %zu" , ibv_mr->lkey, ibv_mr->addr, ibv_mr->length); - mr =rte_calloc ("MANA MR" ,1 ,sizeof (*mr),0 ); - mr->lkey = ibv_mr->lkey; - mr->addr = (uintptr_t )ibv_mr->addr; - mr->len = ibv_mr->length; - mr->verb_obj = ibv_mr; + mr.lkey = ibv_mr->lkey; + mr.addr = (uintptr_t )ibv_mr->addr; + mr.len = ibv_mr->length; + mr.verb_obj = ibv_mr;rte_spinlock_lock (&priv->mr_btree_lock); - ret =mana_mr_btree_insert (&priv->mr_btree, mr); + ret =mana_mr_btree_insert (&priv->mr_btree, &mr);rte_spinlock_unlock (&priv->mr_btree_lock);if (ret) {ibv_dereg_mr (ibv_mr);
@@ -90,7 +89,7 @@ mana_new_pmd_mr(struct mana_mr_btree *local_tree, struct mana_priv *priv,return ret; } - ret =mana_mr_btree_insert (local_tree, mr); + ret =mana_mr_btree_insert (local_tree, &mr);if (ret) {/* Don't need to clean up MR as it's already * in the global tree
Signature · 1 line
2.17.1
PATCH v2 2/2 net/mana: properly deal with MR cache expansion failure
From: Long Li <[email protected]>
On MR cache expension failure, the request should fail as there is no path to get a new MR into the tree. Attempting to insert a new MR to the cache tree will result in memory violation.
---
Change in v2:
added "Fixes:" tag.
drivers/net/mana/mana.h | 6 +++--- drivers/net/mana/mr.c | 45 ++++++++++++++++++++++++++++------------- 2 files changed, 34 insertions(+), 17 deletions(-)
drivers/net/mana/mana.h +3 -3
@@ -522,9 +522,9 @@ void mana_del_pmd_mr(struct mana_mr_cache *mr);void mana_mempool_chunk_cb (struct rte_mempool *mp,void *opaque,struct rte_mempool_memhdr *memhdr,unsigned int idx); -struct mana_mr_cache *mana_mr_btree_lookup (struct mana_mr_btree *bt, -uint16_t *idx, -uintptr_t addr,size_t len); +int mana_mr_btree_lookup (struct mana_mr_btree *bt,uint16_t *idx, +uintptr_t addr,size_t len, +struct mana_mr_cache **cache);int mana_mr_btree_insert (struct mana_mr_btree *bt,struct mana_mr_cache *entry);int mana_mr_btree_init (struct mana_mr_btree *bt,int n,int socket);void mana_mr_btree_free (struct mana_mr_btree *bt);
drivers/net/mana/mr.c +31 -14
100 lines not on this page · raw message
Signature · 1 line
2.17.1
Re: [Patch v2 1/2] net/mana: fix memory leak on MR variable allocation
In reply to [email protected]Quoted 10 lines · On 2/9/2024 12:05 AM, [email protected] wrote:
From: Long Li <[email protected]>
Use a MR on the stack instead of allocating it. This fixes the memory leak in the code where a MR is allocated but never freed.
Fixes 0f5db3c68ba7 ("net/mana: implement memory registration")Signed-off-by Long Li <[email protected]>
Series applied to dpdk-next-net/main, thanks.
Quoted 8 lines · On 1/30/2024 1:24 AM, [email protected] wrote:
From: Long Li <[email protected]>
The content of the MR is copied to the cache trees, it's not necessary to allocate a MR to do this. Use a variable on the stack instead.
This also fixes the memory leak in the code where a MR is allocated but never freed.
patch title describes what is done, but not gives information about reasoning and impact.
Is this a performance improvement (if so how much), or is this a fix for the memory leak (if so we need fixes tag for backport), or just a refactoring?
Quoted 47 lines
Signed-off-by Long Li <[email protected]>--- drivers/net/mana/mr.c | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-)drivers/net/mana/mr.c +7
-8@@ -40,7 +40,7 @@ mana_new_pmd_mr(struct mana_mr_btree *local_tree, struct mana_priv *priv,struct ibv_mr *ibv_mr;struct mana_range ranges[pool->nb_mem_chunks];uint32_t i; -struct mana_mr_cache *mr; +struct mana_mr_cache mr;int ret;rte_mempool_mem_iter (pool, mana_mempool_chunk_cb, ranges);@@ -75,14 +75,13 @@ mana_new_pmd_mr(struct mana_mr_btree *local_tree, struct mana_priv *priv,DP_LOG (DEBUG ,"MR lkey %u addr %p len %zu" , ibv_mr->lkey, ibv_mr->addr, ibv_mr->length); - mr =rte_calloc ("MANA MR" ,1 ,sizeof (*mr),0 ); - mr->lkey = ibv_mr->lkey; - mr->addr = (uintptr_t )ibv_mr->addr; - mr->len = ibv_mr->length; - mr->verb_obj = ibv_mr; + mr.lkey = ibv_mr->lkey; + mr.addr = (uintptr_t )ibv_mr->addr; + mr.len = ibv_mr->length; + mr.verb_obj = ibv_mr;rte_spinlock_lock (&priv->mr_btree_lock); - ret =mana_mr_btree_insert (&priv->mr_btree, mr); + ret =mana_mr_btree_insert (&priv->mr_btree, &mr);rte_spinlock_unlock (&priv->mr_btree_lock);if (ret) {ibv_dereg_mr (ibv_mr);@@ -90,7 +89,7 @@ mana_new_pmd_mr(struct mana_mr_btree *local_tree, struct mana_priv *priv,return ret; } - ret =mana_mr_btree_insert (local_tree, mr); + ret =mana_mr_btree_insert (local_tree, &mr);if (ret) {/* Don't need to clean up MR as it's already * in the global tree
Quoted 9 lines
Quoted 8 lines
From: Long Li <[email protected]>
The content of the MR is copied to the cache trees, it's not necessary to allocate a MR to do this. Use a variable on the stack instead.
This also fixes the memory leak in the code where a MR is allocated but never freed.
Quoted 5 lines
patch title describes what is done, but not gives information about reasoning and impact.
Is this a performance improvement (if so how much), or is this a fix for the memory leak (if so we need fixes tag for backport), or just a refactoring?
It's for fixing memory leak. I'll send v2 for better wording.
Quoted 52 lines
drivers/net/mana/mr.c mana_new_pmd_mr(struct mana_mr_btree *local_tree,
Quoted 11 lines
Signed-off-by Long Li <[email protected]>--- drivers/net/mana/mr.c | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-)drivers/net/mana/mr.c index renamed from drivers/net/mana/mr.c +0
-0
d6a5ad1460..c9d0f7ef5a100644drivers/net/mana/mr.c +0
-0@@ -40,7 +40,7 @@ mana_new_pmd_mr(struct mana_mr_btree *local_tree,struct
mana_priv*priv,drivers/net/mana/mr.c mana_new_pmd_mr(struct mana_mr_btree *local_tree, struct mana_priv *priv,
Quoted 8 lines
drivers/net/mana/mr.c +1
-1struct ibv_mr *ibv_mr;struct mana_range ranges[pool->nb_mem_chunks];uint32_t i; -struct mana_mr_cache *mr; +struct mana_mr_cache mr;int ret; rte_mempool_mem_iter(pool, mana_mempool_chunk_cb, ranges); @@-75,14
Quoted 1 line
+75,13 @@ mana_new_pmd_mr(struct
mana_mr_btree*local_tree, struct
mana_priv*priv,drivers/net/mana/mr.c mana_new_pmd_mr(struct mana_mr_btree *local_tree,
Quoted 20 lines
drivers/net/mana/mr.c +5
-6DP_LOG (DEBUG ,"MR lkey %u addr %p len %zu" , ibv_mr->lkey, ibv_mr->addr, ibv_mr->length); - mr =rte_calloc ("MANA MR" ,1 ,sizeof (*mr),0 ); - mr->lkey = ibv_mr->lkey; - mr->addr = (uintptr_t )ibv_mr->addr; - mr->len = ibv_mr->length; - mr->verb_obj = ibv_mr; + mr.lkey = ibv_mr->lkey; + mr.addr = (uintptr_t )ibv_mr->addr; + mr.len = ibv_mr->length; + mr.verb_obj = ibv_mr;rte_spinlock_lock (&priv->mr_btree_lock); - ret =mana_mr_btree_insert (&priv->mr_btree, mr); + ret =mana_mr_btree_insert (&priv->mr_btree, &mr);rte_spinlock_unlock (&priv->mr_btree_lock);if (ret) {ibv_dereg_mr (ibv_mr);@@ -90,7 +89,7 @@ mana_new_pmd_mr(struct mana_mr_btree *local_tree,struct
mana_priv*priv,Quoted 8 lines
drivers/net/mana/mr.c +1
-1return ret; } - ret =mana_mr_btree_insert (local_tree, mr); + ret =mana_mr_btree_insert (local_tree, &mr);if (ret) {/* Don't need to clean up MR as it's already * in the global tree