1111#pragma once
1212
1313#include " cameron314/concurrentqueue.h"
14- #include " lockfree_object_pool.h"
1514#include " memory_block_list.h"
1615#include " srsran/adt/static_vector.h"
1716#include " srsran/support/error_handling.h"
@@ -66,6 +65,12 @@ class fixed_size_memory_block_pool
6665 // / Thread-local cache that stores a list of batches of memory blocks.
6766 using local_cache_type = static_vector<memory_block_batch, MAX_LOCAL_BATCH_CAPACITY>;
6867
68+ // Given that we use the MPMC queue in https://github.com/cameron314/concurrentqueue, we have to over-dimension it
69+ // to account the potential number of producers. The way to exactly over-dimension this queue is inconvenient, so
70+ // we just try to conservatively ensure it can accommodate up to 32 producers for a block size of 32. If this is
71+ // not enough, the queue will resize itself and malloc in the process.
72+ const static size_t OVER_DIM_CENTRAL_CACHE = 2 * 32 * 32 ;
73+
6974 // / Ctor of the memory pool. It is set as private because the class works as a singleton.
7075 explicit fixed_size_memory_block_pool (size_t nof_blocks_, size_t memory_block_size_) :
7176 // Make sure that there are no gaps between blocks when they are allocated as paret of a single array.
@@ -79,11 +84,7 @@ class fixed_size_memory_block_pool
7984 // Allocate the required memory for the given number of segments and segment size.
8085 allocated_memory(mblock_size * nof_blocks),
8186 // Pre-reserve space in the central cache to hold all batches and avoid reallocations.
82- // Given that we use the MPMC queue in https://github.com/cameron314/concurrentqueue, we have to over-dimension it
83- // to account the potential number of producers. The way to exactly over-dimension this queue is inconvenient, so
84- // we just try to conservatively ensure it can accommodate up to 32 producers for a block size of 32. If this is
85- // not enough, the queue will resize itself and malloc in the process.
86- central_mem_cache(nof_total_batches() + 2 * 32 * 32)
87+ central_mem_cache(nof_total_batches() + OVER_DIM_CENTRAL_CACHE)
8788 {
8889 srsran_assert (nof_blocks > max_local_cache_size (),
8990 " The number of segments in the pool must be much larger than the thread cache size ({} <= {})" ,
0 commit comments