diff mbox series

[3/4] vhost: allocate and free packets in bulk

Message ID 431a22e899c4491e6af747714ff4cc6fb9ed2c28.1617723339.git.bnemeth@redhat.com (mailing list archive)
State Superseded, archived
Delegated to: Maxime Coquelin
Headers show
Series Use bulk alloc/free in virtio packed | expand

Checks

Context Check Description
ci/checkpatch success coding style OK

Commit Message

Balazs Nemeth April 6, 2021, 3:44 p.m. UTC
Now that all allocation and freeing has been moved together, use the
faster bulk versions instead of handling packets one by one.

Signed-off-by: Balazs Nemeth <bnemeth@redhat.com>
---
 lib/librte_vhost/virtio_net.c | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)
diff mbox series

Patch

diff --git a/lib/librte_vhost/virtio_net.c b/lib/librte_vhost/virtio_net.c
index 496f750e3..e1696c0c0 100644
--- a/lib/librte_vhost/virtio_net.c
+++ b/lib/librte_vhost/virtio_net.c
@@ -2471,8 +2471,9 @@  virtio_dev_tx_packed(struct virtio_net *dev,
 	uint32_t remained = count;
 	uint16_t i;
 
-	for (i = 0; i < count; ++i)
-		pkts[i] = rte_pktmbuf_alloc(mbuf_pool);
+	if (rte_pktmbuf_alloc_bulk(mbuf_pool, pkts, count)) {
+		return 0;
+	}
 
 	do {
 		rte_prefetch0(&vq->desc_packed[vq->last_avail_idx]);
@@ -2497,8 +2498,9 @@  virtio_dev_tx_packed(struct virtio_net *dev,
 
 	} while (remained);
 
-	for (i = pkt_idx; i < count; ++i)
-		rte_pktmbuf_free(pkts[i]);
+	if (pkt_idx != count) {
+		rte_pktmbuf_free_bulk(&pkts[pkt_idx], count - pkt_idx);
+	}
 
 	if (vq->shadow_used_idx) {
 		do_data_copy_dequeue(vq);