mbox series

[net-next,0/4] net: inet: Retire port only listening_hash

Message ID 20220512000546.188616-1-kafai@fb.com (mailing list archive)
Headers show
Series net: inet: Retire port only listening_hash | expand

Message

Martin KaFai Lau May 12, 2022, 12:05 a.m. UTC
This series is to retire the port only listening_hash.

The listen sk is currently stored in two hash tables,
listening_hash (hashed by port) and lhash2 (hashed by port and address).

After commit 0ee58dad5b06 ("net: tcp6: prefer listeners bound to an address")
and commit d9fbc7f6431f ("net: tcp: prefer listeners bound to an address"),
the TCP-SYN lookup fast path does not use listening_hash.

The commit 05c0b35709c5 ("tcp: seq_file: Replace listening_hash with lhash2")
also moved the seq_file (/proc/net/tcp) iteration usage from
listening_hash to lhash2.

There are still a few listening_hash usages left.
One of them is inet_reuseport_add_sock() which uses the listening_hash
to search a listen sk during the listen() system call.  This turns
out to be very slow on use cases that listen on many different
VIPs at a popular port (e.g. 443).  [ On top of the slowness in
adding to the tail in the IPv6 case ]. A latter patch has a
selftest to demonstrate this case.

This series takes this chance to move all remaining listening_hash
usages to lhash2 and then retire listening_hash.

Martin KaFai Lau (4):
  net: inet: Remove count from inet_listen_hashbucket
  net: inet: Open code inet_hash2 and inet_unhash2
  net: inet: Retire port only listening_hash
  net: selftests: Stress reuseport listen

 include/net/inet_connection_sock.h            |   2 -
 include/net/inet_hashtables.h                 |  42 +------
 net/dccp/proto.c                              |   1 -
 net/ipv4/inet_diag.c                          |   5 +-
 net/ipv4/inet_hashtables.c                    | 119 +++++-------------
 net/ipv4/tcp.c                                |   1 -
 net/ipv4/tcp_ipv4.c                           |  21 ++--
 net/ipv6/inet6_hashtables.c                   |   5 +-
 net/mptcp/mptcp_diag.c                        |   4 +-
 tools/testing/selftests/net/Makefile          |   2 +
 .../selftests/net/stress_reuseport_listen.c   | 105 ++++++++++++++++
 .../selftests/net/stress_reuseport_listen.sh  |  25 ++++
 12 files changed, 180 insertions(+), 152 deletions(-)
 create mode 100644 tools/testing/selftests/net/stress_reuseport_listen.c
 create mode 100755 tools/testing/selftests/net/stress_reuseport_listen.sh

Comments

Eric Dumazet May 12, 2022, 9:01 p.m. UTC | #1
On Wed, May 11, 2022 at 5:05 PM Martin KaFai Lau <kafai@fb.com> wrote:
>
> This series is to retire the port only listening_hash.
>
> The listen sk is currently stored in two hash tables,
> listening_hash (hashed by port) and lhash2 (hashed by port and address).
>
> After commit 0ee58dad5b06 ("net: tcp6: prefer listeners bound to an address")
> and commit d9fbc7f6431f ("net: tcp: prefer listeners bound to an address"),
> the TCP-SYN lookup fast path does not use listening_hash.
>
> The commit 05c0b35709c5 ("tcp: seq_file: Replace listening_hash with lhash2")
> also moved the seq_file (/proc/net/tcp) iteration usage from
> listening_hash to lhash2.
>
> There are still a few listening_hash usages left.
> One of them is inet_reuseport_add_sock() which uses the listening_hash
> to search a listen sk during the listen() system call.  This turns
> out to be very slow on use cases that listen on many different
> VIPs at a popular port (e.g. 443).  [ On top of the slowness in
> adding to the tail in the IPv6 case ]. A latter patch has a
> selftest to demonstrate this case.
>
> This series takes this chance to move all remaining listening_hash
> usages to lhash2 and then retire listening_hash.
>
> Martin KaFai Lau (4):
>   net: inet: Remove count from inet_listen_hashbucket
>   net: inet: Open code inet_hash2 and inet_unhash2
>   net: inet: Retire port only listening_hash
>   net: selftests: Stress reuseport listen
>

Nice patches, thanks Martin.

Reviewed-by: Eric Dumazet <edumazet@google.com>
patchwork-bot+netdevbpf@kernel.org May 13, 2022, 12:10 a.m. UTC | #2
Hello:

This series was applied to netdev/net-next.git (master)
by Jakub Kicinski <kuba@kernel.org>:

On Wed, 11 May 2022 17:05:46 -0700 you wrote:
> This series is to retire the port only listening_hash.
> 
> The listen sk is currently stored in two hash tables,
> listening_hash (hashed by port) and lhash2 (hashed by port and address).
> 
> After commit 0ee58dad5b06 ("net: tcp6: prefer listeners bound to an address")
> and commit d9fbc7f6431f ("net: tcp: prefer listeners bound to an address"),
> the TCP-SYN lookup fast path does not use listening_hash.
> 
> [...]

Here is the summary with links:
  - [net-next,1/4] net: inet: Remove count from inet_listen_hashbucket
    https://git.kernel.org/netdev/net-next/c/8ea1eebb49a2
  - [net-next,2/4] net: inet: Open code inet_hash2 and inet_unhash2
    https://git.kernel.org/netdev/net-next/c/e8d0059000b2
  - [net-next,3/4] net: inet: Retire port only listening_hash
    https://git.kernel.org/netdev/net-next/c/cae3873c5b3a
  - [net-next,4/4] net: selftests: Stress reuseport listen
    https://git.kernel.org/netdev/net-next/c/ec8cb4f617a2

You are awesome, thank you!