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

Alexey Kardashevskiy aik at ozlabs.ru
Wed Aug 2 14:33:03 AEST 2017


On 02/08/17 04:14, Thomas Huth wrote:
> On 01.08.2017 08:39, Nikunj A Dadhania wrote:
>> 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.
> 
> Not sure whether this is a really good idea... I think theoretically an
> OF client could open multiple network devices and use them in parallel -
> and then the devices would destroy their shared receive buffers mutually.
> Maybe you could change the code so that the buffers are only allocated
> when the device is opened, and released again when the device is closed
> again?

Agree, something like this would make sense imho:


diff --git a/include/netdriver.h b/include/netdriver.h
index d81134e..5fd1d6e 100644
--- a/include/netdriver.h
+++ b/include/netdriver.h
@@ -19,6 +19,7 @@ typedef struct net_driver {
        uint8_t mac_addr[6];
        uint32_t reg;
        int running;
+    void *dev;
 } net_driver_t;

 #endif
diff --git a/lib/libvirtio/virtio-net.c b/lib/libvirtio/virtio-net.c
index 2573031..bfbf718 100644
--- a/lib/libvirtio/virtio-net.c
+++ b/lib/libvirtio/virtio-net.c
@@ -197,6 +197,8 @@ dev_error:
  */
 static int virtionet_term(net_driver_t *driver)
 {
+    struct virtio_device *dev = driver->dev;
+
        dprintf("virtionet_term()\n");

        if (driver->running == 0)
@@ -210,6 +212,8 @@ static int virtionet_term(net_driver_t *driver)

        driver->running = 0;

+    /* free the buffers, etc */
+
        return 0;
 }

@@ -334,6 +338,8 @@ net_driver_t *virtionet_open(struct virtio_device *dev)
        if (virtionet_init(driver))
                goto FAIL;

+    driver->dev = dev;
+
        return driver;

 FAIL:  SLOF_free_mem(driver, sizeof(*driver));






-- 
Alexey


More information about the SLOF mailing list