Index | Thread | Search

From:
Stefan Fritsch <sf@openbsd.org>
Subject:
Re: UDP and IPv6 toelpitz flow id
To:
Alexander Bluhm <alexander.bluhm@gmx.net>
Cc:
tech@openbsd.org
Date:
Mon, 17 Feb 2025 10:32:31 +0100

Download raw body.

Thread
On Fri, 14 Feb 2025, Alexander Bluhm wrote:

> In IPv4 TCP output we use the toelpitz hash as flow id.  It is
> calculated in in_pcbconnect() and can be used for all connected
> sockets.  Diff below adds it for UDP and TCP IPv6.
> 
> sf@ recommends doing this for vio(4) multiqueue distribution.
> My tests do not show a difference in throughput.  Consistent
> behavior and distributing packets makes sense anyway.
> 
> ok?

In my test setup, if I disable pf, this gives an improvement in traffic 
distribution over the queues and a ~ 20% performance increase with UDP 
send on v4/v6 and TCP send on v6. No noticable difference with pf enabled.

ok sf@

> 
> bluhm
> 
> Index: netinet/tcp_output.c
> ===================================================================
> RCS file: /data/mirror/openbsd/cvs/src/sys/netinet/tcp_output.c,v
> diff -u -p -r1.152 tcp_output.c
> --- netinet/tcp_output.c	30 Jan 2025 14:40:50 -0000	1.152
> +++ netinet/tcp_output.c	14 Feb 2025 19:35:46 -0000
> @@ -1072,6 +1072,10 @@ send:
>  #if NPF > 0
>  	pf_mbuf_link_inpcb(m, tp->t_inpcb);
>  #endif
> +#if NSTOEPLITZ > 0
> +	m->m_pkthdr.ph_flowid = tp->t_inpcb->inp_flowid;
> +	SET(m->m_pkthdr.csum_flags, M_FLOWID);
> +#endif
>  
>  	switch (tp->pf) {
>  	case 0:	/*default to PF_INET*/
> @@ -1089,10 +1093,6 @@ send:
>  				ip->ip_tos |= IPTOS_ECN_ECT0;
>  #endif
>  		}
> -#if NSTOEPLITZ > 0
> -		m->m_pkthdr.ph_flowid = tp->t_inpcb->inp_flowid;
> -		SET(m->m_pkthdr.csum_flags, M_FLOWID);
> -#endif
>  		error = ip_output(m, tp->t_inpcb->inp_options,
>  		    &tp->t_inpcb->inp_route,
>  		    (ip_mtudisc ? IP_MTUDISC : 0), NULL,
> Index: netinet/udp_usrreq.c
> ===================================================================
> RCS file: /data/mirror/openbsd/cvs/src/sys/netinet/udp_usrreq.c,v
> diff -u -p -r1.332 udp_usrreq.c
> --- netinet/udp_usrreq.c	12 Feb 2025 21:28:11 -0000	1.332
> +++ netinet/udp_usrreq.c	14 Feb 2025 18:50:25 -0000
> @@ -68,6 +68,9 @@
>   * Research Laboratory (NRL).
>   */
>  
> +#include "pf.h"
> +#include "stoeplitz.h"
> +
>  #include <sys/param.h>
>  #include <sys/systm.h>
>  #include <sys/mbuf.h>
> @@ -102,7 +105,6 @@
>  #include <netinet6/ip6protosw.h>
>  #endif /* INET6 */
>  
> -#include "pf.h"
>  #if NPF > 0
>  #include <net/pfvar.h>
>  #endif
> @@ -1081,10 +1083,15 @@ udp_output(struct inpcb *inp, struct mbu
>  	/* force routing table */
>  	m->m_pkthdr.ph_rtableid = inp->inp_rtableid;
>  
> +	if (inp->inp_socket->so_state & SS_ISCONNECTED) {
>  #if NPF > 0
> -	if (inp->inp_socket->so_state & SS_ISCONNECTED)
>  		pf_mbuf_link_inpcb(m, inp);
>  #endif
> +#if NSTOEPLITZ > 0
> +		m->m_pkthdr.ph_flowid = inp->inp_flowid;
> +		SET(m->m_pkthdr.csum_flags, M_FLOWID);
> +#endif
> +	}
>  
>  	error = ip_output(m, inp->inp_options, &inp->inp_route,
>  	    (inp->inp_socket->so_options & SO_BROADCAST), inp->inp_moptions,
> Index: netinet6/udp6_output.c
> ===================================================================
> RCS file: /data/mirror/openbsd/cvs/src/sys/netinet6/udp6_output.c,v
> diff -u -p -r1.65 udp6_output.c
> --- netinet6/udp6_output.c	17 Apr 2024 20:48:51 -0000	1.65
> +++ netinet6/udp6_output.c	14 Feb 2025 18:50:41 -0000
> @@ -60,6 +60,7 @@
>   */
>  
>  #include "pf.h"
> +#include "stoeplitz.h"
>  
>  #include <sys/param.h>
>  #include <sys/mbuf.h>
> @@ -227,10 +228,15 @@ udp6_output(struct inpcb *inp, struct mb
>  	/* force routing table */
>  	m->m_pkthdr.ph_rtableid = inp->inp_rtableid;
>  
> +	if (inp->inp_socket->so_state & SS_ISCONNECTED) {
>  #if NPF > 0
> -	if (inp->inp_socket->so_state & SS_ISCONNECTED)
>  		pf_mbuf_link_inpcb(m, inp);
>  #endif
> +#if NSTOEPLITZ > 0
> +		m->m_pkthdr.ph_flowid = inp->inp_flowid;
> +		SET(m->m_pkthdr.csum_flags, M_FLOWID);
> +#endif
> +	}
>  
>  	error = ip6_output(m, optp, &inp->inp_route,
>  	    flags, inp->inp_moptions6, &inp->inp_seclevel);
>