From 90dfc392ccafa1f8078a66a95a5103ec22b7452e Mon Sep 17 00:00:00 2001 From: Dariusz Stojaczyk Date: Wed, 25 Apr 2018 08:58:50 +0200 Subject: [PATCH] event/reactor: take into account ring metadata size in event mempools See previous patch for some background. rte_mempool uses the following formula for its ring allocation size: ``` count = rte_align32pow2(mp->size + 1); sz = sizeof(struct rte_ring) + count * sizeof(void *); sz = RTE_ALIGN(sz, RTE_CACHE_LINE_SIZE); ``` With count==262144, rte_mempool was trying to allocate (2MB + sizeof(struct rte_ring) physically contiguous memory. Change-Id: I69e8cdcbcaaaa8a053540588afa6eb2fd36c525b Signed-off-by: Dariusz Stojaczyk Reviewed-on: https://review.gerrithub.io/408926 Tested-by: SPDK Automated Test System Reviewed-by: Daniel Verkamp Reviewed-by: Ben Walker Reviewed-by: Jim Harris --- lib/event/reactor.c | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/lib/event/reactor.c b/lib/event/reactor.c index c8143a817..28c8f4764 100644 --- a/lib/event/reactor.c +++ b/lib/event/reactor.c @@ -40,6 +40,7 @@ #include "spdk/log.h" #include "spdk/io_channel.h" #include "spdk/env.h" +#include "spdk/util.h" #define SPDK_MAX_SOCKET 64 @@ -366,7 +367,19 @@ _spdk_reactor_context_switch_monitor_stop(void *arg1, void *arg2) static size_t _spdk_reactor_get_max_event_cnt(uint8_t socket_count) { - return 262144 / socket_count - 1; + size_t cnt; + + /* Try to make event ring fill at most 2MB of memory, + * as some ring implementations may require physical address + * contingency. We don't want to introduce a requirement of + * at least 2 physically contiguous 2MB hugepages. + */ + cnt = spdk_min(262144 / socket_count, 262144 / 2); + /* Take into account one extra element required by + * some ring implementations. + */ + cnt -= 1; + return cnt; } void