Skip to contentSkip to conversation

mempool: implement index-based per core cache

RFC In review Dharmik Thakkar 11 participants 52 messages Sep 30, 2021 – Jul 31, 2023

lore
Share & tools
lore
#0 lore raw

RFC 1/1 mempool: implement index-based per core cache

Current mempool per core cache implementation is based on pointer For most architectures, each pointer consumes 64b Replace it with index-based implementation, where in each buffer is addressed by (pool address + index)
It will reduce memory requirements

L3Fwd performance testing reveals minor improvements in the cache performance and no change in throughput

Micro-benchmarking the patch using mempool_perf_test shows significant improvement with majority of the test cases

Future plan involves replacing global pool's pointer-based implementation with index-based implementation

---
 drivers/mempool/ring/rte_mempool_ring.c |  2 +-
 lib/mempool/rte_mempool.c               |  8 +++
 lib/mempool/rte_mempool.h               | 74 ++++++++++++++++++++++---
 3 files changed, 74 insertions(+), 10 deletions(-)
drivers/mempool/ring/rte_mempool_ring.c +1 -1
index b1f09ff28f4d..e55913e47f21 100644
@@ -101,7 +101,7 @@ ring_alloc(struct rte_mempool *mp, uint32_t rg_flags)
 		return -rte_errno;
 
 	mp->pool_data = r;
-
+	mp->local_cache_base_addr = &r[1];
 	return 0;
 }
 
lib/mempool/rte_mempool.c +8 -0
index 59a588425bd6..424bdb19c323 100644
@@ -480,6 +480,7 @@ rte_mempool_populate_default(struct rte_mempool *mp)
 	int ret;
 	bool need_iova_contig_obj;
 	size_t max_alloc_size = SIZE_MAX;
+	unsigned lcore_id;
 
 	ret = mempool_ops_alloc_once(mp);
 	if (ret != 0)
@@ -600,6 +601,13 @@ rte_mempool_populate_default(struct rte_mempool *mp)
 		}
 	}
 
+	/* Init all default caches. */
+	if (mp->cache_size != 0) {
+		for (lcore_id = 0; lcore_id < RTE_MAX_LCORE; lcore_id++)
+			mp->local_cache[lcore_id].local_cache_base_value =
+				*(void **)mp->local_cache_base_addr;
+	}
+
 	rte_mempool_trace_populate_default(mp);
 	return mp->size;
 
lib/mempool/rte_mempool.h +65 -9

162 lines not on this page · raw message

Signature · 1 line
2.17.1
#1 lore raw
Quoted 10 lines · Dharmik Thakkar

Current mempool per core cache implementation is based on pointer For most architectures, each pointer consumes 64b Replace it with index-based implementation, where in each buffer is addressed by (pool address + index)
It will reduce memory requirements

L3Fwd performance testing reveals minor improvements in the cache performance and no change in throughput

Quoted 6 lines

Micro-benchmarking the patch using mempool_perf_test shows significant improvement with majority of the test cases

Future plan involves replacing global pool's pointer-based implementation with index-based implementation

Sane idea. Like VPP, we tried to do this for rte_graph, but not observed much gain.
Since lcore cache is typically 512, maybe there is a gain on the mempool path. Also, Since you are enabling only for local cache, it is good as mempool drivers can work as-is.(i.e HW drivers works with 64bit) I think, getting more performance numbers for various cases may be the next step.

Quoted 224 lines
---
 drivers/mempool/ring/rte_mempool_ring.c |  2 +-
 lib/mempool/rte_mempool.c               |  8 +++
 lib/mempool/rte_mempool.h               | 74 ++++++++++++++++++++++---
 3 files changed, 74 insertions(+), 10 deletions(-)
drivers/mempool/ring/rte_mempool_ring.c +1 -1
index b1f09ff28f4d..e55913e47f21 100644
@@ -101,7 +101,7 @@ ring_alloc(struct rte_mempool *mp, uint32_t rg_flags)
                return -rte_errno;
 
        mp->pool_data = r;
-
+       mp->local_cache_base_addr = &r[1];
        return 0;
 }
 
lib/mempool/rte_mempool.c +8 -0
index 59a588425bd6..424bdb19c323 100644
@@ -480,6 +480,7 @@ rte_mempool_populate_default(struct rte_mempool *mp)
        int ret;
        bool need_iova_contig_obj;
        size_t max_alloc_size = SIZE_MAX;
+       unsigned lcore_id;
 
        ret = mempool_ops_alloc_once(mp);
        if (ret != 0)
@@ -600,6 +601,13 @@ rte_mempool_populate_default(struct rte_mempool *mp)
                }
        }
 
+       /* Init all default caches. */
+       if (mp->cache_size != 0) {
+               for (lcore_id = 0; lcore_id < RTE_MAX_LCORE; lcore_id++)
+                       mp->local_cache[lcore_id].local_cache_base_value =
+                               *(void **)mp->local_cache_base_addr;
+       }
+
        rte_mempool_trace_populate_default(mp);
        return mp->size;
 
lib/mempool/rte_mempool.h +65 -10
index 4235d6f0bf2b..545405c0d3ce 100644
@@ -51,6 +51,8 @@
 #include <rte_memcpy.h>
 #include <rte_common.h>
 
+#include <arm_neon.h>
+
 #include "rte_mempool_trace_fp.h"
 
 #ifdef __cplusplus
@@ -91,11 +93,12 @@ struct rte_mempool_cache {
        uint32_t size;        /**< Size of the cache */
        uint32_t flushthresh; /**< Threshold before we flush excess elements */
        uint32_t len;         /**< Current cache count */
+       void *local_cache_base_value; /**< Base value to calculate indices */
        /*
         * Cache is allocated to this size to allow it to overflow in certain
         * cases to avoid needless emptying of cache.
         */
-       void *objs[RTE_MEMPOOL_CACHE_MAX_SIZE * 3]; /**< Cache objects */
+       uint32_t objs[RTE_MEMPOOL_CACHE_MAX_SIZE * 3]; /**< Cache objects */
 } __rte_cache_aligned;
 
 /**
@@ -172,7 +175,6 @@ struct rte_mempool_objtlr {
  * A list of memory where objects are stored
  */
 STAILQ_HEAD(rte_mempool_memhdr_list, rte_mempool_memhdr);
-
 /**
  * Callback used to free a memory chunk
  */
@@ -244,6 +246,7 @@ struct rte_mempool {
        int32_t ops_index;
 
        struct rte_mempool_cache *local_cache; /**< Per-lcore local cache */
+       void *local_cache_base_addr; /**< Reference to the base value */
 
        uint32_t populated_size;         /**< Number of populated objects. */
        struct rte_mempool_objhdr_list elt_list; /**< List of objects in pool */
@@ -1269,7 +1272,15 @@ rte_mempool_cache_flush(struct rte_mempool_cache *cache,
        if (cache == NULL || cache->len == 0)
                return;
        rte_mempool_trace_cache_flush(cache, mp);
-       rte_mempool_ops_enqueue_bulk(mp, cache->objs, cache->len);
+
+       unsigned int i;
+       unsigned int cache_len = cache->len;
+       void *obj_table[RTE_MEMPOOL_CACHE_MAX_SIZE * 3];
+       void *base_value = cache->local_cache_base_value;
+       uint32_t *cache_objs = cache->objs;
+       for (i = 0; i < cache_len; i++)
+               obj_table[i] = (void *) RTE_PTR_ADD(base_value, cache_objs[i]);
+       rte_mempool_ops_enqueue_bulk(mp, obj_table, cache->len);
        cache->len = 0;
 }
 
@@ -1289,7 +1300,9 @@ static __rte_always_inline void
 __mempool_generic_put(struct rte_mempool *mp, void * const *obj_table,
                      unsigned int n, struct rte_mempool_cache *cache)
 {
-       void **cache_objs;
+       uint32_t *cache_objs;
+       void *base_value;
+       uint32_t i;
 
        /* increment stat now, adding in mempool always success */
        __MEMPOOL_STAT_ADD(mp, put_bulk, 1);
@@ -1301,6 +1314,12 @@ __mempool_generic_put(struct rte_mempool *mp, void * const *obj_table,
 
        cache_objs = &cache->objs[cache->len];
 
+       base_value = cache->local_cache_base_value;
+
+       uint64x2_t v_obj_table;
+       uint64x2_t v_base_value = vdupq_n_u64((uint64_t)base_value);
+       uint32x2_t v_cache_objs;
+
        /*
         * The cache follows the following algorithm
         *   1. Add the objects to the cache
@@ -1309,12 +1328,26 @@ __mempool_generic_put(struct rte_mempool *mp, void * const *obj_table,
         */
 
        /* Add elements back into the cache */
-       rte_memcpy(&cache_objs[0], obj_table, sizeof(void *) * n);
+
+#if defined __ARM_NEON
+       for (i = 0; i < (n & ~0x1); i+=2) {
+               v_obj_table = vld1q_u64((const uint64_t *)&obj_table[i]);
+               v_cache_objs = vqmovn_u64(vsubq_u64(v_obj_table, v_base_value));
+               vst1_u32(cache_objs + i, v_cache_objs);
+       }
+       if (n & 0x1) {
+               cache_objs[i] = (uint32_t) RTE_PTR_DIFF(obj_table[i], base_value);
+       }
+#else
+       for (i = 0; i < n; i++) {
+               cache_objs[i] = (uint32_t) RTE_PTR_DIFF(obj_table[i], base_value);
+       }
+#endif
 
        cache->len += n;
 
        if (cache->len >= cache->flushthresh) {
-               rte_mempool_ops_enqueue_bulk(mp, &cache->objs[cache->size],
+               rte_mempool_ops_enqueue_bulk(mp, obj_table + cache->len - cache->size,
                                cache->len - cache->size);
                cache->len = cache->size;
        }
@@ -1415,23 +1448,26 @@ __mempool_generic_get(struct rte_mempool *mp, void **obj_table,
                      unsigned int n, struct rte_mempool_cache *cache)
 {
        int ret;
+       uint32_t i;
        uint32_t index, len;
-       void **cache_objs;
+       uint32_t *cache_objs;
 
        /* No cache provided or cannot be satisfied from cache */
        if (unlikely(cache == NULL || n >= cache->size))
                goto ring_dequeue;
 
+       void *base_value = cache->local_cache_base_value;
        cache_objs = cache->objs;
 
        /* Can this be satisfied from the cache? */
        if (cache->len < n) {
                /* No. Backfill the cache first, and then fill from it */
                uint32_t req = n + (cache->size - cache->len);
+               void *temp_objs[RTE_MEMPOOL_CACHE_MAX_SIZE * 3]; /**< Cache objects */
 
                /* How many do we require i.e. number to fill the cache + the request */
                ret = rte_mempool_ops_dequeue_bulk(mp,
-                       &cache->objs[cache->len], req);
+                       temp_objs, req);
                if (unlikely(ret < 0)) {
                        /*
                         * In the off chance that we are buffer constrained,
@@ -1442,12 +1478,32 @@ __mempool_generic_get(struct rte_mempool *mp, void **obj_table,
                        goto ring_dequeue;
                }
 
+               len = cache->len;
+               for (i = 0; i < req; ++i, ++len) {
+                       cache_objs[len] = (uint32_t) RTE_PTR_DIFF(temp_objs[i], base_value);
+               }
+
                cache->len += req;
        }
 
+       uint64x2_t v_obj_table;
+       uint64x2_t v_cache_objs;
+       uint64x2_t v_base_value = vdupq_n_u64((uint64_t)base_value);
+
        /* Now fill in the response ... */
+#if defined __ARM_NEON
+       for (index = 0, len = cache->len - 1; index < (n & ~0x1); index+=2,
+                                               len-=2, obj_table+=2) {
+               v_cache_objs = vmovl_u32(vld1_u32(cache_objs + len - 1));
+               v_obj_table = vaddq_u64(v_cache_objs, v_base_value);
+               vst1q_u64((uint64_t *)obj_table, v_obj_table);
+       }
+       if (n & 0x1)
+               *obj_table = (void *) RTE_PTR_ADD(base_value, cache_objs[len]);
+#else
        for (index = 0, len = cache->len - 1; index < n; ++index, len--, obj_table++)
-               *obj_table = cache_objs[len];
+               *obj_table = (void *) RTE_PTR_ADD(base_value, cache_objs[len]);
+#endif
 
        cache->len -= n;
 
--

2.17.1

#2 lore raw

<snip>

Quoted 21 lines
Quoted 9 lines · Dharmik Thakkar

Current mempool per core cache implementation is based on pointer For most architectures, each pointer consumes 64b Replace it with index-based implementation, where in each buffer is addressed by (pool address + index) It will reduce memory requirements

L3Fwd performance testing reveals minor improvements in the cache performance and no change in throughput

Quoted 7 lines

Micro-benchmarking the patch using mempool_perf_test shows significant improvement with majority of the test cases

Future plan involves replacing global pool's pointer-based implementation with index-based implementation

Quoted 6 lines

Sane idea. Like VPP, we tried to do this for rte_graph, but not observed much gain.
Since lcore cache is typically 512, maybe there is a gain on the mempool path. Also, Since you are enabling only for local cache, it is good as mempool drivers can work as-is.(i.e HW drivers works with 64bit) I think, getting more performance numbers for various cases may be the next step.

The gain is not observed in terms of PPS improvement, but do see some improvements that PMUs indicate. This approach definitely results in savings in number of cache lines utilized.

Quoted 245 lines

drivers/mempool/ring/rte_mempool_ring.c ring_alloc(struct rte_mempool *mp, uint32_t

Quoted 13 lines
---
 drivers/mempool/ring/rte_mempool_ring.c |  2 +-
 lib/mempool/rte_mempool.c               |  8 +++
 lib/mempool/rte_mempool.h               | 74 ++++++++++++++++++++++---
 3 files changed, 74 insertions(+), 10 deletions(-)
drivers/mempool/ring/rte_mempool_ring.c +0 -0
index b1f09ff28f4d..e55913e47f21 100644
@@ -101,7 +101,7 @@ ring_alloc(struct rte_mempool *mp, uint32_t

rg_flags)

lib/mempool/rte_mempool.c rte_mempool_populate_default(struct

Quoted 13 lines
drivers/mempool/ring/rte_mempool_ring.c +1 -1
                return -rte_errno;
 
        mp->pool_data = r;
-
+       mp->local_cache_base_addr = &r[1];
        return 0;
 }
 
lib/mempool/rte_mempool.c +0 -0
index 59a588425bd6..424bdb19c323 100644
@@ -480,6 +480,7 @@ rte_mempool_populate_default(struct

rte_mempool *mp)

lib/mempool/rte_mempool.c rte_mempool_populate_default(struct

Quoted 8 lines
lib/mempool/rte_mempool.c +1 -0
        int ret;
        bool need_iova_contig_obj;
        size_t max_alloc_size = SIZE_MAX;
+       unsigned lcore_id;
 
        ret = mempool_ops_alloc_once(mp);
        if (ret != 0)
@@ -600,6 +601,13 @@ rte_mempool_populate_default(struct

rte_mempool *mp)

Quoted 27 lines
lib/mempool/rte_mempool.c +7 -0
                }
        }
 
+       /* Init all default caches. */
+       if (mp->cache_size != 0) {
+               for (lcore_id = 0; lcore_id < RTE_MAX_LCORE; lcore_id++)
+                       mp->local_cache[lcore_id].local_cache_base_value =
+                               *(void **)mp->local_cache_base_addr;
+       }
+
        rte_mempool_trace_populate_default(mp);
        return mp->size;
 
lib/mempool/rte_mempool.h +2 -0
index 4235d6f0bf2b..545405c0d3ce 100644
@@ -51,6 +51,8 @@
 #include <rte_memcpy.h>
 #include <rte_common.h>
 
+#include <arm_neon.h>
+
 #include "rte_mempool_trace_fp.h"
 
 #ifdef __cplusplus

lib/mempool/rte_mempool.h struct rte_mempool_cache { · line 94

Quoted 2 lines
lib/mempool/rte_mempool.h +0 -0
@@ -91,11 +93,12 @@ struct rte_mempool_cache {
        uint32_t size;        /**< Size of the cache */
        uint32_t flushthresh; /**< Threshold before we flush excess elements

*/

lib/mempool/rte_mempool.h struct rte_mempool_cache {

Quoted 8 lines
lib/mempool/rte_mempool.h +2 -1
        uint32_t len;         /**< Current cache count */
+       void *local_cache_base_value; /**< Base value to calculate
+ indices */
        /*
         * Cache is allocated to this size to allow it to overflow in certain
         * cases to avoid needless emptying of cache.
         */
-       void *objs[RTE_MEMPOOL_CACHE_MAX_SIZE * 3]; /**< Cache objects

*/

Quoted 21 lines
lib/mempool/rte_mempool.h +2 -1
+       uint32_t objs[RTE_MEMPOOL_CACHE_MAX_SIZE * 3]; /**< Cache
+ objects */
 } __rte_cache_aligned;
 
 /**
@@ -172,7 +175,6 @@ struct rte_mempool_objtlr {
  * A list of memory where objects are stored
  */
 STAILQ_HEAD(rte_mempool_memhdr_list, rte_mempool_memhdr);
-
 /**
  * Callback used to free a memory chunk
  */
@@ -244,6 +246,7 @@ struct rte_mempool {
        int32_t ops_index;
 
        struct rte_mempool_cache *local_cache; /**< Per-lcore local

cache */
+ void *local_cache_base_addr; /**< Reference to the base value
+ */

Quoted 3 lines

uint32_t populated_size; /**< Number of populated objects. */
struct rte_mempool_objhdr_list elt_list; /**< List of objects
in pool */ @@ -1269,7 +1272,15 @@ rte_mempool_cache_flush(struct

rte_mempool_cache *cache,

lib/mempool/rte_mempool.h __mempool_generic_put(struct rte_mempool

Quoted 41 lines
        if (cache == NULL || cache->len == 0)
                return;
        rte_mempool_trace_cache_flush(cache, mp);
lib/mempool/rte_mempool.h +12 -2
-       rte_mempool_ops_enqueue_bulk(mp, cache->objs, cache->len);
+
+       unsigned int i;
+       unsigned int cache_len = cache->len;
+       void *obj_table[RTE_MEMPOOL_CACHE_MAX_SIZE * 3];
+       void *base_value = cache->local_cache_base_value;
+       uint32_t *cache_objs = cache->objs;
+       for (i = 0; i < cache_len; i++)
+               obj_table[i] = (void *) RTE_PTR_ADD(base_value, cache_objs[i]);
+       rte_mempool_ops_enqueue_bulk(mp, obj_table, cache->len);
        cache->len = 0;
 }
@@ -1289,7 +1300,9 @@ static __rte_always_inline void
 __mempool_generic_put(struct rte_mempool *mp, void * const *obj_table,
                      unsigned int n, struct rte_mempool_cache *cache)
 {
-       void **cache_objs;
+       uint32_t *cache_objs;
+       void *base_value;
+       uint32_t i;
 
        /* increment stat now, adding in mempool always success */
        __MEMPOOL_STAT_ADD(mp, put_bulk, 1); @@ -1301,6 +1314,12 @@

__mempool_generic_put(struct rte_mempool *mp, void * const *obj_table,

        cache_objs = &cache->objs[cache->len];
lib/mempool/rte_mempool.h +6 -0
+       base_value = cache->local_cache_base_value;
+
+       uint64x2_t v_obj_table;
+       uint64x2_t v_base_value = vdupq_n_u64((uint64_t)base_value);
+       uint32x2_t v_cache_objs;
+
        /*
         * The cache follows the following algorithm
         *   1. Add the objects to the cache
@@ -1309,12 +1328,26 @@ __mempool_generic_put(struct rte_mempool

*mp, void * const *obj_table,

lib/mempool/rte_mempool.h __mempool_generic_put(struct rte_mempool *mp, void * const *obj_table,

Quoted 9 lines
lib/mempool/rte_mempool.h +5 -1
         */
 
        /* Add elements back into the cache */
-       rte_memcpy(&cache_objs[0], obj_table, sizeof(void *) * n);
+
+#if defined __ARM_NEON
+       for (i = 0; i < (n & ~0x1); i+=2) {
+               v_obj_table = vld1q_u64((const uint64_t *)&obj_table[i]);
+               v_cache_objs = vqmovn_u64(vsubq_u64(v_obj_table,

v_base_value));

lib/mempool/rte_mempool.h __mempool_generic_get(struct rte_mempool

Quoted 21 lines
lib/mempool/rte_mempool.h +12 -1
+               vst1_u32(cache_objs + i, v_cache_objs);
+       }
+       if (n & 0x1) {
+               cache_objs[i] = (uint32_t) RTE_PTR_DIFF(obj_table[i], base_value);
+       }
+#else
+       for (i = 0; i < n; i++) {
+               cache_objs[i] = (uint32_t) RTE_PTR_DIFF(obj_table[i], base_value);
+       }
+#endif
 
        cache->len += n;
 
        if (cache->len >= cache->flushthresh) {
-               rte_mempool_ops_enqueue_bulk(mp, &cache->objs[cache->size],
+               rte_mempool_ops_enqueue_bulk(mp, obj_table +
+ cache->len - cache->size,
                                cache->len - cache->size);
                cache->len = cache->size;
        }
@@ -1415,23 +1448,26 @@ __mempool_generic_get(struct rte_mempool

*mp, void **obj_table,

Quoted 13 lines
lib/mempool/rte_mempool.h +3 -1
                      unsigned int n, struct rte_mempool_cache *cache)
 {
        int ret;
+       uint32_t i;
        uint32_t index, len;
-       void **cache_objs;
+       uint32_t *cache_objs;
 
        /* No cache provided or cannot be satisfied from cache */
        if (unlikely(cache == NULL || n >= cache->size))
                goto ring_dequeue;
 
+       void *base_value = cache->local_cache_base_value;

lib/mempool/rte_mempool.h __mempool_generic_get(struct rte_mempool *mp, void **obj_table,

Quoted 10 lines
lib/mempool/rte_mempool.h +2 -0
        cache_objs = cache->objs;
 
        /* Can this be satisfied from the cache? */
        if (cache->len < n) {
                /* No. Backfill the cache first, and then fill from it */
                uint32_t req = n + (cache->size - cache->len);
+               void *temp_objs[RTE_MEMPOOL_CACHE_MAX_SIZE * 3]; /**<
+ Cache objects */
 
                /* How many do we require i.e. number to fill the cache + the

request */

Quoted 7 lines
lib/mempool/rte_mempool.h +1 -1
                ret = rte_mempool_ops_dequeue_bulk(mp,
-                       &cache->objs[cache->len], req);
+                       temp_objs, req);
                if (unlikely(ret < 0)) {
                        /*
                         * In the off chance that we are buffer

constrained, @@ -1442,12 +1478,32 @@ __mempool_generic_get(struct

rte_mempool *mp, void **obj_table,

lib/mempool/rte_mempool.h __mempool_generic_get(struct rte_mempool *mp, void **obj_table,

Quoted 6 lines
                        goto ring_dequeue;
                }
lib/mempool/rte_mempool.h +3 -0
+               len = cache->len;
+               for (i = 0; i < req; ++i, ++len) {
+                       cache_objs[len] = (uint32_t) RTE_PTR_DIFF(temp_objs[i],

base_value);

Quoted 11 lines
lib/mempool/rte_mempool.h +7 -0
+               }
+
                cache->len += req;
        }
 
+       uint64x2_t v_obj_table;
+       uint64x2_t v_cache_objs;
+       uint64x2_t v_base_value = vdupq_n_u64((uint64_t)base_value);
+
        /* Now fill in the response ... */
+#if defined __ARM_NEON

lib/mempool/rte_mempool.h __mempool_generic_get(struct rte_mempool *mp, void **obj_table,

Quoted 10 lines
lib/mempool/rte_mempool.h +9 -0
+       for (index = 0, len = cache->len - 1; index < (n & ~0x1); index+=2,
+                                               len-=2, obj_table+=2) {
+               v_cache_objs = vmovl_u32(vld1_u32(cache_objs + len - 1));
+               v_obj_table = vaddq_u64(v_cache_objs, v_base_value);
+               vst1q_u64((uint64_t *)obj_table, v_obj_table);
+       }
+       if (n & 0x1)
+               *obj_table = (void *) RTE_PTR_ADD(base_value,
+cache_objs[len]); #else
        for (index = 0, len = cache->len - 1; index < n; ++index, len--,

obj_table++)

Quoted 9 lines
lib/mempool/rte_mempool.h +2 -2
-               *obj_table = cache_objs[len];
+               *obj_table = (void *) RTE_PTR_ADD(base_value,
+cache_objs[len]); #endif
 
        cache->len -= n;
 
--

2.17.1

#3 lore raw
Quoted 24 lines · Honnappa Nagarahalli

<snip>

Quoted 21 lines
Quoted 16 lines · Dharmik Thakkar

Current mempool per core cache implementation is based on pointer For most architectures, each pointer consumes 64b Replace it with index-based implementation, where in each buffer is addressed by (pool address + index) It will reduce memory requirements

L3Fwd performance testing reveals minor improvements in the cache performance and no change in throughput

Micro-benchmarking the patch using mempool_perf_test shows significant improvement with majority of the test cases

Future plan involves replacing global pool's pointer-based implementation with index-based implementation

Quoted 7 lines
Quoted 6 lines

Sane idea. Like VPP, we tried to do this for rte_graph, but not observed much gain.
Since lcore cache is typically 512, maybe there is a gain on the mempool path. Also, Since you are enabling only for local cache, it is good as mempool drivers can work as-is.(i.e HW drivers works with 64bit) I think, getting more performance numbers for various cases may be the next step.

The gain is not observed in terms of PPS improvement, but do see some improvements that PMUs indicate. This approach definitely results in savings in number of cache lines utilized.

OK. IMO, If PPS has regression then this path is not viable, else it may be OK.

Quoted 246 lines
Quoted 246 lines

drivers/mempool/ring/rte_mempool_ring.c ring_alloc(struct rte_mempool *mp, uint32_t

Quoted 14 lines

---
 drivers/mempool/ring/rte_mempool_ring.c |  2 +-
 lib/mempool/rte_mempool.c               |  8 +++
 lib/mempool/rte_mempool.h               | 74 ++++++++++++++++++++++---
 3 files changed, 74 insertions(+), 10 deletions(-)
drivers/mempool/ring/rte_mempool_ring.c +0 -0
index b1f09ff28f4d..e55913e47f21 100644
@@ -101,7 +101,7 @@ ring_alloc(struct rte_mempool *mp, uint32_t

rg_flags)

lib/mempool/rte_mempool.c rte_mempool_populate_default(struct

Quoted 13 lines
drivers/mempool/ring/rte_mempool_ring.c +1 -1
                return -rte_errno;
 
        mp->pool_data = r;
-
+       mp->local_cache_base_addr = &r[1];
        return 0;
 }
 
lib/mempool/rte_mempool.c +0 -0
index 59a588425bd6..424bdb19c323 100644
@@ -480,6 +480,7 @@ rte_mempool_populate_default(struct

rte_mempool *mp)

lib/mempool/rte_mempool.c rte_mempool_populate_default(struct

Quoted 8 lines
lib/mempool/rte_mempool.c +1 -0
        int ret;
        bool need_iova_contig_obj;
        size_t max_alloc_size = SIZE_MAX;
+       unsigned lcore_id;
 
        ret = mempool_ops_alloc_once(mp);
        if (ret != 0)
@@ -600,6 +601,13 @@ rte_mempool_populate_default(struct

rte_mempool *mp)

Quoted 27 lines
lib/mempool/rte_mempool.c +7 -0
                }
        }
 
+       /* Init all default caches. */
+       if (mp->cache_size != 0) {
+               for (lcore_id = 0; lcore_id < RTE_MAX_LCORE; lcore_id++)
+                       mp->local_cache[lcore_id].local_cache_base_value =
+                               *(void **)mp->local_cache_base_addr;
+       }
+
        rte_mempool_trace_populate_default(mp);
        return mp->size;
 
lib/mempool/rte_mempool.h +2 -0
index 4235d6f0bf2b..545405c0d3ce 100644
@@ -51,6 +51,8 @@
 #include <rte_memcpy.h>
 #include <rte_common.h>
 
+#include <arm_neon.h>
+
 #include "rte_mempool_trace_fp.h"
 
 #ifdef __cplusplus

lib/mempool/rte_mempool.h struct rte_mempool_cache { · line 94

Quoted 2 lines
lib/mempool/rte_mempool.h +0 -0
@@ -91,11 +93,12 @@ struct rte_mempool_cache {
        uint32_t size;        /**< Size of the cache */
        uint32_t flushthresh; /**< Threshold before we flush excess elements

*/

lib/mempool/rte_mempool.h struct rte_mempool_cache {

Quoted 8 lines
lib/mempool/rte_mempool.h +2 -1
        uint32_t len;         /**< Current cache count */
+       void *local_cache_base_value; /**< Base value to calculate
+ indices */
        /*
         * Cache is allocated to this size to allow it to overflow in certain
         * cases to avoid needless emptying of cache.
         */
-       void *objs[RTE_MEMPOOL_CACHE_MAX_SIZE * 3]; /**< Cache objects

*/

Quoted 21 lines
lib/mempool/rte_mempool.h +2 -1
+       uint32_t objs[RTE_MEMPOOL_CACHE_MAX_SIZE * 3]; /**< Cache
+ objects */
 } __rte_cache_aligned;
 
 /**
@@ -172,7 +175,6 @@ struct rte_mempool_objtlr {
  * A list of memory where objects are stored
  */
 STAILQ_HEAD(rte_mempool_memhdr_list, rte_mempool_memhdr);
-
 /**
  * Callback used to free a memory chunk
  */
@@ -244,6 +246,7 @@ struct rte_mempool {
        int32_t ops_index;
 
        struct rte_mempool_cache *local_cache; /**< Per-lcore local

cache */
+ void *local_cache_base_addr; /**< Reference to the base value
+ */

Quoted 3 lines

uint32_t populated_size; /**< Number of populated objects. */
struct rte_mempool_objhdr_list elt_list; /**< List of objects
in pool */ @@ -1269,7 +1272,15 @@ rte_mempool_cache_flush(struct

rte_mempool_cache *cache,

lib/mempool/rte_mempool.h __mempool_generic_put(struct rte_mempool

Quoted 41 lines
        if (cache == NULL || cache->len == 0)
                return;
        rte_mempool_trace_cache_flush(cache, mp);
lib/mempool/rte_mempool.h +12 -2
-       rte_mempool_ops_enqueue_bulk(mp, cache->objs, cache->len);
+
+       unsigned int i;
+       unsigned int cache_len = cache->len;
+       void *obj_table[RTE_MEMPOOL_CACHE_MAX_SIZE * 3];
+       void *base_value = cache->local_cache_base_value;
+       uint32_t *cache_objs = cache->objs;
+       for (i = 0; i < cache_len; i++)
+               obj_table[i] = (void *) RTE_PTR_ADD(base_value, cache_objs[i]);
+       rte_mempool_ops_enqueue_bulk(mp, obj_table, cache->len);
        cache->len = 0;
 }
@@ -1289,7 +1300,9 @@ static __rte_always_inline void
 __mempool_generic_put(struct rte_mempool *mp, void * const *obj_table,
                      unsigned int n, struct rte_mempool_cache *cache)
 {
-       void **cache_objs;
+       uint32_t *cache_objs;
+       void *base_value;
+       uint32_t i;
 
        /* increment stat now, adding in mempool always success */
        __MEMPOOL_STAT_ADD(mp, put_bulk, 1); @@ -1301,6 +1314,12 @@

__mempool_generic_put(struct rte_mempool *mp, void * const *obj_table,

        cache_objs = &cache->objs[cache->len];
lib/mempool/rte_mempool.h +6 -0
+       base_value = cache->local_cache_base_value;
+
+       uint64x2_t v_obj_table;
+       uint64x2_t v_base_value = vdupq_n_u64((uint64_t)base_value);
+       uint32x2_t v_cache_objs;
+
        /*
         * The cache follows the following algorithm
         *   1. Add the objects to the cache
@@ -1309,12 +1328,26 @@ __mempool_generic_put(struct rte_mempool

*mp, void * const *obj_table,

lib/mempool/rte_mempool.h __mempool_generic_put(struct rte_mempool *mp, void * const *obj_table,

Quoted 9 lines
lib/mempool/rte_mempool.h +5 -1
         */
 
        /* Add elements back into the cache */
-       rte_memcpy(&cache_objs[0], obj_table, sizeof(void *) * n);
+
+#if defined __ARM_NEON
+       for (i = 0; i < (n & ~0x1); i+=2) {
+               v_obj_table = vld1q_u64((const uint64_t *)&obj_table[i]);
+               v_cache_objs = vqmovn_u64(vsubq_u64(v_obj_table,

v_base_value));

lib/mempool/rte_mempool.h __mempool_generic_get(struct rte_mempool

Quoted 21 lines
lib/mempool/rte_mempool.h +12 -1
+               vst1_u32(cache_objs + i, v_cache_objs);
+       }
+       if (n & 0x1) {
+               cache_objs[i] = (uint32_t) RTE_PTR_DIFF(obj_table[i], base_value);
+       }
+#else
+       for (i = 0; i < n; i++) {
+               cache_objs[i] = (uint32_t) RTE_PTR_DIFF(obj_table[i], base_value);
+       }
+#endif
 
        cache->len += n;
 
        if (cache->len >= cache->flushthresh) {
-               rte_mempool_ops_enqueue_bulk(mp, &cache->objs[cache->size],
+               rte_mempool_ops_enqueue_bulk(mp, obj_table +
+ cache->len - cache->size,
                                cache->len - cache->size);
                cache->len = cache->size;
        }
@@ -1415,23 +1448,26 @@ __mempool_generic_get(struct rte_mempool

*mp, void **obj_table,

Quoted 13 lines
lib/mempool/rte_mempool.h +3 -1
                      unsigned int n, struct rte_mempool_cache *cache)
 {
        int ret;
+       uint32_t i;
        uint32_t index, len;
-       void **cache_objs;
+       uint32_t *cache_objs;
 
        /* No cache provided or cannot be satisfied from cache */
        if (unlikely(cache == NULL || n >= cache->size))
                goto ring_dequeue;
 
+       void *base_value = cache->local_cache_base_value;

lib/mempool/rte_mempool.h __mempool_generic_get(struct rte_mempool *mp, void **obj_table,

Quoted 10 lines
lib/mempool/rte_mempool.h +2 -0
        cache_objs = cache->objs;
 
        /* Can this be satisfied from the cache? */
        if (cache->len < n) {
                /* No. Backfill the cache first, and then fill from it */
                uint32_t req = n + (cache->size - cache->len);
+               void *temp_objs[RTE_MEMPOOL_CACHE_MAX_SIZE * 3]; /**<
+ Cache objects */
 
                /* How many do we require i.e. number to fill the cache + the

request */

Quoted 7 lines
lib/mempool/rte_mempool.h +1 -1
                ret = rte_mempool_ops_dequeue_bulk(mp,
-                       &cache->objs[cache->len], req);
+                       temp_objs, req);
                if (unlikely(ret < 0)) {
                        /*
                         * In the off chance that we are buffer

constrained, @@ -1442,12 +1478,32 @@ __mempool_generic_get(struct

rte_mempool *mp, void **obj_table,

lib/mempool/rte_mempool.h __mempool_generic_get(struct rte_mempool *mp, void **obj_table,

Quoted 6 lines
                        goto ring_dequeue;
                }
lib/mempool/rte_mempool.h +3 -0
+               len = cache->len;
+               for (i = 0; i < req; ++i, ++len) {
+                       cache_objs[len] = (uint32_t) RTE_PTR_DIFF(temp_objs[i],

base_value);

Quoted 11 lines
lib/mempool/rte_mempool.h +7 -0
+               }
+
                cache->len += req;
        }
 
+       uint64x2_t v_obj_table;
+       uint64x2_t v_cache_objs;
+       uint64x2_t v_base_value = vdupq_n_u64((uint64_t)base_value);
+
        /* Now fill in the response ... */
+#if defined __ARM_NEON

lib/mempool/rte_mempool.h __mempool_generic_get(struct rte_mempool *mp, void **obj_table,

Quoted 10 lines
lib/mempool/rte_mempool.h +9 -0
+       for (index = 0, len = cache->len - 1; index < (n & ~0x1); index+=2,
+                                               len-=2, obj_table+=2) {
+               v_cache_objs = vmovl_u32(vld1_u32(cache_objs + len - 1));
+               v_obj_table = vaddq_u64(v_cache_objs, v_base_value);
+               vst1q_u64((uint64_t *)obj_table, v_obj_table);
+       }
+       if (n & 0x1)
+               *obj_table = (void *) RTE_PTR_ADD(base_value,
+cache_objs[len]); #else
        for (index = 0, len = cache->len - 1; index < n; ++index, len--,

obj_table++)

Quoted 9 lines
lib/mempool/rte_mempool.h +2 -2
-               *obj_table = cache_objs[len];
+               *obj_table = (void *) RTE_PTR_ADD(base_value,
+cache_objs[len]); #endif
 
        cache->len -= n;
 
--

2.17.1

#4 lore raw

<snip>

Quoted 29 lines
Quoted 19 lines
Quoted 19 lines
Quoted 15 lines · Dharmik Thakkar

Current mempool per core cache implementation is based on pointer For most architectures, each pointer consumes 64b Replace it with index-based implementation, where in each buffer is addressed by (pool address + index) It will reduce memory requirements

L3Fwd performance testing reveals minor improvements in the cache performance and no change in throughput

Micro-benchmarking the patch using mempool_perf_test shows significant improvement with majority of the test cases

Future plan involves replacing global pool's pointer-based implementation with index-based implementation

Quoted 6 lines
Quoted 6 lines
Quoted 1 line

Sane idea. Like VPP, we tried to do this for rte_graph, but not observed much gain.
Since lcore cache is typically 512, maybe there is a gain on the mempool

path.

Quoted 3 lines
Quoted 3 lines

Also, Since you are enabling only for local cache, it is good as mempool drivers can work as-is.(i.e HW drivers works with 64bit) I think, getting more performance numbers for various cases may be the

Quoted 6 lines

next step.

Quoted 1 line

The gain is not observed in terms of PPS improvement, but do see some

improvements that PMUs indicate. This approach definitely results in savings in number of cache lines utilized.

OK. IMO, If PPS has regression then this path is not viable, else it may be OK.

PPS has not regressed. It has improved, but not significantly.
Other way to look at this is, we are doing the same work with less amount of resources.

Quoted 264 lines
Quoted 71 lines
Quoted 71 lines

drivers/mempool/ring/rte_mempool_ring.c ring_alloc(struct rte_mempool *mp, uint32_t

Quoted 16 lines



---
 drivers/mempool/ring/rte_mempool_ring.c |  2 +-
 lib/mempool/rte_mempool.c               |  8 +++
 lib/mempool/rte_mempool.h               | 74 ++++++++++++++++++++++---
 3 files changed, 74 insertions(+), 10 deletions(-)
drivers/mempool/ring/rte_mempool_ring.c +0 -0
index b1f09ff28f4d..e55913e47f21 100644
@@ -101,7 +101,7 @@ ring_alloc(struct rte_mempool *mp, uint32_t

rg_flags)

lib/mempool/rte_mempool.c rte_mempool_populate_default(struct

Quoted 13 lines
drivers/mempool/ring/rte_mempool_ring.c +1 -1
                return -rte_errno;
 
        mp->pool_data = r;
-
+       mp->local_cache_base_addr = &r[1];
        return 0;
 }
 
lib/mempool/rte_mempool.c +0 -0
index 59a588425bd6..424bdb19c323 100644
@@ -480,6 +480,7 @@ rte_mempool_populate_default(struct

rte_mempool *mp)

lib/mempool/rte_mempool.c rte_mempool_populate_default(struct

Quoted 8 lines
lib/mempool/rte_mempool.c +1 -0
        int ret;
        bool need_iova_contig_obj;
        size_t max_alloc_size = SIZE_MAX;
+       unsigned lcore_id;
 
        ret = mempool_ops_alloc_once(mp);
        if (ret != 0)
@@ -600,6 +601,13 @@ rte_mempool_populate_default(struct

rte_mempool *mp)

Quoted 29 lines
lib/mempool/rte_mempool.c +7 -0
                }
        }
 
+       /* Init all default caches. */
+       if (mp->cache_size != 0) {
+               for (lcore_id = 0; lcore_id < RTE_MAX_LCORE; lcore_id++)
+                       mp->local_cache[lcore_id].local_cache_base_value =
+                               *(void **)mp->local_cache_base_addr;
+       }
+
        rte_mempool_trace_populate_default(mp);
        return mp->size;
 
lib/mempool/rte_mempool.h +2 -0
index 4235d6f0bf2b..545405c0d3ce 100644
@@ -51,6 +51,8 @@
 #include <rte_memcpy.h>
 #include <rte_common.h>
 
+#include <arm_neon.h>
+
 #include "rte_mempool_trace_fp.h"
 
 #ifdef __cplusplus
@@ -91,11 +93,12 @@ struct rte_mempool_cache {
        uint32_t size;        /**< Size of the cache */
        uint32_t flushthresh; /**< Threshold before we flush
Quoted 1 line

excess elements

*/

Quoted 8 lines
Quoted 8 lines

lib/mempool/rte_mempool.h struct rte_mempool_cache {

Quoted 8 lines

uint32_t len; /**< Current cache count */

lib/mempool/rte_mempool.h +2 -1
+       void *local_cache_base_value; /**< Base value to calculate
+ indices */
        /*
         * Cache is allocated to this size to allow it to overflow in certain
         * cases to avoid needless emptying of cache.
         */
-       void *objs[RTE_MEMPOOL_CACHE_MAX_SIZE * 3]; /**< Cache

objects

Quoted 27 lines
Quoted 27 lines

*/

Quoted 21 lines
lib/mempool/rte_mempool.h +2 -1
+       uint32_t objs[RTE_MEMPOOL_CACHE_MAX_SIZE * 3]; /**< Cache
+ objects */
 } __rte_cache_aligned;
 
 /**
@@ -172,7 +175,6 @@ struct rte_mempool_objtlr {
  * A list of memory where objects are stored
  */
 STAILQ_HEAD(rte_mempool_memhdr_list, rte_mempool_memhdr);
-
 /**
  * Callback used to free a memory chunk
  */
@@ -244,6 +246,7 @@ struct rte_mempool {
        int32_t ops_index;
 
        struct rte_mempool_cache *local_cache; /**< Per-lcore

local cache */
+ void *local_cache_base_addr; /**< Reference to the base
+ value */

Quoted 4 lines

uint32_t populated_size; /**< Number of populated objects. */
struct rte_mempool_objhdr_list elt_list; /**< List of
objects in pool */ @@ -1269,7 +1272,15 @@ rte_mempool_cache_flush(struct

rte_mempool_cache *cache,

Quoted 12 lines
Quoted 4 lines
Quoted 4 lines
        if (cache == NULL || cache->len == 0)
                return;
        rte_mempool_trace_cache_flush(cache, mp);

- rte_mempool_ops_enqueue_bulk(mp, cache->objs, cache->len);

Quoted 8 lines

lib/mempool/rte_mempool.h rte_mempool_cache_flush(struct rte_mempool_cache *cache,

Quoted 8 lines
lib/mempool/rte_mempool.h +8 -0
+
+       unsigned int i;
+       unsigned int cache_len = cache->len;
+       void *obj_table[RTE_MEMPOOL_CACHE_MAX_SIZE * 3];
+       void *base_value = cache->local_cache_base_value;
+       uint32_t *cache_objs = cache->objs;
+       for (i = 0; i < cache_len; i++)
+               obj_table[i] = (void *) RTE_PTR_ADD(base_value,

cache_objs[i]);

Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
lib/mempool/rte_mempool.h +1 -0
+       rte_mempool_ops_enqueue_bulk(mp, obj_table, cache->len);
        cache->len = 0;
 }
@@ -1289,7 +1300,9 @@ static __rte_always_inline void

__mempool_generic_put(struct rte_mempool *mp, void * const

*obj_table,

Quoted 14 lines
Quoted 14 lines
Quoted 14 lines

unsigned int n, struct rte_mempool_cache
*cache) {

lib/mempool/rte_mempool.h +3 -1
-       void **cache_objs;
+       uint32_t *cache_objs;
+       void *base_value;
+       uint32_t i;
 
        /* increment stat now, adding in mempool always success */
        __MEMPOOL_STAT_ADD(mp, put_bulk, 1); @@ -1301,6 +1314,12

@@ __mempool_generic_put(struct rte_mempool *mp, void * const *obj_table,

        cache_objs = &cache->objs[cache->len];
Quoted 10 lines
Quoted 10 lines

lib/mempool/rte_mempool.h __mempool_generic_put(struct

Quoted 10 lines
lib/mempool/rte_mempool.h +6 -0
+       base_value = cache->local_cache_base_value;
+
+       uint64x2_t v_obj_table;
+       uint64x2_t v_base_value = vdupq_n_u64((uint64_t)base_value);
+       uint32x2_t v_cache_objs;
+
        /*
         * The cache follows the following algorithm
         *   1. Add the objects to the cache
@@ -1309,12 +1328,26 @@ __mempool_generic_put(struct

rte_mempool

Quoted 11 lines
Quoted 11 lines

*mp, void * const *obj_table,

lib/mempool/rte_mempool.h __mempool_generic_put(struct rte_mempool *mp, void * const *obj_table,

Quoted 9 lines
lib/mempool/rte_mempool.h +5 -1
         */
 
        /* Add elements back into the cache */
-       rte_memcpy(&cache_objs[0], obj_table, sizeof(void *) * n);
+
+#if defined __ARM_NEON
+       for (i = 0; i < (n & ~0x1); i+=2) {
+               v_obj_table = vld1q_u64((const uint64_t *)&obj_table[i]);
+               v_cache_objs = vqmovn_u64(vsubq_u64(v_obj_table,

v_base_value));

Quoted 4 lines
Quoted 4 lines

lib/mempool/rte_mempool.h __mempool_generic_put(struct rte_mempool *mp, void * const *obj_table,

Quoted 4 lines
lib/mempool/rte_mempool.h +4 -0
+               vst1_u32(cache_objs + i, v_cache_objs);
+       }
+       if (n & 0x1) {
+               cache_objs[i] = (uint32_t) RTE_PTR_DIFF(obj_table[i],

base_value);

Quoted 4 lines
Quoted 4 lines

lib/mempool/rte_mempool.h __mempool_generic_put(struct rte_mempool *mp, void * const *obj_table,

Quoted 4 lines
lib/mempool/rte_mempool.h +4 -0
+       }
+#else
+       for (i = 0; i < n; i++) {
+               cache_objs[i] = (uint32_t) RTE_PTR_DIFF(obj_table[i],

base_value);

Quoted 7 lines
Quoted 7 lines

lib/mempool/rte_mempool.h __mempool_generic_put(struct rte_mempool *mp, void * const *obj_table,

Quoted 7 lines
lib/mempool/rte_mempool.h +2 -1
+       }
+#endif
 
        cache->len += n;
 
        if (cache->len >= cache->flushthresh) {
-               rte_mempool_ops_enqueue_bulk(mp, &cache->objs[cache-
Quoted 7 lines

size],

Quoted 6 lines

lib/mempool/rte_mempool.h __mempool_generic_get(struct

Quoted 6 lines
lib/mempool/rte_mempool.h +2 -0
+               rte_mempool_ops_enqueue_bulk(mp, obj_table +
+ cache->len - cache->size,
                                cache->len - cache->size);
                cache->len = cache->size;
        }
@@ -1415,23 +1448,26 @@ __mempool_generic_get(struct

rte_mempool

Quoted 25 lines
Quoted 25 lines

*mp, void **obj_table,

Quoted 24 lines
lib/mempool/rte_mempool.h +5 -1
                      unsigned int n, struct rte_mempool_cache
 *cache) {
        int ret;
+       uint32_t i;
        uint32_t index, len;
-       void **cache_objs;
+       uint32_t *cache_objs;
 
        /* No cache provided or cannot be satisfied from cache */
        if (unlikely(cache == NULL || n >= cache->size))
                goto ring_dequeue;
 
+       void *base_value = cache->local_cache_base_value;
        cache_objs = cache->objs;
 
        /* Can this be satisfied from the cache? */
        if (cache->len < n) {
                /* No. Backfill the cache first, and then fill from it */
                uint32_t req = n + (cache->size - cache->len);
+               void *temp_objs[RTE_MEMPOOL_CACHE_MAX_SIZE * 3];
+ /**< Cache objects */
 
                /* How many do we require i.e. number to fill the

cache + the

Quoted 8 lines
Quoted 8 lines

request */

Quoted 7 lines

ret = rte_mempool_ops_dequeue_bulk(mp,

lib/mempool/rte_mempool.h +1 -1
-                       &cache->objs[cache->len], req);
+                       temp_objs, req);
                if (unlikely(ret < 0)) {
                        /*
                         * In the off chance that we are buffer

constrained, @@ -1442,12 +1478,32 @@

__mempool_generic_get(struct

Quoted 42 lines
Quoted 42 lines

rte_mempool *mp, void **obj_table,

lib/mempool/rte_mempool.h __mempool_generic_get(struct rte_mempool *mp, void **obj_table,

Quoted 7 lines
                        goto ring_dequeue;
                }
lib/mempool/rte_mempool.h +4 -0
+               len = cache->len;
+               for (i = 0; i < req; ++i, ++len) {
+                       cache_objs[len] = (uint32_t)
+ RTE_PTR_DIFF(temp_objs[i],

base_value);

Quoted 22 lines
lib/mempool/rte_mempool.h +17 -0
+               }
+
                cache->len += req;
        }
 
+       uint64x2_t v_obj_table;
+       uint64x2_t v_cache_objs;
+       uint64x2_t v_base_value =
+ vdupq_n_u64((uint64_t)base_value);
+
        /* Now fill in the response ... */
+#if defined __ARM_NEON
+       for (index = 0, len = cache->len - 1; index < (n & ~0x1); index+=2,
+                                               len-=2, obj_table+=2) {
+               v_cache_objs = vmovl_u32(vld1_u32(cache_objs + len - 1));
+               v_obj_table = vaddq_u64(v_cache_objs, v_base_value);
+               vst1q_u64((uint64_t *)obj_table, v_obj_table);
+       }
+       if (n & 0x1)
+               *obj_table = (void *) RTE_PTR_ADD(base_value,
+cache_objs[len]); #else
        for (index = 0, len = cache->len - 1; index < n; ++index,
Quoted 1 line

len--,

obj_table++)

Quoted 9 lines
lib/mempool/rte_mempool.h +2 -2
-               *obj_table = cache_objs[len];
+               *obj_table = (void *) RTE_PTR_ADD(base_value,
+cache_objs[len]); #endif
 
        cache->len -= n;
 
--

2.17.1

#5 lore raw
In reply to Jerin Jacob
Quoted 33 lines · Jerin Jacob
Quoted 30 lines · Honnappa Nagarahalli

<snip>

Quoted 27 lines
Quoted 9 lines · Dharmik Thakkar

Current mempool per core cache implementation is based on pointer For most architectures, each pointer consumes 64b Replace it with index-based implementation, where in each buffer is addressed by (pool address + index) It will reduce memory requirements

L3Fwd performance testing reveals minor improvements in the cache performance and no change in throughput

Quoted 7 lines

Micro-benchmarking the patch using mempool_perf_test shows significant improvement with majority of the test cases

Future plan involves replacing global pool's pointer-based implementation with index-based implementation

Sane idea. Like VPP, we tried to do this for rte_graph, but not observed much gain.
Since lcore cache is typically 512, maybe there is a gain on the mempool path. Also, Since you are enabling only for local cache, it is good as mempool drivers can work as-is.(i.e HW drivers works with 64bit) I think, getting more performance numbers for various cases may be the next step.

Quoted 3 lines
Quoted 1 line

The gain is not observed in terms of PPS improvement, but do see some improvements that PMUs indicate. This approach definitely results in savings in number of cache lines utilized.

OK. IMO, If PPS has regression then this path is not viable, else it may be OK.

Looks good then.

Quoted 248 lines
Quoted 248 lines
Quoted 248 lines

drivers/mempool/ring/rte_mempool_ring.c ring_alloc(struct rte_mempool *mp, uint32_t

Quoted 16 lines



---
 drivers/mempool/ring/rte_mempool_ring.c |  2 +-
 lib/mempool/rte_mempool.c               |  8 +++
 lib/mempool/rte_mempool.h               | 74 ++++++++++++++++++++++---
 3 files changed, 74 insertions(+), 10 deletions(-)
drivers/mempool/ring/rte_mempool_ring.c +0 -0
index b1f09ff28f4d..e55913e47f21 100644
@@ -101,7 +101,7 @@ ring_alloc(struct rte_mempool *mp, uint32_t

rg_flags)

lib/mempool/rte_mempool.c rte_mempool_populate_default(struct

Quoted 13 lines
drivers/mempool/ring/rte_mempool_ring.c +1 -1
                return -rte_errno;
 
        mp->pool_data = r;
-
+       mp->local_cache_base_addr = &r[1];
        return 0;
 }
 
lib/mempool/rte_mempool.c +0 -0
index 59a588425bd6..424bdb19c323 100644
@@ -480,6 +480,7 @@ rte_mempool_populate_default(struct

rte_mempool *mp)

lib/mempool/rte_mempool.c rte_mempool_populate_default(struct

Quoted 8 lines
lib/mempool/rte_mempool.c +1 -0
        int ret;
        bool need_iova_contig_obj;
        size_t max_alloc_size = SIZE_MAX;
+       unsigned lcore_id;
 
        ret = mempool_ops_alloc_once(mp);
        if (ret != 0)
@@ -600,6 +601,13 @@ rte_mempool_populate_default(struct

rte_mempool *mp)

Quoted 27 lines
lib/mempool/rte_mempool.c +7 -0
                }
        }
 
+       /* Init all default caches. */
+       if (mp->cache_size != 0) {
+               for (lcore_id = 0; lcore_id < RTE_MAX_LCORE; lcore_id++)
+                       mp->local_cache[lcore_id].local_cache_base_value =
+                               *(void **)mp->local_cache_base_addr;
+       }
+
        rte_mempool_trace_populate_default(mp);
        return mp->size;
 
lib/mempool/rte_mempool.h +2 -0
index 4235d6f0bf2b..545405c0d3ce 100644
@@ -51,6 +51,8 @@
 #include <rte_memcpy.h>
 #include <rte_common.h>
 
+#include <arm_neon.h>
+
 #include "rte_mempool_trace_fp.h"
 
 #ifdef __cplusplus

lib/mempool/rte_mempool.h struct rte_mempool_cache { · line 94

Quoted 2 lines
lib/mempool/rte_mempool.h +0 -0
@@ -91,11 +93,12 @@ struct rte_mempool_cache {
        uint32_t size;        /**< Size of the cache */
        uint32_t flushthresh; /**< Threshold before we flush excess elements

*/

lib/mempool/rte_mempool.h struct rte_mempool_cache {

Quoted 8 lines
lib/mempool/rte_mempool.h +2 -1
        uint32_t len;         /**< Current cache count */
+       void *local_cache_base_value; /**< Base value to calculate
+ indices */
        /*
         * Cache is allocated to this size to allow it to overflow in certain
         * cases to avoid needless emptying of cache.
         */
-       void *objs[RTE_MEMPOOL_CACHE_MAX_SIZE * 3]; /**< Cache objects

*/

Quoted 21 lines
lib/mempool/rte_mempool.h +2 -1
+       uint32_t objs[RTE_MEMPOOL_CACHE_MAX_SIZE * 3]; /**< Cache
+ objects */
 } __rte_cache_aligned;
 
 /**
@@ -172,7 +175,6 @@ struct rte_mempool_objtlr {
  * A list of memory where objects are stored
  */
 STAILQ_HEAD(rte_mempool_memhdr_list, rte_mempool_memhdr);
-
 /**
  * Callback used to free a memory chunk
  */
@@ -244,6 +246,7 @@ struct rte_mempool {
        int32_t ops_index;
 
        struct rte_mempool_cache *local_cache; /**< Per-lcore local

cache */
+ void *local_cache_base_addr; /**< Reference to the base value
+ */

Quoted 3 lines

uint32_t populated_size; /**< Number of populated objects. */
struct rte_mempool_objhdr_list elt_list; /**< List of objects
in pool */ @@ -1269,7 +1272,15 @@ rte_mempool_cache_flush(struct

rte_mempool_cache *cache,

lib/mempool/rte_mempool.h __mempool_generic_put(struct rte_mempool

Quoted 41 lines
        if (cache == NULL || cache->len == 0)
                return;
        rte_mempool_trace_cache_flush(cache, mp);
lib/mempool/rte_mempool.h +12 -2
-       rte_mempool_ops_enqueue_bulk(mp, cache->objs, cache->len);
+
+       unsigned int i;
+       unsigned int cache_len = cache->len;
+       void *obj_table[RTE_MEMPOOL_CACHE_MAX_SIZE * 3];
+       void *base_value = cache->local_cache_base_value;
+       uint32_t *cache_objs = cache->objs;
+       for (i = 0; i < cache_len; i++)
+               obj_table[i] = (void *) RTE_PTR_ADD(base_value, cache_objs[i]);
+       rte_mempool_ops_enqueue_bulk(mp, obj_table, cache->len);
        cache->len = 0;
 }
@@ -1289,7 +1300,9 @@ static __rte_always_inline void
 __mempool_generic_put(struct rte_mempool *mp, void * const *obj_table,
                      unsigned int n, struct rte_mempool_cache *cache)
 {
-       void **cache_objs;
+       uint32_t *cache_objs;
+       void *base_value;
+       uint32_t i;
 
        /* increment stat now, adding in mempool always success */
        __MEMPOOL_STAT_ADD(mp, put_bulk, 1); @@ -1301,6 +1314,12 @@

__mempool_generic_put(struct rte_mempool *mp, void * const *obj_table,

        cache_objs = &cache->objs[cache->len];
lib/mempool/rte_mempool.h +6 -0
+       base_value = cache->local_cache_base_value;
+
+       uint64x2_t v_obj_table;
+       uint64x2_t v_base_value = vdupq_n_u64((uint64_t)base_value);
+       uint32x2_t v_cache_objs;
+
        /*
         * The cache follows the following algorithm
         *   1. Add the objects to the cache
@@ -1309,12 +1328,26 @@ __mempool_generic_put(struct rte_mempool

*mp, void * const *obj_table,

lib/mempool/rte_mempool.h __mempool_generic_put(struct rte_mempool *mp, void * const *obj_table,

Quoted 9 lines
lib/mempool/rte_mempool.h +5 -1
         */
 
        /* Add elements back into the cache */
-       rte_memcpy(&cache_objs[0], obj_table, sizeof(void *) * n);
+
+#if defined __ARM_NEON
+       for (i = 0; i < (n & ~0x1); i+=2) {
+               v_obj_table = vld1q_u64((const uint64_t *)&obj_table[i]);
+               v_cache_objs = vqmovn_u64(vsubq_u64(v_obj_table,

v_base_value));

lib/mempool/rte_mempool.h __mempool_generic_get(struct rte_mempool

Quoted 21 lines
lib/mempool/rte_mempool.h +12 -1
+               vst1_u32(cache_objs + i, v_cache_objs);
+       }
+       if (n & 0x1) {
+               cache_objs[i] = (uint32_t) RTE_PTR_DIFF(obj_table[i], base_value);
+       }
+#else
+       for (i = 0; i < n; i++) {
+               cache_objs[i] = (uint32_t) RTE_PTR_DIFF(obj_table[i], base_value);
+       }
+#endif
 
        cache->len += n;
 
        if (cache->len >= cache->flushthresh) {
-               rte_mempool_ops_enqueue_bulk(mp, &cache->objs[cache->size],
+               rte_mempool_ops_enqueue_bulk(mp, obj_table +
+ cache->len - cache->size,
                                cache->len - cache->size);
                cache->len = cache->size;
        }
@@ -1415,23 +1448,26 @@ __mempool_generic_get(struct rte_mempool

*mp, void **obj_table,

Quoted 13 lines
lib/mempool/rte_mempool.h +3 -1
                      unsigned int n, struct rte_mempool_cache *cache)
 {
        int ret;
+       uint32_t i;
        uint32_t index, len;
-       void **cache_objs;
+       uint32_t *cache_objs;
 
        /* No cache provided or cannot be satisfied from cache */
        if (unlikely(cache == NULL || n >= cache->size))
                goto ring_dequeue;
 
+       void *base_value = cache->local_cache_base_value;

lib/mempool/rte_mempool.h __mempool_generic_get(struct rte_mempool *mp, void **obj_table,

Quoted 10 lines
lib/mempool/rte_mempool.h +2 -0
        cache_objs = cache->objs;
 
        /* Can this be satisfied from the cache? */
        if (cache->len < n) {
                /* No. Backfill the cache first, and then fill from it */
                uint32_t req = n + (cache->size - cache->len);
+               void *temp_objs[RTE_MEMPOOL_CACHE_MAX_SIZE * 3]; /**<
+ Cache objects */
 
                /* How many do we require i.e. number to fill the cache + the

request */

Quoted 7 lines
lib/mempool/rte_mempool.h +1 -1
                ret = rte_mempool_ops_dequeue_bulk(mp,
-                       &cache->objs[cache->len], req);
+                       temp_objs, req);
                if (unlikely(ret < 0)) {
                        /*
                         * In the off chance that we are buffer

constrained, @@ -1442,12 +1478,32 @@ __mempool_generic_get(struct

rte_mempool *mp, void **obj_table,

lib/mempool/rte_mempool.h __mempool_generic_get(struct rte_mempool *mp, void **obj_table,

Quoted 6 lines
                        goto ring_dequeue;
                }
lib/mempool/rte_mempool.h +3 -0
+               len = cache->len;
+               for (i = 0; i < req; ++i, ++len) {
+                       cache_objs[len] = (uint32_t) RTE_PTR_DIFF(temp_objs[i],

base_value);

Quoted 11 lines
lib/mempool/rte_mempool.h +7 -0
+               }
+
                cache->len += req;
        }
 
+       uint64x2_t v_obj_table;
+       uint64x2_t v_cache_objs;
+       uint64x2_t v_base_value = vdupq_n_u64((uint64_t)base_value);
+
        /* Now fill in the response ... */
+#if defined __ARM_NEON

lib/mempool/rte_mempool.h __mempool_generic_get(struct rte_mempool *mp, void **obj_table,

Quoted 10 lines
lib/mempool/rte_mempool.h +9 -0
+       for (index = 0, len = cache->len - 1; index < (n & ~0x1); index+=2,
+                                               len-=2, obj_table+=2) {
+               v_cache_objs = vmovl_u32(vld1_u32(cache_objs + len - 1));
+               v_obj_table = vaddq_u64(v_cache_objs, v_base_value);
+               vst1q_u64((uint64_t *)obj_table, v_obj_table);
+       }
+       if (n & 0x1)
+               *obj_table = (void *) RTE_PTR_ADD(base_value,
+cache_objs[len]); #else
        for (index = 0, len = cache->len - 1; index < n; ++index, len--,

obj_table++)

Quoted 9 lines
lib/mempool/rte_mempool.h +2 -2
-               *obj_table = cache_objs[len];
+               *obj_table = (void *) RTE_PTR_ADD(base_value,
+cache_objs[len]); #endif
 
        cache->len -= n;
 
--

2.17.1

#6 lore raw
In reply to Dharmik Thakkar
Quoted 4 lines

Current mempool per core cache implementation is based on pointer For most architectures, each pointer consumes 64b Replace it with index-based implementation, where in each buffer is addressed by (pool address + index)

I don't think it is going to work:
On 64-bit systems difference between pool address and it's elem address could be bigger than 4GB.

Quoted 234 lines

It will reduce memory requirements

L3Fwd performance testing reveals minor improvements in the cache performance and no change in throughput

Micro-benchmarking the patch using mempool_perf_test shows significant improvement with majority of the test cases

Future plan involves replacing global pool's pointer-based implementation with index-based implementation

---
 drivers/mempool/ring/rte_mempool_ring.c |  2 +-
 lib/mempool/rte_mempool.c               |  8 +++
 lib/mempool/rte_mempool.h               | 74 ++++++++++++++++++++++---
 3 files changed, 74 insertions(+), 10 deletions(-)
drivers/mempool/ring/rte_mempool_ring.c +1 -1
index b1f09ff28f4d..e55913e47f21 100644
@@ -101,7 +101,7 @@ ring_alloc(struct rte_mempool *mp, uint32_t rg_flags)
 		return -rte_errno;
 
 	mp->pool_data = r;
-
+	mp->local_cache_base_addr = &r[1];
 	return 0;
 }
 
lib/mempool/rte_mempool.c +8 -0
index 59a588425bd6..424bdb19c323 100644
@@ -480,6 +480,7 @@ rte_mempool_populate_default(struct rte_mempool *mp)
 	int ret;
 	bool need_iova_contig_obj;
 	size_t max_alloc_size = SIZE_MAX;
+	unsigned lcore_id;
 
 	ret = mempool_ops_alloc_once(mp);
 	if (ret != 0)
@@ -600,6 +601,13 @@ rte_mempool_populate_default(struct rte_mempool *mp)
 		}
 	}
 
+	/* Init all default caches. */
+	if (mp->cache_size != 0) {
+		for (lcore_id = 0; lcore_id < RTE_MAX_LCORE; lcore_id++)
+			mp->local_cache[lcore_id].local_cache_base_value =
+				*(void **)mp->local_cache_base_addr;
+	}
+
 	rte_mempool_trace_populate_default(mp);
 	return mp->size;
 
lib/mempool/rte_mempool.h +65 -10
index 4235d6f0bf2b..545405c0d3ce 100644
@@ -51,6 +51,8 @@
 #include <rte_memcpy.h>
 #include <rte_common.h>
 
+#include <arm_neon.h>
+
 #include "rte_mempool_trace_fp.h"
 
 #ifdef __cplusplus
@@ -91,11 +93,12 @@ struct rte_mempool_cache {
 	uint32_t size;	      /**< Size of the cache */
 	uint32_t flushthresh; /**< Threshold before we flush excess elements */
 	uint32_t len;	      /**< Current cache count */
+	void *local_cache_base_value; /**< Base value to calculate indices */
 	/*
 	 * Cache is allocated to this size to allow it to overflow in certain
 	 * cases to avoid needless emptying of cache.
 	 */
-	void *objs[RTE_MEMPOOL_CACHE_MAX_SIZE * 3]; /**< Cache objects */
+	uint32_t objs[RTE_MEMPOOL_CACHE_MAX_SIZE * 3]; /**< Cache objects */
 } __rte_cache_aligned;
 
 /**
@@ -172,7 +175,6 @@ struct rte_mempool_objtlr {
  * A list of memory where objects are stored
  */
 STAILQ_HEAD(rte_mempool_memhdr_list, rte_mempool_memhdr);
-
 /**
  * Callback used to free a memory chunk
  */
@@ -244,6 +246,7 @@ struct rte_mempool {
 	int32_t ops_index;
 
 	struct rte_mempool_cache *local_cache; /**< Per-lcore local cache */
+	void *local_cache_base_addr; /**< Reference to the base value */
 
 	uint32_t populated_size;         /**< Number of populated objects. */
 	struct rte_mempool_objhdr_list elt_list; /**< List of objects in pool */
@@ -1269,7 +1272,15 @@ rte_mempool_cache_flush(struct rte_mempool_cache *cache,
 	if (cache == NULL || cache->len == 0)
 		return;
 	rte_mempool_trace_cache_flush(cache, mp);
-	rte_mempool_ops_enqueue_bulk(mp, cache->objs, cache->len);
+
+	unsigned int i;
+	unsigned int cache_len = cache->len;
+	void *obj_table[RTE_MEMPOOL_CACHE_MAX_SIZE * 3];
+	void *base_value = cache->local_cache_base_value;
+	uint32_t *cache_objs = cache->objs;
+	for (i = 0; i < cache_len; i++)
+		obj_table[i] = (void *) RTE_PTR_ADD(base_value, cache_objs[i]);
+	rte_mempool_ops_enqueue_bulk(mp, obj_table, cache->len);
 	cache->len = 0;
 }
 
@@ -1289,7 +1300,9 @@ static __rte_always_inline void
 __mempool_generic_put(struct rte_mempool *mp, void * const *obj_table,
 		      unsigned int n, struct rte_mempool_cache *cache)
 {
-	void **cache_objs;
+	uint32_t *cache_objs;
+	void *base_value;
+	uint32_t i;
 
 	/* increment stat now, adding in mempool always success */
 	__MEMPOOL_STAT_ADD(mp, put_bulk, 1);
@@ -1301,6 +1314,12 @@ __mempool_generic_put(struct rte_mempool *mp, void * const *obj_table,
 
 	cache_objs = &cache->objs[cache->len];
 
+	base_value = cache->local_cache_base_value;
+
+	uint64x2_t v_obj_table;
+	uint64x2_t v_base_value = vdupq_n_u64((uint64_t)base_value);
+	uint32x2_t v_cache_objs;
+
 	/*
 	 * The cache follows the following algorithm
 	 *   1. Add the objects to the cache
@@ -1309,12 +1328,26 @@ __mempool_generic_put(struct rte_mempool *mp, void * const *obj_table,
 	 */
 
 	/* Add elements back into the cache */
-	rte_memcpy(&cache_objs[0], obj_table, sizeof(void *) * n);
+
+#if defined __ARM_NEON
+	for (i = 0; i < (n & ~0x1); i+=2) {
+		v_obj_table = vld1q_u64((const uint64_t *)&obj_table[i]);
+		v_cache_objs = vqmovn_u64(vsubq_u64(v_obj_table, v_base_value));
+		vst1_u32(cache_objs + i, v_cache_objs);
+	}
+	if (n & 0x1) {
+		cache_objs[i] = (uint32_t) RTE_PTR_DIFF(obj_table[i], base_value);
+	}
+#else
+	for (i = 0; i < n; i++) {
+		cache_objs[i] = (uint32_t) RTE_PTR_DIFF(obj_table[i], base_value);
+	}
+#endif
 
 	cache->len += n;
 
 	if (cache->len >= cache->flushthresh) {
-		rte_mempool_ops_enqueue_bulk(mp, &cache->objs[cache->size],
+		rte_mempool_ops_enqueue_bulk(mp, obj_table + cache->len - cache->size,
 				cache->len - cache->size);
 		cache->len = cache->size;
 	}
@@ -1415,23 +1448,26 @@ __mempool_generic_get(struct rte_mempool *mp, void **obj_table,
 		      unsigned int n, struct rte_mempool_cache *cache)
 {
 	int ret;
+	uint32_t i;
 	uint32_t index, len;
-	void **cache_objs;
+	uint32_t *cache_objs;
 
 	/* No cache provided or cannot be satisfied from cache */
 	if (unlikely(cache == NULL || n >= cache->size))
 		goto ring_dequeue;
 
+	void *base_value = cache->local_cache_base_value;
 	cache_objs = cache->objs;
 
 	/* Can this be satisfied from the cache? */
 	if (cache->len < n) {
 		/* No. Backfill the cache first, and then fill from it */
 		uint32_t req = n + (cache->size - cache->len);
+		void *temp_objs[RTE_MEMPOOL_CACHE_MAX_SIZE * 3]; /**< Cache objects */
 
 		/* How many do we require i.e. number to fill the cache + the request */
 		ret = rte_mempool_ops_dequeue_bulk(mp,
-			&cache->objs[cache->len], req);
+			temp_objs, req);
 		if (unlikely(ret < 0)) {
 			/*
 			 * In the off chance that we are buffer constrained,
@@ -1442,12 +1478,32 @@ __mempool_generic_get(struct rte_mempool *mp, void **obj_table,
 			goto ring_dequeue;
 		}
 
+		len = cache->len;
+		for (i = 0; i < req; ++i, ++len) {
+			cache_objs[len] = (uint32_t) RTE_PTR_DIFF(temp_objs[i], base_value);
+		}
+
 		cache->len += req;
 	}
 
+	uint64x2_t v_obj_table;
+	uint64x2_t v_cache_objs;
+	uint64x2_t v_base_value = vdupq_n_u64((uint64_t)base_value);
+
 	/* Now fill in the response ... */
+#if defined __ARM_NEON
+	for (index = 0, len = cache->len - 1; index < (n & ~0x1); index+=2,
+						len-=2, obj_table+=2) {
+		v_cache_objs = vmovl_u32(vld1_u32(cache_objs + len - 1));
+		v_obj_table = vaddq_u64(v_cache_objs, v_base_value);
+		vst1q_u64((uint64_t *)obj_table, v_obj_table);
+	}
+	if (n & 0x1)
+		*obj_table = (void *) RTE_PTR_ADD(base_value, cache_objs[len]);
+#else
 	for (index = 0, len = cache->len - 1; index < n; ++index, len--, obj_table++)
-		*obj_table = cache_objs[len];
+		*obj_table = (void *) RTE_PTR_ADD(base_value, cache_objs[len]);
+#endif
 
 	cache->len -= n;
 
--

2.17.1

#7 lore raw

<snip>

Quoted 9 lines
Quoted 5 lines

Current mempool per core cache implementation is based on pointer For most architectures, each pointer consumes 64b Replace it with index-based implementation, where in each buffer is addressed by (pool address + index)

I don't think it is going to work:
On 64-bit systems difference between pool address and it's elem address could be bigger than 4GB.

Are you talking about a case where the memory pool size is more than 4GB?

Quoted 262 lines

drivers/mempool/ring/rte_mempool_ring.c ring_alloc(struct rte_mempool *mp, uint32_t

Quoted 25 lines

It will reduce memory requirements

L3Fwd performance testing reveals minor improvements in the cache performance and no change in throughput

Micro-benchmarking the patch using mempool_perf_test shows significant improvement with majority of the test cases

Future plan involves replacing global pool's pointer-based implementation with index-based implementation

---
 drivers/mempool/ring/rte_mempool_ring.c |  2 +-
 lib/mempool/rte_mempool.c               |  8 +++
 lib/mempool/rte_mempool.h               | 74 ++++++++++++++++++++++---
 3 files changed, 74 insertions(+), 10 deletions(-)
drivers/mempool/ring/rte_mempool_ring.c +0 -0
index b1f09ff28f4d..e55913e47f21 100644
@@ -101,7 +101,7 @@ ring_alloc(struct rte_mempool *mp, uint32_t

rg_flags)

lib/mempool/rte_mempool.c rte_mempool_populate_default(struct

Quoted 13 lines
drivers/mempool/ring/rte_mempool_ring.c +1 -1
 		return -rte_errno;
 
 	mp->pool_data = r;
-
+	mp->local_cache_base_addr = &r[1];
 	return 0;
 }
 
lib/mempool/rte_mempool.c +0 -0
index 59a588425bd6..424bdb19c323 100644
@@ -480,6 +480,7 @@ rte_mempool_populate_default(struct

rte_mempool *mp)

lib/mempool/rte_mempool.c rte_mempool_populate_default(struct

Quoted 8 lines
lib/mempool/rte_mempool.c +1 -0
 	int ret;
 	bool need_iova_contig_obj;
 	size_t max_alloc_size = SIZE_MAX;
+	unsigned lcore_id;
 
 	ret = mempool_ops_alloc_once(mp);
 	if (ret != 0)
@@ -600,6 +601,13 @@ rte_mempool_populate_default(struct

rte_mempool *mp)

Quoted 27 lines
lib/mempool/rte_mempool.c +7 -0
 		}
 	}
 
+	/* Init all default caches. */
+	if (mp->cache_size != 0) {
+		for (lcore_id = 0; lcore_id < RTE_MAX_LCORE; lcore_id++)
+			mp->local_cache[lcore_id].local_cache_base_value =
+				*(void **)mp->local_cache_base_addr;
+	}
+
 	rte_mempool_trace_populate_default(mp);
 	return mp->size;
 
lib/mempool/rte_mempool.h +2 -0
index 4235d6f0bf2b..545405c0d3ce 100644
@@ -51,6 +51,8 @@
 #include <rte_memcpy.h>
 #include <rte_common.h>
 
+#include <arm_neon.h>
+
 #include "rte_mempool_trace_fp.h"
 
 #ifdef __cplusplus

lib/mempool/rte_mempool.h struct rte_mempool_cache { · line 94

Quoted 2 lines
lib/mempool/rte_mempool.h +0 -0
@@ -91,11 +93,12 @@ struct rte_mempool_cache {
 	uint32_t size;	      /**< Size of the cache */
 	uint32_t flushthresh; /**< Threshold before we flush excess elements

*/

lib/mempool/rte_mempool.h struct rte_mempool_cache {

Quoted 8 lines
lib/mempool/rte_mempool.h +2 -1
 	uint32_t len;	      /**< Current cache count */
+	void *local_cache_base_value; /**< Base value to calculate indices
+*/
 	/*
 	 * Cache is allocated to this size to allow it to overflow in certain
 	 * cases to avoid needless emptying of cache.
 	 */
-	void *objs[RTE_MEMPOOL_CACHE_MAX_SIZE * 3]; /**< Cache

objects */

lib/mempool/rte_mempool.h struct rte_mempool_cache { · line 102

Quoted 1 line
lib/mempool/rte_mempool.h +1 -0
+	uint32_t objs[RTE_MEMPOOL_CACHE_MAX_SIZE * 3]; /**< Cache

objects */

Quoted 19 lines
lib/mempool/rte_mempool.h +1 -1
 } __rte_cache_aligned;
 
 /**
@@ -172,7 +175,6 @@ struct rte_mempool_objtlr {
  * A list of memory where objects are stored
  */
 STAILQ_HEAD(rte_mempool_memhdr_list, rte_mempool_memhdr);
-
 /**
  * Callback used to free a memory chunk
  */
@@ -244,6 +246,7 @@ struct rte_mempool {
 	int32_t ops_index;
 
 	struct rte_mempool_cache *local_cache; /**< Per-lcore local cache */
+	void *local_cache_base_addr; /**< Reference to the base value */
 
 	uint32_t populated_size;         /**< Number of populated objects. */
 	struct rte_mempool_objhdr_list elt_list; /**< List of objects in
Quoted 1 line

pool */ @@ -1269,7 +1272,15 @@ rte_mempool_cache_flush(struct

rte_mempool_cache *cache,

lib/mempool/rte_mempool.h rte_mempool_cache_flush(struct rte_mempool_cache *cache,

Quoted 12 lines
lib/mempool/rte_mempool.h +8 -1
 	if (cache == NULL || cache->len == 0)
 		return;
 	rte_mempool_trace_cache_flush(cache, mp);
-	rte_mempool_ops_enqueue_bulk(mp, cache->objs, cache->len);
+
+	unsigned int i;
+	unsigned int cache_len = cache->len;
+	void *obj_table[RTE_MEMPOOL_CACHE_MAX_SIZE * 3];
+	void *base_value = cache->local_cache_base_value;
+	uint32_t *cache_objs = cache->objs;
+	for (i = 0; i < cache_len; i++)
+		obj_table[i] = (void *) RTE_PTR_ADD(base_value,

cache_objs[i]);

Quoted 5 lines
lib/mempool/rte_mempool.h +1 -0
+	rte_mempool_ops_enqueue_bulk(mp, obj_table, cache->len);
 	cache->len = 0;
 }

lib/mempool/rte_mempool.h static __rte_always_inline void · line 1307

Quoted 9 lines
lib/mempool/rte_mempool.h +3 -1
@@ -1289,7 +1300,9 @@ static __rte_always_inline void
 __mempool_generic_put(struct rte_mempool *mp, void * const *obj_table,
 		      unsigned int n, struct rte_mempool_cache *cache)  {
-	void **cache_objs;
+	uint32_t *cache_objs;
+	void *base_value;
+	uint32_t i;
 
 	/* increment stat now, adding in mempool always success */
 	__MEMPOOL_STAT_ADD(mp, put_bulk, 1); @@ -1301,6 +1314,12

@@

lib/mempool/rte_mempool.h __mempool_generic_put(struct rte_mempool

Quoted 14 lines
lib/mempool/rte_mempool.h +0 -0
 __mempool_generic_put(struct rte_mempool *mp, void * const *obj_table,
lib/mempool/rte_mempool.h +6 -0
 	cache_objs = &cache->objs[cache->len];
 
+	base_value = cache->local_cache_base_value;
+
+	uint64x2_t v_obj_table;
+	uint64x2_t v_base_value = vdupq_n_u64((uint64_t)base_value);
+	uint32x2_t v_cache_objs;
+
 	/*
 	 * The cache follows the following algorithm
 	 *   1. Add the objects to the cache
@@ -1309,12 +1328,26 @@ __mempool_generic_put(struct rte_mempool

*mp, void * const *obj_table,

lib/mempool/rte_mempool.h __mempool_generic_put(struct rte_mempool *mp, void * const *obj_table,

Quoted 9 lines
lib/mempool/rte_mempool.h +5 -1
 	 */
 
 	/* Add elements back into the cache */
-	rte_memcpy(&cache_objs[0], obj_table, sizeof(void *) * n);
+
+#if defined __ARM_NEON
+	for (i = 0; i < (n & ~0x1); i+=2) {
+		v_obj_table = vld1q_u64((const uint64_t *)&obj_table[i]);
+		v_cache_objs = vqmovn_u64(vsubq_u64(v_obj_table,

v_base_value));

lib/mempool/rte_mempool.h __mempool_generic_put(struct rte_mempool *mp, void * const *obj_table,

Quoted 4 lines
lib/mempool/rte_mempool.h +4 -0
+		vst1_u32(cache_objs + i, v_cache_objs);
+	}
+	if (n & 0x1) {
+		cache_objs[i] = (uint32_t) RTE_PTR_DIFF(obj_table[i],

base_value);

lib/mempool/rte_mempool.h __mempool_generic_put(struct rte_mempool *mp, void * const *obj_table,

Quoted 4 lines
lib/mempool/rte_mempool.h +4 -0
+	}
+#else
+	for (i = 0; i < n; i++) {
+		cache_objs[i] = (uint32_t) RTE_PTR_DIFF(obj_table[i],

base_value);

lib/mempool/rte_mempool.h __mempool_generic_put(struct rte_mempool *mp, void * const *obj_table,

Quoted 9 lines
lib/mempool/rte_mempool.h +3 -1
+	}
+#endif
 
 	cache->len += n;
 
 	if (cache->len >= cache->flushthresh) {
-		rte_mempool_ops_enqueue_bulk(mp, &cache->objs[cache-
 size],
+		rte_mempool_ops_enqueue_bulk(mp, obj_table + cache->len

-

lib/mempool/rte_mempool.h __mempool_generic_get(struct rte_mempool

Quoted 5 lines
lib/mempool/rte_mempool.h +1 -0
+cache->size,
 				cache->len - cache->size);
 		cache->len = cache->size;
 	}
@@ -1415,23 +1448,26 @@ __mempool_generic_get(struct rte_mempool

*mp, void **obj_table,

Quoted 9 lines
lib/mempool/rte_mempool.h +2 -1
 		      unsigned int n, struct rte_mempool_cache *cache)  {
 	int ret;
+	uint32_t i;
 	uint32_t index, len;
-	void **cache_objs;
+	uint32_t *cache_objs;
 
 	/* No cache provided or cannot be satisfied from cache */
 	if (unlikely(cache == NULL || n >= cache->size))

lib/mempool/rte_mempool.h __mempool_generic_get(struct rte_mempool *mp, void **obj_table,

Quoted 10 lines
lib/mempool/rte_mempool.h +2 -0
 		goto ring_dequeue;
 
+	void *base_value = cache->local_cache_base_value;
 	cache_objs = cache->objs;
 
 	/* Can this be satisfied from the cache? */
 	if (cache->len < n) {
 		/* No. Backfill the cache first, and then fill from it */
 		uint32_t req = n + (cache->size - cache->len);
+		void *temp_objs[RTE_MEMPOOL_CACHE_MAX_SIZE * 3];

/**< Cache objects

lib/mempool/rte_mempool.h __mempool_generic_get(struct rte_mempool · line 1468

Quoted 3 lines
lib/mempool/rte_mempool.h +1 -0
+*/
 
 		/* How many do we require i.e. number to fill the cache + the

request */

lib/mempool/rte_mempool.h __mempool_generic_get(struct rte_mempool *mp, void **obj_table, · line 1473

Quoted 6 lines
lib/mempool/rte_mempool.h +1 -1
 		ret = rte_mempool_ops_dequeue_bulk(mp,
-			&cache->objs[cache->len], req);
+			temp_objs, req);
 		if (unlikely(ret < 0)) {
 			/*
 			 * In the off chance that we are buffer constrained,

@@ -1442,12

Quoted 1 line

+1478,32 @@ __mempool_generic_get(struct rte_mempool *mp, void

**obj_table,

lib/mempool/rte_mempool.h __mempool_generic_get(struct rte_mempool *mp, void **obj_table,

Quoted 6 lines
lib/mempool/rte_mempool.h +3 -0
 			goto ring_dequeue;
 		}
 
+		len = cache->len;
+		for (i = 0; i < req; ++i, ++len) {
+			cache_objs[len] = (uint32_t)

RTE_PTR_DIFF(temp_objs[i], base_value);

Quoted 9 lines
lib/mempool/rte_mempool.h +6 -0
+		}
+
 		cache->len += req;
 	}
 
+	uint64x2_t v_obj_table;
+	uint64x2_t v_cache_objs;
+	uint64x2_t v_base_value = vdupq_n_u64((uint64_t)base_value);
+

lib/mempool/rte_mempool.h __mempool_generic_get(struct rte_mempool *mp, void **obj_table,

Quoted 10 lines
lib/mempool/rte_mempool.h +9 -0
 	/* Now fill in the response ... */
+#if defined __ARM_NEON
+	for (index = 0, len = cache->len - 1; index < (n & ~0x1); index+=2,
+						len-=2, obj_table+=2) {
+		v_cache_objs = vmovl_u32(vld1_u32(cache_objs + len - 1));
+		v_obj_table = vaddq_u64(v_cache_objs, v_base_value);
+		vst1q_u64((uint64_t *)obj_table, v_obj_table);
+	}
+	if (n & 0x1)
+		*obj_table = (void *) RTE_PTR_ADD(base_value,

cache_objs[len]);

lib/mempool/rte_mempool.h

Quoted 2 lines
lib/mempool/rte_mempool.h +1 -0
+#else
 	for (index = 0, len = cache->len - 1; index < n; ++index, len--,

obj_table++)

lib/mempool/rte_mempool.h

Quoted 2 lines
lib/mempool/rte_mempool.h +1 -1
-		*obj_table = cache_objs[len];
+		*obj_table = (void *) RTE_PTR_ADD(base_value,

cache_objs[len]);

Quoted 6 lines
lib/mempool/rte_mempool.h +1 -1
+#endif
 
 	cache->len -= n;
 
--

2.17.1

#8 lore raw
Quoted 10 lines
Quoted 9 lines
Quoted 5 lines

Current mempool per core cache implementation is based on pointer For most architectures, each pointer consumes 64b Replace it with index-based implementation, where in each buffer is addressed by (pool address + index)

I don't think it is going to work:
On 64-bit systems difference between pool address and it's elem address could be bigger than 4GB.

Are you talking about a case where the memory pool size is more than 4GB?

That is one possible scenario.
Another possibility - user populates mempool himself with some external memory by calling rte_mempool_populate_iova() directly.
I suppose such situation can even occur even with normal rte_mempool_create(), though it should be a really rare one.

Quoted 263 lines
Quoted 263 lines

drivers/mempool/ring/rte_mempool_ring.c ring_alloc(struct rte_mempool *mp, uint32_t

Quoted 26 lines

It will reduce memory requirements

L3Fwd performance testing reveals minor improvements in the cache performance and no change in throughput

Micro-benchmarking the patch using mempool_perf_test shows significant improvement with majority of the test cases

Future plan involves replacing global pool's pointer-based implementation with index-based implementation

---
 drivers/mempool/ring/rte_mempool_ring.c |  2 +-
 lib/mempool/rte_mempool.c               |  8 +++
 lib/mempool/rte_mempool.h               | 74 ++++++++++++++++++++++---
 3 files changed, 74 insertions(+), 10 deletions(-)
drivers/mempool/ring/rte_mempool_ring.c +0 -0
index b1f09ff28f4d..e55913e47f21 100644
@@ -101,7 +101,7 @@ ring_alloc(struct rte_mempool *mp, uint32_t

rg_flags)

lib/mempool/rte_mempool.c rte_mempool_populate_default(struct

Quoted 13 lines
drivers/mempool/ring/rte_mempool_ring.c +1 -1
 		return -rte_errno;
 
 	mp->pool_data = r;
-
+	mp->local_cache_base_addr = &r[1];
 	return 0;
 }
 
lib/mempool/rte_mempool.c +0 -0
index 59a588425bd6..424bdb19c323 100644
@@ -480,6 +480,7 @@ rte_mempool_populate_default(struct

rte_mempool *mp)

lib/mempool/rte_mempool.c rte_mempool_populate_default(struct

Quoted 8 lines
lib/mempool/rte_mempool.c +1 -0
 	int ret;
 	bool need_iova_contig_obj;
 	size_t max_alloc_size = SIZE_MAX;
+	unsigned lcore_id;
 
 	ret = mempool_ops_alloc_once(mp);
 	if (ret != 0)
@@ -600,6 +601,13 @@ rte_mempool_populate_default(struct

rte_mempool *mp)

Quoted 27 lines
lib/mempool/rte_mempool.c +7 -0
 		}
 	}
 
+	/* Init all default caches. */
+	if (mp->cache_size != 0) {
+		for (lcore_id = 0; lcore_id < RTE_MAX_LCORE; lcore_id++)
+			mp->local_cache[lcore_id].local_cache_base_value =
+				*(void **)mp->local_cache_base_addr;
+	}
+
 	rte_mempool_trace_populate_default(mp);
 	return mp->size;
 
lib/mempool/rte_mempool.h +2 -0
index 4235d6f0bf2b..545405c0d3ce 100644
@@ -51,6 +51,8 @@
 #include <rte_memcpy.h>
 #include <rte_common.h>
 
+#include <arm_neon.h>
+
 #include "rte_mempool_trace_fp.h"
 
 #ifdef __cplusplus

lib/mempool/rte_mempool.h struct rte_mempool_cache { · line 94

Quoted 2 lines
lib/mempool/rte_mempool.h +0 -0
@@ -91,11 +93,12 @@ struct rte_mempool_cache {
 	uint32_t size;	      /**< Size of the cache */
 	uint32_t flushthresh; /**< Threshold before we flush excess elements

*/

lib/mempool/rte_mempool.h struct rte_mempool_cache {

Quoted 8 lines
lib/mempool/rte_mempool.h +2 -1
 	uint32_t len;	      /**< Current cache count */
+	void *local_cache_base_value; /**< Base value to calculate indices
+*/
 	/*
 	 * Cache is allocated to this size to allow it to overflow in certain
 	 * cases to avoid needless emptying of cache.
 	 */
-	void *objs[RTE_MEMPOOL_CACHE_MAX_SIZE * 3]; /**< Cache

objects */

lib/mempool/rte_mempool.h struct rte_mempool_cache { · line 102

Quoted 1 line
lib/mempool/rte_mempool.h +1 -0
+	uint32_t objs[RTE_MEMPOOL_CACHE_MAX_SIZE * 3]; /**< Cache

objects */

Quoted 19 lines
lib/mempool/rte_mempool.h +1 -1
 } __rte_cache_aligned;
 
 /**
@@ -172,7 +175,6 @@ struct rte_mempool_objtlr {
  * A list of memory where objects are stored
  */
 STAILQ_HEAD(rte_mempool_memhdr_list, rte_mempool_memhdr);
-
 /**
  * Callback used to free a memory chunk
  */
@@ -244,6 +246,7 @@ struct rte_mempool {
 	int32_t ops_index;
 
 	struct rte_mempool_cache *local_cache; /**< Per-lcore local cache */
+	void *local_cache_base_addr; /**< Reference to the base value */
 
 	uint32_t populated_size;         /**< Number of populated objects. */
 	struct rte_mempool_objhdr_list elt_list; /**< List of objects in
Quoted 1 line

pool */ @@ -1269,7 +1272,15 @@ rte_mempool_cache_flush(struct

rte_mempool_cache *cache,

lib/mempool/rte_mempool.h rte_mempool_cache_flush(struct rte_mempool_cache *cache,

Quoted 12 lines
lib/mempool/rte_mempool.h +8 -1
 	if (cache == NULL || cache->len == 0)
 		return;
 	rte_mempool_trace_cache_flush(cache, mp);
-	rte_mempool_ops_enqueue_bulk(mp, cache->objs, cache->len);
+
+	unsigned int i;
+	unsigned int cache_len = cache->len;
+	void *obj_table[RTE_MEMPOOL_CACHE_MAX_SIZE * 3];
+	void *base_value = cache->local_cache_base_value;
+	uint32_t *cache_objs = cache->objs;
+	for (i = 0; i < cache_len; i++)
+		obj_table[i] = (void *) RTE_PTR_ADD(base_value,

cache_objs[i]);

Quoted 5 lines
lib/mempool/rte_mempool.h +1 -0
+	rte_mempool_ops_enqueue_bulk(mp, obj_table, cache->len);
 	cache->len = 0;
 }

lib/mempool/rte_mempool.h static __rte_always_inline void · line 1307

Quoted 9 lines
lib/mempool/rte_mempool.h +3 -1
@@ -1289,7 +1300,9 @@ static __rte_always_inline void
 __mempool_generic_put(struct rte_mempool *mp, void * const *obj_table,
 		      unsigned int n, struct rte_mempool_cache *cache)  {
-	void **cache_objs;
+	uint32_t *cache_objs;
+	void *base_value;
+	uint32_t i;
 
 	/* increment stat now, adding in mempool always success */
 	__MEMPOOL_STAT_ADD(mp, put_bulk, 1); @@ -1301,6 +1314,12

@@

lib/mempool/rte_mempool.h __mempool_generic_put(struct rte_mempool

Quoted 14 lines
lib/mempool/rte_mempool.h +0 -0
 __mempool_generic_put(struct rte_mempool *mp, void * const *obj_table,
lib/mempool/rte_mempool.h +6 -0
 	cache_objs = &cache->objs[cache->len];
 
+	base_value = cache->local_cache_base_value;
+
+	uint64x2_t v_obj_table;
+	uint64x2_t v_base_value = vdupq_n_u64((uint64_t)base_value);
+	uint32x2_t v_cache_objs;
+
 	/*
 	 * The cache follows the following algorithm
 	 *   1. Add the objects to the cache
@@ -1309,12 +1328,26 @@ __mempool_generic_put(struct rte_mempool

*mp, void * const *obj_table,

lib/mempool/rte_mempool.h __mempool_generic_put(struct rte_mempool *mp, void * const *obj_table,

Quoted 9 lines
lib/mempool/rte_mempool.h +5 -1
 	 */
 
 	/* Add elements back into the cache */
-	rte_memcpy(&cache_objs[0], obj_table, sizeof(void *) * n);
+
+#if defined __ARM_NEON
+	for (i = 0; i < (n & ~0x1); i+=2) {
+		v_obj_table = vld1q_u64((const uint64_t *)&obj_table[i]);
+		v_cache_objs = vqmovn_u64(vsubq_u64(v_obj_table,

v_base_value));

lib/mempool/rte_mempool.h __mempool_generic_put(struct rte_mempool *mp, void * const *obj_table,

Quoted 4 lines
lib/mempool/rte_mempool.h +4 -0
+		vst1_u32(cache_objs + i, v_cache_objs);
+	}
+	if (n & 0x1) {
+		cache_objs[i] = (uint32_t) RTE_PTR_DIFF(obj_table[i],

base_value);

lib/mempool/rte_mempool.h __mempool_generic_put(struct rte_mempool *mp, void * const *obj_table,

Quoted 4 lines
lib/mempool/rte_mempool.h +4 -0
+	}
+#else
+	for (i = 0; i < n; i++) {
+		cache_objs[i] = (uint32_t) RTE_PTR_DIFF(obj_table[i],

base_value);

lib/mempool/rte_mempool.h __mempool_generic_put(struct rte_mempool *mp, void * const *obj_table,

Quoted 9 lines
lib/mempool/rte_mempool.h +3 -1
+	}
+#endif
 
 	cache->len += n;
 
 	if (cache->len >= cache->flushthresh) {
-		rte_mempool_ops_enqueue_bulk(mp, &cache->objs[cache-
 size],
+		rte_mempool_ops_enqueue_bulk(mp, obj_table + cache->len

-

lib/mempool/rte_mempool.h __mempool_generic_get(struct rte_mempool

Quoted 5 lines
lib/mempool/rte_mempool.h +1 -0
+cache->size,
 				cache->len - cache->size);
 		cache->len = cache->size;
 	}
@@ -1415,23 +1448,26 @@ __mempool_generic_get(struct rte_mempool

*mp, void **obj_table,

Quoted 9 lines
lib/mempool/rte_mempool.h +2 -1
 		      unsigned int n, struct rte_mempool_cache *cache)  {
 	int ret;
+	uint32_t i;
 	uint32_t index, len;
-	void **cache_objs;
+	uint32_t *cache_objs;
 
 	/* No cache provided or cannot be satisfied from cache */
 	if (unlikely(cache == NULL || n >= cache->size))

lib/mempool/rte_mempool.h __mempool_generic_get(struct rte_mempool *mp, void **obj_table,

Quoted 10 lines
lib/mempool/rte_mempool.h +2 -0
 		goto ring_dequeue;
 
+	void *base_value = cache->local_cache_base_value;
 	cache_objs = cache->objs;
 
 	/* Can this be satisfied from the cache? */
 	if (cache->len < n) {
 		/* No. Backfill the cache first, and then fill from it */
 		uint32_t req = n + (cache->size - cache->len);
+		void *temp_objs[RTE_MEMPOOL_CACHE_MAX_SIZE * 3];

/**< Cache objects

lib/mempool/rte_mempool.h __mempool_generic_get(struct rte_mempool · line 1468

Quoted 3 lines
lib/mempool/rte_mempool.h +1 -0
+*/
 
 		/* How many do we require i.e. number to fill the cache + the

request */

lib/mempool/rte_mempool.h __mempool_generic_get(struct rte_mempool *mp, void **obj_table, · line 1473

Quoted 6 lines
lib/mempool/rte_mempool.h +1 -1
 		ret = rte_mempool_ops_dequeue_bulk(mp,
-			&cache->objs[cache->len], req);
+			temp_objs, req);
 		if (unlikely(ret < 0)) {
 			/*
 			 * In the off chance that we are buffer constrained,

@@ -1442,12

Quoted 1 line

+1478,32 @@ __mempool_generic_get(struct rte_mempool *mp, void

**obj_table,

lib/mempool/rte_mempool.h __mempool_generic_get(struct rte_mempool *mp, void **obj_table,

Quoted 6 lines
lib/mempool/rte_mempool.h +3 -0
 			goto ring_dequeue;
 		}
 
+		len = cache->len;
+		for (i = 0; i < req; ++i, ++len) {
+			cache_objs[len] = (uint32_t)

RTE_PTR_DIFF(temp_objs[i], base_value);

Quoted 9 lines
lib/mempool/rte_mempool.h +6 -0
+		}
+
 		cache->len += req;
 	}
 
+	uint64x2_t v_obj_table;
+	uint64x2_t v_cache_objs;
+	uint64x2_t v_base_value = vdupq_n_u64((uint64_t)base_value);
+

lib/mempool/rte_mempool.h __mempool_generic_get(struct rte_mempool *mp, void **obj_table,

Quoted 10 lines
lib/mempool/rte_mempool.h +9 -0
 	/* Now fill in the response ... */
+#if defined __ARM_NEON
+	for (index = 0, len = cache->len - 1; index < (n & ~0x1); index+=2,
+						len-=2, obj_table+=2) {
+		v_cache_objs = vmovl_u32(vld1_u32(cache_objs + len - 1));
+		v_obj_table = vaddq_u64(v_cache_objs, v_base_value);
+		vst1q_u64((uint64_t *)obj_table, v_obj_table);
+	}
+	if (n & 0x1)
+		*obj_table = (void *) RTE_PTR_ADD(base_value,

cache_objs[len]);

lib/mempool/rte_mempool.h

Quoted 2 lines
lib/mempool/rte_mempool.h +1 -0
+#else
 	for (index = 0, len = cache->len - 1; index < n; ++index, len--,

obj_table++)

lib/mempool/rte_mempool.h

Quoted 2 lines
lib/mempool/rte_mempool.h +1 -1
-		*obj_table = cache_objs[len];
+		*obj_table = (void *) RTE_PTR_ADD(base_value,

cache_objs[len]);

Quoted 6 lines
lib/mempool/rte_mempool.h +1 -1
+#endif
 
 	cache->len -= n;
 
--

2.17.1

#9 lore raw

<snip>

Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 6 lines

Current mempool per core cache implementation is based on pointer For most architectures, each pointer consumes 64b Replace it with index-based implementation, where in each buffer is addressed by (pool address + index)

Quoted 8 lines
Quoted 4 lines
Quoted 3 lines

I don't think it is going to work:
On 64-bit systems difference between pool address and it's elem address could be bigger than 4GB.

Are you talking about a case where the memory pool size is more than 4GB?

That is one possible scenario.
Another possibility - user populates mempool himself with some external memory by calling rte_mempool_populate_iova() directly.

Is the concern that IOVA might not be contiguous for all the memory used by the mempool?

Quoted 2 lines

I suppose such situation can even occur even with normal rte_mempool_create(), though it should be a really rare one.

All in all, this feature needs to be configurable during compile time.

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

<snip>

#10 lore raw
Quoted 7 lines

From: dev [mailto:[email protected]] On Behalf Of Honnappa Nagarahalli
Sent: Monday, 4 October 2021 18.36

<snip>

Quoted 2 lines
Quoted 7 lines
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

Current mempool per core cache implementation is based on

pointer

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

For most architectures, each pointer consumes 64b Replace it

with

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

index-based implementation, where in each buffer is addressed

by

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

(pool address + index)

I like Dharmik's suggestion very much. CPU cache is a critical and limited resource.

DPDK has a tendency of using pointers where indexes could be used instead. I suppose pointers provide the additional flexibility of mixing entries from different memory pools, e.g. multiple mbuf pools.

Quoted 8 lines
Quoted 5 lines
Quoted 5 lines
Quoted 4 lines

I don't think it is going to work:
On 64-bit systems difference between pool address and it's elem address could be bigger than 4GB.

Are you talking about a case where the memory pool size is more

than 4GB?

Quoted 2 lines

That is one possible scenario.

That could be solved by making the index an element index instead of a pointer offset: address = (pool address + index * element size).

Quoted 9 lines
Quoted 1 line

Another possibility - user populates mempool himself with some

external

Quoted 1 line

memory by calling rte_mempool_populate_iova() directly.

Is the concern that IOVA might not be contiguous for all the memory used by the mempool?

Quoted 2 lines

I suppose such situation can even occur even with normal rte_mempool_create(), though it should be a really rare one.

All in all, this feature needs to be configurable during compile time.

#11 lore raw
In reply to Honnappa Nagarahalli
Quoted 29 lines

From: Morten Brørup
Sent: Saturday, 30 October 2021 12.24

Quoted 7 lines

From: dev [mailto:[email protected]] On Behalf Of Honnappa Nagarahalli
Sent: Monday, 4 October 2021 18.36

<snip>

Quoted 2 lines
Quoted 7 lines
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

Current mempool per core cache implementation is based on

pointer

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

For most architectures, each pointer consumes 64b Replace it

with

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

index-based implementation, where in each buffer is addressed

by

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

(pool address + index)

I like Dharmik's suggestion very much. CPU cache is a critical and limited resource.

DPDK has a tendency of using pointers where indexes could be used instead. I suppose pointers provide the additional flexibility of mixing entries from different memory pools, e.g. multiple mbuf pools.

Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines

I don't think it is going to work:
On 64-bit systems difference between pool address and it's elem address could be bigger than 4GB.

Quoted 7 lines
Quoted 4 lines
Quoted 1 line
Quoted 1 line

Are you talking about a case where the memory pool size is more

than 4GB?

Quoted 2 lines

That is one possible scenario.

That could be solved by making the index an element index instead of a pointer offset: address = (pool address + index * element size).

Or instead of scaling the index with the element size, which is only known at runtime, the index could be more efficiently scaled by a compile time constant such as RTE_MEMPOOL_ALIGN (= RTE_CACHE_LINE_SIZE). With a cache line size of 64 byte, that would allow indexing into mempools up to 256 GB in size.

Quoted 11 lines
Quoted 10 lines
Quoted 2 lines

Another possibility - user populates mempool himself with some

external

Quoted 1 line

memory by calling rte_mempool_populate_iova() directly.

Is the concern that IOVA might not be contiguous for all the memory used by the mempool?

Quoted 2 lines

I suppose such situation can even occur even with normal rte_mempool_create(), though it should be a really rare one.

All in all, this feature needs to be configurable during compile

time.

#12 lore raw

Hi,

Thank you everyone for the comments! I am currently working on making the global pool ring’s implementation as index based. Once done, I will send a patch for community review. I will also make it as a compile time option.

Quoted 20 lines · Morten Brørup
Quoted 19 lines

From: Morten Brørup
Sent: Saturday, 30 October 2021 12.24

Quoted 14 lines

From: dev [mailto:[email protected]] On Behalf Of Honnappa Nagarahalli
Sent: Monday, 4 October 2021 18.36

<snip>

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

Current mempool per core cache implementation is based on

pointer

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

For most architectures, each pointer consumes 64b Replace it

with

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

index-based implementation, where in each buffer is addressed

by

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

(pool address + index)

Quoted 7 lines
Quoted 7 lines

I like Dharmik's suggestion very much. CPU cache is a critical and limited resource.

DPDK has a tendency of using pointers where indexes could be used instead. I suppose pointers provide the additional flexibility of mixing entries from different memory pools, e.g. multiple mbuf pools.

Agreed, thank you!

Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 4 lines

I don't think it is going to work:
On 64-bit systems difference between pool address and it's elem address could be bigger than 4GB.

Are you talking about a case where the memory pool size is more

Quoted 9 lines
Quoted 6 lines
Quoted 3 lines

than 4GB?

Quoted 2 lines

That is one possible scenario.

That could be solved by making the index an element index instead of a pointer offset: address = (pool address + index * element size).

Or instead of scaling the index with the element size, which is only known at runtime, the index could be more efficiently scaled by a compile time constant such as RTE_MEMPOOL_ALIGN (= RTE_CACHE_LINE_SIZE). With a cache line size of 64 byte, that would allow indexing into mempools up to 256 GB in size.

Looking at this snippet [1] from rte_mempool_op_populate_helper(), there is an ‘offset’ added to avoid objects to cross page boundaries. If my understanding is correct, using the index of element instead of a pointer offset will pose a challenge for some of the corner cases.

[1]

        for (i = 0; i < max_objs; i++) {                                           
                /* avoid objects to cross page boundaries */
                if (check_obj_bounds(va + off, pg_sz, total_elt_sz) < 0) {
                        off += RTE_PTR_ALIGN_CEIL(va + off, pg_sz) - (va + off);
                        if (flags & RTE_MEMPOOL_POPULATE_F_ALIGN_OBJ)
                                off += total_elt_sz -
                                        (((uintptr_t)(va + off - 1) %
                                                total_elt_sz) + 1);
                }
Quoted 12 lines
Quoted 11 lines
Quoted 10 lines
Quoted 2 lines

Another possibility - user populates mempool himself with some

external

Quoted 1 line

memory by calling rte_mempool_populate_iova() directly.

Is the concern that IOVA might not be contiguous for all the memory used by the mempool?

Quoted 2 lines

I suppose such situation can even occur even with normal rte_mempool_create(), though it should be a really rare one.

All in all, this feature needs to be configurable during compile

time.

#13 lore raw
Quoted 9 lines

From: dev [mailto:[email protected]] On Behalf Of Dharmik Thakkar
Sent: Wednesday, 3 November 2021 16.13

Hi,

Thank you everyone for the comments! I am currently working on making the global pool ring’s implementation as index based.
Once done, I will send a patch for community review. I will also make it as a compile time option.

Sounds good to me.

This could probably be abstracted to other libraries too. E.g. the ring library holds pointers to objects (void *); an alternative ring library could hold indexes to objects (uint32_t). A ring often holds objects from the same mempool, and the application knows which mempool, so indexing would be useful here too.

Quoted 59 lines
Quoted 2 lines

On Oct 31, 2021, at 3:14 AM, Morten Brørup <[email protected]>

Quoted 17 lines · wrote:
Quoted 17 lines

From: Morten Brørup
Sent: Saturday, 30 October 2021 12.24

Quoted 13 lines

From: dev [mailto:[email protected]] On Behalf Of Honnappa Nagarahalli
Sent: Monday, 4 October 2021 18.36

<snip>

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

Current mempool per core cache implementation is based on

pointer

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

For most architectures, each pointer consumes 64b Replace it

with

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

index-based implementation, where in each buffer is addressed

by

Quoted 8 lines
Quoted 8 lines
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

(pool address + index)

I like Dharmik's suggestion very much. CPU cache is a critical and limited resource.

DPDK has a tendency of using pointers where indexes could be used instead. I suppose pointers provide the additional flexibility of mixing entries from different memory pools, e.g. multiple mbuf

pools.

Quoted 1 line
Quoted 1 line

Agreed, thank you!

Quoted 10 lines
Quoted 10 lines
Quoted 8 lines
Quoted 5 lines
Quoted 5 lines
Quoted 4 lines

I don't think it is going to work:
On 64-bit systems difference between pool address and it's elem address could be bigger than 4GB.

Are you talking about a case where the memory pool size is more

than 4GB?

Quoted 2 lines

That is one possible scenario.

That could be solved by making the index an element index instead of

a

Quoted 3 lines
Quoted 1 line

pointer offset: address = (pool address + index * element size).

Or instead of scaling the index with the element size, which is only

known at runtime, the index could be more efficiently scaled by a compile time constant such as RTE_MEMPOOL_ALIGN (= RTE_CACHE_LINE_SIZE). With a cache line size of 64 byte, that would allow indexing into mempools up to 256 GB in size.

Quoted 1 line

Looking at this snippet [1] from rte_mempool_op_populate_helper(), there is an ‘offset’ added to avoid objects to cross page boundaries. If my understanding is correct, using the index of element instead of a pointer offset will pose a challenge for some of the corner cases.

[1]

Quoted 12 lines
        for (i = 0; i < max_objs; i++) {
                /* avoid objects to cross page boundaries */
                if (check_obj_bounds(va + off, pg_sz, total_elt_sz) <
0) {
                        off += RTE_PTR_ALIGN_CEIL(va + off, pg_sz) -
(va + off);
                        if (flags & RTE_MEMPOOL_POPULATE_F_ALIGN_OBJ)
                                off += total_elt_sz -
                                        (((uintptr_t)(va + off - 1) %
                                                total_elt_sz) + 1);
                }

OK. Alternatively to scaling the index with a cache line size, you can scale it with sizeof(uintptr_t) to be able to address 32 or 16 GB mempools on respectively 64 bit and 32 bit architectures. Both x86 and ARM CPUs have instructions to access memory with an added offset multiplied by 4 or 8. So that should be high performance.

Quoted 12 lines
Quoted 12 lines
Quoted 11 lines
Quoted 10 lines
Quoted 2 lines

Another possibility - user populates mempool himself with some

external

Quoted 1 line

memory by calling rte_mempool_populate_iova() directly.

Is the concern that IOVA might not be contiguous for all the memory used by the mempool?

Quoted 2 lines

I suppose such situation can even occur even with normal rte_mempool_create(), though it should be a really rare one.

All in all, this feature needs to be configurable during compile

time.

#14 lore raw
Quoted 9 lines · Morten Brørup
Quoted 6 lines

From: dev [mailto:[email protected]] On Behalf Of Dharmik Thakkar
Sent: Wednesday, 3 November 2021 16.13

Hi,

Quoted 9 lines
Quoted 4 lines

Thank you everyone for the comments! I am currently working on making the global pool ring’s implementation as index based.
Once done, I will send a patch for community review. I will also make it as a compile time option.

Sounds good to me.

This could probably be abstracted to other libraries too. E.g. the ring library holds pointers to objects (void *); an alternative ring library could hold indexes to objects (uint32_t). A ring often holds objects from the same mempool, and the application knows which mempool, so indexing would be useful here too.

Yes, ring library within DPDK has the APIs to support configurable element size

Quoted 72 lines
Quoted 59 lines
Quoted 2 lines

On Oct 31, 2021, at 3:14 AM, Morten Brørup <[email protected]>

Quoted 17 lines · wrote:
Quoted 17 lines

From: Morten Brørup
Sent: Saturday, 30 October 2021 12.24

Quoted 13 lines

From: dev [mailto:[email protected]] On Behalf Of Honnappa Nagarahalli
Sent: Monday, 4 October 2021 18.36

<snip>

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

Current mempool per core cache implementation is based on

pointer

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

For most architectures, each pointer consumes 64b Replace it

with

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

index-based implementation, where in each buffer is addressed

by

Quoted 8 lines
Quoted 8 lines
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

(pool address + index)

I like Dharmik's suggestion very much. CPU cache is a critical and limited resource.

DPDK has a tendency of using pointers where indexes could be used instead. I suppose pointers provide the additional flexibility of mixing entries from different memory pools, e.g. multiple mbuf

pools.

Quoted 1 line
Quoted 1 line

Agreed, thank you!

Quoted 10 lines
Quoted 10 lines
Quoted 8 lines
Quoted 5 lines
Quoted 5 lines
Quoted 4 lines

I don't think it is going to work:
On 64-bit systems difference between pool address and it's elem address could be bigger than 4GB.

Are you talking about a case where the memory pool size is more

than 4GB?

Quoted 2 lines

That is one possible scenario.

That could be solved by making the index an element index instead of

a

Quoted 3 lines
Quoted 1 line

pointer offset: address = (pool address + index * element size).

Or instead of scaling the index with the element size, which is only

known at runtime, the index could be more efficiently scaled by a compile time constant such as RTE_MEMPOOL_ALIGN (= RTE_CACHE_LINE_SIZE). With a cache line size of 64 byte, that would allow indexing into mempools up to 256 GB in size.

Quoted 1 line

Looking at this snippet [1] from rte_mempool_op_populate_helper(), there is an ‘offset’ added to avoid objects to cross page boundaries. If my understanding is correct, using the index of element instead of a pointer offset will pose a challenge for some of the corner cases.

[1]

Quoted 12 lines
       for (i = 0; i < max_objs; i++) {
               /* avoid objects to cross page boundaries */
               if (check_obj_bounds(va + off, pg_sz, total_elt_sz) <
0) {
                       off += RTE_PTR_ALIGN_CEIL(va + off, pg_sz) -
(va + off);
                       if (flags & RTE_MEMPOOL_POPULATE_F_ALIGN_OBJ)
                               off += total_elt_sz -
                                       (((uintptr_t)(va + off - 1) %
                                               total_elt_sz) + 1);
               }
Quoted 1 line

OK. Alternatively to scaling the index with a cache line size, you can scale it with sizeof(uintptr_t) to be able to address 32 or 16 GB mempools on respectively 64 bit and 32 bit architectures. Both x86 and ARM CPUs have instructions to access memory with an added offset multiplied by 4 or 8. So that should be high performance.

Yes, agreed this can be done.
Cache line size can also be used when ‘MEMPOOL_F_NO_CACHE_ALIGN’ is not enabled.
On a side note, I wanted to better understand the need for having the 'MEMPOOL_F_NO_CACHE_ALIGN' option.

Quoted 14 lines
Quoted 13 lines
Quoted 13 lines
Quoted 12 lines
Quoted 11 lines
Quoted 3 lines

Another possibility - user populates mempool himself with some

external

Quoted 1 line

memory by calling rte_mempool_populate_iova() directly.

Is the concern that IOVA might not be contiguous for all the memory used by the mempool?

Quoted 2 lines

I suppose such situation can even occur even with normal rte_mempool_create(), though it should be a really rare one.

All in all, this feature needs to be configurable during compile

time.

#15 lore raw

+ Ring library maintainers (@Honnappa and @Konstantin) for my rants about its documentation.

Quoted 21 lines

From: dev [mailto:[email protected]] On Behalf Of Dharmik Thakkar
Sent: Thursday, 4 November 2021 05.42

Quoted 1 line

On Nov 3, 2021, at 10:52 AM, Morten Brørup <[email protected]>

Quoted 7 lines · wrote:
Quoted 7 lines

From: dev [mailto:[email protected]] On Behalf Of Dharmik Thakkar
Sent: Wednesday, 3 November 2021 16.13

Hi,

Thank you everyone for the comments! I am currently working on

making

Quoted 2 lines
Quoted 2 lines

the global pool ring’s implementation as index based. Once done, I will send a patch for community review. I will also

make

Quoted 5 lines
Quoted 1 line

it as a compile time option.

Sounds good to me.

This could probably be abstracted to other libraries too. E.g. the

Quoted 8 lines

ring library holds pointers to objects (void *); an alternative ring library could hold indexes to objects (uint32_t). A ring often holds objects from the same mempool, and the application knows which mempool, so indexing would be useful here too.

Quoted 1 line

Yes, ring library within DPDK has the APIs to support configurable element size

I remember seeing that feature proposed on the mailing list too, but I couldn't find it in the API documentation, so I was not sure it was ever accepted.

The containers section of the API documentation (/doc/api/doxy-api-index.md) doesn't contain any references to it. And the description of the RTE Ring library, which the "ring" link in the API documentation refers to, clearly says: The Ring Manager is a fixed-size queue, implemented as a table of *pointers*. (My emphasis.) So I thought it wasn't accepted.

However, searching for it in the source code reveals that it is indeed there! And the Ring Library chapter in the Programmer's Guide does mention that the objects can be something else than pointers.

So the documentation is not all screwed up, just a little sparse. :-)

Quoted 85 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

On Oct 31, 2021, at 3:14 AM, Morten Brørup

<[email protected]>

Quoted 26 lines
Quoted 26 lines
Quoted 25 lines · wrote:
Quoted 25 lines

From: Morten Brørup
Sent: Saturday, 30 October 2021 12.24

Quoted 7 lines

From: dev [mailto:[email protected]] On Behalf Of Honnappa Nagarahalli
Sent: Monday, 4 October 2021 18.36

<snip>

Quoted 2 lines
Quoted 7 lines
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

Current mempool per core cache implementation is based on

pointer

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

For most architectures, each pointer consumes 64b Replace it

with

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

index-based implementation, where in each buffer is addressed

by

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

(pool address + index)

I like Dharmik's suggestion very much. CPU cache is a critical and limited resource.

DPDK has a tendency of using pointers where indexes could be used instead. I suppose pointers provide the additional flexibility of mixing entries from different memory pools, e.g. multiple mbuf

Quoted 8 lines
Quoted 8 lines

pools.

Quoted 1 line
Quoted 1 line

Agreed, thank you!

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

I don't think it is going to work:
On 64-bit systems difference between pool address and it's

elem

Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 5 lines
Quoted 2 lines
Quoted 2 lines
Quoted 1 line

address could be bigger than 4GB.

Are you talking about a case where the memory pool size is more

than 4GB?

Quoted 2 lines

That is one possible scenario.

That could be solved by making the index an element index instead

of

Quoted 4 lines
Quoted 4 lines

a

Quoted 3 lines
Quoted 1 line

pointer offset: address = (pool address + index * element size).

Or instead of scaling the index with the element size, which is

only

Quoted 8 lines
Quoted 8 lines

known at runtime, the index could be more efficiently scaled by a compile time constant such as RTE_MEMPOOL_ALIGN (= RTE_CACHE_LINE_SIZE). With a cache line size of 64 byte, that would allow indexing into mempools up to 256 GB in size.

Quoted 1 line

Looking at this snippet [1] from rte_mempool_op_populate_helper(), there is an ‘offset’ added to avoid objects to cross page

boundaries.

Quoted 1 line
Quoted 1 line

If my understanding is correct, using the index of element instead

of a

Quoted 16 lines
Quoted 15 lines

pointer offset will pose a challenge for some of the corner cases.

[1]

       for (i = 0; i < max_objs; i++) {
               /* avoid objects to cross page boundaries */
               if (check_obj_bounds(va + off, pg_sz, total_elt_sz) <
0) {
                       off += RTE_PTR_ALIGN_CEIL(va + off, pg_sz) -
(va + off);
                       if (flags & RTE_MEMPOOL_POPULATE_F_ALIGN_OBJ)
                               off += total_elt_sz -
                                       (((uintptr_t)(va + off - 1) %
                                               total_elt_sz) + 1);
               }
Quoted 1 line

OK. Alternatively to scaling the index with a cache line size, you

can scale it with sizeof(uintptr_t) to be able to address 32 or 16 GB mempools on respectively 64 bit and 32 bit architectures. Both x86 and ARM CPUs have instructions to access memory with an added offset multiplied by 4 or 8. So that should be high performance.

Quoted 5 lines

Yes, agreed this can be done.
Cache line size can also be used when ‘MEMPOOL_F_NO_CACHE_ALIGN’ is not enabled.
On a side note, I wanted to better understand the need for having the 'MEMPOOL_F_NO_CACHE_ALIGN' option.

The description of this field is misleading, and should be corrected. The correct description would be: Don't need to align objs on cache lines.

It is useful for mempools containing very small objects, to conserve memory.

Quoted 16 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 4 lines

Another possibility - user populates mempool himself with some

external

Quoted 1 line

memory by calling rte_mempool_populate_iova() directly.

Is the concern that IOVA might not be contiguous for all the

memory

Quoted 8 lines
Quoted 7 lines
Quoted 7 lines
Quoted 6 lines
Quoted 5 lines

used by the mempool?

Quoted 2 lines

I suppose such situation can even occur even with normal rte_mempool_create(), though it should be a really rare one.

All in all, this feature needs to be configurable during compile

time.

#16 lore raw

<snip>

Quoted 78 lines
Quoted 72 lines
Quoted 15 lines
Quoted 15 lines
Quoted 15 lines
Quoted 15 lines
Quoted 8 lines
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

Current mempool per core cache implementation is based on

pointer

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

For most architectures, each pointer consumes 64b Replace it

with

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

index-based implementation, where in each buffer is addressed

by

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

(pool address + index)

I like Dharmik's suggestion very much. CPU cache is a critical and limited resource.

DPDK has a tendency of using pointers where indexes could be used instead. I suppose pointers provide the additional flexibility of mixing entries from different memory pools, e.g. multiple mbuf

Quoted 8 lines
Quoted 8 lines

pools.

Quoted 1 line
Quoted 1 line

Agreed, thank you!

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

I don't think it is going to work:
On 64-bit systems difference between pool address and it's

elem

Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 6 lines
Quoted 3 lines
Quoted 3 lines
Quoted 1 line

address could be bigger than 4GB.

Are you talking about a case where the memory pool size is more

than 4GB?

Quoted 2 lines

That is one possible scenario.

That could be solved by making the index an element index instead

of

Quoted 4 lines
Quoted 4 lines

a

Quoted 3 lines
Quoted 1 line

pointer offset: address = (pool address + index * element size).

Or instead of scaling the index with the element size, which is

only

Quoted 8 lines
Quoted 8 lines

known at runtime, the index could be more efficiently scaled by a compile time constant such as RTE_MEMPOOL_ALIGN (= RTE_CACHE_LINE_SIZE). With a cache line size of 64 byte, that would allow indexing into mempools up to 256 GB in size.

Quoted 1 line

Looking at this snippet [1] from rte_mempool_op_populate_helper(), there is an ‘offset’ added to avoid objects to cross page

boundaries.

Quoted 1 line
Quoted 1 line

If my understanding is correct, using the index of element instead

of a

Quoted 17 lines
Quoted 16 lines

pointer offset will pose a challenge for some of the corner cases.

[1]

       for (i = 0; i < max_objs; i++) {
               /* avoid objects to cross page boundaries */
               if (check_obj_bounds(va + off, pg_sz, total_elt_sz)
<
0) {
                       off += RTE_PTR_ALIGN_CEIL(va + off, pg_sz) -
(va + off);
                       if (flags & RTE_MEMPOOL_POPULATE_F_ALIGN_OBJ)
                               off += total_elt_sz -
                                       (((uintptr_t)(va + off - 1) %
                                               total_elt_sz) + 1);
               }
Quoted 1 line

OK. Alternatively to scaling the index with a cache line size, you

can scale it with sizeof(uintptr_t) to be able to address 32 or 16 GB mempools on respectively 64 bit and 32 bit architectures. Both x86 and ARM CPUs have instructions to access memory with an added offset multiplied by 4 or 8. So that should be high performance.

Quoted 5 lines

Yes, agreed this can be done.
Cache line size can also be used when ‘MEMPOOL_F_NO_CACHE_ALIGN’ is not enabled.
On a side note, I wanted to better understand the need for having the 'MEMPOOL_F_NO_CACHE_ALIGN' option.

Quoted 4 lines

The description of this field is misleading, and should be corrected. The correct description would be: Don't need to align objs on cache lines.

It is useful for mempools containing very small objects, to conserve memory.

I think we can assume that mbuf pools are created with the 'MEMPOOL_F_NO_CACHE_ALIGN' flag set. With this we can use offset calculated with cache line size as the unit.

Quoted 17 lines
Quoted 17 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 5 lines

Another possibility - user populates mempool himself with some

external

Quoted 1 line

memory by calling rte_mempool_populate_iova() directly.

Is the concern that IOVA might not be contiguous for all the

memory

Quoted 8 lines
Quoted 7 lines
Quoted 7 lines
Quoted 6 lines
Quoted 5 lines

used by the mempool?

Quoted 2 lines

I suppose such situation can even occur even with normal rte_mempool_create(), though it should be a really rare one.

All in all, this feature needs to be configurable during compile

time.

#17 lore raw
Quoted 104 lines

From: Honnappa Nagarahalli [mailto:[email protected]]
Sent: Monday, 8 November 2021 05.33

<snip>

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

Current mempool per core cache implementation is based on

pointer

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

For most architectures, each pointer consumes 64b Replace

it

Quoted 10 lines
Quoted 10 lines
Quoted 10 lines
Quoted 10 lines
Quoted 10 lines
Quoted 10 lines
Quoted 5 lines

with

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

index-based implementation, where in each buffer is addressed

by

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

(pool address + index)

I like Dharmik's suggestion very much. CPU cache is a critical and limited resource.

DPDK has a tendency of using pointers where indexes could be

used

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

instead. I suppose pointers provide the additional flexibility

of

Quoted 10 lines
Quoted 10 lines
Quoted 9 lines
Quoted 9 lines
Quoted 1 line
Quoted 1 line

mixing entries from different memory pools, e.g. multiple mbuf

pools.

Quoted 1 line
Quoted 1 line

Agreed, thank you!

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

I don't think it is going to work:
On 64-bit systems difference between pool address and it's

elem

Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 6 lines
Quoted 3 lines
Quoted 3 lines
Quoted 1 line

address could be bigger than 4GB.

Are you talking about a case where the memory pool size is more

than 4GB?

Quoted 2 lines

That is one possible scenario.

That could be solved by making the index an element index

instead

Quoted 3 lines
Quoted 3 lines

of

Quoted 2 lines
Quoted 2 lines

a

Quoted 1 line
Quoted 1 line

pointer offset: address = (pool address + index * element

size).

Quoted 4 lines
Quoted 4 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

Or instead of scaling the index with the element size, which is

only

Quoted 1 line
Quoted 1 line

known at runtime, the index could be more efficiently scaled by

a

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

compile time constant such as RTE_MEMPOOL_ALIGN (= RTE_CACHE_LINE_SIZE). With a cache line size of 64 byte, that

would

Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines

allow indexing into mempools up to 256 GB in size.

Quoted 1 line

Looking at this snippet [1] from

rte_mempool_op_populate_helper(),

Quoted 3 lines
Quoted 3 lines
Quoted 1 line
Quoted 1 line

there is an ‘offset’ added to avoid objects to cross page

boundaries.

Quoted 1 line
Quoted 1 line

If my understanding is correct, using the index of element

instead

Quoted 2 lines
Quoted 2 lines

of a

Quoted 1 line
Quoted 1 line

pointer offset will pose a challenge for some of the corner

cases.

Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines

[1]

       for (i = 0; i < max_objs; i++) {
               /* avoid objects to cross page boundaries */
               if (check_obj_bounds(va + off, pg_sz,

total_elt_sz)

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

<

0) {
                       off += RTE_PTR_ALIGN_CEIL(va + off,

pg_sz) -

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

(va + off);
if (flags &

RTE_MEMPOOL_POPULATE_F_ALIGN_OBJ)

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
                               off += total_elt_sz -
                                       (((uintptr_t)(va + off -

1) %

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
                                               total_elt_sz) +

1);

Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 2 lines
               }

OK. Alternatively to scaling the index with a cache line size,

you

Quoted 1 line
Quoted 1 line

can scale it with sizeof(uintptr_t) to be able to address 32 or 16

GB

Quoted 1 line
Quoted 1 line

mempools on respectively 64 bit and 32 bit architectures. Both x86

and

Quoted 7 lines
Quoted 7 lines

ARM CPUs have instructions to access memory with an added offset multiplied by 4 or 8. So that should be high performance.

Yes, agreed this can be done.
Cache line size can also be used when ‘MEMPOOL_F_NO_CACHE_ALIGN’ is not enabled.
On a side note, I wanted to better understand the need for having

the

Quoted 4 lines
Quoted 1 line

'MEMPOOL_F_NO_CACHE_ALIGN' option.

The description of this field is misleading, and should be corrected. The correct description would be: Don't need to align objs on cache

Quoted 7 lines

lines.

Quoted 2 lines

It is useful for mempools containing very small objects, to conserve

memory.
I think we can assume that mbuf pools are created with the 'MEMPOOL_F_NO_CACHE_ALIGN' flag set. With this we can use offset calculated with cache line size as the unit.

You mean MEMPOOL_F_NO_CACHE_ALIGN flag not set. ;-)

I agree. And since the flag is a hint only, it can be ignored if the mempool library is scaling the index with the cache line size.

However, a mempool may contain other objects than mbufs, and those objects may be small, so ignoring the MEMPOOL_F_NO_CACHE_ALIGN flag may cost a lot of memory for such mempools.

Quoted 20 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines

Another possibility - user populates mempool himself with

some

Quoted 9 lines
Quoted 9 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

external

Quoted 1 line

memory by calling rte_mempool_populate_iova() directly.

Is the concern that IOVA might not be contiguous for all the

memory

Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines

used by the mempool?

Quoted 2 lines

I suppose such situation can even occur even with normal rte_mempool_create(), though it should be a really rare one.

All in all, this feature needs to be configurable during

compile

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 2 lines
Quoted 2 lines
Quoted 1 line

time.

#18 lore raw

<snip>

Quoted 107 lines
Quoted 107 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

Current mempool per core cache implementation is based
on

pointer

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

For most architectures, each pointer consumes 64b
Replace

it

Quoted 10 lines
Quoted 10 lines
Quoted 10 lines
Quoted 10 lines
Quoted 10 lines
Quoted 10 lines
Quoted 5 lines

with

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

index-based implementation, where in each buffer is
addressed

by

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

(pool address + index)

I like Dharmik's suggestion very much. CPU cache is a critical and limited resource.

DPDK has a tendency of using pointers where indexes could be

used

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

instead. I suppose pointers provide the additional flexibility

of

Quoted 12 lines
Quoted 12 lines
Quoted 11 lines
Quoted 11 lines
Quoted 2 lines
Quoted 2 lines

mixing entries from different memory pools, e.g. multiple mbuf

pools.

Quoted 1 line
Quoted 1 line

Agreed, thank you!

Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines

I don't think it is going to work:
On 64-bit systems difference between pool address and it's

elem

Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 6 lines
Quoted 3 lines
Quoted 3 lines
Quoted 1 line

address could be bigger than 4GB.

Are you talking about a case where the memory pool size is more

than 4GB?

Quoted 2 lines

That is one possible scenario.

That could be solved by making the index an element index

instead

Quoted 3 lines
Quoted 3 lines

of

Quoted 2 lines
Quoted 2 lines

a

Quoted 1 line
Quoted 1 line

pointer offset: address = (pool address + index * element

size).

Quoted 5 lines
Quoted 5 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

Or instead of scaling the index with the element size, which is

only

Quoted 1 line
Quoted 1 line

known at runtime, the index could be more efficiently scaled by

a

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

compile time constant such as RTE_MEMPOOL_ALIGN (= RTE_CACHE_LINE_SIZE). With a cache line size of 64 byte, that

would

Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines

allow indexing into mempools up to 256 GB in size.

Quoted 1 line

Looking at this snippet [1] from

rte_mempool_op_populate_helper(),

Quoted 3 lines
Quoted 3 lines
Quoted 1 line
Quoted 1 line

there is an ‘offset’ added to avoid objects to cross page

boundaries.

Quoted 1 line
Quoted 1 line

If my understanding is correct, using the index of element

instead

Quoted 2 lines
Quoted 2 lines

of a

Quoted 1 line
Quoted 1 line

pointer offset will pose a challenge for some of the corner

cases.

Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines

[1]

       for (i = 0; i < max_objs; i++) {
               /* avoid objects to cross page boundaries */
               if (check_obj_bounds(va + off, pg_sz,

total_elt_sz)

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

<

0) {
                       off += RTE_PTR_ALIGN_CEIL(va + off,

pg_sz) -

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

(va + off);
if (flags &

RTE_MEMPOOL_POPULATE_F_ALIGN_OBJ)

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
                               off += total_elt_sz -
                                       (((uintptr_t)(va + off -

1) %

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
                                               total_elt_sz) +

1);

Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 2 lines
               }

OK. Alternatively to scaling the index with a cache line size,

you

Quoted 1 line
Quoted 1 line

can scale it with sizeof(uintptr_t) to be able to address 32 or 16

GB

Quoted 1 line
Quoted 1 line

mempools on respectively 64 bit and 32 bit architectures. Both x86

and

Quoted 7 lines
Quoted 7 lines

ARM CPUs have instructions to access memory with an added offset multiplied by 4 or 8. So that should be high performance.

Yes, agreed this can be done.
Cache line size can also be used when ‘MEMPOOL_F_NO_CACHE_ALIGN’ is not enabled.
On a side note, I wanted to better understand the need for having

the

Quoted 4 lines
Quoted 1 line

'MEMPOOL_F_NO_CACHE_ALIGN' option.

The description of this field is misleading, and should be corrected. The correct description would be: Don't need to align objs on cache

lines.

Quoted 1 line
Quoted 7 lines
Quoted 5 lines
Quoted 1 line

It is useful for mempools containing very small objects, to conserve

memory.
I think we can assume that mbuf pools are created with the 'MEMPOOL_F_NO_CACHE_ALIGN' flag set. With this we can use offset calculated with cache line size as the unit.

You mean MEMPOOL_F_NO_CACHE_ALIGN flag not set. ;-)

Yes 😊

Quoted 3 lines

I agree. And since the flag is a hint only, it can be ignored if the mempool library is scaling the index with the cache line size.

I do not think we should ignore the flag for reason you mention below.

Quoted 4 lines

However, a mempool may contain other objects than mbufs, and those objects may be small, so ignoring the MEMPOOL_F_NO_CACHE_ALIGN flag may cost a lot of memory for such mempools.

We could use different methods. If MEMPOOL_F_NO_CACHE_ALIGN is set, use the unit as 'sizeof(uintptr_t)', if not set use cache line size as the unit.

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

<snip>

#19 lore raw
Quoted 146 lines

From: dev [mailto:[email protected]] On Behalf Of Honnappa Nagarahalli
Sent: Monday, 8 November 2021 16.29

<snip>

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

Current mempool per core cache implementation is

based

Quoted 8 lines
Quoted 8 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 1 line
Quoted 1 line
Quoted 1 line

on

pointer

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

For most architectures, each pointer consumes 64b
Replace

it

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

with

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

index-based implementation, where in each buffer is
addressed

Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 2 lines

by

Quoted 1 line
Quoted 1 line
Quoted 1 line

(pool address + index)

I like Dharmik's suggestion very much. CPU cache is a critical and limited resource.

DPDK has a tendency of using pointers where indexes could

be

Quoted 12 lines
Quoted 12 lines

used

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

instead. I suppose pointers provide the additional flexibility

of

Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 2 lines
Quoted 2 lines

mixing entries from different memory pools, e.g. multiple mbuf

pools.

Quoted 1 line
Quoted 1 line

Agreed, thank you!

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

I don't think it is going to work:
On 64-bit systems difference between pool address and
it's

elem

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 1 line

address could be bigger than 4GB.

Are you talking about a case where the memory pool size

is

Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 4 lines
Quoted 1 line
Quoted 1 line

more

than 4GB?

Quoted 2 lines

That is one possible scenario.

Quoted 8 lines
Quoted 8 lines
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

That could be solved by making the index an element index

instead

Quoted 3 lines
Quoted 3 lines

of

Quoted 2 lines
Quoted 2 lines

a

Quoted 1 line
Quoted 1 line

pointer offset: address = (pool address + index * element

size).

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

Or instead of scaling the index with the element size,

which

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 1 line
Quoted 1 line
Quoted 1 line

is

only

Quoted 1 line
Quoted 1 line

known at runtime, the index could be more efficiently scaled

by

Quoted 3 lines
Quoted 3 lines

a

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

compile time constant such as RTE_MEMPOOL_ALIGN (= RTE_CACHE_LINE_SIZE). With a cache line size of 64 byte,

that

Quoted 22 lines
Quoted 22 lines

would

Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines

allow indexing into mempools up to 256 GB in size.

Quoted 1 line

Looking at this snippet [1] from

rte_mempool_op_populate_helper(),

Quoted 3 lines
Quoted 3 lines
Quoted 1 line
Quoted 1 line

there is an ‘offset’ added to avoid objects to cross page

boundaries.

Quoted 1 line
Quoted 1 line

If my understanding is correct, using the index of element

instead

Quoted 2 lines
Quoted 2 lines

of a

Quoted 1 line
Quoted 1 line

pointer offset will pose a challenge for some of the corner

cases.

Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines

[1]

       for (i = 0; i < max_objs; i++) {
               /* avoid objects to cross page boundaries */
               if (check_obj_bounds(va + off, pg_sz,

total_elt_sz)

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

<

0) {
                       off += RTE_PTR_ALIGN_CEIL(va + off,
Quoted 6 lines
Quoted 6 lines

pg_sz) -

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

(va + off);
if (flags &

RTE_MEMPOOL_POPULATE_F_ALIGN_OBJ)

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
                               off += total_elt_sz -
                                       (((uintptr_t)(va +

off -

Quoted 2 lines
Quoted 2 lines

1) %

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

total_elt_sz)

+

Quoted 5 lines
Quoted 5 lines

1);

Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 2 lines
               }

OK. Alternatively to scaling the index with a cache line

size,

Quoted 2 lines
Quoted 2 lines

you

Quoted 1 line
Quoted 1 line

can scale it with sizeof(uintptr_t) to be able to address 32 or

16

Quoted 2 lines
Quoted 2 lines

GB

Quoted 1 line
Quoted 1 line

mempools on respectively 64 bit and 32 bit architectures. Both

x86

Quoted 2 lines
Quoted 2 lines

and

Quoted 1 line
Quoted 1 line

ARM CPUs have instructions to access memory with an added

offset

Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines

multiplied by 4 or 8. So that should be high performance.

Yes, agreed this can be done.
Cache line size can also be used when

‘MEMPOOL_F_NO_CACHE_ALIGN’

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

is not enabled.
On a side note, I wanted to better understand the need for

having

Quoted 4 lines
Quoted 4 lines

the

Quoted 3 lines
Quoted 1 line

'MEMPOOL_F_NO_CACHE_ALIGN' option.

The description of this field is misleading, and should be

corrected.

Quoted 1 line
Quoted 1 line
Quoted 1 line

The correct description would be: Don't need to align objs on

cache

Quoted 3 lines
Quoted 3 lines

lines.

Quoted 2 lines

It is useful for mempools containing very small objects, to

conserve

Quoted 6 lines
Quoted 4 lines

memory.
I think we can assume that mbuf pools are created with the 'MEMPOOL_F_NO_CACHE_ALIGN' flag set. With this we can use offset calculated with cache line size as the unit.

You mean MEMPOOL_F_NO_CACHE_ALIGN flag not set. ;-)

Yes 😊

Quoted 2 lines

I agree. And since the flag is a hint only, it can be ignored if the

mempool

Quoted 1 line

library is scaling the index with the cache line size.

I do not think we should ignore the flag for reason you mention below.

Quoted 1 line
Quoted 9 lines
Quoted 1 line

However, a mempool may contain other objects than mbufs, and those

objects

Quoted 1 line

may be small, so ignoring the MEMPOOL_F_NO_CACHE_ALIGN flag may cost

a

Quoted 1 line

lot of memory for such mempools.

We could use different methods. If MEMPOOL_F_NO_CACHE_ALIGN is set, use the unit as 'sizeof(uintptr_t)', if not set use cache line size as the unit.

That would require that the indexing multiplier is a runtime parameter instead of a compile time parameter. So it would have a performance penalty.

The indexing multiplier could be compile time configurable, so it is a tradeoff between granularity and maximum mempool size.

#20 lore raw

<snip>

Quoted 156 lines
Quoted 139 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

Current mempool per core cache implementation is

based

Quoted 8 lines
Quoted 8 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 1 line
Quoted 1 line

on

pointer

Quoted 2 lines
Quoted 2 lines

For most architectures, each pointer consumes 64b
Replace

it

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

with

Quoted 2 lines
Quoted 2 lines

index-based implementation, where in each buffer is
addressed

Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 2 lines

by

Quoted 1 line
Quoted 1 line

(pool address + index)

I like Dharmik's suggestion very much. CPU cache is a critical and limited resource.

DPDK has a tendency of using pointers where indexes could

be

Quoted 12 lines
Quoted 12 lines

used

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

instead. I suppose pointers provide the additional flexibility

of

Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 2 lines
Quoted 2 lines

mixing entries from different memory pools, e.g. multiple mbuf

pools.

Quoted 1 line
Quoted 1 line

Agreed, thank you!

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

I don't think it is going to work:
On 64-bit systems difference between pool address and
it's

elem

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

address could be bigger than 4GB.
Are you talking about a case where the memory pool
size

is

Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 4 lines
Quoted 1 line
Quoted 1 line

more

than 4GB?

Quoted 2 lines

That is one possible scenario.

Quoted 8 lines
Quoted 8 lines
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

That could be solved by making the index an element index

instead

Quoted 3 lines
Quoted 3 lines

of

Quoted 2 lines
Quoted 2 lines

a

Quoted 1 line
Quoted 1 line

pointer offset: address = (pool address + index * element

size).

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

Or instead of scaling the index with the element size,

which

Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 1 line
Quoted 1 line
Quoted 1 line

is

only

Quoted 2 lines
Quoted 2 lines

known at runtime, the index could be more efficiently scaled

by

Quoted 3 lines
Quoted 3 lines

a

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

compile time constant such as RTE_MEMPOOL_ALIGN (= RTE_CACHE_LINE_SIZE). With a cache line size of 64 byte,

that

Quoted 22 lines
Quoted 22 lines

would

Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines

allow indexing into mempools up to 256 GB in size.

Quoted 1 line

Looking at this snippet [1] from

rte_mempool_op_populate_helper(),

Quoted 3 lines
Quoted 3 lines
Quoted 1 line
Quoted 1 line

there is an ‘offset’ added to avoid objects to cross page

boundaries.

Quoted 1 line
Quoted 1 line

If my understanding is correct, using the index of element

instead

Quoted 2 lines
Quoted 2 lines

of a

Quoted 1 line
Quoted 1 line

pointer offset will pose a challenge for some of the corner

cases.

Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines

[1]

       for (i = 0; i < max_objs; i++) {
               /* avoid objects to cross page boundaries */
               if (check_obj_bounds(va + off, pg_sz,

total_elt_sz)

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

<

0) {
                       off += RTE_PTR_ALIGN_CEIL(va + off,
Quoted 6 lines
Quoted 6 lines

pg_sz) -

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

(va + off);
if (flags &

RTE_MEMPOOL_POPULATE_F_ALIGN_OBJ)

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
                               off += total_elt_sz -
                                       (((uintptr_t)(va +

off -

Quoted 3 lines
Quoted 3 lines

1) %

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

total_elt_sz)

+

Quoted 5 lines
Quoted 5 lines

1);

Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 2 lines
               }

OK. Alternatively to scaling the index with a cache line

size,

Quoted 3 lines
Quoted 3 lines

you

Quoted 2 lines
Quoted 2 lines

can scale it with sizeof(uintptr_t) to be able to address 32 or

16

Quoted 2 lines
Quoted 2 lines

GB

Quoted 1 line
Quoted 1 line

mempools on respectively 64 bit and 32 bit architectures. Both

x86

Quoted 2 lines
Quoted 2 lines

and

Quoted 1 line
Quoted 1 line

ARM CPUs have instructions to access memory with an added

offset

Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines

multiplied by 4 or 8. So that should be high performance.

Yes, agreed this can be done.
Cache line size can also be used when

‘MEMPOOL_F_NO_CACHE_ALIGN’

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

is not enabled.
On a side note, I wanted to better understand the need for

having

Quoted 4 lines
Quoted 4 lines

the

Quoted 3 lines
Quoted 1 line

'MEMPOOL_F_NO_CACHE_ALIGN' option.

The description of this field is misleading, and should be

corrected.

Quoted 1 line
Quoted 1 line
Quoted 1 line

The correct description would be: Don't need to align objs on

cache

Quoted 3 lines
Quoted 3 lines

lines.

Quoted 2 lines

It is useful for mempools containing very small objects, to

conserve

Quoted 6 lines
Quoted 4 lines

memory.
I think we can assume that mbuf pools are created with the 'MEMPOOL_F_NO_CACHE_ALIGN' flag set. With this we can use offset calculated with cache line size as the unit.

You mean MEMPOOL_F_NO_CACHE_ALIGN flag not set. ;-)

Yes 😊

Quoted 1 line
Quoted 9 lines
Quoted 1 line

I agree. And since the flag is a hint only, it can be ignored if the

mempool

Quoted 1 line

library is scaling the index with the cache line size.

I do not think we should ignore the flag for reason you mention below.

Quoted 2 lines

However, a mempool may contain other objects than mbufs, and those

objects

Quoted 1 line

may be small, so ignoring the MEMPOOL_F_NO_CACHE_ALIGN flag may

cost

Quoted 6 lines

a

Quoted 1 line

lot of memory for such mempools.

We could use different methods. If MEMPOOL_F_NO_CACHE_ALIGN is set, use the unit as 'sizeof(uintptr_t)', if not set use cache line size as the unit.

Quoted 5 lines

That would require that the indexing multiplier is a runtime parameter instead of a compile time parameter. So it would have a performance penalty.

The indexing multiplier could be compile time configurable, so it is a tradeoff between granularity and maximum mempool size.

I meant compile time configurable. i.e.

#ifdef MEMPOOL_F_NO_CACHE_ALIGN
<use sizeof(uintptr_t) as the multiplier>
#else
<use cache line size as the multiplier> /* This should provide enough memory for packet buffers */ #endif

#21 lore raw
Quoted 187 lines

From: dev [mailto:[email protected]] On Behalf Of Honnappa Nagarahalli
Sent: Monday, 8 November 2021 16.46

<snip>

Quoted 10 lines
Quoted 10 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

Current mempool per core cache implementation is

based

Quoted 7 lines
Quoted 7 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 1 line

on

pointer

Quoted 2 lines

For most architectures, each pointer consumes 64b
Replace

it

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

with

Quoted 1 line

index-based implementation, where in each buffer

is

Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 3 lines
Quoted 1 line

addressed

by

Quoted 1 line

(pool address + index)

I like Dharmik's suggestion very much. CPU cache is a critical and limited resource.

DPDK has a tendency of using pointers where indexes

could

Quoted 6 lines
Quoted 6 lines

be

Quoted 5 lines
Quoted 5 lines

used

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

instead. I suppose pointers provide the additional flexibility

of

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

mixing entries from different memory pools, e.g.

multiple

Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
Quoted 1 line
Quoted 1 line

mbuf

pools.

Quoted 1 line
Quoted 1 line

Agreed, thank you!

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

I don't think it is going to work:
On 64-bit systems difference between pool address

and

Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

it's

elem

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

address could be bigger than 4GB.
Are you talking about a case where the memory pool
size

Quoted 7 lines
Quoted 7 lines

is

Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 4 lines
Quoted 1 line

more

than 4GB?

Quoted 2 lines

That is one possible scenario.

That could be solved by making the index an element

index

Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines

instead

Quoted 3 lines
Quoted 3 lines

of

Quoted 2 lines
Quoted 2 lines

a

Quoted 1 line
Quoted 1 line

pointer offset: address = (pool address + index *

element

Quoted 12 lines
Quoted 12 lines
Quoted 3 lines
Quoted 3 lines

size).

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

Or instead of scaling the index with the element size,

which

Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 1 line
Quoted 1 line
Quoted 1 line

is

only

Quoted 2 lines
Quoted 2 lines

known at runtime, the index could be more efficiently scaled

by

Quoted 3 lines
Quoted 3 lines

a

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

compile time constant such as RTE_MEMPOOL_ALIGN (= RTE_CACHE_LINE_SIZE). With a cache line size of 64 byte,

Quoted 8 lines
Quoted 8 lines

that

Quoted 7 lines
Quoted 7 lines

would

Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines

allow indexing into mempools up to 256 GB in size.

Quoted 1 line

Looking at this snippet [1] from

rte_mempool_op_populate_helper(),

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

there is an ‘offset’ added to avoid objects to cross

page

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

boundaries.

Quoted 1 line
Quoted 1 line

If my understanding is correct, using the index of

element

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

instead

Quoted 2 lines
Quoted 2 lines

of a

Quoted 1 line
Quoted 1 line

pointer offset will pose a challenge for some of the

corner

Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines

cases.

Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines

[1]

       for (i = 0; i < max_objs; i++) {
               /* avoid objects to cross page boundaries

*/

Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

if (check_obj_bounds(va + off, pg_sz,

total_elt_sz)

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

<

0) {
                       off += RTE_PTR_ALIGN_CEIL(va +

off,

Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines

pg_sz) -

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

(va + off);
if (flags &

RTE_MEMPOOL_POPULATE_F_ALIGN_OBJ)

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
                               off += total_elt_sz -
                                       (((uintptr_t)(va

+

Quoted 5 lines
Quoted 5 lines

off -

Quoted 3 lines
Quoted 3 lines

1) %

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

total_elt_sz)

+

Quoted 8 lines
Quoted 8 lines
Quoted 5 lines
Quoted 5 lines

1);

Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 2 lines
               }

OK. Alternatively to scaling the index with a cache line

size,

Quoted 2 lines
Quoted 2 lines

you

Quoted 1 line
Quoted 1 line

can scale it with sizeof(uintptr_t) to be able to address

32

Quoted 4 lines
Quoted 4 lines
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

or

16

Quoted 2 lines
Quoted 2 lines

GB

Quoted 1 line
Quoted 1 line

mempools on respectively 64 bit and 32 bit architectures.

Both

Quoted 18 lines
Quoted 18 lines

x86

Quoted 2 lines
Quoted 2 lines

and

Quoted 1 line
Quoted 1 line

ARM CPUs have instructions to access memory with an added

offset

Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines

multiplied by 4 or 8. So that should be high performance.

Yes, agreed this can be done.
Cache line size can also be used when

‘MEMPOOL_F_NO_CACHE_ALIGN’

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

is not enabled.
On a side note, I wanted to better understand the need for

having

Quoted 4 lines
Quoted 4 lines

the

Quoted 3 lines
Quoted 1 line

'MEMPOOL_F_NO_CACHE_ALIGN' option.

The description of this field is misleading, and should be

corrected.

Quoted 1 line
Quoted 1 line
Quoted 1 line

The correct description would be: Don't need to align objs on

Quoted 8 lines
Quoted 8 lines

cache

Quoted 3 lines
Quoted 3 lines

lines.

Quoted 2 lines

It is useful for mempools containing very small objects, to

conserve

Quoted 3 lines
Quoted 3 lines

memory.
I think we can assume that mbuf pools are created with the 'MEMPOOL_F_NO_CACHE_ALIGN' flag set. With this we can use

offset

Quoted 7 lines
Quoted 7 lines
Quoted 3 lines
Quoted 1 line

calculated with cache line size as the unit.

You mean MEMPOOL_F_NO_CACHE_ALIGN flag not set. ;-)

Yes 😊

Quoted 2 lines

I agree. And since the flag is a hint only, it can be ignored if

the

Quoted 3 lines
Quoted 3 lines

mempool

Quoted 1 line

library is scaling the index with the cache line size.

I do not think we should ignore the flag for reason you mention

below.

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

However, a mempool may contain other objects than mbufs, and

those

Quoted 7 lines
Quoted 2 lines

objects

Quoted 1 line

may be small, so ignoring the MEMPOOL_F_NO_CACHE_ALIGN flag may

cost

Quoted 4 lines

a

Quoted 1 line

lot of memory for such mempools.

We could use different methods. If MEMPOOL_F_NO_CACHE_ALIGN is set, use the unit as 'sizeof(uintptr_t)', if not set use cache line size

as

Quoted 4 lines
Quoted 2 lines

the unit.

That would require that the indexing multiplier is a runtime

parameter instead

Quoted 3 lines

of a compile time parameter. So it would have a performance penalty.

The indexing multiplier could be compile time configurable, so it is

a tradeoff

Quoted 1 line

between granularity and maximum mempool size.

Quoted 8 lines

I meant compile time configurable. i.e.

#ifdef MEMPOOL_F_NO_CACHE_ALIGN
<use sizeof(uintptr_t) as the multiplier>
#else
<use cache line size as the multiplier> /* This should provide enough memory for packet buffers */
#endif

Please note that MEMPOOL_F_NO_CACHE_ALIGN is a runtime flag passed when creating a mempool, not a compile time option.

#22 lore raw
Quoted 190 lines · Morten Brørup
Quoted 190 lines

From: dev [mailto:[email protected]] On Behalf Of Honnappa Nagarahalli
Sent: Monday, 8 November 2021 16.46

<snip>

Quoted 10 lines
Quoted 10 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

Current mempool per core cache implementation is

based

Quoted 7 lines
Quoted 7 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines

on
pointer
For most architectures, each pointer consumes 64b
Replace

it

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

with
index-based implementation, where in each buffer

is

Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 3 lines

addressed
by
(pool address + index)

I like Dharmik's suggestion very much. CPU cache is a critical and limited resource.

DPDK has a tendency of using pointers where indexes

could

Quoted 6 lines
Quoted 6 lines

be

Quoted 5 lines
Quoted 5 lines

used

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

instead. I suppose pointers provide the additional flexibility

of

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

mixing entries from different memory pools, e.g.

multiple

Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
Quoted 1 line
Quoted 1 line

mbuf

pools.

Quoted 1 line
Quoted 1 line

Agreed, thank you!

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

I don't think it is going to work:
On 64-bit systems difference between pool address

and

Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

it's

elem

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

address could be bigger than 4GB.
Are you talking about a case where the memory pool
size

Quoted 7 lines
Quoted 7 lines

is

Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 4 lines

more
than 4GB?

That is one possible scenario.

That could be solved by making the index an element

index

Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines

instead

Quoted 3 lines
Quoted 3 lines

of

Quoted 2 lines
Quoted 2 lines

a

Quoted 1 line
Quoted 1 line

pointer offset: address = (pool address + index *

element

Quoted 12 lines
Quoted 12 lines
Quoted 3 lines
Quoted 3 lines

size).

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

Or instead of scaling the index with the element size,

which

Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 1 line
Quoted 1 line
Quoted 1 line

is

only

Quoted 2 lines
Quoted 2 lines

known at runtime, the index could be more efficiently scaled

by

Quoted 3 lines
Quoted 3 lines

a

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

compile time constant such as RTE_MEMPOOL_ALIGN (= RTE_CACHE_LINE_SIZE). With a cache line size of 64 byte,

Quoted 8 lines
Quoted 8 lines

that

Quoted 7 lines
Quoted 7 lines

would

Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines

allow indexing into mempools up to 256 GB in size.

Quoted 1 line

Looking at this snippet [1] from

rte_mempool_op_populate_helper(),

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

there is an ‘offset’ added to avoid objects to cross

page

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

boundaries.

Quoted 1 line
Quoted 1 line

If my understanding is correct, using the index of

element

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

instead

Quoted 2 lines
Quoted 2 lines

of a

Quoted 1 line
Quoted 1 line

pointer offset will pose a challenge for some of the

corner

Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines

cases.

Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines

[1]

       for (i = 0; i < max_objs; i++) {
               /* avoid objects to cross page boundaries

*/

Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

if (check_obj_bounds(va + off, pg_sz,

total_elt_sz)

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

<

0) {
                       off += RTE_PTR_ALIGN_CEIL(va +

off,

Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines

pg_sz) -

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

(va + off);
if (flags &

RTE_MEMPOOL_POPULATE_F_ALIGN_OBJ)

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
                               off += total_elt_sz -
                                       (((uintptr_t)(va

+

Quoted 5 lines
Quoted 5 lines

off -

Quoted 3 lines
Quoted 3 lines

1) %

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

total_elt_sz)

+

Quoted 8 lines
Quoted 8 lines
Quoted 5 lines
Quoted 5 lines

1);

Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 2 lines
               }

OK. Alternatively to scaling the index with a cache line

size,

Quoted 2 lines
Quoted 2 lines

you

Quoted 1 line
Quoted 1 line

can scale it with sizeof(uintptr_t) to be able to address

32

Quoted 4 lines
Quoted 4 lines
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

or

16

Quoted 2 lines
Quoted 2 lines

GB

Quoted 1 line
Quoted 1 line

mempools on respectively 64 bit and 32 bit architectures.

Both

Quoted 18 lines
Quoted 18 lines

x86

Quoted 2 lines
Quoted 2 lines

and

Quoted 1 line
Quoted 1 line

ARM CPUs have instructions to access memory with an added

offset

Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines

multiplied by 4 or 8. So that should be high performance.

Yes, agreed this can be done.
Cache line size can also be used when

‘MEMPOOL_F_NO_CACHE_ALIGN’

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

is not enabled.
On a side note, I wanted to better understand the need for

having

Quoted 4 lines
Quoted 4 lines

the

Quoted 3 lines
Quoted 1 line

'MEMPOOL_F_NO_CACHE_ALIGN' option.

The description of this field is misleading, and should be

corrected.

Quoted 1 line
Quoted 1 line
Quoted 1 line

The correct description would be: Don't need to align objs on

Quoted 8 lines
Quoted 8 lines

cache

Quoted 3 lines
Quoted 3 lines

lines.

Quoted 2 lines

It is useful for mempools containing very small objects, to

conserve

Quoted 3 lines
Quoted 3 lines

memory.
I think we can assume that mbuf pools are created with the 'MEMPOOL_F_NO_CACHE_ALIGN' flag set. With this we can use

offset

Quoted 7 lines
Quoted 7 lines
Quoted 3 lines
Quoted 1 line

calculated with cache line size as the unit.

You mean MEMPOOL_F_NO_CACHE_ALIGN flag not set. ;-)

Yes 😊

Quoted 2 lines

I agree. And since the flag is a hint only, it can be ignored if

the

Quoted 3 lines
Quoted 3 lines

mempool

Quoted 1 line

library is scaling the index with the cache line size.

I do not think we should ignore the flag for reason you mention

below.

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

However, a mempool may contain other objects than mbufs, and

those

Quoted 7 lines
Quoted 2 lines

objects

Quoted 1 line

may be small, so ignoring the MEMPOOL_F_NO_CACHE_ALIGN flag may

cost

Quoted 4 lines

a

Quoted 1 line

lot of memory for such mempools.

We could use different methods. If MEMPOOL_F_NO_CACHE_ALIGN is set, use the unit as 'sizeof(uintptr_t)', if not set use cache line size

as

Quoted 4 lines
Quoted 2 lines

the unit.

That would require that the indexing multiplier is a runtime

parameter instead

Quoted 3 lines

of a compile time parameter. So it would have a performance penalty.

The indexing multiplier could be compile time configurable, so it is

a tradeoff

Quoted 1 line

between granularity and maximum mempool size.

I meant compile time configurable. i.e.

Quoted 8 lines
Quoted 6 lines

#ifdef MEMPOOL_F_NO_CACHE_ALIGN
<use sizeof(uintptr_t) as the multiplier>
#else
<use cache line size as the multiplier> /* This should provide enough memory for packet buffers */
#endif

Please note that MEMPOOL_F_NO_CACHE_ALIGN is a runtime flag passed when creating a mempool, not a compile time option.

Also, Please share PMU counters stats on L1 and L2 miss with or without this scheme after the rework. IMO, we should not have any regression on
1) Per core mpps
OR
2) L1 and L2 misses.
with l3fwd/testpmd/l2fwd etc,

Quoted 2 lines
#23 lore raw

cover mempool: implement index-based per core cache

In reply to Dharmik Thakkar

Current mempool per core cache implementation stores pointers to mbufs On 64b architectures, each pointer consumes 8B
This patch replaces it with index-based implementation, where in each buffer is addressed by (pool base address + index) It reduces the amount of memory/cache required for per core cache

L3Fwd performance testing reveals minor improvements in the cache performance (L1 and L2 misses reduced by 0.60%)
with no change in throughput

Micro-benchmarking the patch using mempool_perf_test shows significant improvement with majority of the test cases

Number of cores = 1:
n_get_bulk=1 n_put_bulk=1 n_keep=32 %_change_with_patch=18.01 n_get_bulk=1 n_put_bulk=1 n_keep=128 %_change_with_patch=19.91 n_get_bulk=1 n_put_bulk=4 n_keep=32 %_change_with_patch=-20.37 (regression) n_get_bulk=1 n_put_bulk=4 n_keep=128 %_change_with_patch=-17.01 (regression) n_get_bulk=1 n_put_bulk=32 n_keep=32 %_change_with_patch=-25.06 (regression) n_get_bulk=1 n_put_bulk=32 n_keep=128 %_change_with_patch=-23.81 (regression) n_get_bulk=4 n_put_bulk=1 n_keep=32 %_change_with_patch=53.93 n_get_bulk=4 n_put_bulk=1 n_keep=128 %_change_with_patch=60.90 n_get_bulk=4 n_put_bulk=4 n_keep=32 %_change_with_patch=1.64 n_get_bulk=4 n_put_bulk=4 n_keep=128 %_change_with_patch=8.76 n_get_bulk=4 n_put_bulk=32 n_keep=32 %_change_with_patch=-4.71 (regression) n_get_bulk=4 n_put_bulk=32 n_keep=128 %_change_with_patch=-3.19 (regression) n_get_bulk=32 n_put_bulk=1 n_keep=32 %_change_with_patch=65.63 n_get_bulk=32 n_put_bulk=1 n_keep=128 %_change_with_patch=75.19 n_get_bulk=32 n_put_bulk=4 n_keep=32 %_change_with_patch=11.75 n_get_bulk=32 n_put_bulk=4 n_keep=128 %_change_with_patch=15.52 n_get_bulk=32 n_put_bulk=32 n_keep=32 %_change_with_patch=13.45 n_get_bulk=32 n_put_bulk=32 n_keep=128 %_change_with_patch=11.58

Number of core = 2:
n_get_bulk=1 n_put_bulk=1 n_keep=32 %_change_with_patch=18.21 n_get_bulk=1 n_put_bulk=1 n_keep=128 %_change_with_patch=21.89 n_get_bulk=1 n_put_bulk=4 n_keep=32 %_change_with_patch=-21.21 (regression) n_get_bulk=1 n_put_bulk=4 n_keep=128 %_change_with_patch=-17.05 (regression) n_get_bulk=1 n_put_bulk=32 n_keep=32 %_change_with_patch=-26.09 (regression) n_get_bulk=1 n_put_bulk=32 n_keep=128 %_change_with_patch=-23.49 (regression) n_get_bulk=4 n_put_bulk=1 n_keep=32 %_change_with_patch=56.28 n_get_bulk=4 n_put_bulk=1 n_keep=128 %_change_with_patch=67.69 n_get_bulk=4 n_put_bulk=4 n_keep=32 %_change_with_patch=1.45 n_get_bulk=4 n_put_bulk=4 n_keep=128 %_change_with_patch=8.84 n_get_bulk=4 n_put_bulk=32 n_keep=32 %_change_with_patch=-5.27 (regression) n_get_bulk=4 n_put_bulk=32 n_keep=128 %_change_with_patch=-3.09 (regression) n_get_bulk=32 n_put_bulk=1 n_keep=32 %_change_with_patch=76.11 n_get_bulk=32 n_put_bulk=1 n_keep=128 %_change_with_patch=86.06 n_get_bulk=32 n_put_bulk=4 n_keep=32 %_change_with_patch=11.86 n_get_bulk=32 n_put_bulk=4 n_keep=128 %_change_with_patch=16.55 n_get_bulk=32 n_put_bulk=32 n_keep=32 %_change_with_patch=13.01 n_get_bulk=32 n_put_bulk=32 n_keep=128 %_change_with_patch=11.51

From analyzing the results, it is clear that for n_get_bulk and n_put_bulk sizes of 32 there is no performance regression IMO, the other sizes are not practical from performance perspective and the regression in those cases can be safely ignored

Dharmik Thakkar (1):
mempool: implement index-based per core cache

 lib/mempool/rte_mempool.h             | 114 +++++++++++++++++++++++++-
 lib/mempool/rte_mempool_ops_default.c |   7 ++
 2 files changed, 119 insertions(+), 2 deletions(-)
Signature · 1 line
2.25.1
#24 lore raw

PATCH 1/1 mempool: implement index-based per core cache

Current mempool per core cache implementation stores pointers to mbufs On 64b architectures, each pointer consumes 8B
This patch replaces it with index-based implementation, where in each buffer is addressed by (pool base address + index) It reduces the amount of memory/cache required for per core cache

L3Fwd performance testing reveals minor improvements in the cache performance (L1 and L2 misses reduced by 0.60%)
with no change in throughput

---
 lib/mempool/rte_mempool.h             | 114 +++++++++++++++++++++++++-
 lib/mempool/rte_mempool_ops_default.c |   7 ++
 2 files changed, 119 insertions(+), 2 deletions(-)
lib/mempool/rte_mempool.h +112 -2
index 1e7a3c15273c..4fabd3b1920b 100644
@@ -50,6 +50,10 @@
 #include <rte_memcpy.h>
 #include <rte_common.h>
 
+#ifdef RTE_MEMPOOL_INDEX_BASED_LCORE_CACHE
+#include <rte_vect.h>
+#endif
+
 #include "rte_mempool_trace_fp.h"
 
 #ifdef __cplusplus
@@ -239,6 +243,9 @@ struct rte_mempool {
 	int32_t ops_index;
 
 	struct rte_mempool_cache *local_cache; /**< Per-lcore local cache */
+#ifdef RTE_MEMPOOL_INDEX_BASED_LCORE_CACHE
+	void *pool_base_value; /**< Base value to calculate indices */
+#endif
 
 	uint32_t populated_size;         /**< Number of populated objects. */
 	struct rte_mempool_objhdr_list elt_list; /**< List of objects in pool */
@@ -1314,7 +1321,19 @@ rte_mempool_cache_flush(struct rte_mempool_cache *cache,
 	if (cache == NULL || cache->len == 0)
 		return;
 	rte_mempool_trace_cache_flush(cache, mp);
+
+#ifdef RTE_MEMPOOL_INDEX_BASED_LCORE_CACHE
+	unsigned int i;
+	unsigned int cache_len = cache->len;
+	void *obj_table[RTE_MEMPOOL_CACHE_MAX_SIZE * 3];
+	void *base_value = mp->pool_base_value;
+	uint32_t *cache_objs = (uint32_t *) cache->objs;
+	for (i = 0; i < cache_len; i++)
+		obj_table[i] = (void *) RTE_PTR_ADD(base_value, cache_objs[i]);
+	rte_mempool_ops_enqueue_bulk(mp, obj_table, cache->len);
+#else
 	rte_mempool_ops_enqueue_bulk(mp, cache->objs, cache->len);
+#endif
 	cache->len = 0;
 }
 
@@ -1334,8 +1353,13 @@ static __rte_always_inline void
 rte_mempool_do_generic_put(struct rte_mempool *mp, void * const *obj_table,
 			   unsigned int n, struct rte_mempool_cache *cache)
 {
+#ifdef RTE_MEMPOOL_INDEX_BASED_LCORE_CACHE
+	uint32_t *cache_objs;
+	void *base_value;
+	uint32_t i;
+#else
 	void **cache_objs;
-
+#endif
 	/* increment stat now, adding in mempool always success */
 	RTE_MEMPOOL_STAT_ADD(mp, put_bulk, 1);
 	RTE_MEMPOOL_STAT_ADD(mp, put_objs, n);
@@ -1344,7 +1368,13 @@ rte_mempool_do_generic_put(struct rte_mempool *mp, void * const *obj_table,
 	if (unlikely(cache == NULL || n > RTE_MEMPOOL_CACHE_MAX_SIZE))
 		goto ring_enqueue;
 
+#ifdef RTE_MEMPOOL_INDEX_BASED_LCORE_CACHE
+	cache_objs = (uint32_t *) cache->objs;
+	cache_objs = &cache_objs[cache->len];
+	base_value = mp->pool_base_value;
+#else
 	cache_objs = &cache->objs[cache->len];
+#endif
 
 	/*
 	 * The cache follows the following algorithm
@@ -1354,13 +1384,40 @@ rte_mempool_do_generic_put(struct rte_mempool *mp, void * const *obj_table,
 	 */
 
 	/* Add elements back into the cache */
+
+#ifdef RTE_MEMPOOL_INDEX_BASED_LCORE_CACHE
+#if defined __ARM_NEON
+	uint64x2_t v_obj_table;
+	uint64x2_t v_base_value = vdupq_n_u64((uint64_t)base_value);
+	uint32x2_t v_cache_objs;
+
+	for (i = 0; i < (n & ~0x1); i += 2) {
+		v_obj_table = vld1q_u64((const uint64_t *)&obj_table[i]);
+		v_cache_objs = vqmovn_u64(vsubq_u64(v_obj_table, v_base_value));
+		vst1_u32(cache_objs + i, v_cache_objs);
+	}
+	if (n & 0x1) {
+		cache_objs[i] = (uint32_t) RTE_PTR_DIFF(obj_table[i], base_value);
+	}
+#else
+	for (i = 0; i < n; i++) {
+		cache_objs[i] = (uint32_t) RTE_PTR_DIFF(obj_table[i], base_value);
+	}
+#endif
+#else
 	rte_memcpy(&cache_objs[0], obj_table, sizeof(void *) * n);
+#endif
 
 	cache->len += n;
 
 	if (cache->len >= cache->flushthresh) {
+#ifdef RTE_MEMPOOL_INDEX_BASED_LCORE_CACHE
+		rte_mempool_ops_enqueue_bulk(mp, obj_table + cache->len - cache->size,
+				cache->len - cache->size);
+#else
 		rte_mempool_ops_enqueue_bulk(mp, &cache->objs[cache->size],
 				cache->len - cache->size);
+#endif
 		cache->len = cache->size;
 	}
 
@@ -1461,13 +1518,22 @@ rte_mempool_do_generic_get(struct rte_mempool *mp, void **obj_table,
 {
 	int ret;
 	uint32_t index, len;
+#ifdef RTE_MEMPOOL_INDEX_BASED_LCORE_CACHE
+	uint32_t i;
+	uint32_t *cache_objs;
+#else
 	void **cache_objs;
-
+#endif
 	/* No cache provided or cannot be satisfied from cache */
 	if (unlikely(cache == NULL || n >= cache->size))
 		goto ring_dequeue;
 
+#ifdef RTE_MEMPOOL_INDEX_BASED_LCORE_CACHE
+	void *base_value = mp->pool_base_value;
+	cache_objs = (uint32_t *) cache->objs;
+#else
 	cache_objs = cache->objs;
+#endif
 
 	/* Can this be satisfied from the cache? */
 	if (cache->len < n) {
@@ -1475,8 +1541,14 @@ rte_mempool_do_generic_get(struct rte_mempool *mp, void **obj_table,
 		uint32_t req = n + (cache->size - cache->len);
 
 		/* How many do we require i.e. number to fill the cache + the request */
+#ifdef RTE_MEMPOOL_INDEX_BASED_LCORE_CACHE
+		void *temp_objs[RTE_MEMPOOL_CACHE_MAX_SIZE * 3]; /**< Cache objects */
+		ret = rte_mempool_ops_dequeue_bulk(mp,
+			temp_objs, req);
+#else
 		ret = rte_mempool_ops_dequeue_bulk(mp,
 			&cache->objs[cache->len], req);
+#endif
 		if (unlikely(ret < 0)) {
 			/*
 			 * In the off chance that we are buffer constrained,
@@ -1487,12 +1559,50 @@ rte_mempool_do_generic_get(struct rte_mempool *mp, void **obj_table,
 			goto ring_dequeue;
 		}
 
+#ifdef RTE_MEMPOOL_INDEX_BASED_LCORE_CACHE
+		len = cache->len;
+		for (i = 0; i < req; ++i, ++len) {
+			cache_objs[len] = (uint32_t) RTE_PTR_DIFF(temp_objs[i],
+								base_value);
+		}
+#endif
 		cache->len += req;
 	}
 
 	/* Now fill in the response ... */
+#ifdef RTE_MEMPOOL_INDEX_BASED_LCORE_CACHE
+#if defined __ARM_NEON
+	uint64x2_t v_obj_table;
+	uint64x2_t v_cache_objs;
+	uint64x2_t v_base_value = vdupq_n_u64((uint64_t)base_value);
+
+	for (index = 0, len = cache->len - 1; index < (n & ~0x3); index += 4,
+						len -= 4, obj_table += 4) {
+		v_cache_objs = vmovl_u32(vld1_u32(cache_objs + len - 1));
+		v_obj_table = vaddq_u64(v_cache_objs, v_base_value);
+		vst1q_u64((uint64_t *)obj_table, v_obj_table);
+		v_cache_objs = vmovl_u32(vld1_u32(cache_objs + len - 3));
+		v_obj_table = vaddq_u64(v_cache_objs, v_base_value);
+		vst1q_u64((uint64_t *)(obj_table + 2), v_obj_table);
+	}
+	switch (n & 0x3) {
+	case 3:
+		*(obj_table++) = (void *) RTE_PTR_ADD(base_value, cache_objs[len--]);
+								/* fallthrough */
+	case 2:
+		*(obj_table++) = (void *) RTE_PTR_ADD(base_value, cache_objs[len--]);
+								/* fallthrough */
+	case 1:
+		*(obj_table++) = (void *) RTE_PTR_ADD(base_value, cache_objs[len--]);
+	}
+#else
+	for (index = 0, len = cache->len - 1; index < n; ++index, len--, obj_table++)
+		*obj_table = (void *) RTE_PTR_ADD(base_value, cache_objs[len]);
+#endif
+#else
 	for (index = 0, len = cache->len - 1; index < n; ++index, len--, obj_table++)
 		*obj_table = cache_objs[len];
+#endif
 
 	cache->len -= n;
 
lib/mempool/rte_mempool_ops_default.c +7 -0
index 22fccf9d7619..3543cad9d4ce 100644
@@ -127,6 +127,13 @@ rte_mempool_op_populate_helper(struct rte_mempool *mp, unsigned int flags,
 		obj = va + off;
 		obj_cb(mp, obj_cb_arg, obj,
 		       (iova == RTE_BAD_IOVA) ? RTE_BAD_IOVA : (iova + off));
+#ifdef RTE_MEMPOOL_INDEX_BASED_LCORE_CACHE
+		/* Store pool base value to calculate indices for index-based
+		 * lcore cache implementation
+		 */
+		if (i == 0)
+			mp->pool_base_value = obj;
+#endif
 		rte_mempool_ops_enqueue_bulk(mp, &obj, 1);
 		off += mp->elt_size + mp->trailer_size;
 	}
Signature · 1 line
2.25.1
#25 lore raw
Quoted 9 lines

Current mempool per core cache implementation stores pointers to mbufs On 64b architectures, each pointer consumes 8B
This patch replaces it with index-based implementation, where in each buffer is addressed by (pool base address + index) It reduces the amount of memory/cache required for per core cache

Quoted 3 lines

L3Fwd performance testing reveals minor improvements in the cache performance (L1 and L2 misses reduced by 0.60%)
with no change in throughput

I feel really sceptical about that patch and the whole idea in general:
- From what I read above there is no real performance improvement observed.
(In fact on my IA boxes mempool_perf_autotest reports ~20% slowdown,
see below for more details).
- Space utilization difference looks neglectable too.
- The change introduces a new build time config option with a major limitation:
All memzones in a pool have to be within the same 4GB boundary.
To address it properly, extra changes will be required in init(/populate) part of the code. All that will complicate mempool code, will make it more error prone
and harder to maintain.
But, as there is no real gain in return - no point to add such extra complexity at all.

Konstantin

CSX 2.1 GHz
==========

echo 'mempool_perf_autotest' | ./dpdk-test -n 4 --lcores='6-13' --no-pci

params : rate_persec
(normal/index-based/diff %)
(with cache)
cache=512 cores=1 n_get_bulk=32 n_put_bulk=32 n_keep=32 : 740989337.00/504116019.00/-31.97
cache=512 cores=1 n_get_bulk=32 n_put_bulk=32 n_keep=128 : 756495155.00/615002931.00/-18.70
cache=512 cores=2 n_get_bulk=32 n_put_bulk=32 n_keep=32 : 1483499110.00/1007248997.00/-32.10
cache=512 cores=2 n_get_bulk=32 n_put_bulk=32 n_keep=128 : 1512439807.00/1229927218.00/-18.68
cache=512 cores=8 n_get_bulk=32 n_put_bulk=32 n_keep=32 : 5933668757.00/4029048421.00/-32.10
cache=512 cores=8 n_get_bulk=32 n_put_bulk=32 n_keep=128 : 6049234942.00/4921111344.00/-18.65

(with user-owned cache)
cache=512 cores=1 n_get_bulk=32 n_put_bulk=32 n_keep=32 : 630600499.00/504312627.00/-20.03
cache=512 cores=1 n_get_bulk=32 n_put_bulk=32 n_keep=128 : 756259225.00/615042252.00/-18.67 cache=512 cores=2 n_get_bulk=32 n_put_bulk=32 n_keep=32 : 1262052966.00/1007039283.00/-20.21 cache=512 cores=2 n_get_bulk=32 n_put_bulk=32 n_keep=128 : 1517853081.00/1230818508.00/-18.91 cache=512 cores=8 n_get_bulk=32 n_put_bulk=32 n_keep=32 :5054529533.00/4028052273.00/-20.31 cache=512 cores=8 n_get_bulk=32 n_put_bulk=32 n_keep=128 : 6059340592.00/4912893129.00/-18.92

Quoted 234 lines
---
 lib/mempool/rte_mempool.h             | 114 +++++++++++++++++++++++++-
 lib/mempool/rte_mempool_ops_default.c |   7 ++
 2 files changed, 119 insertions(+), 2 deletions(-)
lib/mempool/rte_mempool.h +112 -2
index 1e7a3c15273c..4fabd3b1920b 100644
@@ -50,6 +50,10 @@
 #include <rte_memcpy.h>
 #include <rte_common.h>
 
+#ifdef RTE_MEMPOOL_INDEX_BASED_LCORE_CACHE
+#include <rte_vect.h>
+#endif
+
 #include "rte_mempool_trace_fp.h"
 
 #ifdef __cplusplus
@@ -239,6 +243,9 @@ struct rte_mempool {
 	int32_t ops_index;
 
 	struct rte_mempool_cache *local_cache; /**< Per-lcore local cache */
+#ifdef RTE_MEMPOOL_INDEX_BASED_LCORE_CACHE
+	void *pool_base_value; /**< Base value to calculate indices */
+#endif
 
 	uint32_t populated_size;         /**< Number of populated objects. */
 	struct rte_mempool_objhdr_list elt_list; /**< List of objects in pool */
@@ -1314,7 +1321,19 @@ rte_mempool_cache_flush(struct rte_mempool_cache *cache,
 	if (cache == NULL || cache->len == 0)
 		return;
 	rte_mempool_trace_cache_flush(cache, mp);
+
+#ifdef RTE_MEMPOOL_INDEX_BASED_LCORE_CACHE
+	unsigned int i;
+	unsigned int cache_len = cache->len;
+	void *obj_table[RTE_MEMPOOL_CACHE_MAX_SIZE * 3];
+	void *base_value = mp->pool_base_value;
+	uint32_t *cache_objs = (uint32_t *) cache->objs;
+	for (i = 0; i < cache_len; i++)
+		obj_table[i] = (void *) RTE_PTR_ADD(base_value, cache_objs[i]);
+	rte_mempool_ops_enqueue_bulk(mp, obj_table, cache->len);
+#else
 	rte_mempool_ops_enqueue_bulk(mp, cache->objs, cache->len);
+#endif
 	cache->len = 0;
 }
 
@@ -1334,8 +1353,13 @@ static __rte_always_inline void
 rte_mempool_do_generic_put(struct rte_mempool *mp, void * const *obj_table,
 			   unsigned int n, struct rte_mempool_cache *cache)
 {
+#ifdef RTE_MEMPOOL_INDEX_BASED_LCORE_CACHE
+	uint32_t *cache_objs;
+	void *base_value;
+	uint32_t i;
+#else
 	void **cache_objs;
-
+#endif
 	/* increment stat now, adding in mempool always success */
 	RTE_MEMPOOL_STAT_ADD(mp, put_bulk, 1);
 	RTE_MEMPOOL_STAT_ADD(mp, put_objs, n);
@@ -1344,7 +1368,13 @@ rte_mempool_do_generic_put(struct rte_mempool *mp, void * const *obj_table,
 	if (unlikely(cache == NULL || n > RTE_MEMPOOL_CACHE_MAX_SIZE))
 		goto ring_enqueue;
 
+#ifdef RTE_MEMPOOL_INDEX_BASED_LCORE_CACHE
+	cache_objs = (uint32_t *) cache->objs;
+	cache_objs = &cache_objs[cache->len];
+	base_value = mp->pool_base_value;
+#else
 	cache_objs = &cache->objs[cache->len];
+#endif
 
 	/*
 	 * The cache follows the following algorithm
@@ -1354,13 +1384,40 @@ rte_mempool_do_generic_put(struct rte_mempool *mp, void * const *obj_table,
 	 */
 
 	/* Add elements back into the cache */
+
+#ifdef RTE_MEMPOOL_INDEX_BASED_LCORE_CACHE
+#if defined __ARM_NEON
+	uint64x2_t v_obj_table;
+	uint64x2_t v_base_value = vdupq_n_u64((uint64_t)base_value);
+	uint32x2_t v_cache_objs;
+
+	for (i = 0; i < (n & ~0x1); i += 2) {
+		v_obj_table = vld1q_u64((const uint64_t *)&obj_table[i]);
+		v_cache_objs = vqmovn_u64(vsubq_u64(v_obj_table, v_base_value));
+		vst1_u32(cache_objs + i, v_cache_objs);
+	}
+	if (n & 0x1) {
+		cache_objs[i] = (uint32_t) RTE_PTR_DIFF(obj_table[i], base_value);
+	}
+#else
+	for (i = 0; i < n; i++) {
+		cache_objs[i] = (uint32_t) RTE_PTR_DIFF(obj_table[i], base_value);
+	}
+#endif
+#else
 	rte_memcpy(&cache_objs[0], obj_table, sizeof(void *) * n);
+#endif
 
 	cache->len += n;
 
 	if (cache->len >= cache->flushthresh) {
+#ifdef RTE_MEMPOOL_INDEX_BASED_LCORE_CACHE
+		rte_mempool_ops_enqueue_bulk(mp, obj_table + cache->len - cache->size,
+				cache->len - cache->size);
+#else
 		rte_mempool_ops_enqueue_bulk(mp, &cache->objs[cache->size],
 				cache->len - cache->size);
+#endif
 		cache->len = cache->size;
 	}
 
@@ -1461,13 +1518,22 @@ rte_mempool_do_generic_get(struct rte_mempool *mp, void **obj_table,
 {
 	int ret;
 	uint32_t index, len;
+#ifdef RTE_MEMPOOL_INDEX_BASED_LCORE_CACHE
+	uint32_t i;
+	uint32_t *cache_objs;
+#else
 	void **cache_objs;
-
+#endif
 	/* No cache provided or cannot be satisfied from cache */
 	if (unlikely(cache == NULL || n >= cache->size))
 		goto ring_dequeue;
 
+#ifdef RTE_MEMPOOL_INDEX_BASED_LCORE_CACHE
+	void *base_value = mp->pool_base_value;
+	cache_objs = (uint32_t *) cache->objs;
+#else
 	cache_objs = cache->objs;
+#endif
 
 	/* Can this be satisfied from the cache? */
 	if (cache->len < n) {
@@ -1475,8 +1541,14 @@ rte_mempool_do_generic_get(struct rte_mempool *mp, void **obj_table,
 		uint32_t req = n + (cache->size - cache->len);
 
 		/* How many do we require i.e. number to fill the cache + the request */
+#ifdef RTE_MEMPOOL_INDEX_BASED_LCORE_CACHE
+		void *temp_objs[RTE_MEMPOOL_CACHE_MAX_SIZE * 3]; /**< Cache objects */
+		ret = rte_mempool_ops_dequeue_bulk(mp,
+			temp_objs, req);
+#else
 		ret = rte_mempool_ops_dequeue_bulk(mp,
 			&cache->objs[cache->len], req);
+#endif
 		if (unlikely(ret < 0)) {
 			/*
 			 * In the off chance that we are buffer constrained,
@@ -1487,12 +1559,50 @@ rte_mempool_do_generic_get(struct rte_mempool *mp, void **obj_table,
 			goto ring_dequeue;
 		}
 
+#ifdef RTE_MEMPOOL_INDEX_BASED_LCORE_CACHE
+		len = cache->len;
+		for (i = 0; i < req; ++i, ++len) {
+			cache_objs[len] = (uint32_t) RTE_PTR_DIFF(temp_objs[i],
+								base_value);
+		}
+#endif
 		cache->len += req;
 	}
 
 	/* Now fill in the response ... */
+#ifdef RTE_MEMPOOL_INDEX_BASED_LCORE_CACHE
+#if defined __ARM_NEON
+	uint64x2_t v_obj_table;
+	uint64x2_t v_cache_objs;
+	uint64x2_t v_base_value = vdupq_n_u64((uint64_t)base_value);
+
+	for (index = 0, len = cache->len - 1; index < (n & ~0x3); index += 4,
+						len -= 4, obj_table += 4) {
+		v_cache_objs = vmovl_u32(vld1_u32(cache_objs + len - 1));
+		v_obj_table = vaddq_u64(v_cache_objs, v_base_value);
+		vst1q_u64((uint64_t *)obj_table, v_obj_table);
+		v_cache_objs = vmovl_u32(vld1_u32(cache_objs + len - 3));
+		v_obj_table = vaddq_u64(v_cache_objs, v_base_value);
+		vst1q_u64((uint64_t *)(obj_table + 2), v_obj_table);
+	}
+	switch (n & 0x3) {
+	case 3:
+		*(obj_table++) = (void *) RTE_PTR_ADD(base_value, cache_objs[len--]);
+								/* fallthrough */
+	case 2:
+		*(obj_table++) = (void *) RTE_PTR_ADD(base_value, cache_objs[len--]);
+								/* fallthrough */
+	case 1:
+		*(obj_table++) = (void *) RTE_PTR_ADD(base_value, cache_objs[len--]);
+	}
+#else
+	for (index = 0, len = cache->len - 1; index < n; ++index, len--, obj_table++)
+		*obj_table = (void *) RTE_PTR_ADD(base_value, cache_objs[len]);
+#endif
+#else
 	for (index = 0, len = cache->len - 1; index < n; ++index, len--, obj_table++)
 		*obj_table = cache_objs[len];
+#endif
 
 	cache->len -= n;
 
lib/mempool/rte_mempool_ops_default.c +7 -1
index 22fccf9d7619..3543cad9d4ce 100644
@@ -127,6 +127,13 @@ rte_mempool_op_populate_helper(struct rte_mempool *mp, unsigned int flags,
 		obj = va + off;
 		obj_cb(mp, obj_cb_arg, obj,
 		       (iova == RTE_BAD_IOVA) ? RTE_BAD_IOVA : (iova + off));
+#ifdef RTE_MEMPOOL_INDEX_BASED_LCORE_CACHE
+		/* Store pool base value to calculate indices for index-based
+		 * lcore cache implementation
+		 */
+		if (i == 0)
+			mp->pool_base_value = obj;
+#endif
 		rte_mempool_ops_enqueue_bulk(mp, &obj, 1);
 		off += mp->elt_size + mp->trailer_size;
 	}
--

2.25.1

#26 lore raw

Hi Konstatin,

Thank you for your comments and the test report!

Quoted 11 lines · Konstantin
Quoted 10 lines

Current mempool per core cache implementation stores pointers to mbufs On 64b architectures, each pointer consumes 8B
This patch replaces it with index-based implementation, where in each buffer is addressed by (pool base address + index) It reduces the amount of memory/cache required for per core cache

Quoted 8 lines
Quoted 3 lines

L3Fwd performance testing reveals minor improvements in the cache performance (L1 and L2 misses reduced by 0.60%)
with no change in throughput

I feel really sceptical about that patch and the whole idea in general:
- From what I read above there is no real performance improvement observed. (In fact on my IA boxes mempool_perf_autotest reports ~20% slowdown, see below for more details).

Currently, the optimizations (loop unroll and vectorization) are only implemented for ARM64. Similar optimizations can be implemented for x86 platforms which should close the performance gap and in my understanding should give better performance for a bulk size of 32.

Quoted 1 line

- Space utilization difference looks neglectable too.

Sorry, I did not understand this point.

Quoted 3 lines

- The change introduces a new build time config option with a major limitation:
All memzones in a pool have to be within the same 4GB boundary.
To address it properly, extra changes will be required in init(/populate) part of the code.

I agree to the above mentioned challenges and I am currently working on resolving these issues.

Quoted 264 lines

All that will complicate mempool code, will make it more error prone and harder to maintain.
But, as there is no real gain in return - no point to add such extra complexity at all.

Konstantin

CSX 2.1 GHz
==========

echo 'mempool_perf_autotest' | ./dpdk-test -n 4 --lcores='6-13' --no-pci

params : rate_persec
(normal/index-based/diff %)
(with cache)
cache=512 cores=1 n_get_bulk=32 n_put_bulk=32 n_keep=32 : 740989337.00/504116019.00/-31.97
cache=512 cores=1 n_get_bulk=32 n_put_bulk=32 n_keep=128 : 756495155.00/615002931.00/-18.70
cache=512 cores=2 n_get_bulk=32 n_put_bulk=32 n_keep=32 : 1483499110.00/1007248997.00/-32.10
cache=512 cores=2 n_get_bulk=32 n_put_bulk=32 n_keep=128 : 1512439807.00/1229927218.00/-18.68
cache=512 cores=8 n_get_bulk=32 n_put_bulk=32 n_keep=32 : 5933668757.00/4029048421.00/-32.10
cache=512 cores=8 n_get_bulk=32 n_put_bulk=32 n_keep=128 : 6049234942.00/4921111344.00/-18.65

(with user-owned cache)
cache=512 cores=1 n_get_bulk=32 n_put_bulk=32 n_keep=32 : 630600499.00/504312627.00/-20.03 cache=512 cores=1 n_get_bulk=32 n_put_bulk=32 n_keep=128 : 756259225.00/615042252.00/-18.67 cache=512 cores=2 n_get_bulk=32 n_put_bulk=32 n_keep=32 : 1262052966.00/1007039283.00/-20.21 cache=512 cores=2 n_get_bulk=32 n_put_bulk=32 n_keep=128 : 1517853081.00/1230818508.00/-18.91 cache=512 cores=8 n_get_bulk=32 n_put_bulk=32 n_keep=32 :5054529533.00/4028052273.00/-20.31 cache=512 cores=8 n_get_bulk=32 n_put_bulk=32 n_keep=128 : 6059340592.00/4912893129.00/-18.92

Quoted 234 lines

---
lib/mempool/rte_mempool.h | 114 +++++++++++++++++++++++++-
lib/mempool/rte_mempool_ops_default.c | 7 ++

2 files changed, 119 insertions(+), 2 deletions(-)
lib/mempool/rte_mempool.h +112 -2
index 1e7a3c15273c..4fabd3b1920b 100644
@@ -50,6 +50,10 @@
 #include <rte_memcpy.h>
 #include <rte_common.h>
 
+#ifdef RTE_MEMPOOL_INDEX_BASED_LCORE_CACHE
+#include <rte_vect.h>
+#endif
+
 #include "rte_mempool_trace_fp.h"
 
 #ifdef __cplusplus
@@ -239,6 +243,9 @@ struct rte_mempool {
 	int32_t ops_index;
 
 	struct rte_mempool_cache *local_cache; /**< Per-lcore local cache */
+#ifdef RTE_MEMPOOL_INDEX_BASED_LCORE_CACHE
+	void *pool_base_value; /**< Base value to calculate indices */
+#endif
 
 	uint32_t populated_size;         /**< Number of populated objects. */
 	struct rte_mempool_objhdr_list elt_list; /**< List of objects in pool */
@@ -1314,7 +1321,19 @@ rte_mempool_cache_flush(struct rte_mempool_cache *cache,
 	if (cache == NULL || cache->len == 0)
 		return;
 	rte_mempool_trace_cache_flush(cache, mp);
+
+#ifdef RTE_MEMPOOL_INDEX_BASED_LCORE_CACHE
+	unsigned int i;
+	unsigned int cache_len = cache->len;
+	void *obj_table[RTE_MEMPOOL_CACHE_MAX_SIZE * 3];
+	void *base_value = mp->pool_base_value;
+	uint32_t *cache_objs = (uint32_t *) cache->objs;
+	for (i = 0; i < cache_len; i++)
+		obj_table[i] = (void *) RTE_PTR_ADD(base_value, cache_objs[i]);
+	rte_mempool_ops_enqueue_bulk(mp, obj_table, cache->len);
+#else
 	rte_mempool_ops_enqueue_bulk(mp, cache->objs, cache->len);
+#endif
 	cache->len = 0;
 }
 
@@ -1334,8 +1353,13 @@ static __rte_always_inline void
 rte_mempool_do_generic_put(struct rte_mempool *mp, void * const *obj_table,
 			   unsigned int n, struct rte_mempool_cache *cache)
 {
+#ifdef RTE_MEMPOOL_INDEX_BASED_LCORE_CACHE
+	uint32_t *cache_objs;
+	void *base_value;
+	uint32_t i;
+#else
 	void **cache_objs;
-
+#endif
 	/* increment stat now, adding in mempool always success */
 	RTE_MEMPOOL_STAT_ADD(mp, put_bulk, 1);
 	RTE_MEMPOOL_STAT_ADD(mp, put_objs, n);
@@ -1344,7 +1368,13 @@ rte_mempool_do_generic_put(struct rte_mempool *mp, void * const *obj_table,
 	if (unlikely(cache == NULL || n > RTE_MEMPOOL_CACHE_MAX_SIZE))
 		goto ring_enqueue;
 
+#ifdef RTE_MEMPOOL_INDEX_BASED_LCORE_CACHE
+	cache_objs = (uint32_t *) cache->objs;
+	cache_objs = &cache_objs[cache->len];
+	base_value = mp->pool_base_value;
+#else
 	cache_objs = &cache->objs[cache->len];
+#endif
 
 	/*
 	 * The cache follows the following algorithm
@@ -1354,13 +1384,40 @@ rte_mempool_do_generic_put(struct rte_mempool *mp, void * const *obj_table,
 	 */
 
 	/* Add elements back into the cache */
+
+#ifdef RTE_MEMPOOL_INDEX_BASED_LCORE_CACHE
+#if defined __ARM_NEON
+	uint64x2_t v_obj_table;
+	uint64x2_t v_base_value = vdupq_n_u64((uint64_t)base_value);
+	uint32x2_t v_cache_objs;
+
+	for (i = 0; i < (n & ~0x1); i += 2) {
+		v_obj_table = vld1q_u64((const uint64_t *)&obj_table[i]);
+		v_cache_objs = vqmovn_u64(vsubq_u64(v_obj_table, v_base_value));
+		vst1_u32(cache_objs + i, v_cache_objs);
+	}
+	if (n & 0x1) {
+		cache_objs[i] = (uint32_t) RTE_PTR_DIFF(obj_table[i], base_value);
+	}
+#else
+	for (i = 0; i < n; i++) {
+		cache_objs[i] = (uint32_t) RTE_PTR_DIFF(obj_table[i], base_value);
+	}
+#endif
+#else
 	rte_memcpy(&cache_objs[0], obj_table, sizeof(void *) * n);
+#endif
 
 	cache->len += n;
 
 	if (cache->len >= cache->flushthresh) {
+#ifdef RTE_MEMPOOL_INDEX_BASED_LCORE_CACHE
+		rte_mempool_ops_enqueue_bulk(mp, obj_table + cache->len - cache->size,
+				cache->len - cache->size);
+#else
 		rte_mempool_ops_enqueue_bulk(mp, &cache->objs[cache->size],
 				cache->len - cache->size);
+#endif
 		cache->len = cache->size;
 	}
 
@@ -1461,13 +1518,22 @@ rte_mempool_do_generic_get(struct rte_mempool *mp, void **obj_table,
 {
 	int ret;
 	uint32_t index, len;
+#ifdef RTE_MEMPOOL_INDEX_BASED_LCORE_CACHE
+	uint32_t i;
+	uint32_t *cache_objs;
+#else
 	void **cache_objs;
-
+#endif
 	/* No cache provided or cannot be satisfied from cache */
 	if (unlikely(cache == NULL || n >= cache->size))
 		goto ring_dequeue;
 
+#ifdef RTE_MEMPOOL_INDEX_BASED_LCORE_CACHE
+	void *base_value = mp->pool_base_value;
+	cache_objs = (uint32_t *) cache->objs;
+#else
 	cache_objs = cache->objs;
+#endif
 
 	/* Can this be satisfied from the cache? */
 	if (cache->len < n) {
@@ -1475,8 +1541,14 @@ rte_mempool_do_generic_get(struct rte_mempool *mp, void **obj_table,
 		uint32_t req = n + (cache->size - cache->len);
 
 		/* How many do we require i.e. number to fill the cache + the request */
+#ifdef RTE_MEMPOOL_INDEX_BASED_LCORE_CACHE
+		void *temp_objs[RTE_MEMPOOL_CACHE_MAX_SIZE * 3]; /**< Cache objects */
+		ret = rte_mempool_ops_dequeue_bulk(mp,
+			temp_objs, req);
+#else
 		ret = rte_mempool_ops_dequeue_bulk(mp,
 			&cache->objs[cache->len], req);
+#endif
 		if (unlikely(ret < 0)) {
 			/*
 			 * In the off chance that we are buffer constrained,
@@ -1487,12 +1559,50 @@ rte_mempool_do_generic_get(struct rte_mempool *mp, void **obj_table,
 			goto ring_dequeue;
 		}
 
+#ifdef RTE_MEMPOOL_INDEX_BASED_LCORE_CACHE
+		len = cache->len;
+		for (i = 0; i < req; ++i, ++len) {
+			cache_objs[len] = (uint32_t) RTE_PTR_DIFF(temp_objs[i],
+								base_value);
+		}
+#endif
 		cache->len += req;
 	}
 
 	/* Now fill in the response ... */
+#ifdef RTE_MEMPOOL_INDEX_BASED_LCORE_CACHE
+#if defined __ARM_NEON
+	uint64x2_t v_obj_table;
+	uint64x2_t v_cache_objs;
+	uint64x2_t v_base_value = vdupq_n_u64((uint64_t)base_value);
+
+	for (index = 0, len = cache->len - 1; index < (n & ~0x3); index += 4,
+						len -= 4, obj_table += 4) {
+		v_cache_objs = vmovl_u32(vld1_u32(cache_objs + len - 1));
+		v_obj_table = vaddq_u64(v_cache_objs, v_base_value);
+		vst1q_u64((uint64_t *)obj_table, v_obj_table);
+		v_cache_objs = vmovl_u32(vld1_u32(cache_objs + len - 3));
+		v_obj_table = vaddq_u64(v_cache_objs, v_base_value);
+		vst1q_u64((uint64_t *)(obj_table + 2), v_obj_table);
+	}
+	switch (n & 0x3) {
+	case 3:
+		*(obj_table++) = (void *) RTE_PTR_ADD(base_value, cache_objs[len--]);
+								/* fallthrough */
+	case 2:
+		*(obj_table++) = (void *) RTE_PTR_ADD(base_value, cache_objs[len--]);
+								/* fallthrough */
+	case 1:
+		*(obj_table++) = (void *) RTE_PTR_ADD(base_value, cache_objs[len--]);
+	}
+#else
+	for (index = 0, len = cache->len - 1; index < n; ++index, len--, obj_table++)
+		*obj_table = (void *) RTE_PTR_ADD(base_value, cache_objs[len]);
+#endif
+#else
 	for (index = 0, len = cache->len - 1; index < n; ++index, len--, obj_table++)
 		*obj_table = cache_objs[len];
+#endif
 
 	cache->len -= n;
 
lib/mempool/rte_mempool_ops_default.c +7 -1
index 22fccf9d7619..3543cad9d4ce 100644
@@ -127,6 +127,13 @@ rte_mempool_op_populate_helper(struct rte_mempool *mp, unsigned int flags,
 		obj = va + off;
 		obj_cb(mp, obj_cb_arg, obj,
 		       (iova == RTE_BAD_IOVA) ? RTE_BAD_IOVA : (iova + off));
+#ifdef RTE_MEMPOOL_INDEX_BASED_LCORE_CACHE
+		/* Store pool base value to calculate indices for index-based
+		 * lcore cache implementation
+		 */
+		if (i == 0)
+			mp->pool_base_value = obj;
+#endif
 		rte_mempool_ops_enqueue_bulk(mp, &obj, 1);
 		off += mp->elt_size + mp->trailer_size;
 	}
--

2.25.1

#27 lore raw

Hi Dharmik,

Quoted 11 lines
Quoted 11 lines
Quoted 10 lines

Current mempool per core cache implementation stores pointers to mbufs On 64b architectures, each pointer consumes 8B
This patch replaces it with index-based implementation, where in each buffer is addressed by (pool base address + index) It reduces the amount of memory/cache required for per core cache

L3Fwd performance testing reveals minor improvements in the cache performance (L1 and L2 misses reduced by 0.60%)
with no change in throughput

Quoted 8 lines
Quoted 4 lines

I feel really sceptical about that patch and the whole idea in general:
- From what I read above there is no real performance improvement observed. (In fact on my IA boxes mempool_perf_autotest reports ~20% slowdown, see below for more details).

Currently, the optimizations (loop unroll and vectorization) are only implemented for ARM64. Similar optimizations can be implemented for x86 platforms which should close the performance gap and in my understanding should give better performance for a bulk size of 32.

Might be, but I still don't see the reason for such effort.
As you mentioned there is no performance improvement in 'real' apps: l3fwd, etc. on ARM64 even with vectorized version of the code.

Quoted 3 lines
Quoted 1 line

- Space utilization difference looks neglectable too.

Sorry, I did not understand this point.

As I understand one of the expectations from that patch was:
reduce memory/cache required, which should improve cache utilization (less misses, etc.).
Though I think such improvements would be neglectable and wouldn't cause any real performance gain.

Quoted 5 lines
Quoted 3 lines

- The change introduces a new build time config option with a major limitation:
All memzones in a pool have to be within the same 4GB boundary.
To address it properly, extra changes will be required in init(/populate) part of the code.

I agree to the above mentioned challenges and I am currently working on resolving these issues.

I still think that to justify such changes some really noticeable performance improvement needs to be demonstrated: double-digit speedup for l3fwd/ipsec-secgw/... Otherwise it just not worth the hassle.

Quoted 6 lines
Quoted 6 lines

All that will complicate mempool code, will make it more error prone and harder to maintain.
But, as there is no real gain in return - no point to add such extra complexity at all.

Konstantin

#28 lore raw

Hi Konstatin,

Quoted 21 lines · Konstantin

Hi Dharmik,

Quoted 16 lines
Quoted 15 lines
Quoted 10 lines

Current mempool per core cache implementation stores pointers to mbufs On 64b architectures, each pointer consumes 8B
This patch replaces it with index-based implementation, where in each buffer is addressed by (pool base address + index) It reduces the amount of memory/cache required for per core cache

L3Fwd performance testing reveals minor improvements in the cache performance (L1 and L2 misses reduced by 0.60%)
with no change in throughput

I feel really sceptical about that patch and the whole idea in general:
- From what I read above there is no real performance improvement observed. (In fact on my IA boxes mempool_perf_autotest reports ~20% slowdown, see below for more details).

Quoted 8 lines
Quoted 3 lines

Currently, the optimizations (loop unroll and vectorization) are only implemented for ARM64. Similar optimizations can be implemented for x86 platforms which should close the performance gap and in my understanding should give better performance for a bulk size of 32.

Might be, but I still don't see the reason for such effort.
As you mentioned there is no performance improvement in 'real' apps: l3fwd, etc. on ARM64 even with vectorized version of the code.

IMO, even without performance improvement, it is advantageous because the same performance is being achieved with less memory and cache utilization using the patch.

Quoted 9 lines
Quoted 3 lines
Quoted 1 line

- Space utilization difference looks neglectable too.

Sorry, I did not understand this point.

As I understand one of the expectations from that patch was:
reduce memory/cache required, which should improve cache utilization (less misses, etc.).
Though I think such improvements would be neglectable and wouldn't cause any real performance gain.

The cache utilization performance numbers are for the l3fwd app, which might not be bottlenecked at the mempool per core cache. Theoretically, this patch enables storing twice the number of objects in the cache as compared to the original implementation.

Quoted 11 lines
Quoted 6 lines
Quoted 4 lines

- The change introduces a new build time config option with a major limitation:
All memzones in a pool have to be within the same 4GB boundary.
To address it properly, extra changes will be required in init(/populate) part of the code.

I agree to the above mentioned challenges and I am currently working on resolving these issues.

I still think that to justify such changes some really noticeable performance improvement needs to be demonstrated: double-digit speedup for l3fwd/ipsec-secgw/... Otherwise it just not worth the hassle.

Like I mentioned earlier, the app might not be bottlenecked at the mempool per core cache. That could be the reason the numbers with l3fwd don’t fully show the advantage of the patch. I’m seeing double-digit improvement with mempool_perf_autotest which should not be ignored.

Quoted 6 lines
Quoted 6 lines
Quoted 6 lines

All that will complicate mempool code, will make it more error prone
and harder to maintain.
But, as there is no real gain in return - no point to add such extra complexity at all.

Konstantin

#29 lore raw

Hi Dharmik,

Quoted 33 lines
Quoted 17 lines
Quoted 17 lines
Quoted 16 lines
Quoted 11 lines

Current mempool per core cache implementation stores pointers to mbufs On 64b architectures, each pointer consumes 8B
This patch replaces it with index-based implementation, where in each buffer is addressed by (pool base address + index) It reduces the amount of memory/cache required for per core cache

L3Fwd performance testing reveals minor improvements in the cache performance (L1 and L2 misses reduced by 0.60%)
with no change in throughput

I feel really sceptical about that patch and the whole idea in general:
- From what I read above there is no real performance improvement observed. (In fact on my IA boxes mempool_perf_autotest reports ~20% slowdown, see below for more details).

Quoted 8 lines
Quoted 3 lines

Currently, the optimizations (loop unroll and vectorization) are only implemented for ARM64. Similar optimizations can be implemented for x86 platforms which should close the performance gap and in my understanding should give better performance for a bulk size of 32.

Might be, but I still don't see the reason for such effort.
As you mentioned there is no performance improvement in 'real' apps: l3fwd, etc. on ARM64 even with vectorized version of the code.

IMO, even without performance improvement, it is advantageous because the same performance is being achieved with less memory and cache utilization using the patch.

Quoted 4 lines
Quoted 3 lines
Quoted 1 line

- Space utilization difference looks neglectable too.

Sorry, I did not understand this point.

Quoted 8 lines
Quoted 5 lines

As I understand one of the expectations from that patch was:
reduce memory/cache required, which should improve cache utilization (less misses, etc.).
Though I think such improvements would be neglectable and wouldn't cause any real performance gain.

The cache utilization performance numbers are for the l3fwd app, which might not be bottlenecked at the mempool per core cache. Theoretically, this patch enables storing twice the number of objects in the cache as compared to the original implementation.

It saves you 4 just bytes per mbuf.
Even for simple l2fwd-like workload we access ~100 bytes per mbuf. Let's do a simplistic estimation of number of affected cache-lines l for l2fwd. For bulk of 32 packets, assuming 64B per cache-line and 16B per HW desc:

number of cache-lines accessed
cache with pointers / cache with indexes

mempool_get:                                            (32*8)/64=4          /  (32*4)/64=2
RX (read HW desc):                                    (32*16)/64=8       /   (32*16)/64=8
RX (write mbuf fields, 1st cache line):    (32*64)/64=3       /   (32*64)/64=32
update mac addrs:                                     (32*64)/64=32     /   (32*64)/64=32   
TX (write HW desc):                                   (32*16)/64=8       /   (32*16)/64=8
free mbufs (read 2nd mbuf cache line): (32*64)/64=32    /   (32*64)/64=32   
mempool_put:                                            (32*8)/64=4        /    (32*4)/64=2
total:                                                             120                             116

So, if my calculations are correct, max estimated gain for cache utilization would be:
(120-116)*100/120=3.33%
Note that numbers are for over-simplistic usage scenario.
In more realistic ones, when we have to touch more cache-lines per packet, that difference would be even less noticeable.
So I really doubt we will see some noticeable improvements in terms of cache utilization with that patch.

Quoted 7 lines
Quoted 7 lines
Quoted 6 lines
Quoted 4 lines

- The change introduces a new build time config option with a major limitation:
All memzones in a pool have to be within the same 4GB boundary.
To address it properly, extra changes will be required in init(/populate) part of the code.

I agree to the above mentioned challenges and I am currently working on resolving these issues.

Quoted 7 lines
Quoted 4 lines

I still think that to justify such changes some really noticeable performance improvement needs to be demonstrated: double-digit speedup for l3fwd/ipsec-secgw/... Otherwise it just not worth the hassle.

Like I mentioned earlier, the app might not be bottlenecked at the mempool per core cache. That could be the reason the numbers with l3fwd don’t fully show the advantage of the patch.

As I said above, I don’t think we'll see any real advantage here. But feel free to pick-up different app and prove me wrong. After all we have plenty of sample apps that do provide enough pressure on the cache: l3fwd-acl, ipsec-secgw.
Or you can even apply these patches from Sean:
https://patches.dpdk.org/project/dpdk/list/?series=20999
to run l3fwd with configurable routes.
That should help you to make it cache-bound.

Quoted 1 line

I’m seeing double-digit improvement with mempool_perf_autotest which should not be ignored.

And for other we are seeing double digit degradation.
So far the whole idea doesn't look promising at all, at least to me. Konstantin

#30 lore raw
Quoted 52 lines

Hi Dharmik,

Quoted 33 lines
Quoted 17 lines
Quoted 17 lines
Quoted 16 lines
Quoted 11 lines

Current mempool per core cache implementation stores pointers to mbufs On 64b architectures, each pointer consumes 8B
This patch replaces it with index-based implementation, where in each buffer is addressed by (pool base address + index) It reduces the amount of memory/cache required for per core cache

L3Fwd performance testing reveals minor improvements in the cache performance (L1 and L2 misses reduced by 0.60%)
with no change in throughput

I feel really sceptical about that patch and the whole idea in general:
- From what I read above there is no real performance improvement observed. (In fact on my IA boxes mempool_perf_autotest reports ~20% slowdown, see below for more details).

Quoted 8 lines
Quoted 3 lines

Currently, the optimizations (loop unroll and vectorization) are only implemented for ARM64. Similar optimizations can be implemented for x86 platforms which should close the performance gap and in my understanding should give better performance for a bulk size of 32.

Might be, but I still don't see the reason for such effort.
As you mentioned there is no performance improvement in 'real' apps: l3fwd, etc. on ARM64 even with vectorized version of the code.

IMO, even without performance improvement, it is advantageous because the same performance is being achieved with less memory and cache utilization using the patch.

Quoted 4 lines
Quoted 3 lines
Quoted 1 line

- Space utilization difference looks neglectable too.

Sorry, I did not understand this point.

Quoted 8 lines
Quoted 5 lines

As I understand one of the expectations from that patch was:
reduce memory/cache required, which should improve cache utilization (less misses, etc.).
Though I think such improvements would be neglectable and wouldn't cause any real performance gain.

The cache utilization performance numbers are for the l3fwd app, which might not be bottlenecked at the mempool per core cache. Theoretically, this patch enables storing twice the number of objects in the cache as compared to the original implementation.

It saves you 4 just bytes per mbuf.
Even for simple l2fwd-like workload we access ~100 bytes per mbuf. Let's do a simplistic estimation of number of affected cache-lines l for l2fwd. For bulk of 32 packets, assuming 64B per cache-line and 16B per HW desc:

Quoted 5 lines

number of cache-lines accessed
cache with pointers / cache with indexes

mempool_get:                                            (32*8)/64=4          /  (32*4)/64=2
RX (read HW desc):                                    (32*16)/64=8       /   (32*16)/64=8

RX (write mbuf fields, 1st cache line): (32*64)/64=3 / (32*64)/64=32

Should be:
RX (write mbuf fields, 1st cache line): (32*64)/64=32 / (32*64)/64=32
off course

Quoted 43 lines
update mac addrs:                                     (32*64)/64=32     /   (32*64)/64=32
TX (write HW desc):                                   (32*16)/64=8       /   (32*16)/64=8
free mbufs (read 2nd mbuf cache line): (32*64)/64=32    /   (32*64)/64=32
mempool_put:                                            (32*8)/64=4        /    (32*4)/64=2
total:                                                             120                             116

So, if my calculations are correct, max estimated gain for cache utilization would be:
(120-116)*100/120=3.33%
Note that numbers are for over-simplistic usage scenario.
In more realistic ones, when we have to touch more cache-lines per packet, that difference would be even less noticeable.
So I really doubt we will see some noticeable improvements in terms of cache utilization with that patch.

Quoted 7 lines
Quoted 7 lines
Quoted 6 lines
Quoted 4 lines

- The change introduces a new build time config option with a major limitation:
All memzones in a pool have to be within the same 4GB boundary.
To address it properly, extra changes will be required in init(/populate) part of the code.

I agree to the above mentioned challenges and I am currently working on resolving these issues.

Quoted 7 lines
Quoted 4 lines

I still think that to justify such changes some really noticeable performance improvement needs to be demonstrated: double-digit speedup for l3fwd/ipsec-secgw/... Otherwise it just not worth the hassle.

Like I mentioned earlier, the app might not be bottlenecked at the mempool per core cache. That could be the reason the numbers with l3fwd don’t fully show the advantage of the patch.

As I said above, I don’t think we'll see any real advantage here. But feel free to pick-up different app and prove me wrong. After all we have plenty of sample apps that do provide enough pressure on the cache: l3fwd-acl, ipsec-secgw.
Or you can even apply these patches from Sean:
https://patches.dpdk.org/project/dpdk/list/?series=20999
to run l3fwd with configurable routes.
That should help you to make it cache-bound.

Quoted 1 line

I’m seeing double-digit improvement with mempool_perf_autotest which should not be ignored.

And for other we are seeing double digit degradation.
So far the whole idea doesn't look promising at all, at least to me. Konstantin

#31 lore raw
In reply to Ananyev, Konstantin

Hi,

Thank you for the comments!

Based on the suggestions, I tested the patch for single core L3Fwd performance with increased number of routes/flows (maximum 8K) to increase cache footprint. However, I don’t see much improvement with the patch.

Quoted 86 lines · Konstantin

Hi Dharmik,

Quoted 33 lines
Quoted 17 lines
Quoted 17 lines
Quoted 16 lines
Quoted 11 lines

Current mempool per core cache implementation stores pointers to mbufs On 64b architectures, each pointer consumes 8B
This patch replaces it with index-based implementation, where in each buffer is addressed by (pool base address + index) It reduces the amount of memory/cache required for per core cache

L3Fwd performance testing reveals minor improvements in the cache performance (L1 and L2 misses reduced by 0.60%)
with no change in throughput

I feel really sceptical about that patch and the whole idea in general:
- From what I read above there is no real performance improvement observed. (In fact on my IA boxes mempool_perf_autotest reports ~20% slowdown, see below for more details).

Quoted 8 lines
Quoted 3 lines

Currently, the optimizations (loop unroll and vectorization) are only implemented for ARM64. Similar optimizations can be implemented for x86 platforms which should close the performance gap and in my understanding should give better performance for a bulk size of 32.

Might be, but I still don't see the reason for such effort.
As you mentioned there is no performance improvement in 'real' apps: l3fwd, etc. on ARM64 even with vectorized version of the code.

IMO, even without performance improvement, it is advantageous because the same performance is being achieved with less memory and cache utilization using the patch.

Quoted 4 lines
Quoted 3 lines
Quoted 1 line

- Space utilization difference looks neglectable too.

Sorry, I did not understand this point.

Quoted 8 lines
Quoted 5 lines

As I understand one of the expectations from that patch was:
reduce memory/cache required, which should improve cache utilization (less misses, etc.).
Though I think such improvements would be neglectable and wouldn't cause any real performance gain.

The cache utilization performance numbers are for the l3fwd app, which might not be bottlenecked at the mempool per core cache. Theoretically, this patch enables storing twice the number of objects in the cache as compared to the original implementation.

It saves you 4 just bytes per mbuf.
Even for simple l2fwd-like workload we access ~100 bytes per mbuf. Let's do a simplistic estimation of number of affected cache-lines l for l2fwd. For bulk of 32 packets, assuming 64B per cache-line and 16B per HW desc:

number of cache-lines accessed
cache with pointers / cache with indexes

mempool_get:                                            (32*8)/64=4          /  (32*4)/64=2
RX (read HW desc):                                    (32*16)/64=8       /   (32*16)/64=8
RX (write mbuf fields, 1st cache line):    (32*64)/64=3       /   (32*64)/64=32
update mac addrs:                                     (32*64)/64=32     /   (32*64)/64=32   
TX (write HW desc):                                   (32*16)/64=8       /   (32*16)/64=8
free mbufs (read 2nd mbuf cache line): (32*64)/64=32    /   (32*64)/64=32   
mempool_put:                                            (32*8)/64=4        /    (32*4)/64=2
total:                                                             120                             116

So, if my calculations are correct, max estimated gain for cache utilization would be:
(120-116)*100/120=3.33%
Note that numbers are for over-simplistic usage scenario.
In more realistic ones, when we have to touch more cache-lines per packet, that difference would be even less noticeable.
So I really doubt we will see some noticeable improvements in terms of cache utilization with that patch.

Quoted 7 lines
Quoted 7 lines
Quoted 6 lines
Quoted 4 lines

- The change introduces a new build time config option with a major limitation:
All memzones in a pool have to be within the same 4GB boundary.
To address it properly, extra changes will be required in init(/populate) part of the code.

I agree to the above mentioned challenges and I am currently working on resolving these issues.

Quoted 7 lines
Quoted 4 lines

I still think that to justify such changes some really noticeable performance improvement needs to be demonstrated: double-digit speedup for l3fwd/ipsec-secgw/... Otherwise it just not worth the hassle.

Like I mentioned earlier, the app might not be bottlenecked at the mempool per core cache. That could be the reason the numbers with l3fwd don’t fully show the advantage of the patch.

Quoted 9 lines

As I said above, I don’t think we'll see any real advantage here. But feel free to pick-up different app and prove me wrong. After all we have plenty of sample apps that do provide enough pressure on the cache: l3fwd-acl, ipsec-secgw.
Or you can even apply these patches from Sean:
https://patches.dpdk.org/project/dpdk/list/?series=20999
to run l3fwd with configurable routes.
That should help you to make it cache-bound.

Thank you, Konstantin! This patch was helpful.

Quoted 6 lines
Quoted 1 line

I’m seeing double-digit improvement with mempool_perf_autotest which should not be ignored.

And for other we are seeing double digit degradation.
So far the whole idea doesn't look promising at all, at least to me. Konstantin

#32 lore raw
In reply to Dharmik Thakkar
Quoted 77 lines

From: Dharmik Thakkar [mailto:[email protected]]
Sent: Friday, 24 December 2021 23.59

Current mempool per core cache implementation stores pointers to mbufs On 64b architectures, each pointer consumes 8B
This patch replaces it with index-based implementation, where in each buffer is addressed by (pool base address + index) It reduces the amount of memory/cache required for per core cache

L3Fwd performance testing reveals minor improvements in the cache performance (L1 and L2 misses reduced by 0.60%)
with no change in throughput

Micro-benchmarking the patch using mempool_perf_test shows significant improvement with majority of the test cases

Number of cores = 1:
n_get_bulk=1 n_put_bulk=1 n_keep=32 %_change_with_patch=18.01 n_get_bulk=1 n_put_bulk=1 n_keep=128 %_change_with_patch=19.91 n_get_bulk=1 n_put_bulk=4 n_keep=32 %_change_with_patch=-20.37 (regression)
n_get_bulk=1 n_put_bulk=4 n_keep=128 %_change_with_patch=-17.01 (regression)
n_get_bulk=1 n_put_bulk=32 n_keep=32 %_change_with_patch=-25.06 (regression)
n_get_bulk=1 n_put_bulk=32 n_keep=128 %_change_with_patch=-23.81 (regression)
n_get_bulk=4 n_put_bulk=1 n_keep=32 %_change_with_patch=53.93 n_get_bulk=4 n_put_bulk=1 n_keep=128 %_change_with_patch=60.90 n_get_bulk=4 n_put_bulk=4 n_keep=32 %_change_with_patch=1.64 n_get_bulk=4 n_put_bulk=4 n_keep=128 %_change_with_patch=8.76 n_get_bulk=4 n_put_bulk=32 n_keep=32 %_change_with_patch=-4.71 (regression)
n_get_bulk=4 n_put_bulk=32 n_keep=128 %_change_with_patch=-3.19 (regression)
n_get_bulk=32 n_put_bulk=1 n_keep=32 %_change_with_patch=65.63 n_get_bulk=32 n_put_bulk=1 n_keep=128 %_change_with_patch=75.19 n_get_bulk=32 n_put_bulk=4 n_keep=32 %_change_with_patch=11.75 n_get_bulk=32 n_put_bulk=4 n_keep=128 %_change_with_patch=15.52 n_get_bulk=32 n_put_bulk=32 n_keep=32 %_change_with_patch=13.45 n_get_bulk=32 n_put_bulk=32 n_keep=128 %_change_with_patch=11.58

Number of core = 2:
n_get_bulk=1 n_put_bulk=1 n_keep=32 %_change_with_patch=18.21 n_get_bulk=1 n_put_bulk=1 n_keep=128 %_change_with_patch=21.89 n_get_bulk=1 n_put_bulk=4 n_keep=32 %_change_with_patch=-21.21 (regression)
n_get_bulk=1 n_put_bulk=4 n_keep=128 %_change_with_patch=-17.05 (regression)
n_get_bulk=1 n_put_bulk=32 n_keep=32 %_change_with_patch=-26.09 (regression)
n_get_bulk=1 n_put_bulk=32 n_keep=128 %_change_with_patch=-23.49 (regression)
n_get_bulk=4 n_put_bulk=1 n_keep=32 %_change_with_patch=56.28 n_get_bulk=4 n_put_bulk=1 n_keep=128 %_change_with_patch=67.69 n_get_bulk=4 n_put_bulk=4 n_keep=32 %_change_with_patch=1.45 n_get_bulk=4 n_put_bulk=4 n_keep=128 %_change_with_patch=8.84 n_get_bulk=4 n_put_bulk=32 n_keep=32 %_change_with_patch=-5.27 (regression)
n_get_bulk=4 n_put_bulk=32 n_keep=128 %_change_with_patch=-3.09 (regression)
n_get_bulk=32 n_put_bulk=1 n_keep=32 %_change_with_patch=76.11 n_get_bulk=32 n_put_bulk=1 n_keep=128 %_change_with_patch=86.06 n_get_bulk=32 n_put_bulk=4 n_keep=32 %_change_with_patch=11.86 n_get_bulk=32 n_put_bulk=4 n_keep=128 %_change_with_patch=16.55 n_get_bulk=32 n_put_bulk=32 n_keep=32 %_change_with_patch=13.01 n_get_bulk=32 n_put_bulk=32 n_keep=128 %_change_with_patch=11.51

From analyzing the results, it is clear that for n_get_bulk and n_put_bulk sizes of 32 there is no performance regression IMO, the other sizes are not practical from performance perspective and the regression in those cases can be safely ignored

Dharmik Thakkar (1):
mempool: implement index-based per core cache

Quoted 7 lines
 lib/mempool/rte_mempool.h             | 114 +++++++++++++++++++++++++-
 lib/mempool/rte_mempool_ops_default.c |   7 ++
 2 files changed, 119 insertions(+), 2 deletions(-)

--
2.25.1

I still think this is very interesting. And your performance numbers are looking good.

However, it limits the size of a mempool to 4 GB. As previously discussed, the max mempool size can be increased by multiplying the index with a constant.

I would suggest using sizeof(uintptr_t) as the constant multiplier, so the mempool can hold objects of any size divisible by sizeof(uintptr_t). And it would be silly to use a mempool to hold objects smaller than sizeof(uintptr_t).

How does the performance look if you multiply the index by sizeof(uintptr_t)?

Med venlig hilsen / Kind regards,
-Morten Brørup

#33 lore raw
Quoted 80 lines · Morten Brørup
Quoted 64 lines

From: Dharmik Thakkar [mailto:[email protected]] Sent: Friday, 24 December 2021 23.59

Current mempool per core cache implementation stores pointers to mbufs On 64b architectures, each pointer consumes 8B This patch replaces it with index-based implementation, where in each buffer is addressed by (pool base address + index) It reduces the amount of memory/cache required for per core cache

L3Fwd performance testing reveals minor improvements in the cache performance (L1 and L2 misses reduced by 0.60%) with no change in throughput

Micro-benchmarking the patch using mempool_perf_test shows significant improvement with majority of the test cases

Number of cores = 1: n_get_bulk=1 n_put_bulk=1 n_keep=32 %_change_with_patch=18.01 n_get_bulk=1 n_put_bulk=1 n_keep=128 %_change_with_patch=19.91 n_get_bulk=1 n_put_bulk=4 n_keep=32 %_change_with_patch=-20.37 (regression) n_get_bulk=1 n_put_bulk=4 n_keep=128 %_change_with_patch=-17.01 (regression) n_get_bulk=1 n_put_bulk=32 n_keep=32 %_change_with_patch=-25.06 (regression) n_get_bulk=1 n_put_bulk=32 n_keep=128 %_change_with_patch=-23.81 (regression) n_get_bulk=4 n_put_bulk=1 n_keep=32 %_change_with_patch=53.93 n_get_bulk=4 n_put_bulk=1 n_keep=128 %_change_with_patch=60.90 n_get_bulk=4 n_put_bulk=4 n_keep=32 %_change_with_patch=1.64 n_get_bulk=4 n_put_bulk=4 n_keep=128 %_change_with_patch=8.76 n_get_bulk=4 n_put_bulk=32 n_keep=32 %_change_with_patch=-4.71 (regression) n_get_bulk=4 n_put_bulk=32 n_keep=128 %_change_with_patch=-3.19 (regression) n_get_bulk=32 n_put_bulk=1 n_keep=32 %_change_with_patch=65.63 n_get_bulk=32 n_put_bulk=1 n_keep=128 %_change_with_patch=75.19 n_get_bulk=32 n_put_bulk=4 n_keep=32 %_change_with_patch=11.75 n_get_bulk=32 n_put_bulk=4 n_keep=128 %_change_with_patch=15.52 n_get_bulk=32 n_put_bulk=32 n_keep=32 %_change_with_patch=13.45 n_get_bulk=32 n_put_bulk=32 n_keep=128 %_change_with_patch=11.58

Number of core = 2: n_get_bulk=1 n_put_bulk=1 n_keep=32 %_change_with_patch=18.21 n_get_bulk=1 n_put_bulk=1 n_keep=128 %_change_with_patch=21.89 n_get_bulk=1 n_put_bulk=4 n_keep=32 %_change_with_patch=-21.21 (regression) n_get_bulk=1 n_put_bulk=4 n_keep=128 %_change_with_patch=-17.05 (regression) n_get_bulk=1 n_put_bulk=32 n_keep=32 %_change_with_patch=-26.09 (regression) n_get_bulk=1 n_put_bulk=32 n_keep=128 %_change_with_patch=-23.49 (regression) n_get_bulk=4 n_put_bulk=1 n_keep=32 %_change_with_patch=56.28 n_get_bulk=4 n_put_bulk=1 n_keep=128 %_change_with_patch=67.69 n_get_bulk=4 n_put_bulk=4 n_keep=32 %_change_with_patch=1.45 n_get_bulk=4 n_put_bulk=4 n_keep=128 %_change_with_patch=8.84 n_get_bulk=4 n_put_bulk=32 n_keep=32 %_change_with_patch=-5.27 (regression) n_get_bulk=4 n_put_bulk=32 n_keep=128 %_change_with_patch=-3.09 (regression) n_get_bulk=32 n_put_bulk=1 n_keep=32 %_change_with_patch=76.11 n_get_bulk=32 n_put_bulk=1 n_keep=128 %_change_with_patch=86.06 n_get_bulk=32 n_put_bulk=4 n_keep=32 %_change_with_patch=11.86 n_get_bulk=32 n_put_bulk=4 n_keep=128 %_change_with_patch=16.55 n_get_bulk=32 n_put_bulk=32 n_keep=32 %_change_with_patch=13.01 n_get_bulk=32 n_put_bulk=32 n_keep=128 %_change_with_patch=11.51

From analyzing the results, it is clear that for n_get_bulk and n_put_bulk sizes of 32 there is no performance regression IMO, the other sizes are not practical from performance perspective and the regression in those cases can be safely ignored

Quoted 8 lines

Dharmik Thakkar (1): mempool: implement index-based per core cache

 lib/mempool/rte_mempool.h             | 114 +++++++++++++++++++++++++-

lib/mempool/rte_mempool_ops_default.c | 7 ++ 2 files changed, 119
insertions(+), 2 deletions(-)

-- 2.25.1

I still think this is very interesting. And your performance numbers are looking good.

However, it limits the size of a mempool to 4 GB. As previously discussed, the max mempool size can be increased by multiplying the index with a constant.

Quoted 8 lines

I would suggest using sizeof(uintptr_t) as the constant multiplier, so the mempool can hold objects of any size divisible by sizeof(uintptr_t). And it would be silly to use a mempool to hold objects smaller than sizeof(uintptr_t).

How does the performance look if you multiply the index by sizeof(uintptr_t)?

Each mempool entry is cache aligned, so we can use that if we want a bigger multiplier.

#34 lore raw
Quoted 100 lines

From: Bruce Richardson [mailto:[email protected]]
Sent: Friday, 7 January 2022 12.16

Quoted 1 line · Morten Brørup
Quoted 1 line

From: Dharmik Thakkar [mailto:[email protected]] Sent:

Friday, 24

Quoted 3 lines
Quoted 3 lines

December 2021 23.59

Current mempool per core cache implementation stores pointers to

mbufs

Quoted 1 line
Quoted 1 line

On 64b architectures, each pointer consumes 8B This patch replaces

it

Quoted 1 line
Quoted 1 line

with index-based implementation, where in each buffer is addressed

by

Quoted 8 lines
Quoted 8 lines

(pool base address + index) It reduces the amount of memory/cache required for per core cache

L3Fwd performance testing reveals minor improvements in the cache performance (L1 and L2 misses reduced by 0.60%) with no change in throughput

Micro-benchmarking the patch using mempool_perf_test shows

significant

Quoted 45 lines
Quoted 45 lines

improvement with majority of the test cases

Number of cores = 1: n_get_bulk=1 n_put_bulk=1 n_keep=32 %_change_with_patch=18.01 n_get_bulk=1 n_put_bulk=1 n_keep=128 %_change_with_patch=19.91 n_get_bulk=1 n_put_bulk=4 n_keep=32 %_change_with_patch=-20.37 (regression) n_get_bulk=1 n_put_bulk=4 n_keep=128 %_change_with_patch=-17.01 (regression) n_get_bulk=1 n_put_bulk=32 n_keep=32 %_change_with_patch=-25.06 (regression) n_get_bulk=1 n_put_bulk=32 n_keep=128 %_change_with_patch=-23.81 (regression) n_get_bulk=4 n_put_bulk=1 n_keep=32 %_change_with_patch=53.93 n_get_bulk=4 n_put_bulk=1 n_keep=128 %_change_with_patch=60.90 n_get_bulk=4 n_put_bulk=4 n_keep=32 %_change_with_patch=1.64 n_get_bulk=4 n_put_bulk=4 n_keep=128 %_change_with_patch=8.76 n_get_bulk=4 n_put_bulk=32 n_keep=32 %_change_with_patch=-4.71 (regression) n_get_bulk=4 n_put_bulk=32 n_keep=128 %_change_with_patch=-3.19 (regression) n_get_bulk=32 n_put_bulk=1 n_keep=32 %_change_with_patch=65.63 n_get_bulk=32 n_put_bulk=1 n_keep=128 %_change_with_patch=75.19 n_get_bulk=32 n_put_bulk=4 n_keep=32 %_change_with_patch=11.75 n_get_bulk=32 n_put_bulk=4 n_keep=128 %_change_with_patch=15.52 n_get_bulk=32 n_put_bulk=32 n_keep=32 %_change_with_patch=13.45 n_get_bulk=32 n_put_bulk=32 n_keep=128 %_change_with_patch=11.58

Number of core = 2: n_get_bulk=1 n_put_bulk=1 n_keep=32 %_change_with_patch=18.21 n_get_bulk=1 n_put_bulk=1 n_keep=128 %_change_with_patch=21.89 n_get_bulk=1 n_put_bulk=4 n_keep=32 %_change_with_patch=-21.21 (regression) n_get_bulk=1 n_put_bulk=4 n_keep=128 %_change_with_patch=-17.05 (regression) n_get_bulk=1 n_put_bulk=32 n_keep=32 %_change_with_patch=-26.09 (regression) n_get_bulk=1 n_put_bulk=32 n_keep=128 %_change_with_patch=-23.49 (regression) n_get_bulk=4 n_put_bulk=1 n_keep=32 %_change_with_patch=56.28 n_get_bulk=4 n_put_bulk=1 n_keep=128 %_change_with_patch=67.69 n_get_bulk=4 n_put_bulk=4 n_keep=32 %_change_with_patch=1.45 n_get_bulk=4 n_put_bulk=4 n_keep=128 %_change_with_patch=8.84 n_get_bulk=4 n_put_bulk=32 n_keep=32 %_change_with_patch=-5.27 (regression) n_get_bulk=4 n_put_bulk=32 n_keep=128 %_change_with_patch=-3.09 (regression) n_get_bulk=32 n_put_bulk=1 n_keep=32 %_change_with_patch=76.11 n_get_bulk=32 n_put_bulk=1 n_keep=128 %_change_with_patch=86.06 n_get_bulk=32 n_put_bulk=4 n_keep=32 %_change_with_patch=11.86 n_get_bulk=32 n_put_bulk=4 n_keep=128 %_change_with_patch=16.55 n_get_bulk=32 n_put_bulk=32 n_keep=32 %_change_with_patch=13.01 n_get_bulk=32 n_put_bulk=32 n_keep=128 %_change_with_patch=11.51

Quoted 8 lines
Quoted 8 lines

From analyzing the results, it is clear that for n_get_bulk and n_put_bulk sizes of 32 there is no performance regression IMO, the other sizes are not practical from performance perspective and the regression in those cases can be safely ignored

Dharmik Thakkar (1): mempool: implement index-based per core cache

 lib/mempool/rte_mempool.h             | 114

+++++++++++++++++++++++++-

Quoted 1 line
Quoted 1 line

lib/mempool/rte_mempool_ops_default.c | 7 ++ 2 files changed,

119

Quoted 6 lines
Quoted 4 lines

insertions(+), 2 deletions(-)

-- 2.25.1

I still think this is very interesting. And your performance numbers

are

Quoted 4 lines

looking good.

However, it limits the size of a mempool to 4 GB. As previously discussed, the max mempool size can be increased by multiplying the

index

Quoted 3 lines

with a constant.

I would suggest using sizeof(uintptr_t) as the constant multiplier,

so

Quoted 1 line

the mempool can hold objects of any size divisible by

sizeof(uintptr_t).

Quoted 3 lines

And it would be silly to use a mempool to hold objects smaller than sizeof(uintptr_t).

Quoted 7 lines
Quoted 3 lines

How does the performance look if you multiply the index by sizeof(uintptr_t)?

Each mempool entry is cache aligned, so we can use that if we want a bigger
multiplier.

Thanks for chiming in, Bruce.

Please also read this discussion about the multiplier:
http://inbox.dpdk.org/dev/CALBAE1PrQYyOG96f6ECeW1vPF3TOh1h7MZZULiY95z9xjbRuyA@mail.gmail.com/

#35 lore raw
Quoted 104 lines · Morten Brørup
Quoted 104 lines

From: Bruce Richardson [mailto:[email protected]]
Sent: Friday, 7 January 2022 12.16

Quoted 1 line · Morten Brørup
Quoted 1 line

From: Dharmik Thakkar [mailto:[email protected]] Sent:

Friday, 24

Quoted 3 lines
Quoted 3 lines

December 2021 23.59

Current mempool per core cache implementation stores pointers to

mbufs

Quoted 1 line
Quoted 1 line

On 64b architectures, each pointer consumes 8B This patch replaces

it

Quoted 1 line
Quoted 1 line

with index-based implementation, where in each buffer is addressed

by

Quoted 8 lines
Quoted 8 lines

(pool base address + index) It reduces the amount of memory/cache required for per core cache

L3Fwd performance testing reveals minor improvements in the cache performance (L1 and L2 misses reduced by 0.60%) with no change in throughput

Micro-benchmarking the patch using mempool_perf_test shows

significant

Quoted 45 lines
Quoted 45 lines

improvement with majority of the test cases

Number of cores = 1: n_get_bulk=1 n_put_bulk=1 n_keep=32 %_change_with_patch=18.01 n_get_bulk=1 n_put_bulk=1 n_keep=128 %_change_with_patch=19.91 n_get_bulk=1 n_put_bulk=4 n_keep=32 %_change_with_patch=-20.37 (regression) n_get_bulk=1 n_put_bulk=4 n_keep=128 %_change_with_patch=-17.01 (regression) n_get_bulk=1 n_put_bulk=32 n_keep=32 %_change_with_patch=-25.06 (regression) n_get_bulk=1 n_put_bulk=32 n_keep=128 %_change_with_patch=-23.81 (regression) n_get_bulk=4 n_put_bulk=1 n_keep=32 %_change_with_patch=53.93 n_get_bulk=4 n_put_bulk=1 n_keep=128 %_change_with_patch=60.90 n_get_bulk=4 n_put_bulk=4 n_keep=32 %_change_with_patch=1.64 n_get_bulk=4 n_put_bulk=4 n_keep=128 %_change_with_patch=8.76 n_get_bulk=4 n_put_bulk=32 n_keep=32 %_change_with_patch=-4.71 (regression) n_get_bulk=4 n_put_bulk=32 n_keep=128 %_change_with_patch=-3.19 (regression) n_get_bulk=32 n_put_bulk=1 n_keep=32 %_change_with_patch=65.63 n_get_bulk=32 n_put_bulk=1 n_keep=128 %_change_with_patch=75.19 n_get_bulk=32 n_put_bulk=4 n_keep=32 %_change_with_patch=11.75 n_get_bulk=32 n_put_bulk=4 n_keep=128 %_change_with_patch=15.52 n_get_bulk=32 n_put_bulk=32 n_keep=32 %_change_with_patch=13.45 n_get_bulk=32 n_put_bulk=32 n_keep=128 %_change_with_patch=11.58

Number of core = 2: n_get_bulk=1 n_put_bulk=1 n_keep=32 %_change_with_patch=18.21 n_get_bulk=1 n_put_bulk=1 n_keep=128 %_change_with_patch=21.89 n_get_bulk=1 n_put_bulk=4 n_keep=32 %_change_with_patch=-21.21 (regression) n_get_bulk=1 n_put_bulk=4 n_keep=128 %_change_with_patch=-17.05 (regression) n_get_bulk=1 n_put_bulk=32 n_keep=32 %_change_with_patch=-26.09 (regression) n_get_bulk=1 n_put_bulk=32 n_keep=128 %_change_with_patch=-23.49 (regression) n_get_bulk=4 n_put_bulk=1 n_keep=32 %_change_with_patch=56.28 n_get_bulk=4 n_put_bulk=1 n_keep=128 %_change_with_patch=67.69 n_get_bulk=4 n_put_bulk=4 n_keep=32 %_change_with_patch=1.45 n_get_bulk=4 n_put_bulk=4 n_keep=128 %_change_with_patch=8.84 n_get_bulk=4 n_put_bulk=32 n_keep=32 %_change_with_patch=-5.27 (regression) n_get_bulk=4 n_put_bulk=32 n_keep=128 %_change_with_patch=-3.09 (regression) n_get_bulk=32 n_put_bulk=1 n_keep=32 %_change_with_patch=76.11 n_get_bulk=32 n_put_bulk=1 n_keep=128 %_change_with_patch=86.06 n_get_bulk=32 n_put_bulk=4 n_keep=32 %_change_with_patch=11.86 n_get_bulk=32 n_put_bulk=4 n_keep=128 %_change_with_patch=16.55 n_get_bulk=32 n_put_bulk=32 n_keep=32 %_change_with_patch=13.01 n_get_bulk=32 n_put_bulk=32 n_keep=128 %_change_with_patch=11.51

Quoted 8 lines
Quoted 8 lines

From analyzing the results, it is clear that for n_get_bulk and n_put_bulk sizes of 32 there is no performance regression IMO, the other sizes are not practical from performance perspective and the regression in those cases can be safely ignored

Dharmik Thakkar (1): mempool: implement index-based per core cache

 lib/mempool/rte_mempool.h             | 114

+++++++++++++++++++++++++-

Quoted 1 line
Quoted 1 line

lib/mempool/rte_mempool_ops_default.c | 7 ++ 2 files changed,

119

Quoted 6 lines
Quoted 4 lines

insertions(+), 2 deletions(-)

-- 2.25.1

I still think this is very interesting. And your performance numbers

are

Quoted 4 lines

looking good.

However, it limits the size of a mempool to 4 GB. As previously discussed, the max mempool size can be increased by multiplying the

index

Quoted 3 lines

with a constant.

I would suggest using sizeof(uintptr_t) as the constant multiplier,

so

Quoted 1 line

the mempool can hold objects of any size divisible by

sizeof(uintptr_t).

Quoted 6 lines

And it would be silly to use a mempool to hold objects smaller than sizeof(uintptr_t).

How does the performance look if you multiply the index by sizeof(uintptr_t)?

Quoted 9 lines
Quoted 3 lines

Each mempool entry is cache aligned, so we can use that if we want a bigger
multiplier.

Thanks for chiming in, Bruce.

Please also read this discussion about the multiplier:
http://inbox.dpdk.org/dev/CALBAE1PrQYyOG96f6ECeW1vPF3TOh1h7MZZULiY95z9xjbRuyA@mail.gmail.com/

I actually wondered after I had sent the email whether we had indeed an option to disable the cache alignment or not! Thanks for pointing out that we do. This brings a couple additional thoughts:

* Using indexes for the cache should probably be a runtime flag rather than a build-time one.
* It would seem reasonable to me to disallow use of the indexed-cache flag and the non-cache aligned flag simultaneously.
* On the offchance that that restriction is unacceptable, then we can make things a little more complicated by doing a runtime computation of the "index-shiftwidth" to use.

Overall, I think defaulting to cacheline shiftwidth and disallowing index-based addressing when using unaligned buffers is simplest and easiest unless we can come up with a valid usecase for needing more than that.

/Bruce

#36 lore raw
Quoted 87 lines

From: Bruce Richardson [mailto:[email protected]]
Sent: Friday, 7 January 2022 14.51

Quoted 9 lines · Morten Brørup
Quoted 9 lines

From: Bruce Richardson [mailto:[email protected]]
Sent: Friday, 7 January 2022 12.16

Quoted 1 line · Morten Brørup
Quoted 1 line

From: Dharmik Thakkar [mailto:[email protected]] Sent:

Friday, 24

Quoted 3 lines
Quoted 3 lines

December 2021 23.59

Current mempool per core cache implementation stores pointers

to

Quoted 2 lines
Quoted 2 lines

mbufs

Quoted 1 line
Quoted 1 line

On 64b architectures, each pointer consumes 8B This patch

replaces

Quoted 2 lines
Quoted 2 lines

it

Quoted 1 line
Quoted 1 line

with index-based implementation, where in each buffer is

addressed

Quoted 2 lines
Quoted 2 lines

by

Quoted 1 line
Quoted 1 line

(pool base address + index) It reduces the amount of

memory/cache

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

required for per core cache

L3Fwd performance testing reveals minor improvements in the

cache

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

performance (L1 and L2 misses reduced by 0.60%) with no change

in

Quoted 8 lines
Quoted 8 lines
Quoted 3 lines
Quoted 3 lines

throughput

Micro-benchmarking the patch using mempool_perf_test shows

significant

Quoted 4 lines
Quoted 2 lines

improvement with majority of the test cases

I still think this is very interesting. And your performance

numbers

Quoted 5 lines
Quoted 5 lines

are

Quoted 4 lines

looking good.

However, it limits the size of a mempool to 4 GB. As previously discussed, the max mempool size can be increased by multiplying

the

Quoted 4 lines
Quoted 4 lines

index

Quoted 3 lines

with a constant.

I would suggest using sizeof(uintptr_t) as the constant

multiplier,

Quoted 4 lines
Quoted 4 lines

so

Quoted 1 line

the mempool can hold objects of any size divisible by

sizeof(uintptr_t).

Quoted 1 line

And it would be silly to use a mempool to hold objects smaller

than

Quoted 7 lines
Quoted 7 lines
Quoted 5 lines

sizeof(uintptr_t).

How does the performance look if you multiply the index by sizeof(uintptr_t)?

Each mempool entry is cache aligned, so we can use that if we want

a

Quoted 8 lines
Quoted 2 lines

bigger
multiplier.

Thanks for chiming in, Bruce.

Please also read this discussion about the multiplier:
http://inbox.dpdk.org/dev/CALBAE1PrQYyOG96f6ECeW1vPF3TOh1h7MZZULiY95z9xjbRuyA@mail.gmail.com/

I actually wondered after I had sent the email whether we had indeed an option to disable the cache alignment or not! Thanks for pointing out that
we do. This brings a couple additional thoughts:

* Using indexes for the cache should probably be a runtime flag rather than
a build-time one.
* It would seem reasonable to me to disallow use of the indexed-cache flag
and the non-cache aligned flag simultaneously.
* On the offchance that that restriction is unacceptable, then we can make things a little more complicated by doing a runtime computation
of
the "index-shiftwidth" to use.

Quoted 6 lines

Overall, I think defaulting to cacheline shiftwidth and disallowing index-based addressing when using unaligned buffers is simplest and easiest
unless we can come up with a valid usecase for needing more than that.

/Bruce

This feature is a performance optimization.

With that in mind, it should not introduce function pointers or similar run-time checks or in the fast path, to determine what kind of cache to use per mempool. And if an index multiplier is implemented, it should be a compile time constant, probably something between sizeof(uintptr_t) or RTE_MEMPOOL_ALIGN (=RTE_CACHE_LINE_SIZE).

The patch comes with a tradeoff between better performance and limited mempool size, and possibly some limitations regarding very small objects that are not cache line aligned to avoid wasting memory (RTE_MEMPOOL_POPULATE_F_ALIGN_OBJ).

With no multiplier, the only tradeoff is that the mempool size is limited to 4 GB.

If the multiplier is small (i.e. 8 bytes) the only tradeoff is that the mempool size is limited to 32 GB. (And a waste of memory for objects smaller than 8 byte; but I don't think anyone would use a mempool to hold objects smaller than 8 byte.)

If the multiplier is larger (i.e. 64 bytes cache line size), the mempool size is instead limited to 256 GB, but RTE_MEMPOOL_POPULATE_F_ALIGN_OBJ has no effect.

Note: 32 bit platforms have no benefit from this patch: The pointer already only uses 4 bytes, so replacing the pointer with a 4 byte index makes no difference.

Since this feature is a performance optimization only, and doesn't provide any new features, I don't mind it being a compile time option.

If this feature is a compile time option, and the mempool library is compiled with the large multiplier, then RTE_MEMPOOL_POPULATE_F_ALIGN_OBJ could be made undefined in the public header file, so compilation of applications using the flag will fail. And rte_mempool_create() could RTE_ASSERT() that RTE_MEMPOOL_POPULATE_F_ALIGN_OBJ is not set in its flags parameter, or emit a warning about the flag being ignored. Obviously, rte_mempool_create() should also RTE_ASSERT() that the mempool is not larger than the library supports, possibly emitting a message that the mempool library should be built without this feature to support the larger mempool.

Here is another thought: If only exotic applications use mempools larger than 32 GB, this would be a generally acceptable limit, and DPDK should use index-based cache as default, making the opposite (i.e. pointer-based cache) a compile time option instead. A similar decision was recently made for limiting the RTE_MAX_LCORE default.

Although DPDK is moving away from compile time options in order to better support Linux distros, there should be a general exception for performance and memory optimizations. Otherwise, network appliance vendors will inherit the increasing amount of DPDK bloat, and we (network appliance vendors) will eventually be forced to fork DPDK to get rid of the bloat and achieve the goals originally intended by DPDK. If anyone disagrees with the principle about a general exception for performance and memory optimizations, I would like to pass on the decision to the Techboard!

#37 lore raw
Quoted 110 lines · Morten Brørup
Quoted 88 lines

From: Bruce Richardson [mailto:[email protected]]
Sent: Friday, 7 January 2022 14.51

Quoted 9 lines · Morten Brørup
Quoted 9 lines

From: Bruce Richardson [mailto:[email protected]]
Sent: Friday, 7 January 2022 12.16

Quoted 1 line · Morten Brørup
Quoted 1 line

From: Dharmik Thakkar [mailto:[email protected]] Sent:

Friday, 24

Quoted 3 lines
Quoted 3 lines

December 2021 23.59

Current mempool per core cache implementation stores pointers

to

Quoted 2 lines
Quoted 2 lines

mbufs

Quoted 1 line
Quoted 1 line

On 64b architectures, each pointer consumes 8B This patch

replaces

Quoted 2 lines
Quoted 2 lines

it

Quoted 1 line
Quoted 1 line

with index-based implementation, where in each buffer is

addressed

Quoted 2 lines
Quoted 2 lines

by

Quoted 1 line
Quoted 1 line

(pool base address + index) It reduces the amount of

memory/cache

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

required for per core cache

L3Fwd performance testing reveals minor improvements in the

cache

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

performance (L1 and L2 misses reduced by 0.60%) with no change

in

Quoted 8 lines
Quoted 8 lines
Quoted 3 lines
Quoted 3 lines

throughput

Micro-benchmarking the patch using mempool_perf_test shows

significant

Quoted 4 lines
Quoted 2 lines

improvement with majority of the test cases

I still think this is very interesting. And your performance

numbers

Quoted 5 lines
Quoted 5 lines

are

Quoted 4 lines

looking good.

However, it limits the size of a mempool to 4 GB. As previously discussed, the max mempool size can be increased by multiplying

the

Quoted 4 lines
Quoted 4 lines

index

Quoted 3 lines

with a constant.

I would suggest using sizeof(uintptr_t) as the constant

multiplier,

Quoted 4 lines
Quoted 4 lines

so

Quoted 1 line

the mempool can hold objects of any size divisible by

sizeof(uintptr_t).

Quoted 1 line

And it would be silly to use a mempool to hold objects smaller

than

Quoted 7 lines
Quoted 7 lines
Quoted 5 lines

sizeof(uintptr_t).

How does the performance look if you multiply the index by sizeof(uintptr_t)?

Each mempool entry is cache aligned, so we can use that if we want

a

Quoted 8 lines
Quoted 2 lines

bigger
multiplier.

Thanks for chiming in, Bruce.

Please also read this discussion about the multiplier:
http://inbox.dpdk.org/dev/CALBAE1PrQYyOG96f6ECeW1vPF3TOh1h7MZZULiY95z9xjbRuyA@mail.gmail.com/

I actually wondered after I had sent the email whether we had indeed an option to disable the cache alignment or not! Thanks for pointing out that
we do. This brings a couple additional thoughts:

* Using indexes for the cache should probably be a runtime flag rather than
a build-time one.
* It would seem reasonable to me to disallow use of the indexed-cache flag
and the non-cache aligned flag simultaneously.
* On the offchance that that restriction is unacceptable, then we can make things a little more complicated by doing a runtime computation
of
the "index-shiftwidth" to use.

Quoted 6 lines

Overall, I think defaulting to cacheline shiftwidth and disallowing index-based addressing when using unaligned buffers is simplest and easiest
unless we can come up with a valid usecase for needing more than that.

/Bruce

This feature is a performance optimization.

With that in mind, it should not introduce function pointers or similar run-time checks or in the fast path, to determine what kind of cache to use per mempool. And if an index multiplier is implemented, it should be a compile time constant, probably something between sizeof(uintptr_t) or RTE_MEMPOOL_ALIGN (=RTE_CACHE_LINE_SIZE).

The patch comes with a tradeoff between better performance and limited mempool size, and possibly some limitations regarding very small objects that are not cache line aligned to avoid wasting memory (RTE_MEMPOOL_POPULATE_F_ALIGN_OBJ).

With no multiplier, the only tradeoff is that the mempool size is limited to 4 GB.

If the multiplier is small (i.e. 8 bytes) the only tradeoff is that the mempool size is limited to 32 GB. (And a waste of memory for objects smaller than 8 byte; but I don't think anyone would use a mempool to hold objects smaller than 8 byte.)

If the multiplier is larger (i.e. 64 bytes cache line size), the mempool size is instead limited to 256 GB, but RTE_MEMPOOL_POPULATE_F_ALIGN_OBJ has no effect.

Note: 32 bit platforms have no benefit from this patch: The pointer already only uses 4 bytes, so replacing the pointer with a 4 byte index makes no difference.

Quoted 8 lines

Since this feature is a performance optimization only, and doesn't provide any new features, I don't mind it being a compile time option.

If this feature is a compile time option, and the mempool library is compiled with the large multiplier, then RTE_MEMPOOL_POPULATE_F_ALIGN_OBJ could be made undefined in the public header file, so compilation of applications using the flag will fail. And rte_mempool_create() could RTE_ASSERT() that RTE_MEMPOOL_POPULATE_F_ALIGN_OBJ is not set in its flags parameter, or emit a warning about the flag being ignored. Obviously, rte_mempool_create() should also RTE_ASSERT() that the mempool is not larger than the library supports, possibly emitting a message that the mempool library should be built without this feature to support the larger mempool.

Here is another thought: If only exotic applications use mempools larger than 32 GB, this would be a generally acceptable limit, and DPDK should use index-based cache as default, making the opposite (i.e. pointer-based cache) a compile time option instead. A similar decision was recently made for limiting the RTE_MAX_LCORE default.

Although DPDK is moving away from compile time options in order to better support Linux distros, there should be a general exception for performance and memory optimizations. Otherwise, network appliance vendors will inherit the increasing amount of DPDK bloat, and we (network appliance vendors) will eventually be forced to fork DPDK to get rid of the bloat and achieve the goals originally intended by DPDK.

Agree with Morten's view on this.

Quoted 2 lines

If anyone disagrees with the principle about a general exception for performance and memory optimizations, I would like to pass on the decision to the Techboard!

#38 lore raw

Hi,

Thank you for your valuable review comments and suggestions!

I will be sending out a v2 in which I have increased the size of the mempool to 32GB by using division by sizeof(uintptr_t). However, I am seeing ~5% performance degradation with mempool_perf_autotest (for bulk size of 32) with this change when compared to the base performance.
Earlier, without this change, I was seeing an improvement of ~13% compared to base performance. So, this is a significant degradation. I would appreciate your review comments on v2.

Thank you!

Quoted 126 lines · Jerin Jacob
Quoted 110 lines · Morten Brørup
Quoted 88 lines

From: Bruce Richardson [mailto:[email protected]]
Sent: Friday, 7 January 2022 14.51

Quoted 9 lines · Morten Brørup
Quoted 9 lines

From: Bruce Richardson [mailto:[email protected]]
Sent: Friday, 7 January 2022 12.16

Quoted 1 line · Morten Brørup
Quoted 1 line

From: Dharmik Thakkar [mailto:[email protected]] Sent:

Friday, 24

Quoted 3 lines
Quoted 3 lines

December 2021 23.59

Current mempool per core cache implementation stores pointers

to

Quoted 2 lines
Quoted 2 lines

mbufs

Quoted 1 line
Quoted 1 line

On 64b architectures, each pointer consumes 8B This patch

replaces

Quoted 2 lines
Quoted 2 lines

it

Quoted 1 line
Quoted 1 line

with index-based implementation, where in each buffer is

addressed

Quoted 2 lines
Quoted 2 lines

by

Quoted 1 line
Quoted 1 line

(pool base address + index) It reduces the amount of

memory/cache

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

required for per core cache

L3Fwd performance testing reveals minor improvements in the

cache

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

performance (L1 and L2 misses reduced by 0.60%) with no change

in

Quoted 8 lines
Quoted 8 lines
Quoted 3 lines
Quoted 3 lines

throughput

Micro-benchmarking the patch using mempool_perf_test shows

significant

Quoted 4 lines
Quoted 2 lines

improvement with majority of the test cases

I still think this is very interesting. And your performance

numbers

Quoted 5 lines
Quoted 5 lines

are

Quoted 4 lines

looking good.

However, it limits the size of a mempool to 4 GB. As previously discussed, the max mempool size can be increased by multiplying

the

Quoted 4 lines
Quoted 4 lines

index

Quoted 3 lines

with a constant.

I would suggest using sizeof(uintptr_t) as the constant

multiplier,

Quoted 4 lines
Quoted 4 lines

so

Quoted 1 line

the mempool can hold objects of any size divisible by

sizeof(uintptr_t).

Quoted 1 line

And it would be silly to use a mempool to hold objects smaller

than

Quoted 7 lines
Quoted 7 lines
Quoted 5 lines

sizeof(uintptr_t).

How does the performance look if you multiply the index by sizeof(uintptr_t)?

Each mempool entry is cache aligned, so we can use that if we want

a

Quoted 8 lines
Quoted 2 lines

bigger
multiplier.

Thanks for chiming in, Bruce.

Please also read this discussion about the multiplier:
http://inbox.dpdk.org/dev/CALBAE1PrQYyOG96f6ECeW1vPF3TOh1h7MZZULiY95z9xjbRuyA@mail.gmail.com/

I actually wondered after I had sent the email whether we had indeed an option to disable the cache alignment or not! Thanks for pointing out that
we do. This brings a couple additional thoughts:

* Using indexes for the cache should probably be a runtime flag rather than
a build-time one.
* It would seem reasonable to me to disallow use of the indexed-cache flag
and the non-cache aligned flag simultaneously.
* On the offchance that that restriction is unacceptable, then we can make things a little more complicated by doing a runtime computation
of
the "index-shiftwidth" to use.

Quoted 6 lines

Overall, I think defaulting to cacheline shiftwidth and disallowing index-based addressing when using unaligned buffers is simplest and easiest
unless we can come up with a valid usecase for needing more than that.

/Bruce

This feature is a performance optimization.

With that in mind, it should not introduce function pointers or similar run-time checks or in the fast path, to determine what kind of cache to use per mempool. And if an index multiplier is implemented, it should be a compile time constant, probably something between sizeof(uintptr_t) or RTE_MEMPOOL_ALIGN (=RTE_CACHE_LINE_SIZE).

The patch comes with a tradeoff between better performance and limited mempool size, and possibly some limitations regarding very small objects that are not cache line aligned to avoid wasting memory (RTE_MEMPOOL_POPULATE_F_ALIGN_OBJ).

With no multiplier, the only tradeoff is that the mempool size is limited to 4 GB.

If the multiplier is small (i.e. 8 bytes) the only tradeoff is that the mempool size is limited to 32 GB. (And a waste of memory for objects smaller than 8 byte; but I don't think anyone would use a mempool to hold objects smaller than 8 byte.)

If the multiplier is larger (i.e. 64 bytes cache line size), the mempool size is instead limited to 256 GB, but RTE_MEMPOOL_POPULATE_F_ALIGN_OBJ has no effect.

Note: 32 bit platforms have no benefit from this patch: The pointer already only uses 4 bytes, so replacing the pointer with a 4 byte index makes no difference.

Quoted 8 lines

Since this feature is a performance optimization only, and doesn't provide any new features, I don't mind it being a compile time option.

If this feature is a compile time option, and the mempool library is compiled with the large multiplier, then RTE_MEMPOOL_POPULATE_F_ALIGN_OBJ could be made undefined in the public header file, so compilation of applications using the flag will fail. And rte_mempool_create() could RTE_ASSERT() that RTE_MEMPOOL_POPULATE_F_ALIGN_OBJ is not set in its flags parameter, or emit a warning about the flag being ignored. Obviously, rte_mempool_create() should also RTE_ASSERT() that the mempool is not larger than the library supports, possibly emitting a message that the mempool library should be built without this feature to support the larger mempool.

Here is another thought: If only exotic applications use mempools larger than 32 GB, this would be a generally acceptable limit, and DPDK should use index-based cache as default, making the opposite (i.e. pointer-based cache) a compile time option instead. A similar decision was recently made for limiting the RTE_MAX_LCORE default.

Although DPDK is moving away from compile time options in order to better support Linux distros, there should be a general exception for performance and memory optimizations. Otherwise, network appliance vendors will inherit the increasing amount of DPDK bloat, and we (network appliance vendors) will eventually be forced to fork DPDK to get rid of the bloat and achieve the goals originally intended by DPDK.

Agree with Morten's view on this.

Quoted 2 lines

If anyone disagrees with the principle about a general exception for performance and memory optimizations, I would like to pass on the decision to the Techboard!

#39 lore raw
Quoted 4 lines · On Thu, 13 Jan 2022 05:31:18 +0000 Dharmik Thakkar <[email protected]>…

Hi,

Thank you for your valuable review comments and suggestions!

Quoted 134 lines

I will be sending out a v2 in which I have increased the size of the mempool to 32GB by using division by sizeof(uintptr_t). However, I am seeing ~5% performance degradation with mempool_perf_autotest (for bulk size of 32) with this change when compared to the base performance.
Earlier, without this change, I was seeing an improvement of ~13% compared to base performance. So, this is a significant degradation. I would appreciate your review comments on v2.

Thank you!

Quoted 126 lines · Jerin Jacob
Quoted 110 lines · Morten Brørup
Quoted 88 lines

From: Bruce Richardson [mailto:[email protected]]
Sent: Friday, 7 January 2022 14.51

Quoted 9 lines · Morten Brørup
Quoted 9 lines

From: Bruce Richardson [mailto:[email protected]]
Sent: Friday, 7 January 2022 12.16

Quoted 1 line · Morten Brørup
Quoted 1 line

From: Dharmik Thakkar [mailto:[email protected]] Sent:

Friday, 24

Quoted 3 lines
Quoted 3 lines

December 2021 23.59

Current mempool per core cache implementation stores pointers

to

Quoted 2 lines
Quoted 2 lines

mbufs

Quoted 1 line
Quoted 1 line

On 64b architectures, each pointer consumes 8B This patch

replaces

Quoted 2 lines
Quoted 2 lines

it

Quoted 1 line
Quoted 1 line

with index-based implementation, where in each buffer is

addressed

Quoted 2 lines
Quoted 2 lines

by

Quoted 1 line
Quoted 1 line

(pool base address + index) It reduces the amount of

memory/cache

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

required for per core cache

L3Fwd performance testing reveals minor improvements in the

cache

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

performance (L1 and L2 misses reduced by 0.60%) with no change

in

Quoted 8 lines
Quoted 8 lines
Quoted 3 lines
Quoted 3 lines

throughput

Micro-benchmarking the patch using mempool_perf_test shows

significant

Quoted 4 lines
Quoted 2 lines

improvement with majority of the test cases

I still think this is very interesting. And your performance

numbers

Quoted 5 lines
Quoted 5 lines

are

Quoted 4 lines

looking good.

However, it limits the size of a mempool to 4 GB. As previously discussed, the max mempool size can be increased by multiplying

the

Quoted 4 lines
Quoted 4 lines

index

Quoted 3 lines

with a constant.

I would suggest using sizeof(uintptr_t) as the constant

multiplier,

Quoted 4 lines
Quoted 4 lines

so

Quoted 1 line

the mempool can hold objects of any size divisible by

sizeof(uintptr_t).

Quoted 1 line

And it would be silly to use a mempool to hold objects smaller

than

Quoted 7 lines
Quoted 7 lines
Quoted 5 lines

sizeof(uintptr_t).

How does the performance look if you multiply the index by sizeof(uintptr_t)?

Each mempool entry is cache aligned, so we can use that if we want

a

Quoted 8 lines
Quoted 2 lines

bigger
multiplier.

Thanks for chiming in, Bruce.

Please also read this discussion about the multiplier:
http://inbox.dpdk.org/dev/CALBAE1PrQYyOG96f6ECeW1vPF3TOh1h7MZZULiY95z9xjbRuyA@mail.gmail.com/

I actually wondered after I had sent the email whether we had indeed an option to disable the cache alignment or not! Thanks for pointing out that
we do. This brings a couple additional thoughts:

* Using indexes for the cache should probably be a runtime flag rather than
a build-time one.
* It would seem reasonable to me to disallow use of the indexed-cache flag
and the non-cache aligned flag simultaneously.
* On the offchance that that restriction is unacceptable, then we can make things a little more complicated by doing a runtime computation
of
the "index-shiftwidth" to use.

Quoted 6 lines

Overall, I think defaulting to cacheline shiftwidth and disallowing index-based addressing when using unaligned buffers is simplest and easiest
unless we can come up with a valid usecase for needing more than that.

/Bruce

This feature is a performance optimization.

With that in mind, it should not introduce function pointers or similar run-time checks or in the fast path, to determine what kind of cache to use per mempool. And if an index multiplier is implemented, it should be a compile time constant, probably something between sizeof(uintptr_t) or RTE_MEMPOOL_ALIGN (=RTE_CACHE_LINE_SIZE).

The patch comes with a tradeoff between better performance and limited mempool size, and possibly some limitations regarding very small objects that are not cache line aligned to avoid wasting memory (RTE_MEMPOOL_POPULATE_F_ALIGN_OBJ).

With no multiplier, the only tradeoff is that the mempool size is limited to 4 GB.

If the multiplier is small (i.e. 8 bytes) the only tradeoff is that the mempool size is limited to 32 GB. (And a waste of memory for objects smaller than 8 byte; but I don't think anyone would use a mempool to hold objects smaller than 8 byte.)

If the multiplier is larger (i.e. 64 bytes cache line size), the mempool size is instead limited to 256 GB, but RTE_MEMPOOL_POPULATE_F_ALIGN_OBJ has no effect.

Note: 32 bit platforms have no benefit from this patch: The pointer already only uses 4 bytes, so replacing the pointer with a 4 byte index makes no difference.

Quoted 8 lines

Since this feature is a performance optimization only, and doesn't provide any new features, I don't mind it being a compile time option.

If this feature is a compile time option, and the mempool library is compiled with the large multiplier, then RTE_MEMPOOL_POPULATE_F_ALIGN_OBJ could be made undefined in the public header file, so compilation of applications using the flag will fail. And rte_mempool_create() could RTE_ASSERT() that RTE_MEMPOOL_POPULATE_F_ALIGN_OBJ is not set in its flags parameter, or emit a warning about the flag being ignored. Obviously, rte_mempool_create() should also RTE_ASSERT() that the mempool is not larger than the library supports, possibly emitting a message that the mempool library should be built without this feature to support the larger mempool.

Here is another thought: If only exotic applications use mempools larger than 32 GB, this would be a generally acceptable limit, and DPDK should use index-based cache as default, making the opposite (i.e. pointer-based cache) a compile time option instead. A similar decision was recently made for limiting the RTE_MAX_LCORE default.

Although DPDK is moving away from compile time options in order to better support Linux distros, there should be a general exception for performance and memory optimizations. Otherwise, network appliance vendors will inherit the increasing amount of DPDK bloat, and we (network appliance vendors) will eventually be forced to fork DPDK to get rid of the bloat and achieve the goals originally intended by DPDK.

Agree with Morten's view on this.

Quoted 2 lines

If anyone disagrees with the principle about a general exception for performance and memory optimizations, I would like to pass on the decision to the Techboard!

NAK
Having compile time stuff like this means one side or the other is not tested by CI infrastructure. There never was sufficient justification, and lots of objections. Dropping the patch.

#40 lore raw

The v2 was not sent, and Stephen dropped the patch from patchwork.

Do we abandon this feature?
Should I remove it from the roadmap?

06/07/2023 19:43, Stephen Hemminger:

Quoted 148 lines
Quoted 4 lines · On Thu, 13 Jan 2022 05:31:18 +0000 Dharmik Thakkar <[email protected]>…

Hi,

Thank you for your valuable review comments and suggestions!

Quoted 134 lines

I will be sending out a v2 in which I have increased the size of the mempool to 32GB by using division by sizeof(uintptr_t). However, I am seeing ~5% performance degradation with mempool_perf_autotest (for bulk size of 32) with this change when compared to the base performance.
Earlier, without this change, I was seeing an improvement of ~13% compared to base performance. So, this is a significant degradation. I would appreciate your review comments on v2.

Thank you!

Quoted 126 lines · Jerin Jacob
Quoted 110 lines · Morten Brørup
Quoted 88 lines

From: Bruce Richardson [mailto:[email protected]]
Sent: Friday, 7 January 2022 14.51

Quoted 9 lines · Morten Brørup
Quoted 9 lines

From: Bruce Richardson [mailto:[email protected]]
Sent: Friday, 7 January 2022 12.16

Quoted 1 line · Morten Brørup
Quoted 1 line

From: Dharmik Thakkar [mailto:[email protected]] Sent:

Friday, 24

Quoted 3 lines
Quoted 3 lines

December 2021 23.59

Current mempool per core cache implementation stores pointers

to

Quoted 2 lines
Quoted 2 lines

mbufs

Quoted 1 line
Quoted 1 line

On 64b architectures, each pointer consumes 8B This patch

replaces

Quoted 2 lines
Quoted 2 lines

it

Quoted 1 line
Quoted 1 line

with index-based implementation, where in each buffer is

addressed

Quoted 2 lines
Quoted 2 lines

by

Quoted 1 line
Quoted 1 line

(pool base address + index) It reduces the amount of

memory/cache

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

required for per core cache

L3Fwd performance testing reveals minor improvements in the

cache

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

performance (L1 and L2 misses reduced by 0.60%) with no change

in

Quoted 8 lines
Quoted 8 lines
Quoted 3 lines
Quoted 3 lines

throughput

Micro-benchmarking the patch using mempool_perf_test shows

significant

Quoted 4 lines
Quoted 2 lines

improvement with majority of the test cases

I still think this is very interesting. And your performance

numbers

Quoted 5 lines
Quoted 5 lines

are

Quoted 4 lines

looking good.

However, it limits the size of a mempool to 4 GB. As previously discussed, the max mempool size can be increased by multiplying

the

Quoted 4 lines
Quoted 4 lines

index

Quoted 3 lines

with a constant.

I would suggest using sizeof(uintptr_t) as the constant

multiplier,

Quoted 4 lines
Quoted 4 lines

so

Quoted 1 line

the mempool can hold objects of any size divisible by

sizeof(uintptr_t).

Quoted 1 line

And it would be silly to use a mempool to hold objects smaller

than

Quoted 7 lines
Quoted 7 lines
Quoted 5 lines

sizeof(uintptr_t).

How does the performance look if you multiply the index by sizeof(uintptr_t)?

Each mempool entry is cache aligned, so we can use that if we want

a

Quoted 8 lines
Quoted 2 lines

bigger
multiplier.

Thanks for chiming in, Bruce.

Please also read this discussion about the multiplier:
http://inbox.dpdk.org/dev/CALBAE1PrQYyOG96f6ECeW1vPF3TOh1h7MZZULiY95z9xjbRuyA@mail.gmail.com/

I actually wondered after I had sent the email whether we had indeed an option to disable the cache alignment or not! Thanks for pointing out that
we do. This brings a couple additional thoughts:

* Using indexes for the cache should probably be a runtime flag rather than
a build-time one.
* It would seem reasonable to me to disallow use of the indexed-cache flag
and the non-cache aligned flag simultaneously.
* On the offchance that that restriction is unacceptable, then we can make things a little more complicated by doing a runtime computation
of
the "index-shiftwidth" to use.

Quoted 6 lines

Overall, I think defaulting to cacheline shiftwidth and disallowing index-based addressing when using unaligned buffers is simplest and easiest
unless we can come up with a valid usecase for needing more than that.

/Bruce

This feature is a performance optimization.

With that in mind, it should not introduce function pointers or similar run-time checks or in the fast path, to determine what kind of cache to use per mempool. And if an index multiplier is implemented, it should be a compile time constant, probably something between sizeof(uintptr_t) or RTE_MEMPOOL_ALIGN (=RTE_CACHE_LINE_SIZE).

The patch comes with a tradeoff between better performance and limited mempool size, and possibly some limitations regarding very small objects that are not cache line aligned to avoid wasting memory (RTE_MEMPOOL_POPULATE_F_ALIGN_OBJ).

With no multiplier, the only tradeoff is that the mempool size is limited to 4 GB.

If the multiplier is small (i.e. 8 bytes) the only tradeoff is that the mempool size is limited to 32 GB. (And a waste of memory for objects smaller than 8 byte; but I don't think anyone would use a mempool to hold objects smaller than 8 byte.)

If the multiplier is larger (i.e. 64 bytes cache line size), the mempool size is instead limited to 256 GB, but RTE_MEMPOOL_POPULATE_F_ALIGN_OBJ has no effect.

Note: 32 bit platforms have no benefit from this patch: The pointer already only uses 4 bytes, so replacing the pointer with a 4 byte index makes no difference.

Quoted 8 lines

Since this feature is a performance optimization only, and doesn't provide any new features, I don't mind it being a compile time option.

If this feature is a compile time option, and the mempool library is compiled with the large multiplier, then RTE_MEMPOOL_POPULATE_F_ALIGN_OBJ could be made undefined in the public header file, so compilation of applications using the flag will fail. And rte_mempool_create() could RTE_ASSERT() that RTE_MEMPOOL_POPULATE_F_ALIGN_OBJ is not set in its flags parameter, or emit a warning about the flag being ignored. Obviously, rte_mempool_create() should also RTE_ASSERT() that the mempool is not larger than the library supports, possibly emitting a message that the mempool library should be built without this feature to support the larger mempool.

Here is another thought: If only exotic applications use mempools larger than 32 GB, this would be a generally acceptable limit, and DPDK should use index-based cache as default, making the opposite (i.e. pointer-based cache) a compile time option instead. A similar decision was recently made for limiting the RTE_MAX_LCORE default.

Although DPDK is moving away from compile time options in order to better support Linux distros, there should be a general exception for performance and memory optimizations. Otherwise, network appliance vendors will inherit the increasing amount of DPDK bloat, and we (network appliance vendors) will eventually be forced to fork DPDK to get rid of the bloat and achieve the goals originally intended by DPDK.

Agree with Morten's view on this.

Quoted 2 lines

If anyone disagrees with the principle about a general exception for performance and memory optimizations, I would like to pass on the decision to the Techboard!

NAK
Having compile time stuff like this means one side or the other is not tested by CI infrastructure. There never was sufficient justification, and lots of objections. Dropping the patch.

#41 lore raw
Quoted 6 lines

From: Thomas Monjalon [mailto:[email protected]]
Sent: Monday, 31 July 2023 14.24

The v2 was not sent, and Stephen dropped the patch from patchwork.

Do we abandon this feature?

+1, because I think that the zero-copy mempool cache access functions make this patch irrelevant.

Quoted 1 line

Should I remove it from the roadmap?

+1

Quoted 199 lines

06/07/2023 19:43, Stephen Hemminger:

Quoted 8 lines
Quoted 5 lines · On Thu, 13 Jan 2022 05:31:18 +0000 Dharmik Thakkar <[email protected]>…

Hi,

Thank you for your valuable review comments and suggestions!

I will be sending out a v2 in which I have increased the size of the

mempool to 32GB by using division by sizeof(uintptr_t).

Quoted 1 line
Quoted 1 line

However, I am seeing ~5% performance degradation with

mempool_perf_autotest (for bulk size of 32) with this change

Quoted 2 lines
Quoted 2 lines

when compared to the base performance.
Earlier, without this change, I was seeing an improvement of ~13% compared

to base performance. So, this is a significant degradation.

Quoted 7 lines
Quoted 7 lines

I would appreciate your review comments on v2.

Thank you!

Quoted 3 lines · Jerin Jacob

On Sat, Jan 8, 2022 at 3:07 PM Morten Brørup <[email protected]>

Quoted 62 lines · wrote:
Quoted 62 lines
Quoted 62 lines
Quoted 62 lines
Quoted 62 lines

From: Bruce Richardson [mailto:[email protected]]
Sent: Friday, 7 January 2022 14.51

Quoted 9 lines · Morten Brørup
Quoted 9 lines

From: Bruce Richardson [mailto:[email protected]]
Sent: Friday, 7 January 2022 12.16

Quoted 1 line · Morten Brørup
Quoted 1 line

From: Dharmik Thakkar [mailto:[email protected]] Sent:

Friday, 24

Quoted 3 lines
Quoted 3 lines

December 2021 23.59

Current mempool per core cache implementation stores pointers

to

Quoted 2 lines
Quoted 2 lines

mbufs

Quoted 1 line
Quoted 1 line

On 64b architectures, each pointer consumes 8B This patch

replaces

Quoted 2 lines
Quoted 2 lines

it

Quoted 1 line
Quoted 1 line

with index-based implementation, where in each buffer is

addressed

Quoted 2 lines
Quoted 2 lines

by

Quoted 1 line
Quoted 1 line

(pool base address + index) It reduces the amount of

memory/cache

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

required for per core cache

L3Fwd performance testing reveals minor improvements in the

cache

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

performance (L1 and L2 misses reduced by 0.60%) with no change

in

Quoted 8 lines
Quoted 8 lines
Quoted 3 lines
Quoted 3 lines

throughput

Micro-benchmarking the patch using mempool_perf_test shows

significant

Quoted 4 lines
Quoted 2 lines

improvement with majority of the test cases

I still think this is very interesting. And your performance

numbers

Quoted 5 lines
Quoted 5 lines

are

Quoted 4 lines

looking good.

However, it limits the size of a mempool to 4 GB. As previously discussed, the max mempool size can be increased by multiplying

the

Quoted 4 lines
Quoted 4 lines

index

Quoted 3 lines

with a constant.

I would suggest using sizeof(uintptr_t) as the constant

multiplier,

Quoted 4 lines
Quoted 4 lines

so

Quoted 1 line

the mempool can hold objects of any size divisible by

sizeof(uintptr_t).

Quoted 1 line

And it would be silly to use a mempool to hold objects smaller

than

Quoted 7 lines
Quoted 7 lines
Quoted 5 lines

sizeof(uintptr_t).

How does the performance look if you multiply the index by sizeof(uintptr_t)?

Each mempool entry is cache aligned, so we can use that if we want

Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines

a

Quoted 7 lines
Quoted 2 lines

bigger
multiplier.

Thanks for chiming in, Bruce.

Please also read this discussion about the multiplier:

http://inbox.dpdk.org/dev/CALBAE1PrQYyOG96f6ECeW1vPF3TOh1h7MZZULiY95z9xjbRuyA@
mail.gmail.com/

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 1 line

I actually wondered after I had sent the email whether we had indeed

an

Quoted 20 lines
Quoted 20 lines
Quoted 20 lines
Quoted 20 lines
Quoted 20 lines

option to disable the cache alignment or not! Thanks for pointing out that
we do. This brings a couple additional thoughts:

* Using indexes for the cache should probably be a runtime flag rather than
a build-time one.
* It would seem reasonable to me to disallow use of the indexed-cache flag
and the non-cache aligned flag simultaneously.
* On the offchance that that restriction is unacceptable, then we can make things a little more complicated by doing a runtime computation
of
the "index-shiftwidth" to use.

Overall, I think defaulting to cacheline shiftwidth and disallowing index-based addressing when using unaligned buffers is simplest and easiest
unless we can come up with a valid usecase for needing more than that.

Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 1 line

/Bruce

This feature is a performance optimization.

With that in mind, it should not introduce function pointers or similar

run-time checks or in the fast path, to determine what kind of cache to use per mempool. And if an index multiplier is implemented, it should be a compile time constant, probably something between sizeof(uintptr_t) or RTE_MEMPOOL_ALIGN (=RTE_CACHE_LINE_SIZE).

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

The patch comes with a tradeoff between better performance and limited

mempool size, and possibly some limitations regarding very small objects that are not cache line aligned to avoid wasting memory (RTE_MEMPOOL_POPULATE_F_ALIGN_OBJ).

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

With no multiplier, the only tradeoff is that the mempool size is

limited to 4 GB.

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

If the multiplier is small (i.e. 8 bytes) the only tradeoff is that the

mempool size is limited to 32 GB. (And a waste of memory for objects smaller than 8 byte; but I don't think anyone would use a mempool to hold objects smaller than 8 byte.)

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

If the multiplier is larger (i.e. 64 bytes cache line size), the

mempool size is instead limited to 256 GB, but
RTE_MEMPOOL_POPULATE_F_ALIGN_OBJ has no effect.

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

Note: 32 bit platforms have no benefit from this patch: The pointer

already only uses 4 bytes, so replacing the pointer with a 4 byte index makes no difference.

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

Since this feature is a performance optimization only, and doesn't

provide any new features, I don't mind it being a compile time option.

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

If this feature is a compile time option, and the mempool library is

compiled with the large multiplier, then RTE_MEMPOOL_POPULATE_F_ALIGN_OBJ could be made undefined in the public header file, so compilation of applications using the flag will fail. And rte_mempool_create() could RTE_ASSERT() that RTE_MEMPOOL_POPULATE_F_ALIGN_OBJ is not set in its flags parameter, or emit a warning about the flag being ignored. Obviously, rte_mempool_create() should also RTE_ASSERT() that the mempool is not larger than the library supports, possibly emitting a message that the mempool library should be built without this feature to support the larger mempool.

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

Here is another thought: If only exotic applications use mempools

larger than 32 GB, this would be a generally acceptable limit, and DPDK should use index-based cache as default, making the opposite (i.e. pointer-based cache) a compile time option instead. A similar decision was recently made for limiting the RTE_MAX_LCORE default.

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

Although DPDK is moving away from compile time options in order to

better support Linux distros, there should be a general exception for performance and memory optimizations. Otherwise, network appliance vendors will inherit the increasing amount of DPDK bloat, and we (network appliance vendors) will eventually be forced to fork DPDK to get rid of the bloat and achieve the goals originally intended by DPDK.

Quoted 4 lines
Quoted 4 lines
Quoted 4 lines

Agree with Morten's view on this.

Quoted 1 line

If anyone disagrees with the principle about a general exception for

performance and memory optimizations, I would like to pass on the decision to the Techboard!

Quoted 4 lines
Quoted 1 line
Quoted 1 line
Quoted 1 line

NAK
Having compile time stuff like this means one side or the other is not

tested

Quoted 1 line

by CI infrastructure. There never was sufficient justification, and lots of

objections.

Quoted 3 lines

Dropping the patch.

#42 lore raw
Quoted 20 lines

-----Original Message-----
From: Morten Brørup <[email protected]>
Sent: Monday, July 31, 2023 7:33 AM
To: [email protected]; Dharmik Jayesh Thakkar <[email protected]>
Cc: [email protected]; Jerin Jacob <[email protected]>; Bruce Richardson <[email protected]>; Honnappa Nagarahalli <[email protected]>; nd <[email protected]>; Ruifeng Wang <[email protected]>; Stephen Hemminger <[email protected]>; [email protected]; [email protected]
Subject: RE: [PATCH 0/1] mempool: implement index-based per core cache

Quoted 5 lines

From: Thomas Monjalon [mailto:[email protected]]
Sent: Monday, 31 July 2023 14.24

The v2 was not sent, and Stephen dropped the patch from patchwork.

Quoted 8 lines
Quoted 1 line

Do we abandon this feature?

+1, because I think that the zero-copy mempool cache access functions make this patch irrelevant.

Quoted 1 line

Should I remove it from the roadmap?

+1

V2 was sent (https://patches.dpdk.org/project/dpdk/patch/[email protected]/)
However, it is not relevant anymore and can be dropped. Thank you!

Quoted 191 lines
Quoted 25 lines

06/07/2023 19:43, Stephen Hemminger:

Quoted 9 lines
Quoted 6 lines · On Thu, 13 Jan 2022 05:31:18 +0000 Dharmik Thakkar <[email protected]>…

Hi,

Thank you for your valuable review comments and suggestions!

I will be sending out a v2 in which I have increased the size of the

mempool to 32GB by using division by sizeof(uintptr_t).

Quoted 1 line
Quoted 1 line

However, I am seeing ~5% performance degradation with

mempool_perf_autotest (for bulk size of 32) with this change

Quoted 3 lines
Quoted 3 lines

when compared to the base performance.
Earlier, without this change, I was seeing an improvement of ~13% compared

to base performance. So, this is a significant degradation.

Quoted 5 lines
Quoted 5 lines

I would appreciate your review comments on v2.

Thank you!

Quoted 1 line

On Jan 10, 2022, at 12:38 AM, Jerin Jacob <[email protected]>

Quoted 8 lines · wrote:
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

On Sat, Jan 8, 2022 at 3:07 PM Morten Brørup
<[email protected]>

Quoted 4 lines · wrote:
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines

From: Bruce Richardson [mailto:[email protected]]
Sent: Friday, 7 January 2022 14.51

Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines · Morten Brørup
Quoted 5 lines
Quoted 5 lines

From: Bruce Richardson [mailto:[email protected]]
Sent: Friday, 7 January 2022 12.16

Quoted 1 line · Morten Brørup
Quoted 1 line

From: Dharmik Thakkar [mailto:[email protected]]

Sent:

Quoted 59 lines
Quoted 59 lines
Quoted 59 lines
Quoted 59 lines
Quoted 59 lines
Quoted 59 lines
Quoted 5 lines
Quoted 5 lines

Friday, 24

Quoted 4 lines
Quoted 4 lines

December 2021 23.59

Current mempool per core cache implementation stores pointers

to

Quoted 2 lines
Quoted 2 lines

mbufs

Quoted 1 line
Quoted 1 line

On 64b architectures, each pointer consumes 8B This patch

replaces

Quoted 2 lines
Quoted 2 lines

it

Quoted 1 line
Quoted 1 line

with index-based implementation, where in each buffer is

addressed

Quoted 2 lines
Quoted 2 lines

by

Quoted 1 line
Quoted 1 line

(pool base address + index) It reduces the amount of

memory/cache

Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines

required for per core cache

L3Fwd performance testing reveals minor improvements in the

cache

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

performance (L1 and L2 misses reduced by 0.60%) with no change

in

Quoted 9 lines
Quoted 9 lines
Quoted 3 lines
Quoted 3 lines

throughput

Micro-benchmarking the patch using mempool_perf_test shows

significant

Quoted 5 lines
Quoted 2 lines

improvement with majority of the test cases

I still think this is very interesting. And your
performance

numbers

Quoted 6 lines
Quoted 6 lines

are

Quoted 5 lines

looking good.

However, it limits the size of a mempool to 4 GB. As previously discussed, the max mempool size can be increased by multiplying

the

Quoted 4 lines
Quoted 4 lines

index

Quoted 3 lines

with a constant.

I would suggest using sizeof(uintptr_t) as the constant

multiplier,

Quoted 5 lines
Quoted 5 lines

so

Quoted 1 line

the mempool can hold objects of any size divisible by

sizeof(uintptr_t).

Quoted 2 lines

And it would be silly to use a mempool to hold objects smaller

than

Quoted 8 lines
Quoted 8 lines
Quoted 5 lines

sizeof(uintptr_t).

How does the performance look if you multiply the index by sizeof(uintptr_t)?

Each mempool entry is cache aligned, so we can use that if we want

Quoted 9 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines

a

Quoted 7 lines
Quoted 2 lines

bigger
multiplier.

Thanks for chiming in, Bruce.

Please also read this discussion about the multiplier:

http://inbox.dpdk.org/dev/CALBAE1PrQYyOG96f6ECeW1vPF3TOh1h7MZZULiY
95z9

Quoted 63 lines

xjbRuyA@
mail.gmail.com/

Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 1 line

I actually wondered after I had sent the email whether we had indeed

an

Quoted 18 lines
Quoted 18 lines
Quoted 18 lines
Quoted 18 lines
Quoted 18 lines

option to disable the cache alignment or not! Thanks for pointing out that we do. This brings a couple additional thoughts:

* Using indexes for the cache should probably be a runtime flag rather than a build-time one.
* It would seem reasonable to me to disallow use of the indexed-cache flag and the non-cache aligned flag simultaneously.
* On the offchance that that restriction is unacceptable, then we can make things a little more complicated by doing a runtime computation of the "index-shiftwidth" to use.

Overall, I think defaulting to cacheline shiftwidth and disallowing index-based addressing when using unaligned buffers is simplest and easiest unless we can come up with a valid usecase for needing more than that.

Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 1 line

/Bruce

This feature is a performance optimization.

With that in mind, it should not introduce function pointers or similar

run-time checks or in the fast path, to determine what kind of cache to use per mempool. And if an index multiplier is implemented, it should be a compile time constant, probably something between sizeof(uintptr_t) or RTE_MEMPOOL_ALIGN (=RTE_CACHE_LINE_SIZE).

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

The patch comes with a tradeoff between better performance and limited

mempool size, and possibly some limitations regarding very small objects that are not cache line aligned to avoid wasting memory (RTE_MEMPOOL_POPULATE_F_ALIGN_OBJ).

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

With no multiplier, the only tradeoff is that the mempool size is

limited to 4 GB.

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

If the multiplier is small (i.e. 8 bytes) the only tradeoff is that the

mempool size is limited to 32 GB. (And a waste of memory for objects smaller than 8 byte; but I don't think anyone would use a mempool to hold objects smaller than 8 byte.)

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

If the multiplier is larger (i.e. 64 bytes cache line size), the

mempool size is instead limited to 256 GB, but
RTE_MEMPOOL_POPULATE_F_ALIGN_OBJ has no effect.

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

Note: 32 bit platforms have no benefit from this patch: The pointer

already only uses 4 bytes, so replacing the pointer with a 4 byte index makes no difference.

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 8 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

Since this feature is a performance optimization only, and doesn't

provide any new features, I don't mind it being a compile time option.

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

If this feature is a compile time option, and the mempool library is

compiled with the large multiplier, then RTE_MEMPOOL_POPULATE_F_ALIGN_OBJ could be made undefined in the

public

Quoted 8 lines

header file, so compilation of applications using the flag will fail. And rte_mempool_create() could
RTE_ASSERT() that RTE_MEMPOOL_POPULATE_F_ALIGN_OBJ is not set in its flags parameter, or emit a warning about the flag being ignored. Obviously,
rte_mempool_create() should also RTE_ASSERT() that the mempool is not larger than the library supports, possibly emitting a message that the mempool library should be built without this feature to support the larger

Quoted 42 lines

mempool.

Quoted 41 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

Here is another thought: If only exotic applications use mempools

larger than 32 GB, this would be a generally acceptable limit, and DPDK should use index-based cache as default, making the opposite (i.e. pointer-based
cache) a compile time option instead. A similar decision was recently made for limiting the RTE_MAX_LCORE default.

Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines

Although DPDK is moving away from compile time options in order to

better support Linux distros, there should be a general exception for performance and memory optimizations. Otherwise, network appliance vendors will inherit the increasing amount of DPDK bloat, and we (network appliance
vendors) will eventually be forced to fork DPDK to get rid of the bloat and achieve the goals originally intended by DPDK.

Quoted 5 lines
Quoted 5 lines
Quoted 5 lines

Agree with Morten's view on this.

Quoted 2 lines

If anyone disagrees with the principle about a general exception for

performance and memory optimizations, I would like to pass on the decision to the Techboard!

Quoted 5 lines
Quoted 1 line
Quoted 1 line
Quoted 1 line

NAK
Having compile time stuff like this means one side or the other is not

tested

Quoted 2 lines

by CI infrastructure. There never was sufficient justification, and lots of

objections.

Quoted 3 lines

Dropping the patch.

IMPORTANT NOTICE: The contents of this email and any attachments are confidential and may also be privileged. If you are not the intended recipient, please notify the sender immediately and do not disclose the contents to any other person, use it for any purpose, or store or copy the information in any medium. Thank you.

#43 lore raw

v2 cover mempool: implement index-based per core cache

In reply to Dharmik Thakkar

Current mempool per core cache implementation stores pointers to mbufs On 64b architectures, each pointer consumes 8B
This patch replaces it with index-based implementation, where in each buffer is addressed by (pool base address + index) It reduces the amount of memory/cache required for per core cache

L3Fwd performance testing reveals minor improvements in the cache performance (L1 and L2 misses reduced by 0.60%)
with no change in throughput

Micro-benchmarking the patch using mempool_perf_test shows significant improvement with majority of the test cases

Number of cores = 1:
n_get_bulk=1 n_put_bulk=1 n_keep=32 %_change_with_patch=18.01 n_get_bulk=1 n_put_bulk=1 n_keep=128 %_change_with_patch=19.91 n_get_bulk=1 n_put_bulk=4 n_keep=32 %_change_with_patch=-20.37 (regression) n_get_bulk=1 n_put_bulk=4 n_keep=128 %_change_with_patch=-17.01 (regression) n_get_bulk=1 n_put_bulk=32 n_keep=32 %_change_with_patch=-25.06 (regression) n_get_bulk=1 n_put_bulk=32 n_keep=128 %_change_with_patch=-23.81 (regression) n_get_bulk=4 n_put_bulk=1 n_keep=32 %_change_with_patch=53.93 n_get_bulk=4 n_put_bulk=1 n_keep=128 %_change_with_patch=60.90 n_get_bulk=4 n_put_bulk=4 n_keep=32 %_change_with_patch=1.64 n_get_bulk=4 n_put_bulk=4 n_keep=128 %_change_with_patch=8.76 n_get_bulk=4 n_put_bulk=32 n_keep=32 %_change_with_patch=-4.71 (regression) n_get_bulk=4 n_put_bulk=32 n_keep=128 %_change_with_patch=-3.19 (regression) n_get_bulk=32 n_put_bulk=1 n_keep=32 %_change_with_patch=65.63 n_get_bulk=32 n_put_bulk=1 n_keep=128 %_change_with_patch=75.19 n_get_bulk=32 n_put_bulk=4 n_keep=32 %_change_with_patch=11.75 n_get_bulk=32 n_put_bulk=4 n_keep=128 %_change_with_patch=15.52 n_get_bulk=32 n_put_bulk=32 n_keep=32 %_change_with_patch=13.45 n_get_bulk=32 n_put_bulk=32 n_keep=128 %_change_with_patch=11.58

Number of core = 2:
n_get_bulk=1 n_put_bulk=1 n_keep=32 %_change_with_patch=18.21 n_get_bulk=1 n_put_bulk=1 n_keep=128 %_change_with_patch=21.89 n_get_bulk=1 n_put_bulk=4 n_keep=32 %_change_with_patch=-21.21 (regression) n_get_bulk=1 n_put_bulk=4 n_keep=128 %_change_with_patch=-17.05 (regression) n_get_bulk=1 n_put_bulk=32 n_keep=32 %_change_with_patch=-26.09 (regression) n_get_bulk=1 n_put_bulk=32 n_keep=128 %_change_with_patch=-23.49 (regression) n_get_bulk=4 n_put_bulk=1 n_keep=32 %_change_with_patch=56.28 n_get_bulk=4 n_put_bulk=1 n_keep=128 %_change_with_patch=67.69 n_get_bulk=4 n_put_bulk=4 n_keep=32 %_change_with_patch=1.45 n_get_bulk=4 n_put_bulk=4 n_keep=128 %_change_with_patch=8.84 n_get_bulk=4 n_put_bulk=32 n_keep=32 %_change_with_patch=-5.27 (regression) n_get_bulk=4 n_put_bulk=32 n_keep=128 %_change_with_patch=-3.09 (regression) n_get_bulk=32 n_put_bulk=1 n_keep=32 %_change_with_patch=76.11 n_get_bulk=32 n_put_bulk=1 n_keep=128 %_change_with_patch=86.06 n_get_bulk=32 n_put_bulk=4 n_keep=32 %_change_with_patch=11.86 n_get_bulk=32 n_put_bulk=4 n_keep=128 %_change_with_patch=16.55 n_get_bulk=32 n_put_bulk=32 n_keep=32 %_change_with_patch=13.01 n_get_bulk=32 n_put_bulk=32 n_keep=128 %_change_with_patch=11.51

From analyzing the results, it is clear that for n_get_bulk and n_put_bulk sizes of 32 there is no performance regression IMO, the other sizes are not practical from performance perspective and the regression in those cases can be safely ignored

An attempt to increase the size of mempool to 32GB, by dividing the index by sizeof(uintptr_t), has led to a performance degradation of ~5% compared to the base performance
---
v2:
- Increase size of mempool to 32GB (Morten)
- Improve performance for other platforms using dual loop unrolling
---
Dharmik Thakkar (1):
mempool: implement index-based per core cache

 lib/mempool/rte_mempool.h             | 150 +++++++++++++++++++++++++-
 lib/mempool/rte_mempool_ops_default.c |   7 ++
 2 files changed, 156 insertions(+), 1 deletion(-)
Signature · 1 line
2.17.1
#44 lore raw

PATCH v2 1/1 mempool: implement index-based per core cache

Current mempool per core cache implementation stores pointers to mbufs On 64b architectures, each pointer consumes 8B
This patch replaces it with index-based implementation, where in each buffer is addressed by (pool base address + index) It reduces the amount of memory/cache required for per core cache

L3Fwd performance testing reveals minor improvements in the cache performance (L1 and L2 misses reduced by 0.60%)
with no change in throughput

---
 lib/mempool/rte_mempool.h             | 150 +++++++++++++++++++++++++-
 lib/mempool/rte_mempool_ops_default.c |   7 ++
 2 files changed, 156 insertions(+), 1 deletion(-)
lib/mempool/rte_mempool.h +149 -1
index 1e7a3c15273c..f2403fbc97a7 100644
@@ -50,6 +50,10 @@
 #include <rte_memcpy.h>
 #include <rte_common.h>
 
+#ifdef RTE_MEMPOOL_INDEX_BASED_LCORE_CACHE
+#include <rte_vect.h>
+#endif
+
 #include "rte_mempool_trace_fp.h"
 
 #ifdef __cplusplus
@@ -239,6 +243,9 @@ struct rte_mempool {
 	int32_t ops_index;
 
 	struct rte_mempool_cache *local_cache; /**< Per-lcore local cache */
+#ifdef RTE_MEMPOOL_INDEX_BASED_LCORE_CACHE
+	void *pool_base_value; /**< Base value to calculate indices */
+#endif
 
 	uint32_t populated_size;         /**< Number of populated objects. */
 	struct rte_mempool_objhdr_list elt_list; /**< List of objects in pool */
@@ -1314,7 +1321,22 @@ rte_mempool_cache_flush(struct rte_mempool_cache *cache,
 	if (cache == NULL || cache->len == 0)
 		return;
 	rte_mempool_trace_cache_flush(cache, mp);
+
+#ifdef RTE_MEMPOOL_INDEX_BASED_LCORE_CACHE
+	unsigned int i;
+	unsigned int cache_len = cache->len;
+	void *obj_table[RTE_MEMPOOL_CACHE_MAX_SIZE * 3];
+	void *base_value = mp->pool_base_value;
+	uint32_t *cache_objs = (uint32_t *) cache->objs;
+	for (i = 0; i < cache_len; i++) {
+		/* Scale by sizeof(uintptr_t) to accommodate 16GB/32GB mempool */
+		cache_objs[i] = cache_objs[i] << 3;
+		obj_table[i] = (void *) RTE_PTR_ADD(base_value, cache_objs[i]);
+	}
+	rte_mempool_ops_enqueue_bulk(mp, obj_table, cache->len);
+#else
 	rte_mempool_ops_enqueue_bulk(mp, cache->objs, cache->len);
+#endif
 	cache->len = 0;
 }
 
@@ -1334,7 +1356,14 @@ static __rte_always_inline void
 rte_mempool_do_generic_put(struct rte_mempool *mp, void * const *obj_table,
 			   unsigned int n, struct rte_mempool_cache *cache)
 {
+#ifdef RTE_MEMPOOL_INDEX_BASED_LCORE_CACHE
+	uint32_t *cache_objs;
+	void *base_value;
+	uint32_t i;
+	uint32_t temp_objs[2];
+#else
 	void **cache_objs;
+#endif
 
 	/* increment stat now, adding in mempool always success */
 	RTE_MEMPOOL_STAT_ADD(mp, put_bulk, 1);
@@ -1344,7 +1373,13 @@ rte_mempool_do_generic_put(struct rte_mempool *mp, void * const *obj_table,
 	if (unlikely(cache == NULL || n > RTE_MEMPOOL_CACHE_MAX_SIZE))
 		goto ring_enqueue;
 
+#ifdef RTE_MEMPOOL_INDEX_BASED_LCORE_CACHE
+	cache_objs = (uint32_t *) cache->objs;
+	cache_objs = &cache_objs[cache->len];
+	base_value = mp->pool_base_value;
+#else
 	cache_objs = &cache->objs[cache->len];
+#endif
 
 	/*
 	 * The cache follows the following algorithm
@@ -1354,13 +1389,50 @@ rte_mempool_do_generic_put(struct rte_mempool *mp, void * const *obj_table,
 	 */
 
 	/* Add elements back into the cache */
+
+#ifdef RTE_MEMPOOL_INDEX_BASED_LCORE_CACHE
+#if defined __ARM_NEON
+	uint64x2_t v_obj_table;
+	uint64x2_t v_base_value = vdupq_n_u64((uint64_t)base_value);
+	uint32x2_t v_cache_objs;
+
+	for (i = 0; i < (n & ~0x1); i += 2) {
+		v_obj_table = vld1q_u64((const uint64_t *)&obj_table[i]);
+		v_cache_objs = vqmovn_u64(vsubq_u64(v_obj_table, v_base_value));
+
+		/* Scale by sizeof(uintptr_t) to accommodate 16GB/32GB mempool */
+		v_cache_objs = vshr_n_u32(v_cache_objs, 3);
+		vst1_u32(cache_objs + i, v_cache_objs);
+	}
+#else
+	for (i = 0; i < (n & ~0x1); i += 2) {
+		temp_objs[0] = (uint32_t) RTE_PTR_DIFF(obj_table[i], base_value);
+		temp_objs[1] = (uint32_t) RTE_PTR_DIFF(obj_table[i + 1], base_value);
+		/* Scale by sizeof(uintptr_t) to accommodate 16GB/32GB mempool */
+		cache_objs[i] = temp_objs[0] >> 3;
+		cache_objs[i + 1] = temp_objs[1] >> 3;
+	}
+#endif
+	if (n & 0x1) {
+		temp_objs[0] = (uint32_t) RTE_PTR_DIFF(obj_table[i], base_value);
+
+		/* Divide by sizeof(uintptr_t) to accommodate 16G/32G mempool */
+		cache_objs[i] = temp_objs[0] >> 3;
+	}
+#else
 	rte_memcpy(&cache_objs[0], obj_table, sizeof(void *) * n);
+#endif
 
 	cache->len += n;
 
 	if (cache->len >= cache->flushthresh) {
+#ifdef RTE_MEMPOOL_INDEX_BASED_LCORE_CACHE
+		rte_mempool_ops_enqueue_bulk(mp, obj_table + cache->len - cache->size,
+				cache->len - cache->size);
+#else
 		rte_mempool_ops_enqueue_bulk(mp, &cache->objs[cache->size],
 				cache->len - cache->size);
+#endif
 		cache->len = cache->size;
 	}
 
@@ -1461,13 +1533,23 @@ rte_mempool_do_generic_get(struct rte_mempool *mp, void **obj_table,
 {
 	int ret;
 	uint32_t index, len;
+#ifdef RTE_MEMPOOL_INDEX_BASED_LCORE_CACHE
+	uint32_t i;
+	uint32_t *cache_objs;
+	uint32_t objs[2];
+#else
 	void **cache_objs;
-
+#endif
 	/* No cache provided or cannot be satisfied from cache */
 	if (unlikely(cache == NULL || n >= cache->size))
 		goto ring_dequeue;
 
+#ifdef RTE_MEMPOOL_INDEX_BASED_LCORE_CACHE
+	void *base_value = mp->pool_base_value;
+	cache_objs = (uint32_t *) cache->objs;
+#else
 	cache_objs = cache->objs;
+#endif
 
 	/* Can this be satisfied from the cache? */
 	if (cache->len < n) {
@@ -1475,8 +1557,14 @@ rte_mempool_do_generic_get(struct rte_mempool *mp, void **obj_table,
 		uint32_t req = n + (cache->size - cache->len);
 
 		/* How many do we require i.e. number to fill the cache + the request */
+#ifdef RTE_MEMPOOL_INDEX_BASED_LCORE_CACHE
+		void *temp_objs[RTE_MEMPOOL_CACHE_MAX_SIZE * 3]; /**< Cache objects */
+		ret = rte_mempool_ops_dequeue_bulk(mp,
+			temp_objs, req);
+#else
 		ret = rte_mempool_ops_dequeue_bulk(mp,
 			&cache->objs[cache->len], req);
+#endif
 		if (unlikely(ret < 0)) {
 			/*
 			 * In the off chance that we are buffer constrained,
@@ -1487,12 +1575,72 @@ rte_mempool_do_generic_get(struct rte_mempool *mp, void **obj_table,
 			goto ring_dequeue;
 		}
 
+#ifdef RTE_MEMPOOL_INDEX_BASED_LCORE_CACHE
+		len = cache->len;
+		for (i = 0; i < req; ++i, ++len) {
+			cache_objs[len] = (uint32_t) RTE_PTR_DIFF(temp_objs[i],
+								base_value);
+			/* Scale by sizeof(uintptr_t) to accommodate 16GB/32GB mempool */
+			cache_objs[len] = cache_objs[len] >> 3;
+		}
+#endif
+
 		cache->len += req;
 	}
 
 	/* Now fill in the response ... */
+#ifdef RTE_MEMPOOL_INDEX_BASED_LCORE_CACHE
+#if defined __ARM_NEON
+	uint64x2_t v_obj_table;
+	uint64x2_t v_cache_objs;
+	uint64x2_t v_base_value = vdupq_n_u64((uint64_t)base_value);
+
+	for (index = 0, len = cache->len - 1; index < (n & ~0x3); index += 4,
+						len -= 4, obj_table += 4) {
+		v_cache_objs = vmovl_u32(vld1_u32(cache_objs + len - 1));
+		/* Scale by sizeof(uintptr_t) to accommodate 16GB/32GB mempool */
+		v_cache_objs = vshlq_n_u64(v_cache_objs, 3);
+		v_obj_table = vaddq_u64(v_cache_objs, v_base_value);
+		vst1q_u64((uint64_t *)obj_table, v_obj_table);
+		v_cache_objs = vmovl_u32(vld1_u32(cache_objs + len - 3));
+		/* Scale by sizeof(uintptr_t) to accommodate 16GB/32GB mempool */
+		v_cache_objs = vshlq_n_u64(v_cache_objs, 3);
+		v_obj_table = vaddq_u64(v_cache_objs, v_base_value);
+		vst1q_u64((uint64_t *)(obj_table + 2), v_obj_table);
+	}
+	switch (n & 0x3) {
+	case 3:
+		/* Scale by sizeof(uintptr_t) to accommodate 16GB/32GB mempool */
+		objs[0] = cache_objs[len--] << 3;
+		*(obj_table++) = (void *) RTE_PTR_ADD(base_value, objs[0]); /* fallthrough */
+	case 2:
+		/* Scale by sizeof(uintptr_t) to accommodate 16GB/32GB mempool */
+		objs[0] = cache_objs[len--] << 3;
+		*(obj_table++) = (void *) RTE_PTR_ADD(base_value, objs[0]); /* fallthrough */
+	case 1:
+		/* Scale by sizeof(uintptr_t) to accommodate 16GB/32GB mempool */
+		objs[0] = cache_objs[len] << 3;
+		*(obj_table) = (void *) RTE_PTR_ADD(base_value, objs[0]);
+	}
+#else
+	for (index = 0, len = cache->len - 1; index < (n & ~0x1); index += 2,
+						len -= 2, obj_table += 2) {
+		/* Scale by sizeof(uintptr_t) to accommodate 16GB/32GB mempool */
+		objs[0] = cache_objs[len] << 3;
+		objs[1] = cache_objs[len - 1] << 3;
+		*obj_table = (void *) RTE_PTR_ADD(base_value, objs[0]);
+		*(obj_table + 1) = (void *) RTE_PTR_ADD(base_value, objs[1]);
+	}
+
+	if (n & 0x1) {
+		objs[0] = cache_objs[len] << 3;
+		*obj_table = (void *) RTE_PTR_ADD(base_value, objs[0]);
+	}
+#endif
+#else
 	for (index = 0, len = cache->len - 1; index < n; ++index, len--, obj_table++)
 		*obj_table = cache_objs[len];
+#endif
 
 	cache->len -= n;
 
lib/mempool/rte_mempool_ops_default.c +7 -0
index 22fccf9d7619..3543cad9d4ce 100644
@@ -127,6 +127,13 @@ rte_mempool_op_populate_helper(struct rte_mempool *mp, unsigned int flags,
 		obj = va + off;
 		obj_cb(mp, obj_cb_arg, obj,
 		       (iova == RTE_BAD_IOVA) ? RTE_BAD_IOVA : (iova + off));
+#ifdef RTE_MEMPOOL_INDEX_BASED_LCORE_CACHE
+		/* Store pool base value to calculate indices for index-based
+		 * lcore cache implementation
+		 */
+		if (i == 0)
+			mp->pool_base_value = obj;
+#endif
 		rte_mempool_ops_enqueue_bulk(mp, &obj, 1);
 		off += mp->elt_size + mp->trailer_size;
 	}
Signature · 1 line
2.17.1
#45 lore raw
Quoted 11 lines · Dharmik Thakkar

Current mempool per core cache implementation stores pointers to mbufs On 64b architectures, each pointer consumes 8B
This patch replaces it with index-based implementation, where in each buffer is addressed by (pool base address + index) It reduces the amount of memory/cache required for per core cache

L3Fwd performance testing reveals minor improvements in the cache performance (L1 and L2 misses reduced by 0.60%)
with no change in throughput

Quoted 8 lines

---

        /* Now fill in the response ... */

+#ifdef RTE_MEMPOOL_INDEX_BASED_LCORE_CACHE

Instead of having this #ifdef clutter everywhere for the pair, I think, we can define RTE_MEMPOOL_INDEX_BASED_LCORE_CACHE once, and have a different implementation.
i.e
#ifdef RTE_MEMPOOL_INDEX_BASED_LCORE_CACHE
void x()
{

}
void y()
{

}
#else

void x()
{

}
void y()
{

}

#endif

call
x();
y();

in the main code.

lib/mempool/rte_mempool_ops_default.c rte_mempool_op_populate_helper(struct rte_mempool *mp, unsigned int flags, · line 130

Quoted 9 lines
lib/mempool/rte_mempool_ops_default.c +1 -0
index 22fccf9d7619..3543cad9d4ce 100644
@@ -127,6 +127,13 @@ rte_mempool_op_populate_helper(struct rte_mempool *mp, unsigned int flags,
                obj = va + off;
                obj_cb(mp, obj_cb_arg, obj,
                       (iova == RTE_BAD_IOVA) ? RTE_BAD_IOVA : (iova + off));
+#ifdef RTE_MEMPOOL_INDEX_BASED_LCORE_CACHE

This is the only place used in C code.
Since we are going compile time approach. Can make this unconditional? That will enable the use of this model in the application, without recompiling DPDK.
All application needs to

#define RTE_MEMPOOL_INDEX_BASED_LCORE_CACHE 1
#include <rte_mempool.h>

I believe enabling such structuring helps to avoid DPDK recompilation of code.

Quoted 12 lines
lib/mempool/rte_mempool_ops_default.c +6 -1
+               /* Store pool base value to calculate indices for index-based
+                * lcore cache implementation
+                */
+               if (i == 0)
+                       mp->pool_base_value = obj;
+#endif
                rte_mempool_ops_enqueue_bulk(mp, &obj, 1);
                off += mp->elt_size + mp->trailer_size;
        }
--

2.17.1

#46 lore raw
In reply to Dharmik Thakkar

+CC Beilei as i40e maintainer

Quoted 51 lines

From: Dharmik Thakkar [mailto:[email protected]]
Sent: Thursday, 13 January 2022 06.37

Current mempool per core cache implementation stores pointers to mbufs On 64b architectures, each pointer consumes 8B
This patch replaces it with index-based implementation, where in each buffer is addressed by (pool base address + index) It reduces the amount of memory/cache required for per core cache

L3Fwd performance testing reveals minor improvements in the cache performance (L1 and L2 misses reduced by 0.60%)
with no change in throughput

---
 lib/mempool/rte_mempool.h             | 150 +++++++++++++++++++++++++-
 lib/mempool/rte_mempool_ops_default.c |   7 ++
 2 files changed, 156 insertions(+), 1 deletion(-)
lib/mempool/rte_mempool.h +7 -0
index 1e7a3c15273c..f2403fbc97a7 100644
@@ -50,6 +50,10 @@
 #include <rte_memcpy.h>
 #include <rte_common.h>
 
+#ifdef RTE_MEMPOOL_INDEX_BASED_LCORE_CACHE
+#include <rte_vect.h>
+#endif
+
 #include "rte_mempool_trace_fp.h"
 
 #ifdef __cplusplus
@@ -239,6 +243,9 @@ struct rte_mempool {
 	int32_t ops_index;
 
 	struct rte_mempool_cache *local_cache; /**< Per-lcore local cache
 */
+#ifdef RTE_MEMPOOL_INDEX_BASED_LCORE_CACHE
+	void *pool_base_value; /**< Base value to calculate indices */
+#endif
 
 	uint32_t populated_size;         /**< Number of populated

objects. */
struct rte_mempool_objhdr_list elt_list; /**< List of objects in
pool */

lib/mempool/rte_mempool.h +0 -0
@@ -1314,7 +1321,22 @@ rte_mempool_cache_flush(struct rte_mempool_cache
 *cache,

lib/mempool/rte_mempool.h rte_mempool_cache_flush(struct rte_mempool_cache · line 1331

Quoted 10 lines
lib/mempool/rte_mempool.h +7 -0
 	if (cache == NULL || cache->len == 0)
 		return;
 	rte_mempool_trace_cache_flush(cache, mp);
+
+#ifdef RTE_MEMPOOL_INDEX_BASED_LCORE_CACHE
+	unsigned int i;
+	unsigned int cache_len = cache->len;
+	void *obj_table[RTE_MEMPOOL_CACHE_MAX_SIZE * 3];
+	void *base_value = mp->pool_base_value;
+	uint32_t *cache_objs = (uint32_t *) cache->objs;

Hi Dharmik and Honnappa,

The essence of this patch is based on recasting the type of the objs field in the rte_mempool_cache structure from an array of pointers to an array of uint32_t.

However, this effectively breaks the ABI, because the rte_mempool_cache structure is public and part of the API.

Some drivers [1] even bypass the mempool API and access the rte_mempool_cache structure directly, assuming that the objs array in the cache is an array of pointers. So you cannot recast the fields in the rte_mempool_cache structure the way this patch requires.

Although I do consider bypassing an API's accessor functions "spaghetti code", this driver's behavior is formally acceptable as long as the rte_mempool_cache structure is not marked as internal.

I really liked your idea of using indexes instead of pointers, so I'm very sorry to shoot it down. :-(

[1]: E.g. the Intel i40e PMD, http://code.dpdk.org/dpdk/latest/source/drivers/net/i40e/i40e_rxtx_vec_avx512.c#L25

-Morten

#47 lore raw
Quoted 66 lines

+CC Beilei as i40e maintainer

Quoted 49 lines

From: Dharmik Thakkar [mailto:[email protected]]
Sent: Thursday, 13 January 2022 06.37

Current mempool per core cache implementation stores pointers to mbufs On 64b architectures, each pointer consumes 8B This patch replaces it with index-based implementation, where in each buffer is addressed by (pool base address + index) It reduces the amount of memory/cache required for per core cache

L3Fwd performance testing reveals minor improvements in the cache performance (L1 and L2 misses reduced by 0.60%) with no change in throughput

---
 lib/mempool/rte_mempool.h             | 150 +++++++++++++++++++++++++-
 lib/mempool/rte_mempool_ops_default.c |   7 ++
 2 files changed, 156 insertions(+), 1 deletion(-)
lib/mempool/rte_mempool.h +7 -0
index 1e7a3c15273c..f2403fbc97a7 100644
@@ -50,6 +50,10 @@
 #include <rte_memcpy.h>
 #include <rte_common.h>
 
+#ifdef RTE_MEMPOOL_INDEX_BASED_LCORE_CACHE
+#include <rte_vect.h>
+#endif
+
 #include "rte_mempool_trace_fp.h"
 
 #ifdef __cplusplus
@@ -239,6 +243,9 @@ struct rte_mempool {
 	int32_t ops_index;
 
 	struct rte_mempool_cache *local_cache; /**< Per-lcore local cache */
+#ifdef RTE_MEMPOOL_INDEX_BASED_LCORE_CACHE
+	void *pool_base_value; /**< Base value to calculate indices */
+#endif
 
 	uint32_t populated_size;         /**< Number of populated

objects. */
struct rte_mempool_objhdr_list elt_list; /**< List of objects in
pool */ @@ -1314,7 +1321,22 @@ rte_mempool_cache_flush(struct rte_mempool_cache *cache,

lib/mempool/rte_mempool.h rte_mempool_cache_flush(struct rte_mempool_cache *cache, · line 1330

Quoted 10 lines
lib/mempool/rte_mempool.h +7 -0
 	if (cache == NULL || cache->len == 0)
 		return;
 	rte_mempool_trace_cache_flush(cache, mp);
+
+#ifdef RTE_MEMPOOL_INDEX_BASED_LCORE_CACHE
+	unsigned int i;
+	unsigned int cache_len = cache->len;
+	void *obj_table[RTE_MEMPOOL_CACHE_MAX_SIZE * 3];
+	void *base_value = mp->pool_base_value;
+	uint32_t *cache_objs = (uint32_t *) cache->objs;

Hi Dharmik and Honnappa,

Quoted 6 lines

The essence of this patch is based on recasting the type of the objs field in the rte_mempool_cache structure from an array of pointers to an array of uint32_t.

However, this effectively breaks the ABI, because the rte_mempool_cache structure is public and part of the API.

The patch does not change the public structure, the new member is under compile time flag, not sure how it breaks the ABI.

Quoted 5 lines

Some drivers [1] even bypass the mempool API and access the rte_mempool_cache structure directly, assuming that the objs array in the cache is an array of pointers. So you cannot recast the fields in the rte_mempool_cache structure the way this patch requires.

IMO, those drivers are at fault. The mempool cache structure is public only because the APIs are inline. We should still maintain modularity and not use the members of structures belonging to another library directly. A similar effort involving rte_ring was not accepted sometime back [1]

[1] http://inbox.dpdk.org/dev/DBAPR08MB5814907968595EE56F5E20A798390@DBAPR08MB5814.eurprd08.prod.outlook.com/

Quoted 11 lines

Although I do consider bypassing an API's accessor functions "spaghetti code", this driver's behavior is formally acceptable as long as the rte_mempool_cache structure is not marked as internal.

I really liked your idea of using indexes instead of pointers, so I'm very sorry to shoot it down. :-(

[1]: E.g. the Intel i40e PMD,
http://code.dpdk.org/dpdk/latest/source/drivers/net/i40e/i40e_rxtx_vec_avx
512.c#L25

It is possible to throw an error when this feature is enabled in this file. Alternatively, this PMD could implement the code for index based mempool.

Quoted 2 lines

-Morten

#48 lore raw

+Ray Kinsella, ABI Policy maintainer

Quoted 110 lines

From: Honnappa Nagarahalli [mailto:[email protected]]
Sent: Friday, 21 January 2022 07.01

Quoted 7 lines

+CC Beilei as i40e maintainer

Quoted 4 lines

From: Dharmik Thakkar [mailto:[email protected]]
Sent: Thursday, 13 January 2022 06.37

Current mempool per core cache implementation stores pointers to

mbufs

Quoted 1 line
Quoted 1 line

On 64b architectures, each pointer consumes 8B This patch replaces

it

Quoted 1 line
Quoted 1 line

with index-based implementation, where in each buffer is addressed

by

Quoted 7 lines
Quoted 7 lines

(pool base address + index) It reduces the amount of memory/cache required for per core cache

L3Fwd performance testing reveals minor improvements in the cache performance (L1 and L2 misses reduced by 0.60%) with no change in throughput

Quoted 5 lines
Quoted 5 lines
---
 lib/mempool/rte_mempool.h             | 150

+++++++++++++++++++++++++-

Quoted 17 lines
Quoted 17 lines
 lib/mempool/rte_mempool_ops_default.c |   7 ++
 2 files changed, 156 insertions(+), 1 deletion(-)
lib/mempool/rte_mempool.h +4 -0
index 1e7a3c15273c..f2403fbc97a7 100644
@@ -50,6 +50,10 @@
 #include <rte_memcpy.h>
 #include <rte_common.h>
 
+#ifdef RTE_MEMPOOL_INDEX_BASED_LCORE_CACHE
+#include <rte_vect.h>
+#endif
+
 #include "rte_mempool_trace_fp.h"
 
Quoted 5 lines

lib/mempool/rte_mempool.h struct rte_mempool { · line 245

Quoted 5 lines
lib/mempool/rte_mempool.h +0 -0
 #ifdef __cplusplus
@@ -239,6 +243,9 @@ struct rte_mempool {
 	int32_t ops_index;
 
 	struct rte_mempool_cache *local_cache; /**< Per-lcore local cache

*/

Quoted 22 lines
Quoted 9 lines
lib/mempool/rte_mempool.h +3 -0
+#ifdef RTE_MEMPOOL_INDEX_BASED_LCORE_CACHE
+	void *pool_base_value; /**< Base value to calculate indices */
+#endif
 
 	uint32_t populated_size;         /**< Number of populated

objects. */
struct rte_mempool_objhdr_list elt_list; /**< List of objects in
pool */ @@ -1314,7 +1321,22 @@ rte_mempool_cache_flush(struct rte_mempool_cache *cache,

lib/mempool/rte_mempool.h rte_mempool_cache_flush(struct rte_mempool_cache *cache, · line 1330

Quoted 10 lines
lib/mempool/rte_mempool.h +7 -0
 	if (cache == NULL || cache->len == 0)
 		return;
 	rte_mempool_trace_cache_flush(cache, mp);
+
+#ifdef RTE_MEMPOOL_INDEX_BASED_LCORE_CACHE
+	unsigned int i;
+	unsigned int cache_len = cache->len;
+	void *obj_table[RTE_MEMPOOL_CACHE_MAX_SIZE * 3];
+	void *base_value = mp->pool_base_value;
+	uint32_t *cache_objs = (uint32_t *) cache->objs;

Hi Dharmik and Honnappa,

Quoted 1 line

The essence of this patch is based on recasting the type of the objs

field in the

Quoted 4 lines

rte_mempool_cache structure from an array of pointers to an array of uint32_t.

However, this effectively breaks the ABI, because the

rte_mempool_cache

Quoted 1 line

structure is public and part of the API.

The patch does not change the public structure, the new member is under compile time flag, not sure how it breaks the ABI.

Quoted 3 lines

Some drivers [1] even bypass the mempool API and access the rte_mempool_cache structure directly, assuming that the objs array in

the

Quoted 2 lines

cache is an array of pointers. So you cannot recast the fields in the rte_mempool_cache structure the way this patch requires.

IMO, those drivers are at fault. The mempool cache structure is public only because the APIs are inline. We should still maintain modularity and not use the members of structures belonging to another library directly. A similar effort involving rte_ring was not accepted sometime back [1]

[1]
http://inbox.dpdk.org/dev/DBAPR08MB5814907968595EE56F5E20A798390@DBAPR0
8MB5814.eurprd08.prod.outlook.com/

Quoted 2 lines

Although I do consider bypassing an API's accessor functions

"spaghetti

Quoted 4 lines

code", this driver's behavior is formally acceptable as long as the rte_mempool_cache structure is not marked as internal.

I really liked your idea of using indexes instead of pointers, so I'm

very sorry to

Quoted 2 lines

shoot it down. :-(

Quoted 9 lines
Quoted 2 lines

[1]: E.g. the Intel i40e PMD,

http://code.dpdk.org/dpdk/latest/source/drivers/net/i40e/i40e_rxtx_vec_
avx

Quoted 1 line

512.c#L25

It is possible to throw an error when this feature is enabled in this file. Alternatively, this PMD could implement the code for index based mempool.

I agree with both your points, Honnappa.

The ABI remains intact, and only changes when this feature is enabled at compile time.

In addition to your suggestions, I propose that the patch modifies the objs type in the mempool cache structure itself, instead of type casting it through an access variable. This should throw an error when compiling an application that accesses it as a pointer array instead of a uint32_t array - like the affected Intel PMDs.

The updated objs field in the mempool cache structure should have the same size when compiled as the original objs field, so this feature doesn't change anything else in the ABI, only the type of the mempool cache objects.

Also, the description of the feature should stress that applications accessing the cache objects directly will fail miserably.

#49 lore raw
Quoted 124 lines · Morten Brørup

+Ray Kinsella, ABI Policy maintainer

Quoted 110 lines

From: Honnappa Nagarahalli [mailto:[email protected]]
Sent: Friday, 21 January 2022 07.01

Quoted 7 lines

+CC Beilei as i40e maintainer

Quoted 4 lines

From: Dharmik Thakkar [mailto:[email protected]]
Sent: Thursday, 13 January 2022 06.37

Current mempool per core cache implementation stores pointers to

mbufs

Quoted 1 line
Quoted 1 line

On 64b architectures, each pointer consumes 8B This patch replaces

it

Quoted 1 line
Quoted 1 line

with index-based implementation, where in each buffer is addressed

by

Quoted 7 lines
Quoted 7 lines

(pool base address + index) It reduces the amount of memory/cache required for per core cache

L3Fwd performance testing reveals minor improvements in the cache performance (L1 and L2 misses reduced by 0.60%) with no change in throughput

Quoted 5 lines
Quoted 5 lines
---
 lib/mempool/rte_mempool.h             | 150

+++++++++++++++++++++++++-

Quoted 17 lines
Quoted 17 lines
 lib/mempool/rte_mempool_ops_default.c |   7 ++
 2 files changed, 156 insertions(+), 1 deletion(-)
lib/mempool/rte_mempool.h +4 -0
index 1e7a3c15273c..f2403fbc97a7 100644
@@ -50,6 +50,10 @@
 #include <rte_memcpy.h>
 #include <rte_common.h>
 
+#ifdef RTE_MEMPOOL_INDEX_BASED_LCORE_CACHE
+#include <rte_vect.h>
+#endif
+
 #include "rte_mempool_trace_fp.h"
 
Quoted 5 lines

lib/mempool/rte_mempool.h struct rte_mempool { · line 245

Quoted 5 lines
lib/mempool/rte_mempool.h +0 -0
 #ifdef __cplusplus
@@ -239,6 +243,9 @@ struct rte_mempool {
 	int32_t ops_index;
 
 	struct rte_mempool_cache *local_cache; /**< Per-lcore local cache

*/

Quoted 22 lines
Quoted 9 lines
lib/mempool/rte_mempool.h +3 -0
+#ifdef RTE_MEMPOOL_INDEX_BASED_LCORE_CACHE
+	void *pool_base_value; /**< Base value to calculate indices */
+#endif
 
 	uint32_t populated_size;         /**< Number of populated

objects. */
struct rte_mempool_objhdr_list elt_list; /**< List of objects in
pool */ @@ -1314,7 +1321,22 @@ rte_mempool_cache_flush(struct rte_mempool_cache *cache,

lib/mempool/rte_mempool.h rte_mempool_cache_flush(struct rte_mempool_cache *cache, · line 1330

Quoted 10 lines
lib/mempool/rte_mempool.h +7 -0
 	if (cache == NULL || cache->len == 0)
 		return;
 	rte_mempool_trace_cache_flush(cache, mp);
+
+#ifdef RTE_MEMPOOL_INDEX_BASED_LCORE_CACHE
+	unsigned int i;
+	unsigned int cache_len = cache->len;
+	void *obj_table[RTE_MEMPOOL_CACHE_MAX_SIZE * 3];
+	void *base_value = mp->pool_base_value;
+	uint32_t *cache_objs = (uint32_t *) cache->objs;

Hi Dharmik and Honnappa,

Quoted 1 line

The essence of this patch is based on recasting the type of the objs

field in the

Quoted 4 lines

rte_mempool_cache structure from an array of pointers to an array of uint32_t.

However, this effectively breaks the ABI, because the

rte_mempool_cache

Quoted 1 line

structure is public and part of the API.

The patch does not change the public structure, the new member is under compile time flag, not sure how it breaks the ABI.

Quoted 3 lines

Some drivers [1] even bypass the mempool API and access the rte_mempool_cache structure directly, assuming that the objs array in

the

Quoted 2 lines

cache is an array of pointers. So you cannot recast the fields in the rte_mempool_cache structure the way this patch requires.

IMO, those drivers are at fault. The mempool cache structure is public only because the APIs are inline. We should still maintain modularity and not use the members of structures belonging to another library directly. A similar effort involving rte_ring was not accepted sometime back [1]

[1]
http://inbox.dpdk.org/dev/DBAPR08MB5814907968595EE56F5E20A798390@DBAPR0
8MB5814.eurprd08.prod.outlook.com/

Quoted 2 lines

Although I do consider bypassing an API's accessor functions

"spaghetti

Quoted 4 lines

code", this driver's behavior is formally acceptable as long as the rte_mempool_cache structure is not marked as internal.

I really liked your idea of using indexes instead of pointers, so I'm

very sorry to

Quoted 2 lines

shoot it down. :-(

Quoted 9 lines
Quoted 2 lines

[1]: E.g. the Intel i40e PMD,

http://code.dpdk.org/dpdk/latest/source/drivers/net/i40e/i40e_rxtx_vec_
avx

Quoted 1 line

512.c#L25

It is possible to throw an error when this feature is enabled in this file. Alternatively, this PMD could implement the code for index based mempool.

I agree with both your points, Honnappa.

Quoted 7 lines

The ABI remains intact, and only changes when this feature is enabled at compile time.

In addition to your suggestions, I propose that the patch modifies the objs type in the mempool cache structure itself, instead of type casting it through an access variable. This should throw an error when compiling an application that accesses it as a pointer array instead of a uint32_t array - like the affected Intel PMDs.

The updated objs field in the mempool cache structure should have the same size when compiled as the original objs field, so this feature doesn't change anything else in the ABI, only the type of the mempool cache objects.

Also, the description of the feature should stress that applications accessing the cache objects directly will fail miserably.

Thanks for CC'ing me Morten.

My 2c is that, I would be slow in supporting this patch as it introduces code paths that are harder (impossible?) to test regularly. So yes, it is optional, in that case are we just adding automatically dead code - I would ask, if a runtime option not make more sense for this?

Also we can't automatically assume what the PMD's are doing are breaking an unwritten rule (breaking abstractions) - I would guess these are doing it for solid performance reasons. If so that would futher support my point about making the mempool runtime configurable and query-able (is this mempool a bucket of indexes or pointers etc), and enabling the PMDs to ask rather than assume.

Like Morten, I like the idea, saving memory and reducing cache misses with indexes, this is all good IMHO.

Signature · 1 line
Regards, Ray K
#50 lore raw
In reply to Honnappa Nagarahalli
Quoted 82 lines · Honnappa Nagarahalli
Quoted 52 lines

+CC Beilei as i40e maintainer

Quoted 35 lines

From: Dharmik Thakkar [mailto:[email protected]] Sent:
Thursday, 13 January 2022 06.37

Current mempool per core cache implementation stores pointers to mbufs On 64b architectures, each pointer consumes 8B This patch replaces it with index-based implementation, where in each buffer is addressed by (pool base address + index) It reduces the amount of memory/cache required for per core cache

L3Fwd performance testing reveals minor improvements in the cache performance (L1 and L2 misses reduced by 0.60%) with no change in throughput

Ruifeng Wang <[email protected]> --- lib/mempool/rte_mempool.h | 150 +++++++++++++++++++++++++-
lib/mempool/rte_mempool_ops_default.c | 7 ++ 2 files changed, 156
insertions(+), 1 deletion(-)

lib/mempool/rte_mempool.h +0 -0
index 1e7a3c15273c..f2403fbc97a7 100644 ---

a/lib/mempool/rte_mempool.h +++ b/lib/mempool/rte_mempool.h @@ -50,6 +50,10 @@ #include <rte_memcpy.h> #include <rte_common.h>

lib/mempool/rte_mempool.h +2 -0
+#ifdef RTE_MEMPOOL_INDEX_BASED_LCORE_CACHE +#include <rte_vect.h>
+#endif + #include "rte_mempool_trace_fp.h"
 
 #ifdef __cplusplus @@ -239,6 +243,9 @@ struct rte_mempool { int32_t
 ops_index;
 
 	struct rte_mempool_cache *local_cache; /**< Per-lcore local cache
 	*/ +#ifdef RTE_MEMPOOL_INDEX_BASED_LCORE_CACHE +	void
 	*pool_base_value; /**< Base value to calculate indices */ +#endif
 

lib/mempool/rte_mempool.h

Quoted 10 lines
lib/mempool/rte_mempool.h +0 -0
 	uint32_t populated_size;         /**< Number of populated objects.
 	*/ struct rte_mempool_objhdr_list elt_list; /**< List of objects in
 	pool */ @@ -1314,7 +1321,22 @@ rte_mempool_cache_flush(struct
 	rte_mempool_cache *cache, if (cache == NULL || cache->len == 0)
 	return; rte_mempool_trace_cache_flush(cache, mp); + +#ifdef
 	RTE_MEMPOOL_INDEX_BASED_LCORE_CACHE +	unsigned int i; +
 	unsigned int cache_len = cache->len; +	void
 	*obj_table[RTE_MEMPOOL_CACHE_MAX_SIZE * 3]; +	void *base_value =
 	mp->pool_base_value; +	uint32_t *cache_objs = (uint32_t *)
 	cache->objs;

Hi Dharmik and Honnappa,

Quoted 6 lines

The essence of this patch is based on recasting the type of the objs field in the rte_mempool_cache structure from an array of pointers to an array of uint32_t.

However, this effectively breaks the ABI, because the rte_mempool_cache structure is public and part of the API.

The patch does not change the public structure, the new member is under compile time flag, not sure how it breaks the ABI.

Quoted 5 lines

Some drivers [1] even bypass the mempool API and access the rte_mempool_cache structure directly, assuming that the objs array in the cache is an array of pointers. So you cannot recast the fields in the rte_mempool_cache structure the way this patch requires.

IMO, those drivers are at fault. The mempool cache structure is public only because the APIs are inline. We should still maintain modularity and not use the members of structures belonging to another library directly. A similar effort involving rte_ring was not accepted sometime back [1]

[1]
http://inbox.dpdk.org/dev/DBAPR08MB5814907968595EE56F5E20A798390@DBAPR08MB5814.eurprd08.prod.outlook.com/

Quoted 8 lines

Although I do consider bypassing an API's accessor functions "spaghetti code", this driver's behavior is formally acceptable as long as the rte_mempool_cache structure is not marked as internal.

I really liked your idea of using indexes instead of pointers, so I'm very sorry to shoot it down. :-(

Quoted 7 lines
Quoted 3 lines

[1]: E.g. the Intel i40e PMD,
http://code.dpdk.org/dpdk/latest/source/drivers/net/i40e/i40e_rxtx_vec_avx
512.c#L25

It is possible to throw an error when this feature is enabled in this file. Alternatively, this PMD could implement the code for index based mempool.

Yes, it can implement it, and if this model get put in mempool it probably will [even if it's just a fallback to the mempool code in that case].

However, I would object to adding in this model in the library right now if it cannot be proved to show some benefit in a realworld case. As I understand it, the only benefit seen has been in unit test cases? I want to ensure that for any perf improvements we put in that they have some real-world applicabilty - the amoung of applicability will depend on the scope and impact - and by the same token that we don't reject simplifications or improvements on the basis that they *might* cause issues, if all perf data fails to show any problem.

So for this patch, can we get some perf numbers for an app where it does show the value of it? L3fwd is a very trivial app, and as such is usually fairly reliable in showing perf benefits of optimizations if they exist. Perhaps for this case, we need something with a bigger cache footprint perhaps?

Regards,
/Bruce

#51 lore raw
In reply to Dharmik Thakkar
Quoted 35 lines

-----Original Message-----
From: Dharmik Thakkar <[email protected]>
Sent: Thursday, January 13, 2022 13:37
To: Olivier Matz <[email protected]>; Andrew Rybchenko <[email protected]>
Cc: [email protected]; [email protected]; [email protected]; [email protected]; Dharmik Thakkar <[email protected]>
Subject: [PATCH v2 1/1] mempool: implement index-based per core cache

Current mempool per core cache implementation stores pointers to mbufs On 64b architectures, each pointer consumes 8B
This patch replaces it with index-based implementation, where in each buffer is addressed by (pool base address + index) It reduces the amount of memory/cache required for per core cache

L3Fwd performance testing reveals minor improvements in the cache performance (L1 and L2 misses reduced by 0.60%)
with no change in throughput

---
 lib/mempool/rte_mempool.h             | 150 +++++++++++++++++++++++++-
 lib/mempool/rte_mempool_ops_default.c |   7 ++
 2 files changed, 156 insertions(+), 1 deletion(-)
lib/mempool/rte_mempool.h +0 -0
index 1e7a3c15273c..f2403fbc97a7 100644
lib/mempool/rte_mempool_ops_default.c +0 -0
index 22fccf9d7619..3543cad9d4ce 100644

lib/mempool/rte_mempool_ops_default.c rte_mempool_op_populate_helper(struct rte_mempool *mp, unsigned int flags, · line 135

Quoted 9 lines
lib/mempool/rte_mempool_ops_default.c +6 -0
@@ -127,6 +127,13 @@ rte_mempool_op_populate_helper(struct rte_mempool *mp, unsigned int flags,
 		obj = va + off;
 		obj_cb(mp, obj_cb_arg, obj,
 		       (iova == RTE_BAD_IOVA) ? RTE_BAD_IOVA : (iova + off));
+#ifdef RTE_MEMPOOL_INDEX_BASED_LCORE_CACHE
+		/* Store pool base value to calculate indices for index-based
+		 * lcore cache implementation
+		 */
+		if (i == 0)
+			mp->pool_base_value = obj;

This is wrong, the populate may run many times. ;-)

I tried bellow patch to run "rte_pktmbuf_pool_create(mbuf_pool_0, 1048575, 256, 0, 4096, 0)"

This is the debug message (also, your patch will make DPDK mempool not support > 4GB):

2bfffdb40 (from last debug line 'max') - 1b3fff240 (from first line 'base addr') = 10BFFE900

****mempool mbuf_pool_0 (size = 1048575, populated_size = 46952, elt_size = 4224): base addr = 0x1b3fff240, max = 0x0, diff = 18446744066394688960 (max_objs = 1048575) ****mempool mbuf_pool_0 (size = 1048575, populated_size = 297358, elt_size = 4224): base addr = 0x1c0000040, max = 0x0, diff = 18446744066193358784 (max_objs = 1001623) ****mempool mbuf_pool_0 (size = 1048575, populated_size = 547764, elt_size = 4224): base addr = 0x200000040, max = 0x0, diff = 18446744065119616960 (max_objs = 751217) ****mempool mbuf_pool_0 (size = 1048575, populated_size = 798170, elt_size = 4224): base addr = 0x240000040, max = 0x0, diff = 18446744064045875136 (max_objs = 500811) ****mempool mbuf_pool_0 (size = 1048575, populated_size = 1048575, elt_size = 4224): base addr = 0x280000040, max = 0x2bfffdb40, diff = 1073732352 (max_objs = 250405)

lib/mempool/rte_mempool_ops_default.c +12 -0
index 22fccf9d76..854067cd43 100644
@@ -99,6 +99,7 @@ rte_mempool_op_populate_helper(struct rte_mempool *mp, unsigned int flags,
        unsigned int i;
        void *obj;
        int ret;
+       void *pool_base_value = NULL, *pool_max_value = NULL;
 
        ret = rte_mempool_get_page_size(mp, &pg_sz);
        if (ret < 0)
@@ -128,9 +129,20 @@ rte_mempool_op_populate_helper(struct rte_mempool *mp, unsigned int flags,
                obj_cb(mp, obj_cb_arg, obj,
                       (iova == RTE_BAD_IOVA) ? RTE_BAD_IOVA : (iova + off));
                rte_mempool_ops_enqueue_bulk(mp, &obj, 1);
+               if (i == 0)
+                       pool_base_value = obj;
+               else if (i == (max_objs - 1))
+                       pool_max_value = obj;
                off += mp->elt_size + mp->trailer_size;
        }
 
+       printf("****mempool %s (size = %u, populated_size = %u, elt_size = %u): base addr = 0x%llx, max = 0x%llx, diff = %lu (max_objs = %u)\n",
+               mp->name, mp->size, mp->populated_size,
+               mp->elt_size,
+               (unsigned long long) pool_base_value,
+               (unsigned long long) pool_max_value,
+               RTE_PTR_DIFF(pool_max_value, pool_base_value), max_objs);
+
        return i;
 }
 
Quoted 6 lines
lib/mempool/rte_mempool_ops_default.c +1 -1
+#endif
 		rte_mempool_ops_enqueue_bulk(mp, &obj, 1);
 		off += mp->elt_size + mp->trailer_size;
 	}
--

2.17.1