[dpdk-dev] mempool: try to get objects from cache when the mempool is single consumer and multiple producer

Message ID 1483957487-92635-1-git-send-email-liuwf@arraynetworks.com.cn
State Superseded, archived
Headers show

Checks

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

Commit Message

Wenfeng Liu Jan. 9, 2017, 10:24 a.m.
We put objects to cache when the mempool is multiple producer, however the cache will not be used when it is single consumer.
With this patch we can get objects from cache when the single consumer is happen to be one of the producers, and this improves performance.

Signed-off-by: Wenfeng Liu <liuwf@arraynetworks.com.cn>
---
 lib/librte_mempool/rte_mempool.h | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

Comments

Ananyev, Konstantin Jan. 9, 2017, 10:36 a.m. | #1
Hi,

> -----Original Message-----
> From: dev [mailto:dev-bounces@dpdk.org] On Behalf Of Wenfeng Liu
> Sent: Monday, January 9, 2017 10:25 AM
> To: olivier.matz@6wind.com
> Cc: dev@dpdk.org
> Subject: [dpdk-dev] [PATCH] mempool: try to get objects from cache when the mempool is single consumer and multiple producer
> 
> We put objects to cache when the mempool is multiple producer, however the cache will not be used when it is single consumer.
> With this patch we can get objects from cache when the single consumer is happen to be one of the producers, and this improves
> performance.
> 
> Signed-off-by: Wenfeng Liu <liuwf@arraynetworks.com.cn>
> ---
>  lib/librte_mempool/rte_mempool.h | 5 +++--
>  1 file changed, 3 insertions(+), 2 deletions(-)
> 
> diff --git a/lib/librte_mempool/rte_mempool.h b/lib/librte_mempool/rte_mempool.h
> index d315d42..4ab5a95 100644
> --- a/lib/librte_mempool/rte_mempool.h
> +++ b/lib/librte_mempool/rte_mempool.h
> @@ -1250,8 +1250,9 @@ __mempool_generic_get(struct rte_mempool *mp, void **obj_table,
>  	uint32_t index, len;
>  	void **cache_objs;
> 
> -	/* No cache provided or single consumer */
> -	if (unlikely(cache == NULL || flags & MEMPOOL_F_SC_GET ||
> +	/* No cache provided or single consumer and single producer */
> +	if (unlikely(cache == NULL ||
> +		     (flags & MEMPOOL_F_SC_GET) && (flags & MEMPOOL_F_SP_PUT) ||


I suppose that's a good thing to do...
Might be go one step further and don't check flags at all?
if (unlikely(cache == NULL || n >= cache->size)
   goto ring_dequeue;
If people don't want to have a mempool with cache,
they can just specify it at mempool creation time.
Again cache might improve performance even for SC|SP case.
Konstantin   

>  		     n >= cache->size))
>  		goto ring_dequeue;
> 
> --
> 2.7.4

Patch

diff --git a/lib/librte_mempool/rte_mempool.h b/lib/librte_mempool/rte_mempool.h
index d315d42..4ab5a95 100644
--- a/lib/librte_mempool/rte_mempool.h
+++ b/lib/librte_mempool/rte_mempool.h
@@ -1250,8 +1250,9 @@  __mempool_generic_get(struct rte_mempool *mp, void **obj_table,
 	uint32_t index, len;
 	void **cache_objs;
 
-	/* No cache provided or single consumer */
-	if (unlikely(cache == NULL || flags & MEMPOOL_F_SC_GET ||
+	/* No cache provided or single consumer and single producer */
+	if (unlikely(cache == NULL ||
+		     (flags & MEMPOOL_F_SC_GET) && (flags & MEMPOOL_F_SP_PUT) ||
 		     n >= cache->size))
 		goto ring_dequeue;