On Thu, Mar 19, 2026 at 11:55:11AM +0100, Morten Brørup wrote: > > From: Bruce Richardson [mailto:[email protected]] > > Sent: Thursday, 19 March 2026 10.41 > > > > On Thu, Mar 19, 2026 at 09:13:00AM +0000, Morten Brørup wrote: > > > The descriptions for the mempool creation functions contained advice > > for > > > choosing the optimum (in terms of memory usage) number of elements > > and > > > cache size. > > > The advice was based on implementation details, which was changed > > long > > > ago, making the advice completely irrelevant. > > > > > > > The comment is still correct in most cases, since the default backing > > storage remains an rte_ring. If passing a power-of-2 size to mempool > > create > > one will get a backing rte_ring store which is twice as large as > > requested, > > leading to lots of ring slots being wasted. For example, for a pool > > with > > 16k elements, the actual ring size allocated will be 32k, leading to > > wasting 128k of RAM, and also potentially cache too. The latter will > > occur > > because of the nature of the ring to iterate through all mempool/ring > > entries, meaning that even if only 16k of the 32k slots will ever be > > used, > > all 32k slots will be passed through the cpu cache if it works on the > > mempool directly and not just from the per-core cache. > > You are right about the waste of memory in the ring driver. And good point > about the CPU cache! > > However, only pointer entries (8 byte each) are being wasted, not object > entries (which are much larger). This is not 100 % clear from the advice. > > Furthermore, with 16k mbufs of 2368 byte each, the mempool itself consumes 37 > MB worth of memory, so do we really care about wasting 128 KB? > > IMHO, removing the advice improves the quality of the documentation. > I don't think a detail about saving 0.3 % of the memory used by the mempool > should be presented so prominently in the documentation. >
Ok, point taken. It would actually be the cache wastage that would worry me more, but again the cache use from the extra ring space is probably small compared to that from the buffers if we are cycling through the whole mempool. /Bruce

