linux/net/ipv6
Eric Dumazet d4438ce68b inet: call inet6_ehashfn() once from inet6_hash_connect()
inet6_ehashfn() being called from __inet6_check_established()
has a big impact on performance, as shown in the Tested section.

After prior patch, we can compute the hash for port 0
from inet6_hash_connect(), and derive each hash in
__inet_hash_connect() from this initial hash:

hash(saddr, lport, daddr, dport) == hash(saddr, 0, daddr, dport) + lport

Apply the same principle for __inet_check_established(),
although inet_ehashfn() has a smaller cost.

Tested:

Server: ulimit -n 40000; neper/tcp_crr -T 200 -F 30000 -6 --nolog
Client: ulimit -n 40000; neper/tcp_crr -T 200 -F 30000 -6 --nolog -c -H server

Before this patch:

  utime_start=0.286131
  utime_end=4.378886
  stime_start=11.952556
  stime_end=1991.655533
  num_transactions=1446830
  latency_min=0.001061085
  latency_max=12.075275028
  latency_mean=0.376375302
  latency_stddev=1.361969596
  num_samples=306383
  throughput=151866.56

perf top:

 50.01%  [kernel]       [k] __inet6_check_established
 20.65%  [kernel]       [k] __inet_hash_connect
 15.81%  [kernel]       [k] inet6_ehashfn
  2.92%  [kernel]       [k] rcu_all_qs
  2.34%  [kernel]       [k] __cond_resched
  0.50%  [kernel]       [k] _raw_spin_lock
  0.34%  [kernel]       [k] sched_balance_trigger
  0.24%  [kernel]       [k] queued_spin_lock_slowpath

After this patch:

  utime_start=0.315047
  utime_end=9.257617
  stime_start=7.041489
  stime_end=1923.688387
  num_transactions=3057968
  latency_min=0.003041375
  latency_max=7.056589232
  latency_mean=0.141075048    # Better latency metrics
  latency_stddev=0.526900516
  num_samples=312996
  throughput=320677.21        # 111 % increase, and 229 % for the series

perf top: inet6_ehashfn is no longer seen.

 39.67%  [kernel]       [k] __inet_hash_connect
 37.06%  [kernel]       [k] __inet6_check_established
  4.79%  [kernel]       [k] rcu_all_qs
  3.82%  [kernel]       [k] __cond_resched
  1.76%  [kernel]       [k] sched_balance_domains
  0.82%  [kernel]       [k] _raw_spin_lock
  0.81%  [kernel]       [k] sched_balance_rq
  0.81%  [kernel]       [k] sched_balance_trigger
  0.76%  [kernel]       [k] queued_spin_lock_slowpath

