DPDK patches and discussions
 help / color / mirror / Atom feed
* [PATCH] kni: fix possible alloc_q starvation when mbufs are exhausted
@ 2022-11-09  5:13 Yangchao Zhou
  2022-11-09  6:04 ` [PATCH v2] " Yangchao Zhou
  0 siblings, 1 reply; 10+ messages in thread
From: Yangchao Zhou @ 2022-11-09  5:13 UTC (permalink / raw)
  To: dev; +Cc: Hemant, stable

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(-)

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;
 }
-- 
2.25.1


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

end of thread, other threads:[~2023-03-11  9:16 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-11-09  5:13 [PATCH] kni: fix possible alloc_q starvation when mbufs are exhausted Yangchao Zhou
2022-11-09  6:04 ` [PATCH v2] " Yangchao Zhou
2022-11-09 16:39   ` Stephen Hemminger
2022-11-11  9:12     ` Matt
2022-12-09 16:15       ` Ferruh Yigit
2022-12-30  4:23   ` [PATCH v3] " Yangchao Zhou
2023-01-03 12:47     ` Ferruh Yigit
2023-01-04 11:57       ` Matt
2023-01-04 14:34         ` Ferruh Yigit
2023-03-11  9:16           ` Thomas Monjalon

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).