]> git.baikalelectronics.ru Git - kernel.git/commit
net: Add a second bind table hashed by port and address
authorJoanne Koong <joannelkoong@gmail.com>
Fri, 20 May 2022 00:18:33 +0000 (17:18 -0700)
committerJakub Kicinski <kuba@kernel.org>
Sat, 21 May 2022 01:16:24 +0000 (18:16 -0700)
commit717b1aaa1adc0dcf0f971ea8487dcd41c86ffb8c
tree7bc53e45ea3628a75c25931f9f1d5c7f64d63cd5
parentc1d516b40f98514c0d4ee641704cdd2a1a231bcc
net: Add a second bind table hashed by port and address

We currently have one tcp bind table (bhash) which hashes by port
number only. In the socket bind path, we check for bind conflicts by
traversing the specified port's inet_bind2_bucket while holding the
bucket's spinlock (see inet_csk_get_port() and inet_csk_bind_conflict()).

In instances where there are tons of sockets hashed to the same port
at different addresses, checking for a bind conflict is time-intensive
and can cause softirq cpu lockups, as well as stops new tcp connections
since __inet_inherit_port() also contests for the spinlock.

This patch proposes adding a second bind table, bhash2, that hashes by
port and ip address. Searching the bhash2 table leads to significantly
faster conflict resolution and less time holding the spinlock.

Signed-off-by: Joanne Koong <joannelkoong@gmail.com>
Reviewed-by: Eric Dumazet <edumazet@google.com>
Acked-by: Kuniyuki Iwashima <kuniyu@amazon.co.jp>
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
include/net/inet_connection_sock.h
include/net/inet_hashtables.h
include/net/sock.h
net/dccp/proto.c
net/ipv4/inet_connection_sock.c
net/ipv4/inet_hashtables.c
net/ipv4/tcp.c