[SLOF] [PATCH] virtio-net: use common receive buffer for devices

Nikunj A Dadhania nikunj at linux.vnet.ibm.com
Tue Aug 1 16:39:42 AEST 2017


Found that virtio-net is using a around 200K receive buffer per device, if we
connect more than 40 virtio-net devices the heap(8MB) gets over. Because of
which allocation starts failing and the VM does not boot.

Use common receive buffer for all the virtio-net devices. This will reduce the
memory requirement per virtio-net device in slof.

Signed-off-by: Nikunj A Dadhania <nikunj at linux.vnet.ibm.com>
---
 lib/libvirtio/virtio-net.c | 20 ++++++++++++++------
 1 file changed, 14 insertions(+), 6 deletions(-)

diff --git a/lib/libvirtio/virtio-net.c b/lib/libvirtio/virtio-net.c
index 2573031..a93ad7a 100644
--- a/lib/libvirtio/virtio-net.c
+++ b/lib/libvirtio/virtio-net.c
@@ -43,6 +43,7 @@
 struct virtio_device virtiodev;
 static struct vqs vq_rx;     /* Information about receive virtqueues */
 static struct vqs vq_tx;     /* Information about transmit virtqueues */
+static void *rx_buf_mem;
 
 /* See Virtio Spec, appendix C, "Device Operation" */
 struct virtio_net_hdr {
@@ -137,12 +138,19 @@ static int virtionet_init(net_driver_t *driver)
 		virtio_set_guest_features(&virtiodev,  0);
 	}
 
-	/* Allocate memory for one transmit an multiple receive buffers */
-	vq_rx.buf_mem = SLOF_alloc_mem((BUFFER_ENTRY_SIZE+net_hdr_size)
-				   * RX_QUEUE_SIZE);
-	if (!vq_rx.buf_mem) {
-		printf("virtionet: Failed to allocate buffers!\n");
-		goto dev_error;
+	/* Use common buffer to save memory space per device */
+	if (!rx_buf_mem) {
+		/* Allocate memory for one transmit and multiple receive
+		 * buffers
+		 */
+		rx_buf_mem = SLOF_alloc_mem((BUFFER_ENTRY_SIZE+net_hdr_size)
+					    * RX_QUEUE_SIZE);
+		if (!rx_buf_mem) {
+			printf("virtionet: Failed to allocate buffers!\n");
+			goto dev_error;
+		}
+	} else {
+		vq_rx.buf_mem = rx_buf_mem;
 	}
 
 	/* Prepare receive buffer queue */
-- 
2.9.3



More information about the SLOF mailing list