diff --git a/sys/dev/virtual/vkernel/net/if_vke.c b/sys/dev/virtual/vkernel/net/if_vke.c index c09b36d..5a35073 100644 --- a/sys/dev/virtual/vkernel/net/if_vke.c +++ b/sys/dev/virtual/vkernel/net/if_vke.c @@ -66,7 +66,7 @@ #define VKE_CHUNK 8 /* number of mbufs to queue before interrupting */ -#define NETFIFOSIZE 256 +#define NETFIFOSIZE ((int)(nmbclusters * 0.50) / NetifNum) #define NETFIFOMASK (NETFIFOSIZE -1) #define NETFIFOINDEX(u) ((u) & NETFIFOMASK) @@ -75,7 +75,7 @@ #define VKE_COTD_DEAD 2 struct vke_fifo { - struct mbuf *array[NETFIFOSIZE]; + struct mbuf **array; int rindex; int windex; }; @@ -278,6 +278,7 @@ vke_init(void *xsc) { struct vke_softc *sc = xsc; struct ifnet *ifp = &sc->arpcom.ac_if; + size_t mbufptrs = NETFIFOSIZE * sizeof(struct mbuf *); int i; ASSERT_SERIALIZED(ifp->if_serializer); @@ -287,10 +288,18 @@ vke_init(void *xsc) ifp->if_flags |= IFF_RUNNING; ifsq_clr_oactive(ifq_get_subq_default(&ifp->if_snd)); + /* + * Allocate memory for FIFO structures and mbufs. + * NETFIFOSIZE is adjusted to use just 50% of the total mbuf + * clusters for all the active interfaces. + */ sc->sc_txfifo = kmalloc(sizeof(*sc->sc_txfifo), M_DEVBUF, M_WAITOK); sc->sc_txfifo_done = kmalloc(sizeof(*sc->sc_txfifo_done), M_DEVBUF, M_WAITOK); - sc->sc_rxfifo = kmalloc(sizeof(*sc->sc_rxfifo), M_DEVBUF, M_WAITOK); + sc->sc_txfifo->array = kmalloc(mbufptrs, M_DEVBUF, M_WAITOK | M_ZERO); + sc->sc_txfifo_done->array = kmalloc(mbufptrs, M_DEVBUF, M_WAITOK | M_ZERO); + sc->sc_rxfifo->array = kmalloc(mbufptrs, M_DEVBUF, M_WAITOK | M_ZERO); + for (i = 0; i < NETFIFOSIZE; i++) { sc->sc_rxfifo->array[i] = m_getcl(MB_WAIT, MT_DATA, M_PKTHDR); sc->sc_txfifo->array[i] = NULL; @@ -459,16 +468,22 @@ vke_stop(struct vke_softc *sc) } if (sc->sc_txfifo) { + if (sc->sc_txfifo->array) + kfree(sc->sc_txfifo->array, M_DEVBUF); kfree(sc->sc_txfifo, M_DEVBUF); sc->sc_txfifo = NULL; } if (sc->sc_txfifo_done) { + if (sc->sc_txfifo_done->array) + kfree(sc->sc_txfifo_done->array, M_DEVBUF); kfree(sc->sc_txfifo_done, M_DEVBUF); sc->sc_txfifo_done = NULL; } if (sc->sc_rxfifo) { + if (sc->sc_rxfifo->array) + kfree(sc->sc_rxfifo->array, M_DEVBUF); kfree(sc->sc_rxfifo, M_DEVBUF); sc->sc_rxfifo = NULL; }