patches for DPDK stable branches
 help / color / mirror / Atom feed
* [PATCH] app/testpmd: fix external buffer allocation
@ 2021-12-17  9:58 Dmitry Kozlyuk
  2022-01-18 13:28 ` Ferruh Yigit
  0 siblings, 1 reply; 2+ messages in thread
From: Dmitry Kozlyuk @ 2021-12-17  9:58 UTC (permalink / raw)
  To: dev; +Cc: stable, Viacheslav Ovsiienko, Xiaoyun Li, Aman Singh

External pinned buffer memory (--mp-alloc=xbuf)
was allocated as multiple IOVA-contiguous memzones
of 2M size and 2M alignment.
Due to the malloc overhead and the alignment requirement,
each 2M memzone consumed 4M of hugepage memory:
2M of usable memory + X of malloc overhead + (2M-X) padding.
The allocation often failed with 2M hugepages and IOVA-as-PA
if a PA-contiguous span of 2 hugepages could not be found.
Also, with any hugepage size and IOVA mode
memory consumption was almost 2x of the usable amount.

Alignment requirement of 2M for external buffers is redundant.
It was an attempt to ensure IOVA-contiguity
by forcing memzones to start at hugepage boundaries,
while 2M size intended to leave no unused space on the page.
As shown above, this in fact caused excessive memory consumption
and decreased the chance of a successful allocation.
RTE_MEMZONE_F_IOVA_CONTIG already ensures IOVA-contiguity.

Remove the alignment requirement.
Reduce the memzone size by the malloc overhead size (4 cache lines),
so that memory consumption for each memzone is
(2M-X) of usable memory + X of malloc overhead = 2M.
This also means that whenever there are free 2M hugepages,
an IOVA-contiguous memzone can always be allocated.

Fixes: 72512e1897b2 ("app/testpmd: add mempool with external data buffers")
Cc: stable@dpdk.org

Signed-off-by: Dmitry Kozlyuk <dkozlyuk@nvidia.com>
Signed-off-by: Viacheslav Ovsiienko <viacheslavo@nvidia.com>
---
 app/test-pmd/testpmd.c | 19 ++++++++++++-------
 1 file changed, 12 insertions(+), 7 deletions(-)

diff --git a/app/test-pmd/testpmd.c b/app/test-pmd/testpmd.c
index 55eb293cc0..fa04cc6be6 100644
--- a/app/test-pmd/testpmd.c
+++ b/app/test-pmd/testpmd.c
@@ -84,7 +84,13 @@
 #endif
 
 #define EXTMEM_HEAP_NAME "extmem"
-#define EXTBUF_ZONE_SIZE RTE_PGSIZE_2M
+/*
+ * Zone size with the malloc overhead (max of debug and release variants)
+ * must fit into the smallest supported hugepage size (2M),
+ * so that an IOVA-contiguous zone of this size can always be allocated
+ * if there are free 2M hugepages.
+ */
+#define EXTBUF_ZONE_SIZE (RTE_PGSIZE_2M - 4 * RTE_CACHE_LINE_SIZE)
 
 uint16_t verbose_level = 0; /**< Silent by default. */
 int testpmd_logtype; /**< Log type for testpmd logs */
@@ -1061,12 +1067,11 @@ setup_extbuf(uint32_t nb_mbufs, uint16_t mbuf_sz, unsigned int socket_id,
 			ext_num = 0;
 			break;
 		}
-		mz = rte_memzone_reserve_aligned(mz_name, EXTBUF_ZONE_SIZE,
-						 socket_id,
-						 RTE_MEMZONE_IOVA_CONTIG |
-						 RTE_MEMZONE_1GB |
-						 RTE_MEMZONE_SIZE_HINT_ONLY,
-						 EXTBUF_ZONE_SIZE);
+		mz = rte_memzone_reserve(mz_name, EXTBUF_ZONE_SIZE,
+					 socket_id,
+					 RTE_MEMZONE_IOVA_CONTIG |
+					 RTE_MEMZONE_1GB |
+					 RTE_MEMZONE_SIZE_HINT_ONLY);
 		if (mz == NULL) {
 			/*
 			 * The caller exits on external buffer creation
-- 
2.25.1


^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH] app/testpmd: fix external buffer allocation
  2021-12-17  9:58 [PATCH] app/testpmd: fix external buffer allocation Dmitry Kozlyuk
@ 2022-01-18 13:28 ` Ferruh Yigit
  0 siblings, 0 replies; 2+ messages in thread
From: Ferruh Yigit @ 2022-01-18 13:28 UTC (permalink / raw)
  To: Dmitry Kozlyuk, dev; +Cc: stable, Viacheslav Ovsiienko, Xiaoyun Li, Aman Singh

On 12/17/2021 9:58 AM, Dmitry Kozlyuk wrote:
> External pinned buffer memory (--mp-alloc=xbuf)
> was allocated as multiple IOVA-contiguous memzones
> of 2M size and 2M alignment.
> Due to the malloc overhead and the alignment requirement,
> each 2M memzone consumed 4M of hugepage memory:
> 2M of usable memory + X of malloc overhead + (2M-X) padding.
> The allocation often failed with 2M hugepages and IOVA-as-PA
> if a PA-contiguous span of 2 hugepages could not be found.
> Also, with any hugepage size and IOVA mode
> memory consumption was almost 2x of the usable amount.
> 
> Alignment requirement of 2M for external buffers is redundant.
> It was an attempt to ensure IOVA-contiguity
> by forcing memzones to start at hugepage boundaries,
> while 2M size intended to leave no unused space on the page.
> As shown above, this in fact caused excessive memory consumption
> and decreased the chance of a successful allocation.
> RTE_MEMZONE_F_IOVA_CONTIG already ensures IOVA-contiguity.
> 
> Remove the alignment requirement.
> Reduce the memzone size by the malloc overhead size (4 cache lines),
> so that memory consumption for each memzone is
> (2M-X) of usable memory + X of malloc overhead = 2M.
> This also means that whenever there are free 2M hugepages,
> an IOVA-contiguous memzone can always be allocated.
> 
> Fixes: 72512e1897b2 ("app/testpmd: add mempool with external data buffers")
> Cc: stable@dpdk.org
> 
> Signed-off-by: Dmitry Kozlyuk <dkozlyuk@nvidia.com>
> Signed-off-by: Viacheslav Ovsiienko <viacheslavo@nvidia.com>

Applied to dpdk-next-net/main, thanks.


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2022-01-18 13:28 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-12-17  9:58 [PATCH] app/testpmd: fix external buffer allocation Dmitry Kozlyuk
2022-01-18 13:28 ` Ferruh Yigit

patches for DPDK stable branches

This inbox may be cloned and mirrored by anyone:

	git clone --mirror http://inbox.dpdk.org/stable/0 stable/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 stable stable/ http://inbox.dpdk.org/stable \
		stable@dpdk.org
	public-inbox-index stable

Example config snippet for mirrors.
Newsgroup available over NNTP:
	nntp://inbox.dpdk.org/inbox.dpdk.stable


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git