diff mbox series

[v4] vhost: allocate and free packets in bulk in Tx split

Message ID 80bdc62458760c356fe663c4618e79e2f3de5c48.1623152430.git.bnemeth@redhat.com (mailing list archive)
State New
Delegated to: Maxime Coquelin
Headers show
Series [v4] vhost: allocate and free packets in bulk in Tx split | expand

Checks

Context Check Description
ci/iol-testing fail Testing issues
ci/iol-abi-testing success Testing PASS
ci/intel-Testing success Testing PASS
ci/Intel-compilation success Compilation OK
ci/iol-intel-Performance success Performance Testing PASS
ci/iol-intel-Functional success Functional Testing PASS
ci/checkpatch success coding style OK

Commit Message

Balazs Nemeth June 8, 2021, 11:41 a.m. UTC
Same idea as commit a287ac28919d ("vhost: allocate and free packets
in bulk in Tx packed"), allocate and free packets in bulk. Also remove
the unused function virtio_dev_pktmbuf_alloc.

Signed-off-by: Balazs Nemeth <bnemeth@redhat.com>
Reviewed-by: Maxime Coquelin <maxime.coquelin@redhat.com>
---
 lib/vhost/virtio_net.c | 40 +++++++++++-----------------------------
 1 file changed, 11 insertions(+), 29 deletions(-)
diff mbox series

Patch

diff --git a/lib/vhost/virtio_net.c b/lib/vhost/virtio_net.c
index 8da8a86a10..b93482587c 100644
--- a/lib/vhost/virtio_net.c
+++ b/lib/vhost/virtio_net.c
@@ -2652,6 +2652,9 @@  virtio_dev_extbuf_alloc(struct rte_mbuf *pkt, uint32_t size)
 	return 0;
 }
 
+/*
+ * Prepare a host supported pktmbuf.
+ */
 static __rte_always_inline int
 virtio_dev_pktmbuf_prep(struct virtio_net *dev, struct rte_mbuf *pkt,
 			 uint32_t data_len)
@@ -2670,32 +2673,6 @@  virtio_dev_pktmbuf_prep(struct virtio_net *dev, struct rte_mbuf *pkt,
 	return -1;
 }
 
-/*
- * Allocate a host supported pktmbuf.
- */
-static __rte_always_inline struct rte_mbuf *
-virtio_dev_pktmbuf_alloc(struct virtio_net *dev, struct rte_mempool *mp,
-			 uint32_t data_len)
-{
-	struct rte_mbuf *pkt = rte_pktmbuf_alloc(mp);
-
-	if (unlikely(pkt == NULL)) {
-		VHOST_LOG_DATA(ERR,
-			"Failed to allocate memory for mbuf.\n");
-		return NULL;
-	}
-
-	if (virtio_dev_pktmbuf_prep(dev, pkt, data_len)) {
-		/* Data doesn't fit into the buffer and the host supports
-		 * only linear buffers
-		 */
-		rte_pktmbuf_free(pkt);
-		return NULL;
-	}
-
-	return pkt;
-}
-
 __rte_always_inline
 static uint16_t
 virtio_dev_tx_split(struct virtio_net *dev, struct vhost_virtqueue *vq,
@@ -2725,6 +2702,9 @@  virtio_dev_tx_split(struct virtio_net *dev, struct vhost_virtqueue *vq,
 	VHOST_LOG_DATA(DEBUG, "(%d) about to dequeue %u buffers\n",
 			dev->vid, count);
 
+	if (rte_pktmbuf_alloc_bulk(mbuf_pool, pkts, count))
+		return 0;
+
 	for (i = 0; i < count; i++) {
 		struct buf_vector buf_vec[BUF_VECTOR_MAX];
 		uint16_t head_idx;
@@ -2741,8 +2721,8 @@  virtio_dev_tx_split(struct virtio_net *dev, struct vhost_virtqueue *vq,
 
 		update_shadow_used_ring_split(vq, head_idx, 0);
 
-		pkts[i] = virtio_dev_pktmbuf_alloc(dev, mbuf_pool, buf_len);
-		if (unlikely(pkts[i] == NULL)) {
+		err = virtio_dev_pktmbuf_prep(dev, pkts[i], buf_len);
+		if (unlikely(err)) {
 			/*
 			 * mbuf allocation fails for jumbo packets when external
 			 * buffer allocation is not allowed and linear buffer
@@ -2762,7 +2742,6 @@  virtio_dev_tx_split(struct virtio_net *dev, struct vhost_virtqueue *vq,
 		err = copy_desc_to_mbuf(dev, vq, buf_vec, nr_vec, pkts[i],
 				mbuf_pool, legacy_ol_flags);
 		if (unlikely(err)) {
-			rte_pktmbuf_free(pkts[i]);
 			if (!allocerr_warned) {
 				VHOST_LOG_DATA(ERR,
 					"Failed to copy desc to mbuf on %s.\n",
@@ -2775,6 +2754,9 @@  virtio_dev_tx_split(struct virtio_net *dev, struct vhost_virtqueue *vq,
 		}
 	}
 
+	if (dropped)
+		rte_pktmbuf_free_bulk(&pkts[i - 1], count - i + 1);
+
 	vq->last_avail_idx += i;
 
 	do_data_copy_dequeue(vq);