kni: fix possible alloc_q starvation when mbufs are exhausted

Message ID 20221109051339.1998037-1-zhouyates@gmail.com (mailing list archive)
State Superseded, archived
Delegated to: Andrew Rybchenko
Headers
Series kni: fix possible alloc_q starvation when mbufs are exhausted |

Checks

Context Check Description
ci/checkpatch warning coding style issues
ci/Intel-compilation success Compilation OK
ci/github-robot: build success github build: passed
ci/iol-mellanox-Performance success Performance Testing PASS
ci/intel-Testing success Testing PASS
ci/iol-intel-Functional success Functional Testing PASS
ci/iol-aarch64-compile-testing success Testing PASS
ci/iol-intel-Performance success Performance Testing PASS
ci/iol-x86_64-compile-testing success Testing PASS
ci/iol-aarch64-unit-testing success Testing PASS
ci/iol-x86_64-unit-testing success Testing PASS

Commit Message

Matt Nov. 9, 2022, 5:13 a.m. UTC
  In some scenarios, mbufs returned by rte_kni_rx_burst are not freed
immediately. So kni_allocate_mbufs may be failed, but we don't know.

Even worse, when alloc_q is completely exhausted, kni_net_tx in
rte_kni.ko will drop all tx packets. kni_allocate_mbufs is never
called again, even if the mbufs are eventually freed.

In this patch, we always try to allocate mbufs for alloc_q.

Don't worry about alloc_q being allocated too many mbufs, in fact,
the old logic will gradually fill up alloc_q.
Also, the cost of more calls to kni_allocate_mbufs should be acceptable.

Fixes: 3e12a98fe397 ("kni: optimize Rx burst")
Cc: Hemant@freescale.com
Cc: stable@dpdk.org

Signed-off-by: Yangchao Zhou <zhouyates@gmail.com>
---
 lib/kni/rte_kni.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
  

Patch

diff --git a/lib/kni/rte_kni.c b/lib/kni/rte_kni.c
index 8ab6c47153..265c5262f7 100644
--- a/lib/kni/rte_kni.c
+++ b/lib/kni/rte_kni.c
@@ -634,9 +634,9 @@  rte_kni_rx_burst(struct rte_kni *kni, struct rte_mbuf **mbufs, unsigned int num)
 {
 	unsigned int ret = kni_fifo_get(kni->tx_q, (void **)mbufs, num);
 
-	/* If buffers removed, allocate mbufs and then put them into alloc_q */
-	if (ret)
-		kni_allocate_mbufs(kni);
+	/* Always try to allocate mbufs for alloc_q to avoid starvation when
+	 * kni->pktmbuf_pool is exhausted. */
+	kni_allocate_mbufs(kni);
 
 	return ret;
 }