mempool: no cache size limit
RFC PATCH 1/1 mempool: no cache size limit
Replaced the object array of fixed size in the per-lcore local cache with a dynamically sized array, thereby making the RTE_MEMPOOL_CACHE_MAX_SIZE superfluous.
For faster indexing into the per-lcore array of caches, pre-calculate the size (in bytes) of the per-lcore local cache.
Also swapped the position of the private data and the local caches; the private data now are positioned before the local caches, instead of after.
Positioning the private data directly after the mempool header reduces getting the private data pointer to simply adding a constant. The local caches are accessed by dereferencing a pointer anyway, so the performance for accessing these is unaffected by moving their position.
Comments, please?
We should probably keep RTE_MEMPOOL_CACHE_MAX_SIZE in rte_config.h for DPDK 26.11, and deprecate it as obsolete.
--- app/test/test_mempool.c | 2 +- lib/mempool/rte_mempool.c | 103 ++++++++++++++++++++------------------ lib/mempool/rte_mempool.h | 51 ++++++++----------- 3 files changed, 77 insertions(+), 79 deletions(-)
app/test/test_mempool.c +1 -1
@@ -113,7 +113,7 @@ test_mempool_basic(struct rte_mempool *mp, int use_external_cache)printf ("get private data\n" );if (rte_mempool_get_priv (mp) != (char *)mp + -RTE_MEMPOOL_HEADER_SIZE (mp, mp->cache_size)) +sizeof (struct rte_mempool ))GOTO_ERR (ret, out);#ifndef RTE_EXEC_ENV_FREEBSD /* rte_mem_virt2iova() not supported on bsd */
lib/mempool/rte_mempool.c +54 -49
213 lines not on this page · raw message
lib/mempool/rte_mempool.h +22 -29
100 lines not on this page · raw message
Signature · 1 line
2.43.0
Quoted 14 lines · On Mon, 7 Sep 2026 12:06:05 +0000 Morten Brørup <[email protected]>…
Replaced the object array of fixed size in the per-lcore local cache with a dynamically sized array, thereby making the
RTE_MEMPOOL_CACHE_MAX_SIZEsuperfluous.
For faster indexing into the per-lcore array of caches, pre-calculate the size (in bytes) of the per-lcore local cache.Also swapped the position of the private data and the local caches; the private data now are positioned before the local caches, instead of after.
Positioning the private data directly after the mempool header reduces getting the private data pointer to simply adding a constant. The local caches are accessed by dereferencing a pointer anyway, so the performance for accessing these is unaffected by moving their position.
Quoted 6 lines
Comments, please?
We should probably keep
RTE_MEMPOOL_CACHE_MAX_SIZEinrte_config.hfor DPDK 26.11, and deprecate it as obsolete.Signed-off-by Morten Brørup <[email protected]>
Maybe have a very large upper bound to prevent bugs from broken programs?
PATCH v2 1/1 mempool: no cache size limit
In reply to Morten BrørupReplaced the object array of fixed size in the per-lcore local cache with a dynamically sized array, thereby making the RTE_MEMPOOL_CACHE_MAX_SIZE superfluous.
For faster indexing into the per-lcore array of caches, pre-calculate the size (in bytes) of the per-lcore local cache.
Also swapped the position of the private data and the local caches; the private data now are positioned before the local caches, instead of after. This is how the mempool API was documented, but I don't think it warrants a Fixes tag, as it has been implemented the other way around for a long time.
Positioning the private data directly after the mempool header reduces getting the private data pointer to simply adding a constant. The local caches are accessed by dereferencing a pointer anyway, so the performance for accessing these is unaffected by moving their position.
And annotated cache_alloc/free as alloc/free functions.
Comments, please?
We should probably keep RTE_MEMPOOL_CACHE_MAX_SIZE in rte_config.h, and deprecate it as obsolete.
---
v2:
* Fixed bugs.
* Annotated cache_alloc/free as alloc/free functions.
--- app/test/test_mempool.c | 19 ++++--- lib/mempool/rte_mempool.c | 114 +++++++++++++++++++------------------- lib/mempool/rte_mempool.h | 70 +++++++++++------------ 3 files changed, 100 insertions(+), 103 deletions(-)
app/test/test_mempool.c +11 -8
@@ -96,6 +96,9 @@ test_mempool_basic(struct rte_mempool *mp, int use_external_cache) cache =rte_mempool_default_cache (mp,rte_lcore_id ()); } +printf ("test %s\n" , use_external_cache ?"using external cache" : + cache !=NULL ?"using cache" :"without cache" ); +/* dump the mempool status */ rte_mempool_dump (stdout, mp);
@@ -113,7 +116,7 @@ test_mempool_basic(struct rte_mempool *mp, int use_external_cache)printf ("get private data\n" );if (rte_mempool_get_priv (mp) != (char *)mp + -RTE_MEMPOOL_HEADER_SIZE (mp, mp->cache_size)) +sizeof (struct rte_mempool ))GOTO_ERR (ret, out);#ifndef RTE_EXEC_ENV_FREEBSD /* rte_mem_virt2iova() not supported on bsd */
@@ -191,10 +194,10 @@ static int test_mempool_creation_with_exceeded_cache_size(void) {struct rte_mempool *mp_cov; - mp_cov =rte_mempool_create ("test_mempool_cache_too_big" , + mp_cov =rte_mempool_create ("cache_too_big" ,MEMPOOL_SIZE ,MEMPOOL_ELT_SIZE , -RTE_MEMPOOL_CACHE_MAX_SIZE +32 ,0 , +MEMPOOL_SIZE +32 ,0 ,NULL ,NULL , my_obj_init,NULL ,SOCKET_ID_ANY ,0 );
@@ -211,7 +214,7 @@ static int test_mempool_creation_with_invalid_flags(void) {struct rte_mempool *mp_cov; - mp_cov = rte_mempool_create("test_mempool_invalid_flags", MEMPOOL_SIZE, + mp_cov = rte_mempool_create("invalid_flags", MEMPOOL_SIZE, MEMPOOL_ELT_SIZE, 0, 0, NULL, NULL, NULL, NULL,
@@ -333,7 +336,7 @@ test_mempool_sp_sc(void)/* create a mempool with single producer/consumer ring */ if (mp_spsc ==NULL ) { - mp_spsc = rte_mempool_create("test_mempool_sp_sc", MEMPOOL_SIZE, + mp_spsc = rte_mempool_create("sp_sc", MEMPOOL_SIZE, MEMPOOL_ELT_SIZE, 0, 0, my_mp_init, NULL, my_obj_init, NULL,
@@ -343,7 +346,7 @@ test_mempool_sp_sc(void)if (mp_spsc ==NULL )RET_ERR (); } -if (rte_mempool_lookup ("test_mempool_sp_sc" ) != mp_spsc) { +if (rte_mempool_lookup ("sp_sc" ) != mp_spsc) {printf ("Cannot lookup mempool from its name\n" ); ret =-1 ; goto err;
@@ -440,7 +443,7 @@ test_mempool_same_name_twice_creation(void) {struct rte_mempool *mp_tc, *mp_tc2; - mp_tc = rte_mempool_create("test_mempool_same_name", MEMPOOL_SIZE, + mp_tc = rte_mempool_create("same_name", MEMPOOL_SIZE, MEMPOOL_ELT_SIZE, 0, 0, NULL, NULL, NULL, NULL,
@@ -449,7 +452,7 @@ test_mempool_same_name_twice_creation(void)if (mp_tc ==NULL )RET_ERR (); - mp_tc2 = rte_mempool_create("test_mempool_same_name", MEMPOOL_SIZE, + mp_tc2 = rte_mempool_create("same_name", MEMPOOL_SIZE, MEMPOOL_ELT_SIZE, 0, 0, NULL, NULL, NULL, NULL,
lib/mempool/rte_mempool.c +58 -56
233 lines not on this page · raw message
lib/mempool/rte_mempool.h +31 -39
131 lines not on this page · raw message
Signature · 1 line
2.43.0