From ea853e92a33b28c5fa958f739a2cfaab22600b39 Mon Sep 17 00:00:00 2001 From: Lukas Sismis Date: Tue, 24 Feb 2026 16:35:27 +0100 Subject: [PATCH] dpdk: fix mempool sizing to always yield 2^n -1 Following DPDK's recommendation to size mempool to 2^n - 1, the current implementation was flawed for certain combos, e.g. mp_size 1023 and 1 queue, which resulted to 1022. --- src/runmode-dpdk.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/runmode-dpdk.c b/src/runmode-dpdk.c index 57b5e76024..1f280b1df4 100644 --- a/src/runmode-dpdk.c +++ b/src/runmode-dpdk.c @@ -1454,8 +1454,11 @@ static int DeviceConfigureQueues(DPDKIfaceConfig *iconf, const struct rte_eth_de // +4 for VLAN header uint16_t mtu_size = iconf->mtu + RTE_ETHER_CRC_LEN + RTE_ETHER_HDR_LEN + 4; uint16_t mbuf_size = ROUNDUP(mtu_size, 1024) + RTE_PKTMBUF_HEADROOM; - // ceil the div so e.g. mp_size of 262144 and 262143 both lead to 65535 on 4 rx queues - uint32_t q_mp_sz = (iconf->mempool_size + iconf->nb_rx_queues - 1) / iconf->nb_rx_queues - 1; + // Follows DPDK recommendation of having a mempool size that is a power of 2 minus one. + // So e.g. mp_size of 262144 and 262143 both lead to 65535 on 4 rx queues + uint32_t raw = iconf->mempool_size / iconf->nb_rx_queues; + uint32_t next_p2 = rte_align32pow2(raw + 1); + uint32_t q_mp_sz = (next_p2 == raw + 1) ? raw : (next_p2 >> 1) - 1; uint32_t q_mp_cache_sz = iconf->mempool_cache_size_auto ? MempoolCacheSizeCalculate(q_mp_sz) : iconf->mempool_cache_size; SCLogInfo("%s: creating %u packet mempools of size %u, cache size %u, mbuf size %u",