WSL2-Linux-Kernel/net/ipv6
Kuniyuki Iwashima edc12f032a tcp: Save unnecessary inet_twsk_purge() calls.
While destroying netns, we call inet_twsk_purge() in tcp_sk_exit_batch()
and tcpv6_net_exit_batch() for AF_INET and AF_INET6.  These commands
trigger the kernel to walk through the potentially big ehash twice even
though the netns has no TIME_WAIT sockets.

  # ip netns add test
  # ip netns del test

  or

  # unshare -n /bin/true >/dev/null

When tw_refcount is 1, we need not call inet_twsk_purge() at least
for the net.  We can save such unneeded iterations if all netns in
net_exit_list have no TIME_WAIT sockets.  This change eliminates
the tax by the additional unshare() described in the next patch to
guarantee the per-netns ehash size.

Tested:

  # mount -t debugfs none /sys/kernel/debug/
  # echo cleanup_net > /sys/kernel/debug/tracing/set_ftrace_filter
  # echo inet_twsk_purge >> /sys/kernel/debug/tracing/set_ftrace_filter
  # echo function > /sys/kernel/debug/tracing/current_tracer
  # cat ./add_del_unshare.sh
  for i in `seq 1 40`
  do
      (for j in `seq 1 100` ; do  unshare -n /bin/true >/dev/null ; done) &
  done
  wait;
  # ./add_del_unshare.sh

Before the patch:

  # cat /sys/kernel/debug/tracing/trace_pipe
    kworker/u128:0-8       [031] ...1.   174.162765: cleanup_net <-process_one_work
    kworker/u128:0-8       [031] ...1.   174.240796: inet_twsk_purge <-cleanup_net
    kworker/u128:0-8       [032] ...1.   174.244759: inet_twsk_purge <-tcp_sk_exit_batch
    kworker/u128:0-8       [034] ...1.   174.290861: cleanup_net <-process_one_work
    kworker/u128:0-8       [039] ...1.   175.245027: inet_twsk_purge <-cleanup_net
    kworker/u128:0-8       [046] ...1.   175.290541: inet_twsk_purge <-tcp_sk_exit_batch
    kworker/u128:0-8       [037] ...1.   175.321046: cleanup_net <-process_one_work
    kworker/u128:0-8       [024] ...1.   175.941633: inet_twsk_purge <-cleanup_net
    kworker/u128:0-8       [025] ...1.   176.242539: inet_twsk_purge <-tcp_sk_exit_batch

After:

  # cat /sys/kernel/debug/tracing/trace_pipe
    kworker/u128:0-8       [038] ...1.   428.116174: cleanup_net <-process_one_work
    kworker/u128:0-8       [038] ...1.   428.262532: cleanup_net <-process_one_work
    kworker/u128:0-8       [030] ...1.   429.292645: cleanup_net <-process_one_work

Signed-off-by: Kuniyuki Iwashima <kuniyu@amazon.com>
Reviewed-by: Eric Dumazet <edumazet@google.com>
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
2022-09-20 10:21:50 -07:00
..
ila genetlink: start to validate reserved header bytes 2022-08-29 12:47:15 +01:00
netfilter tcp: Access &tcp_hashinfo via net. 2022-09-20 10:21:49 -07:00
Kconfig
Makefile
addrconf.c bonding: add all node mcast address when slave up 2022-09-05 10:07:05 +01:00
addrconf_core.c
addrlabel.c
af_inet6.c bpf: Change bpf_getsockopt(SOL_IPV6) to reuse do_ipv6_getsockopt() 2022-09-02 20:34:32 -07:00
ah6.c
anycast.c
calipso.c
datagram.c
esp6.c tcp: Access &tcp_hashinfo via net. 2022-09-20 10:21:49 -07:00
esp6_offload.c
exthdrs.c
exthdrs_core.c
exthdrs_offload.c
fib6_notifier.c
fib6_rules.c
fou6.c
icmp.c
inet6_connection_sock.c
inet6_hashtables.c tcp: Access &tcp_hashinfo via net. 2022-09-20 10:21:49 -07:00
ioam6.c genetlink: start to validate reserved header bytes 2022-08-29 12:47:15 +01:00
ioam6_iptunnel.c
ip6_checksum.c
ip6_fib.c
ip6_flowlabel.c
ip6_gre.c ipv6: move from strlcpy with unused retval to strscpy 2022-08-22 17:59:42 -07:00
ip6_icmp.c
ip6_input.c
ip6_offload.c net-next: gro: Fix use of skb_gro_header_slow 2022-09-20 11:47:25 +02:00
ip6_offload.h
ip6_output.c net: unify alloclen calculation for paged requests 2022-08-30 12:02:55 +02:00
ip6_tunnel.c ipv6: move from strlcpy with unused retval to strscpy 2022-08-22 17:59:42 -07:00
ip6_udp_tunnel.c
ip6_vti.c ipv6: move from strlcpy with unused retval to strscpy 2022-08-22 17:59:42 -07:00
ip6mr.c bpf: net: Change do_ipv6_getsockopt() to take the sockptr_t argument 2022-09-02 20:34:31 -07:00
ipcomp6.c
ipv6_sockglue.c Merge https://git.kernel.org/pub/scm/linux/kernel/git/bpf/bpf-next 2022-09-06 23:21:18 +02:00
mcast.c bpf: net: Change do_ipv6_getsockopt() to take the sockptr_t argument 2022-09-02 20:34:31 -07:00
mcast_snoop.c
mip6.c
ndisc.c net: fix potential refcount leak in ndisc_router_discovery() 2022-08-15 11:40:28 +01:00
netfilter.c
output_core.c
ping.c
proc.c
protocol.c
raw.c
reassembly.c
route.c
rpl.c
rpl_iptunnel.c
seg6.c Merge git://git.kernel.org/pub/scm/linux/kernel/git/netdev/net 2022-09-08 18:38:30 +02:00
seg6_hmac.c
seg6_iptunnel.c
seg6_local.c seg6: add NEXT-C-SID support for SRv6 End behavior 2022-09-20 12:33:22 +02:00
sit.c ipv6: move from strlcpy with unused retval to strscpy 2022-08-22 17:59:42 -07:00
syncookies.c
sysctl_net_ipv6.c
tcp_ipv6.c tcp: Save unnecessary inet_twsk_purge() calls. 2022-09-20 10:21:50 -07:00
tcpv6_offload.c
tunnel6.c
udp.c rxrpc: Fix ICMP/ICMP6 error handling 2022-09-01 11:42:12 +01:00
udp_impl.h
udp_offload.c
udplite.c
xfrm6_input.c
xfrm6_output.c
xfrm6_policy.c
xfrm6_protocol.c
xfrm6_state.c
xfrm6_tunnel.c