Skip to contentSkip to conversation

mempool: try to get objects from cache when the mempool is single consumer and multiple producer

PATCH In review Wenfeng Liu 4 participants 8 messages Jan 9, 2017 – Jan 13, 2017

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 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.

---
 lib/librte_mempool/rte_mempool.h | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
lib/librte_mempool/rte_mempool.h +3 -2
index d315d42..4ab5a95 100644
@@ -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;
 
Signature · 1 line
2.7.4
#1 lore raw

Hi,

Quoted 21 lines

-----Original Message-----
From: dev [mailto:[email protected]] On Behalf Of Wenfeng Liu
Sent: Monday, January 9, 2017 10:25 AM
To: [email protected]
Cc: [email protected]
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.

---
 lib/librte_mempool/rte_mempool.h | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
lib/librte_mempool/rte_mempool.h +0 -0
index d315d42..4ab5a95 100644

lib/librte_mempool/rte_mempool.h __mempool_generic_get(struct rte_mempool *mp, void **obj_table, · line 1255

Quoted 8 lines
lib/librte_mempool/rte_mempool.h +3 -2
@@ -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

Quoted 5 lines
lib/librte_mempool/rte_mempool.h +0 -1
 		     n >= cache->size))
 		goto ring_dequeue;
 
--

2.7.4

#2 lore raw

PATCH v2 1/1 mempool: don't check mempool flags when cache is enabled

In reply to Wenfeng Liu

Currently we will check mempool flags when we put/get objects from mempool. However, this makes cache useless when mempool is SC|SP, SC|MP, MC|SP cases.
This patch makes cache available in above cases and improves performance.

---
 lib/librte_mempool/rte_mempool.h | 25 ++++++++++---------------
 1 file changed, 10 insertions(+), 15 deletions(-)
