Skip to contentSkip to conversation

Some fixes for mergeable Rx

PATCH Superseded Tiwei Bie 2 participants 10 messages Jun 18, 2019 – Jun 20, 2019 Network drivers

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Tiwei Bie

author
#0 lore raw

cover Some fixes for mergeable Rx

Tiwei Bie (4):
net/virtio: fix memory leak in in-order Rx net/virtio: fix memory leak in mergeable Rx net/virtio: fix memory leak in mergeable packed Rx net/virtio: fix packets check in mergeable packed Rx

 drivers/net/virtio/virtio_rxtx.c | 56 +++++++++++++++-----------------
 1 file changed, 26 insertions(+), 30 deletions(-)
Signature · 1 line
2.17.1
author
#1 lore raw

PATCH 1/4 net/virtio: fix memory leak in in-order Rx

When there is no enough segments for a packet in in-order mergeable Rx path, we should free the whole mbuf chain instead of just the last segment.

Fixes e5f456a98d3c ("net/virtio: support in-order Rx and Tx")
---
 drivers/net/virtio/virtio_rxtx.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/virtio/virtio_rxtx.c +1 -1
index 1f1178467..bdb3a2f18 100644
@@ -1555,7 +1555,7 @@ virtio_recv_pkts_inorder(void *rx_queue,
 		} else {
 			PMD_RX_LOG(ERR,
 					"No enough segments for packet.");
-			virtio_discard_rxbuf_inorder(vq, prev);
+			rte_pktmbuf_free(rx_pkts[nb_rx]);
 			rxvq->stats.errors++;
 			break;
 		}
Signature · 1 line
2.17.1
Reviewed-by on v1 1/4
#2 lore raw

Re: [dpdk-dev] [PATCH 1/4] net/virtio: fix memory leak in in-order Rx

Quoted 3 lines · Tiwei Bie

When there is no enough segments for a packet in in-order mergeable Rx path, we should free the whole mbuf chain instead of just the last segment.

I would write instead:

"
we should free the whole mbuf chain instead of just recycling the last segment. "

Because what was done before the patch it to refill the VQ with the last segment. With your patch, the full chain is freed, then the refill is done afterwards.

Do you agree?

Other than that:

Thanks!
Maxime

Quoted 23 lines
Fixes e5f456a98d3c ("net/virtio: support in-order Rx and Tx")
---
  drivers/net/virtio/virtio_rxtx.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/virtio/virtio_rxtx.c +1 -1
index 1f1178467..bdb3a2f18 100644
@@ -1555,7 +1555,7 @@ virtio_recv_pkts_inorder(void *rx_queue,
  		} else {
  			PMD_RX_LOG(ERR,
  					"No enough segments for packet.");
-			virtio_discard_rxbuf_inorder(vq, prev);
+			rte_pktmbuf_free(rx_pkts[nb_rx]);
  			rxvq->stats.errors++;
  			break;
  		}
author
#3 lore raw

Re: [dpdk-dev] [PATCH 1/4] net/virtio: fix memory leak in in-order Rx

Quoted 12 lines · Maxime Coquelin
Quoted 3 lines · Tiwei Bie

When there is no enough segments for a packet in in-order mergeable Rx path, we should free the whole mbuf chain instead of just the last segment.

I would write instead:

"
we should free the whole mbuf chain instead of just recycling the last segment.
"

Quoted 5 lines

Because what was done before the patch it to refill the VQ with the last segment. With your patch, the full chain is freed, then the refill is done afterwards.

Do you agree?

Yeah, I totally agree :)

Thanks!
Tiwei

Quoted 30 lines

Other than that:

Thanks!
Maxime

Quoted 23 lines
Fixes e5f456a98d3c ("net/virtio: support in-order Rx and Tx")
---
  drivers/net/virtio/virtio_rxtx.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/virtio/virtio_rxtx.c +1 -1
index 1f1178467..bdb3a2f18 100644
@@ -1555,7 +1555,7 @@ virtio_recv_pkts_inorder(void *rx_queue,
  		} else {
  			PMD_RX_LOG(ERR,
  					"No enough segments for packet.");
-			virtio_discard_rxbuf_inorder(vq, prev);
+			rte_pktmbuf_free(rx_pkts[nb_rx]);
  			rxvq->stats.errors++;
  			break;
  		}
author
#4 lore raw

PATCH 2/4 net/virtio: fix memory leak in mergeable Rx

In reply to Tiwei Bie

When there is no enough segments for a packet in mergeable Rx path, we should free the whole mbuf chain instead of just the last segment.

Fixes bcac5aa207f8 ("net/virtio: improve batching in mergeable path")
---
 drivers/net/virtio/virtio_rxtx.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/virtio/virtio_rxtx.c +1 -1
index bdb3a2f18..9cf422ffe 100644
@@ -1737,7 +1737,7 @@ virtio_recv_mergeable_pkts(void *rx_queue,
 		} else {
 			PMD_RX_LOG(ERR,
 					"No enough segments for packet.");
-			virtio_discard_rxbuf(vq, prev);
+			rte_pktmbuf_free(rx_pkts[nb_rx]);
 			rxvq->stats.errors++;
 			break;
 		}
Signature · 1 line
2.17.1
Reviewed-by on v1 2/4
#5 lore raw

Re: [dpdk-dev] [PATCH 2/4] net/virtio: fix memory leak in mergeable Rx

Quoted 11 lines · Tiwei Bie

When there is no enough segments for a packet in mergeable Rx path, we should free the whole mbuf chain instead of just the last segment.

