From d6a44bee4ed00c52ac897cd29eb007e6156ff2a6 Mon Sep 17 00:00:00 2001 From: scottl Date: Thu, 2 Jan 2014 01:51:54 +0000 Subject: [PATCH] MFC r260070 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. Obtained from: Netflix git-svn-id: svn://svn.freebsd.org/base/stable/10@260179 ccf9f872-aa2e-dd11-9fc8-001c23d0bc1f --- 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 8dbadd447..aef3740f6 100644 --- a/sys/net/ieee8023ad_lacp.c +++ b/sys/net/ieee8023ad_lacp.c @@ -874,7 +874,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 258c2f911..beae0b616 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 0db8da800..e52f9014c 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 { -- 2.45.0