lib/librte_mempool/rte_mempool.h +10 -15
index d315d42..aca2f1b 100644
@@ -1038,19 +1038,15 @@ static inline struct rte_mempool_cache *__attribute__((always_inline))
  */
 static inline void __attribute__((always_inline))
 __mempool_generic_put(struct rte_mempool *mp, void * const *obj_table,
-		      unsigned n, struct rte_mempool_cache *cache, int flags)
+		      unsigned n, struct rte_mempool_cache *cache)
 {
 	void **cache_objs;
 
 	/* increment stat now, adding in mempool always success */
 	__MEMPOOL_STAT_ADD(mp, put, n);
 
-	/* No cache provided or single producer */
-	if (unlikely(cache == NULL || flags & MEMPOOL_F_SP_PUT))
-		goto ring_enqueue;
-
-	/* Go straight to ring if put would overflow mem allocated for cache */
-	if (unlikely(n > RTE_MEMPOOL_CACHE_MAX_SIZE))
+	/* No cache provided or if put would overflow mem allocated for cache */
+	if (unlikely(cache == NULL || n > RTE_MEMPOOL_CACHE_MAX_SIZE))
 		goto ring_enqueue;
 
 	cache_objs = &cache->objs[cache->len];
@@ -1104,10 +1100,10 @@ static inline void __attribute__((always_inline))
  */
 static inline void __attribute__((always_inline))
 rte_mempool_generic_put(struct rte_mempool *mp, void * const *obj_table,
-			unsigned n, struct rte_mempool_cache *cache, int flags)
+			unsigned n, struct rte_mempool_cache *cache, __rte_unused int flags)
 {
 	__mempool_check_cookies(mp, obj_table, n, 0);
-	__mempool_generic_put(mp, obj_table, n, cache, flags);
+	__mempool_generic_put(mp, obj_table, n, cache);
 }
 
 /**
@@ -1244,15 +1240,14 @@ static inline void __attribute__((always_inline))
  */
 static inline int __attribute__((always_inline))
 __mempool_generic_get(struct rte_mempool *mp, void **obj_table,
-		      unsigned n, struct rte_mempool_cache *cache, int flags)
+		      unsigned n, struct rte_mempool_cache *cache)
 {
 	int ret;
 	uint32_t index, len;
 	void **cache_objs;
 
-	/* No cache provided or single consumer */
-	if (unlikely(cache == NULL || flags & MEMPOOL_F_SC_GET ||
-		     n >= cache->size))
+	/* No cache provided or cannot be satisfied from cache */
+	if (unlikely(cache == NULL || n >= cache->size))
 		goto ring_dequeue;
 
 	cache_objs = cache->objs;
@@ -1326,10 +1321,10 @@ static inline int __attribute__((always_inline))
  */
 static inline int __attribute__((always_inline))
 rte_mempool_generic_get(struct rte_mempool *mp, void **obj_table, unsigned n,
-			struct rte_mempool_cache *cache, int flags)
+			struct rte_mempool_cache *cache, __rte_unused int flags)
 {
 	int ret;
-	ret = __mempool_generic_get(mp, obj_table, n, cache, flags);
+	ret = __mempool_generic_get(mp, obj_table, n, cache);
 	if (ret == 0)
 		__mempool_check_cookies(mp, obj_table, n, 1);
 	return ret;
Signature · 1 line
1.8.3.1
#3 lore raw

PATCH v3 1/1 mempool: don't check mempool flags when cache is enabled

Currently we will check mempool flags when we put/get objects from mempool. However, this makes cache useless when mempool is SC|SP, SC|MP, MC|SP cases.
This patch makes cache available in above cases and improves performance.

---
 lib/librte_mempool/rte_mempool.h | 25 ++++++++++---------------
 1 file changed, 10 insertions(+), 15 deletions(-)
lib/librte_mempool/rte_mempool.h +10 -15
index d315d42..aca2f1b 100644
@@ -1038,19 +1038,15 @@ static inline struct rte_mempool_cache *__attribute__((always_inline))
  */
 static inline void __attribute__((always_inline))
 __mempool_generic_put(struct rte_mempool *mp, void * const *obj_table,
-		      unsigned n, struct rte_mempool_cache *cache, int flags)
+		      unsigned n, struct rte_mempool_cache *cache)
 {
 	void **cache_objs;
 
 	/* increment stat now, adding in mempool always success */
 	__MEMPOOL_STAT_ADD(mp, put, n);
 
-	/* No cache provided or single producer */
-	if (unlikely(cache == NULL || flags & MEMPOOL_F_SP_PUT))
-		goto ring_enqueue;
-
-	/* Go straight to ring if put would overflow mem allocated for cache */
-	if (unlikely(n > RTE_MEMPOOL_CACHE_MAX_SIZE))
+	/* No cache provided or if put would overflow mem allocated for cache */
+	if (unlikely(cache == NULL || n > RTE_MEMPOOL_CACHE_MAX_SIZE))
 		goto ring_enqueue;
 
 	cache_objs = &cache->objs[cache->len];
@@ -1104,10 +1100,10 @@ static inline void __attribute__((always_inline))
  */
 static inline void __attribute__((always_inline))
 rte_mempool_generic_put(struct rte_mempool *mp, void * const *obj_table,
-			unsigned n, struct rte_mempool_cache *cache, int flags)
+			unsigned n, struct rte_mempool_cache *cache, __rte_unused int flags)
 {
 	__mempool_check_cookies(mp, obj_table, n, 0);
-	__mempool_generic_put(mp, obj_table, n, cache, flags);
+	__mempool_generic_put(mp, obj_table, n, cache);
 }
 
 /**
@@ -1244,15 +1240,14 @@ static inline void __attribute__((always_inline))
  */
 static inline int __attribute__((always_inline))
 __mempool_generic_get(struct rte_mempool *mp, void **obj_table,
-		      unsigned n, struct rte_mempool_cache *cache, int flags)
+		      unsigned n, struct rte_mempool_cache *cache)
 {
 	int ret;
 	uint32_t index, len;
 	void **cache_objs;
 
-	/* No cache provided or single consumer */
-	if (unlikely(cache == NULL || flags & MEMPOOL_F_SC_GET ||
-		     n >= cache->size))
+	/* No cache provided or cannot be satisfied from cache */
+	if (unlikely(cache == NULL || n >= cache->size))
 		goto ring_dequeue;
 
 	cache_objs = cache->objs;
@@ -1326,10 +1321,10 @@ static inline int __attribute__((always_inline))
  */
 static inline int __attribute__((always_inline))
 rte_mempool_generic_get(struct rte_mempool *mp, void **obj_table, unsigned n,
-			struct rte_mempool_cache *cache, int flags)
+			struct rte_mempool_cache *cache, __rte_unused int flags)
 {
 	int ret;
-	ret = __mempool_generic_get(mp, obj_table, n, cache, flags);
+	ret = __mempool_generic_get(mp, obj_table, n, cache);
 	if (ret == 0)
 		__mempool_check_cookies(mp, obj_table, n, 1);
 	return ret;
Signature · 1 line
1.8.3.1
#4 lore raw

Re: [PATCH v3] mempool: don't check mempool flags when cache is enabled

Hi Wengfeng,

Quoted 7 lines · Wenfeng Liu

Currently we will check mempool flags when we put/get objects from mempool. However, this makes cache useless when mempool is SC|SP, SC|MP, MC|SP cases.
This patch makes cache available in above cases and improves performance.

I agree with you and Konstantin. This should enhance performance in single consumer/producer mode.

Quoted 9 lines
(quoted diff) +0 -0
@@ -1104,10 +1100,10 @@ static inline void

__attribute__((always_inline)) */
static inline void __attribute__((always_inline)) rte_mempool_generic_put(struct rte_mempool *mp, void * const
*obj_table,

(quoted diff) +0 -1
-			unsigned n, struct rte_mempool_cache *cache,

int flags)

(quoted diff) +1 -0
+			unsigned n, struct rte_mempool_cache *cache,

__rte_unused int flags) {

Small nit, seen with checkpatch:

WARNING:LONG_LINE: line over 80 characters
#43: FILE: lib/librte_mempool/rte_mempool.h:1103:
+ unsigned n, struct rte_mempool_cache *cache,
__rte_unused int flags)

