From 880c1619f1c41e54b0c4b5aac7ea32596104fa93 Mon Sep 17 00:00:00 2001 From: Antonio Huete Jimenez Date: Tue, 5 Mar 2013 23:33:11 +0100 Subject: [PATCH] vke(4) - Add a tunable to set the max number of mbuf clusters per device. * Also cap it to 256 mbuf clusters by default. --- sys/dev/virtual/vkernel/net/if_vke.c | 26 +++++++++++++++++++------- 1 file changed, 19 insertions(+), 7 deletions(-) diff --git a/sys/dev/virtual/vkernel/net/if_vke.c b/sys/dev/virtual/vkernel/net/if_vke.c index f74d5fe..9c2aaa9 100644 --- a/sys/dev/virtual/vkernel/net/if_vke.c +++ b/sys/dev/virtual/vkernel/net/if_vke.c @@ -79,6 +79,13 @@ struct vke_fifo { }; typedef struct vke_fifo *fifo_t; +/* Default value for a long time */ +#define VKE_DEFAULT_RINGSIZE 256 +static int vke_max_ringsize = 0; +TUNABLE_INT("hw.vke.max_ringsize", &vke_max_ringsize); + +#define LOW_POW_2(n) (1 << (fls(n) - 1)) + struct vke_softc { struct arpcom arpcom; int sc_fd; @@ -769,14 +776,19 @@ havemac: sc->sc_mask = info->netif_mask; /* - * Calculate the number of mbuf clusters we are going to use - * up to 50% of the total mbuf clusters available in the - * system. - * In the case our vkernel has so little mem that it can't - * allocate even VKE_CHUNK for every vke(4) device, just panic. + * Check for a ringsize override via hw.vke.max_ringsize tunable. + * If no override, up to 50% of the mbuf clusters is distributed + * equally among all the vke devices. We don't set more than + * vke_max_ringsize mbuf clusters per device in this case. */ - nmbufs = nmbclusters / (NetifNum * 2); - sc->sc_ringsize = (1 << (fls(nmbufs) - 1)); + if (vke_max_ringsize == 0) { + nmbufs = nmbclusters / (NetifNum * 2); + sc->sc_ringsize = LOW_POW_2(nmbufs); + if (sc->sc_ringsize > VKE_DEFAULT_RINGSIZE) + sc->sc_ringsize = VKE_DEFAULT_RINGSIZE; + } else if (vke_max_ringsize >= VKE_CHUNK) { /* Tunable specified */ + sc->sc_ringsize = LOW_POW_2(vke_max_ringsize); + } KASSERT(sc->sc_ringsize >= VKE_CHUNK, ("Not enough mbuf clusters for %d vke devices", NetifNum)); -- 1.8.0.1