Fixes bcac5aa207f8 ("net/virtio: improve batching in mergeable path")
---
  drivers/net/virtio/virtio_rxtx.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)

Same comment as patch 1.

Other than that:

Thanks,
Maxime

author
#6 lore raw

PATCH 3/4 net/virtio: fix memory leak in mergeable packed Rx

In reply to Tiwei Bie

When there is no enough segments for a packet in mergeable packed Rx path, we should free the whole mbuf chain instead of just the last segment.

Fixes a76290c8f1cf ("net/virtio: implement Rx path for packed queues")
---
 drivers/net/virtio/virtio_rxtx.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/virtio/virtio_rxtx.c +1 -1
index 9cf422ffe..8b75291f5 100644
@@ -1910,7 +1910,7 @@ virtio_recv_mergeable_pkts_packed(void *rx_queue,
 		} else {
 			PMD_RX_LOG(ERR,
 					"No enough segments for packet.");
-			virtio_discard_rxbuf(vq, prev);
+			rte_pktmbuf_free(rx_pkts[nb_rx]);
 			rxvq->stats.errors++;
 			break;
 		}
Signature · 1 line
2.17.1
Reviewed-by on v1 3/4
#7 lore raw

Re: [dpdk-dev] [PATCH 3/4] net/virtio: fix memory leak in mergeable packed Rx

Quoted 11 lines · Tiwei Bie

When there is no enough segments for a packet in mergeable packed Rx path, we should free the whole mbuf chain instead of just the last segment.

Fixes a76290c8f1cf ("net/virtio: implement Rx path for packed queues")
---
  drivers/net/virtio/virtio_rxtx.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)

Same comment as patch 1.

Other than that:

Thanks,
Maxime

author
#8 lore raw

PATCH 4/4 net/virtio: fix packets check in mergeable packed Rx

In reply to Tiwei Bie

We should check the descriptor state instead of vq's internal free count (i.e. the number of descriptors that we haven't made available) for the remaining mergeable packets.

Fixes a76290c8f1cf ("net/virtio: implement Rx path for packed queues")
---
 drivers/net/virtio/virtio_rxtx.c | 50 +++++++++++++++-----------------
 1 file changed, 23 insertions(+), 27 deletions(-)
drivers/net/virtio/virtio_rxtx.c +23 -27
index 8b75291f5..b5062ff84 100644
@@ -1882,38 +1882,34 @@ virtio_recv_mergeable_pkts_packed(void *rx_queue,
 	while (seg_res != 0) {
 		uint16_t rcv_cnt = RTE_MIN((uint16_t)seg_res,
 					VIRTIO_MBUF_BURST_SZ);
-		if (likely(vq->vq_free_cnt >= rcv_cnt)) {
-			num = virtqueue_dequeue_burst_rx_packed(vq, rcv_pkts,
-					len, rcv_cnt);
-			uint16_t extra_idx = 0;
+		uint16_t extra_idx = 0;
 
-			rcv_cnt = num;
-
-			while (extra_idx < rcv_cnt) {
-				rxm = rcv_pkts[extra_idx];
-
-				rxm->data_off =
-					RTE_PKTMBUF_HEADROOM - hdr_size;
-				rxm->pkt_len = (uint32_t)(len[extra_idx]);
-				rxm->data_len = (uint16_t)(len[extra_idx]);
-
-				prev->next = rxm;
-				prev = rxm;
-				rx_pkts[nb_rx]->pkt_len += len[extra_idx];
-				extra_idx += 1;
-			}
-			seg_res -= rcv_cnt;
-			if (!seg_res) {
-				virtio_rx_stats_updated(rxvq, rx_pkts[nb_rx]);
-				nb_rx++;
-			}
-		} else {
-			PMD_RX_LOG(ERR,
-					"No enough segments for packet.");
+		rcv_cnt = virtqueue_dequeue_burst_rx_packed(vq, rcv_pkts,
+				len, rcv_cnt);
+		if (unlikely(rcv_cnt == 0)) {
+			PMD_RX_LOG(ERR, "No enough segments for packet.");
 			rte_pktmbuf_free(rx_pkts[nb_rx]);
 			rxvq->stats.errors++;
 			break;
 		}
+
+		while (extra_idx < rcv_cnt) {
+			rxm = rcv_pkts[extra_idx];
+
+			rxm->data_off = RTE_PKTMBUF_HEADROOM - hdr_size;
+			rxm->pkt_len = (uint32_t)(len[extra_idx]);
+			rxm->data_len = (uint16_t)(len[extra_idx]);
+
+			prev->next = rxm;
+			prev = rxm;
+			rx_pkts[nb_rx]->pkt_len += len[extra_idx];
+			extra_idx += 1;
+		}
+		seg_res -= rcv_cnt;
+		if (!seg_res) {
+			virtio_rx_stats_updated(rxvq, rx_pkts[nb_rx]);
+			nb_rx++;
+		}
 	}
 
 	rxvq->stats.packets += nb_rx;
Signature · 1 line
2.17.1
Reviewed-by on v1 4/4
#9 lore raw

Re: [dpdk-dev] [PATCH 4/4] net/virtio: fix packets check in mergeable packed Rx

Quoted 4 lines · Tiwei Bie

We should check the descriptor state instead of vq's internal free count (i.e. the number of descriptors that we haven't made available) for the remaining mergeable packets.

Quoted 8 lines
Fixes a76290c8f1cf ("net/virtio: implement Rx path for packed queues")
---
  drivers/net/virtio/virtio_rxtx.c | 50 +++++++++++++++-----------------
  1 file changed, 23 insertions(+), 27 deletions(-)

Thanks,
Maxime