Skip to contentSkip to conversation

mempool: optimizations

PATCH In review Morten Brørup 1 participant 2 messages Aug 20 Network drivers

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 mempool: optimizations

This patch introduces some mempool optimizations, which might be controvesial.

1. Access local cache without first accessing the mempool header struct.

When getting/putting objects in a mempool cache, it required accessing the "size" field and "local_cache" pointer in the mempool structure, to determine if the local cache was present.

The mempool structure was changed, so the local cache array is now an integral part of the mempool structure.
This means that local cache can be accessed directly, without first checking the "size" and "local_cache" fields in the mempool header structure.
This avoids a couple of load operations with a potential CPU cache miss when the mempool header itself is not hot in the CPU cache. The "local_cache" field was changed from being a pointer to the local cache array, and instead became the local cache array itself.

This change similarly speeds up rte_mempool_get_priv(), because it no longer needs to access the mempool header structure (specifically, the "cache_size" field) to determine the address of the mempool's private data.

Disadvantage: Memory for local cache is also consumed by mempools configured without cache.

Related changes:
- The mempool cache audit function was improved.
- The mempool autotest accessed the internal RTE_MEMPOOL_HEADER_SIZE macro, and was updated accordingly.

2. Move objects in mempool cache as 32-byte chunks at CPU cache line aligned addresses.

Improved memory copy performance by ensuring that objects in mempool cache can be moved as 32-byte chunks at CPU cache line aligned addresses.

Disadvantage: Mempool cache size must be divisible by 32. For compatibility purposes, a requested cache size not divisible by 32 is handled by a graceful fallback at mempool cache creation and mempool creation.

Related changes:
- The TAP driver used a mempool cache size of 4 mbufs for GSO, and was updated to a cache size of 32 mbufs.

Other changes:
- The description of the RTE_MEMPOOL_NAMESIZE macro was expanded to explain how the value is derived.

---
Depends-on: patch-167311 ("[v3] mempool: remove cache flush threshold field")

 app/test/test_mempool.c       |  3 +-
 drivers/net/tap/rte_eth_tap.c |  2 +-
 lib/eal/include/rte_common.h  | 12 ++++++
 lib/mempool/rte_mempool.c     | 68 ++++++++++++++++++++++-------
 lib/mempool/rte_mempool.h     | 81 ++++++++++++++++++++++-------------
 5 files changed, 117 insertions(+), 49 deletions(-)
app/test/test_mempool.c +1 -2
index e54249ce61..76d45cea2a 100644
@@ -112,8 +112,7 @@ test_mempool_basic(struct rte_mempool *mp, int use_external_cache)
 		GOTO_ERR(ret, out);
 
 	printf("get private data\n");
-	if (rte_mempool_get_priv(mp) != (char *)mp +
-			RTE_MEMPOOL_HEADER_SIZE(mp, mp->cache_size))
+	if (rte_mempool_get_priv(mp) != (char *)mp + sizeof(struct rte_mempool))
 		GOTO_ERR(ret, out);
 
 #ifndef RTE_EXEC_ENV_FREEBSD /* rte_mem_virt2iova() not supported on bsd */
drivers/net/tap/rte_eth_tap.c +1 -1
index b93452f168..b3142561c2 100644
@@ -61,7 +61,7 @@
 #define TAP_MAX_MAC_ADDRS	16
 #define TAP_GSO_MBUFS_PER_CORE	128
 #define TAP_GSO_MBUF_SEG_SIZE	128
-#define TAP_GSO_MBUF_CACHE_SIZE	4
+#define TAP_GSO_MBUF_CACHE_SIZE	32
 #define TAP_GSO_MBUFS_NUM \
 	(TAP_GSO_MBUFS_PER_CORE * TAP_GSO_MBUF_CACHE_SIZE)
 
lib/eal/include/rte_common.h +12 -0
index 79d2a0ab93..0fd0906506 100644
@@ -567,6 +567,15 @@ static void __attribute__((destructor(RTE_PRIO(prio)), used)) func(void)
 #define __rte_assume(condition) __assume(condition)
 #endif
 
+/**
+ * Alignment hint precondition
+ */
+#ifdef RTE_TOOLCHAIN_MSVC
+#define __rte_assume_aligned(ptr, alignment) (ptr)
+#else
+#define __rte_assume_aligned(ptr, alignment) __builtin_assume_aligned(ptr, alignment)
+#endif
+
 /**
  * Disable AddressSanitizer on some code
  */
@@ -775,6 +784,9 @@ rte_is_aligned(const void * const __rte_restrict ptr, const unsigned int align)
 /** Force minimum cache line alignment. */
 #define __rte_cache_min_aligned __rte_aligned(RTE_CACHE_LINE_MIN_SIZE)
 
+/** Cache alignment hint precondition */
+#define __rte_assume_cache_aligned(ptr) __rte_assume_aligned(ptr, RTE_CACHE_LINE_SIZE)
+
 #define _RTE_CACHE_GUARD_HELPER2(unique) \
 	alignas(RTE_CACHE_LINE_SIZE) \
 	char cache_guard_ ## unique[RTE_CACHE_LINE_SIZE * RTE_CACHE_GUARD_LINES]
lib/mempool/rte_mempool.c +52 -16

115 lines not on this page · raw message

lib/mempool/rte_mempool.h +51 -30

144 lines not on this page · raw message

Signature · 1 line
2.43.0
#1 lore raw

PLEASE IGNORE.

It was only for testing Depends-on.

Venlig hilsen / Kind regards,
-Morten Brørup

Quoted 6 lines

-----Original Message-----
From: Morten Brørup [mailto:[email protected]]
Sent: Thursday, 20 August 2026 14.42
To: [email protected]
Cc: Morten Brørup
Subject: [PATCH] mempool: optimizations