From 1a8959dac65d603443885afa1fe3947f655019db Mon Sep 17 00:00:00 2001 From: Scott Long Date: Mon, 30 Dec 2013 01:32:17 +0000 Subject: [PATCH] Multi-queue NIC drivers and multi-port lagg tend to use the same lower bits of the flowid as each other, resulting in a poor distribution of packets among queues in certain cases. Work around this by adding a set of sysctls for controlling a bit-shift on the flowid when doing multi-port aggrigation in lagg and lacp. By default, lagg/lacp will now use bits 16 and higher instead of 0 and higher. Reviewed by: max Obtained from: Netflix MFC after: 3 days --- sys/net/ieee8023ad_lacp.c | 2 +- sys/net/if_lagg.c | 16 +++++++++++++--- sys/net/if_lagg.h | 1 + 3 files changed, 15 insertions(+), 4 deletions(-) diff --git a/sys/net/ieee8023ad_lacp.c b/sys/net/ieee8023ad_lacp.c index 423d3c485fed..1042de6ab819 100644 --- a/sys/net/ieee8023ad_lacp.c +++ b/sys/net/ieee8023ad_lacp.c @@ -877,7 +877,7 @@ lacp_select_tx_port(struct lagg_softc *sc, struct mbuf *m) } if (sc->use_flowid && (m->m_flags & M_FLOWID)) - hash = m->m_pkthdr.flowid; + hash = m->m_pkthdr.flowid >> sc->flowid_shift; else hash = lagg_hashmbuf(sc, m, lsc->lsc_hashkey); hash %= pm->pm_count; diff --git a/sys/net/if_lagg.c b/sys/net/if_lagg.c index 258c2f9113a4..beae0b616b20 100644 --- a/sys/net/if_lagg.c +++ b/sys/net/if_lagg.c @@ -184,6 +184,11 @@ TUNABLE_INT("net.link.lagg.default_use_flowid", &def_use_flowid); SYSCTL_INT(_net_link_lagg, OID_AUTO, default_use_flowid, CTLFLAG_RW, &def_use_flowid, 0, "Default setting for using flow id for load sharing"); +static int def_flowid_shift = 16; /* Default value for using M_FLOWID */ +TUNABLE_INT("net.link.lagg.default_flowid_shift", &def_flowid_shift); +SYSCTL_INT(_net_link_lagg, OID_AUTO, default_flowid_shift, CTLFLAG_RW, + &def_flowid_shift, 0, + "Default setting for flowid shift for load sharing"); static int lagg_modevent(module_t mod, int type, void *data) @@ -293,12 +298,17 @@ lagg_clone_create(struct if_clone *ifc, int unit, caddr_t params) sysctl_ctx_init(&sc->ctx); snprintf(num, sizeof(num), "%u", unit); sc->use_flowid = def_use_flowid; + sc->flowid_shift = def_flowid_shift; sc->sc_oid = oid = SYSCTL_ADD_NODE(&sc->ctx, &SYSCTL_NODE_CHILDREN(_net_link, lagg), OID_AUTO, num, CTLFLAG_RD, NULL, ""); SYSCTL_ADD_INT(&sc->ctx, SYSCTL_CHILDREN(oid), OID_AUTO, - "use_flowid", CTLTYPE_INT|CTLFLAG_RW, &sc->use_flowid, sc->use_flowid, - "Use flow id for load sharing"); + "use_flowid", CTLTYPE_INT|CTLFLAG_RW, &sc->use_flowid, + sc->use_flowid, "Use flow id for load sharing"); + SYSCTL_ADD_INT(&sc->ctx, SYSCTL_CHILDREN(oid), OID_AUTO, + "flowid_shift", CTLTYPE_INT|CTLFLAG_RW, &sc->flowid_shift, + sc->flowid_shift, + "Shift flowid bits to prevent multiqueue collisions"); SYSCTL_ADD_INT(&sc->ctx, SYSCTL_CHILDREN(oid), OID_AUTO, "count", CTLTYPE_INT|CTLFLAG_RD, &sc->sc_count, sc->sc_count, "Total number of ports"); @@ -1850,7 +1860,7 @@ lagg_lb_start(struct lagg_softc *sc, struct mbuf *m) uint32_t p = 0; if (sc->use_flowid && (m->m_flags & M_FLOWID)) - p = m->m_pkthdr.flowid; + p = m->m_pkthdr.flowid >> sc->flowid_shift; else p = lagg_hashmbuf(sc, m, lb->lb_key); p %= sc->sc_count; diff --git a/sys/net/if_lagg.h b/sys/net/if_lagg.h index 0db8da800e31..e52f9014ca1e 100644 --- a/sys/net/if_lagg.h +++ b/sys/net/if_lagg.h @@ -231,6 +231,7 @@ struct lagg_softc { struct sysctl_ctx_list ctx; /* sysctl variables */ struct sysctl_oid *sc_oid; /* sysctl tree oid */ int use_flowid; /* use M_FLOWID */ + int flowid_shift; /* shift the flowid */ }; struct lagg_port {