Signed-off-by: Eric Dumazet <edumazet@google.com>
Reviewed-by: Kuniyuki Iwashima <kuniyu@amazon.com>
Tested-by: Jason Xing <kerneljasonxing@gmail.com>
Reviewed-by: Jason Xing <kerneljasonxing@gmail.com>
Link: https://patch.msgid.link/20250305034550.879255-3-edumazet@google.com
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
2025-03-06 15:26:02 -08:00
..
ila net: ipv6: fix missing dst ref drop in ila lwtunnel 2025-03-06 11:08:45 +01:00
netfilter netfilter pull request 24-11-07 2024-11-07 12:46:04 +01:00
addrconf.c ipv6: Convert inet6_rtm_deladdr() to per-netns RTNL. 2025-01-20 12:16:06 -08:00
addrconf_core.c ipv6: Ensure natural alignment of const ipv6 loopback and router addresses 2024-01-30 12:43:18 +01:00
addrlabel.c ipv6: Use rtnl_register_many(). 2024-10-15 18:52:26 -07:00
af_inet6.c net: inet6: do not leave a dangling sk pointer in inet6_create() 2024-10-15 18:43:08 -07:00
ah6.c net: fill in MODULE_DESCRIPTION()s for ipv6 modules 2024-02-09 14:12:01 -08:00
anycast.c netlink: add IPv6 anycast join/leave notifications 2025-01-09 12:54:45 +01:00
calipso.c move asm/unaligned.h to linux/unaligned.h 2024-10-02 17:23:23 -04:00
datagram.c
esp6.c ipsec-2025-01-27 2025-01-27 15:15:12 -08:00
esp6_offload.c xfrm: Add an inbound percpu state cache. 2024-10-29 11:56:18 +01:00
exthdrs.c net: use sock_kmemdup for ip_options 2025-03-03 17:16:34 -08:00
exthdrs_core.c
exthdrs_offload.c
fib6_notifier.c net: do not acquire rtnl in fib_seq_sum() 2024-10-11 15:35:05 -07:00
fib6_rules.c ipv6: fib_rules: Add DSCP mask matching 2025-02-21 16:08:48 -08:00
fou6.c
icmp.c inet: ping: avoid skb_clone() dance in ping_rcv() 2025-02-28 14:41:33 -08:00
inet6_connection_sock.c
inet6_hashtables.c inet: call inet6_ehashfn() once from inet6_hash_connect() 2025-03-06 15:26:02 -08:00
ioam6.c net: convert to nla_get_*_default() 2024-11-11 10:32:06 -08:00
ioam6_iptunnel.c net: ipv6: fix dst ref loops in rpl, seg6 and ioam6 lwtunnels 2025-02-01 16:55:44 -08:00
ip6_checksum.c
ip6_fib.c ipv6: Fix soft lockups in fib6_select_path under high next hop churn 2024-11-11 15:26:10 -08:00
ip6_flowlabel.c
ip6_gre.c net: rename netns_local to netns_immutable 2025-03-04 12:44:48 +01:00
ip6_icmp.c
ip6_input.c ipv6: Use RCU in ip6_input() 2025-02-06 16:14:15 -08:00
ip6_offload.c net: gro: initialize network_offset in network layer 2024-05-27 16:46:59 -07:00
ip6_offload.h
ip6_output.c inetpeer: do not get a refcount in inet_getpeer() 2024-12-17 19:37:48 -08:00
ip6_tunnel.c net: rename netns_local to netns_immutable 2025-03-04 12:44:48 +01:00
ip6_udp_tunnel.c net: fill in MODULE_DESCRIPTION()s for ipv6 modules 2024-02-09 14:12:01 -08:00
ip6_vti.c net: ipv6: Use link netns in newlink() of rtnl_link_ops 2025-02-21 15:28:02 -08:00
ip6mr.c net: rename netns_local to netns_immutable 2025-03-04 12:44:48 +01:00
ipcomp6.c
ipv6_sockglue.c ipv6: avoid indirect calls for SOL_IP socket options 2024-08-26 14:53:50 -07:00
Kconfig net: ipv6: select DST_CACHE from IPV6_RPL_LWTUNNEL 2024-09-22 19:52:07 +01:00
Makefile
mcast.c ipv6: mcast: add RCU protection to mld_newpack() 2025-02-13 08:37:21 -08:00
mcast_snoop.c
mip6.c net: fill in MODULE_DESCRIPTION()s for ipv6 modules 2024-02-09 14:12:01 -08:00
ndisc.c ndisc: ndisc_send_redirect() cleanup 2025-02-15 09:08:46 -08:00
netfilter.c Merge git://git.kernel.org/pub/scm/linux/kernel/git/netdev/net 2024-06-13 13:13:46 -07:00
output_core.c ipv6: annotate data-races around cnf.hop_limit 2024-03-01 08:42:31 +00:00
ping.c ipv6: initialize inet socket cookies with sockcm_init 2025-02-18 18:27:20 -08:00
proc.c minmax: add a few more MIN_T/MAX_T users 2024-07-28 13:41:14 -07:00
protocol.c
raw.c ipv6: initialize inet socket cookies with sockcm_init 2025-02-18 18:27:20 -08:00
reassembly.c net: Rename mono_delivery_time to tstamp_type for scalabilty 2024-05-23 14:14:23 -07:00
route.c inet: fix lwtunnel_valid_encap_type() lock imbalance 2025-03-05 19:16:56 -08:00
rpl.c
rpl_iptunnel.c net: ipv6: fix dst ref loop on input in rpl lwt 2025-02-27 14:18:22 +01:00
seg6.c ipv6: sr: restruct ifdefines 2024-05-30 18:29:38 -07:00
seg6_hmac.c ipv6: sr: fix memleak in seg6_hmac_init_algo 2024-05-21 13:16:25 +02:00
seg6_iptunnel.c net: ipv6: fix dst ref loop on input in seg6 lwt 2025-02-27 14:18:21 +01:00
seg6_local.c net: ip: make ip_route_input() return drop reasons 2024-11-12 11:24:51 +01:00
sit.c net: rename netns_local to netns_immutable 2025-03-04 12:44:48 +01:00
syncookies.c tcp: use sk_skb_reason_drop to free rx packets 2024-06-19 12:44:22 +01:00
sysctl_net_ipv6.c sysctl: treewide: constify the ctl_table argument of proc_handlers 2024-07-24 20:59:29 +02:00
tcp_ao.c
tcp_ipv6.c tcp: remove READ_ONCE(req->ts_recent) 2025-03-03 15:44:19 -08:00
tcpv6_offload.c net: gro: convert four dev_net() calls 2025-03-03 15:44:19 -08:00
tunnel6.c net: fill in MODULE_DESCRIPTION()s for ipv6 modules 2024-02-09 14:12:01 -08:00
udp.c ipv6: initialize inet socket cookies with sockcm_init 2025-02-18 18:27:20 -08:00
udp_impl.h
udp_offload.c net: gro: convert four dev_net() calls 2025-03-03 15:44:19 -08:00
udplite.c
xfrm6_input.c Merge git://git.kernel.org/pub/scm/linux/kernel/git/netdev/net 2024-05-09 10:01:01 -07:00
xfrm6_output.c xfrm: Fix the usage of skb->sk 2025-01-20 07:06:53 +01:00
xfrm6_policy.c xfrm: respect ip protocols rules criteria when performing dst lookups 2024-09-23 07:02:07 +02:00
xfrm6_protocol.c
xfrm6_state.c
xfrm6_tunnel.c ipsec-next-2024-03-06 2024-03-08 10:56:05 +00:00