The other warnings (Prefer 'unsigned int' to bare use of 'unsigned') can be ignored, since it's not coming from your patch.

While there, I suggest another title that better reflects what is done:
"mempool: use cache in single producer or consumer mode"

Thanks,
Olivier

#5 lore raw

PATCH v4 1/1 mempool: use cache in single producer or consumer mode

In reply to Wenfeng Liu

Currently we will check mempool flags when we put/get objects from mempool. However, this makes cache useless when mempool is SC|SP, SC|MP, MC|SP cases.
This patch makes cache available in above cases and improves performance.

---
 lib/librte_mempool/rte_mempool.h | 26 +++++++++++---------------
 1 file changed, 11 insertions(+), 15 deletions(-)
lib/librte_mempool/rte_mempool.h +11 -15
index d315d42..d0f5b27 100644
@@ -1038,19 +1038,15 @@ static inline struct rte_mempool_cache *__attribute__((always_inline))
  */
 static inline void __attribute__((always_inline))
 __mempool_generic_put(struct rte_mempool *mp, void * const *obj_table,
-		      unsigned n, struct rte_mempool_cache *cache, int flags)
+		      unsigned n, struct rte_mempool_cache *cache)
 {
 	void **cache_objs;
 
 	/* increment stat now, adding in mempool always success */
 	__MEMPOOL_STAT_ADD(mp, put, n);
 
-	/* No cache provided or single producer */
-	if (unlikely(cache == NULL || flags & MEMPOOL_F_SP_PUT))
-		goto ring_enqueue;
-
-	/* Go straight to ring if put would overflow mem allocated for cache */
-	if (unlikely(n > RTE_MEMPOOL_CACHE_MAX_SIZE))
+	/* No cache provided or if put would overflow mem allocated for cache */
+	if (unlikely(cache == NULL || n > RTE_MEMPOOL_CACHE_MAX_SIZE))
 		goto ring_enqueue;
 
 	cache_objs = &cache->objs[cache->len];
@@ -1104,10 +1100,11 @@ static inline void __attribute__((always_inline))
  */
 static inline void __attribute__((always_inline))
 rte_mempool_generic_put(struct rte_mempool *mp, void * const *obj_table,
-			unsigned n, struct rte_mempool_cache *cache, int flags)
+			unsigned n, struct rte_mempool_cache *cache,
+			__rte_unused int flags)
 {
 	__mempool_check_cookies(mp, obj_table, n, 0);
-	__mempool_generic_put(mp, obj_table, n, cache, flags);
+	__mempool_generic_put(mp, obj_table, n, cache);
 }
 
 /**
@@ -1244,15 +1241,14 @@ static inline void __attribute__((always_inline))
  */
 static inline int __attribute__((always_inline))
 __mempool_generic_get(struct rte_mempool *mp, void **obj_table,
-		      unsigned n, struct rte_mempool_cache *cache, int flags)
+		      unsigned n, struct rte_mempool_cache *cache)
 {
 	int ret;
 	uint32_t index, len;
 	void **cache_objs;
 
-	/* No cache provided or single consumer */
-	if (unlikely(cache == NULL || flags & MEMPOOL_F_SC_GET ||
-		     n >= cache->size))
+	/* No cache provided or cannot be satisfied from cache */
+	if (unlikely(cache == NULL || n >= cache->size))
 		goto ring_dequeue;
 
 	cache_objs = cache->objs;
@@ -1326,10 +1322,10 @@ static inline int __attribute__((always_inline))
  */
 static inline int __attribute__((always_inline))
 rte_mempool_generic_get(struct rte_mempool *mp, void **obj_table, unsigned n,
-			struct rte_mempool_cache *cache, int flags)
+			struct rte_mempool_cache *cache, __rte_unused int flags)
 {
 	int ret;
-	ret = __mempool_generic_get(mp, obj_table, n, cache, flags);
+	ret = __mempool_generic_get(mp, obj_table, n, cache);
 	if (ret == 0)
 		__mempool_check_cookies(mp, obj_table, n, 1);
 	return ret;
Signature · 1 line
1.8.3.1
Acked-by on v4 1/1
#6 lore raw

Re: [PATCH v4] mempool: use cache in single producer or consumer mode

Quoted 7 lines · Wenfeng Liu

Currently we will check mempool flags when we put/get objects from mempool. However, this makes cache useless when mempool is SC|SP, SC|MP, MC|SP cases.
This patch makes cache available in above cases and improves performance.

#7 lore raw

Re: [PATCH v4] mempool: use cache in single producer or consumer mode

2017-01-13 16:23, Olivier Matz:

Quoted 11 lines
Quoted 7 lines · Wenfeng Liu

Currently we will check mempool flags when we put/get objects from mempool. However, this makes cache useless when mempool is SC|SP, SC|MP, MC|SP cases.
This patch makes cache available in above cases and improves performance.

Applied, thanks