diff options
author | Tom Herbert <therbert@google.com> | 2013-01-22 04:50:39 -0500 |
---|---|---|
committer | David S. Miller <davem@davemloft.net> | 2013-01-23 13:44:01 -0500 |
commit | 5ba24953e9707387cce87b07f0d5fbdd03c5c11b (patch) | |
tree | c98e56f8a06f07ff585f85cbe6af8cd9c19f2ca6 /net/ipv6/inet6_connection_sock.c | |
parent | ba418fa357a7b3c9d477f4706c6c7c96ddbd1360 (diff) |
soreuseport: TCP/IPv6 implementation
Motivation for soreuseport would be something like a web server
binding to port 80 running with multiple threads, where each thread
might have it's own listener socket. This could be done as an
alternative to other models: 1) have one listener thread which
dispatches completed connections to workers. 2) accept on a single
listener socket from multiple threads. In case #1 the listener thread
can easily become the bottleneck with high connection turn-over rate.
In case #2, the proportion of connections accepted per thread tends
to be uneven under high connection load (assuming simple event loop:
while (1) { accept(); process() }, wakeup does not promote fairness
among the sockets. We have seen the disproportion to be as high
as 3:1 ratio between thread accepting most connections and the one
accepting the fewest. With so_reusport the distribution is
uniform.
Signed-off-by: Tom Herbert <therbert@google.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'net/ipv6/inet6_connection_sock.c')
-rw-r--r-- | net/ipv6/inet6_connection_sock.c | 19 |
1 files changed, 14 insertions, 5 deletions
diff --git a/net/ipv6/inet6_connection_sock.c b/net/ipv6/inet6_connection_sock.c index 30647857a375..e4297a393678 100644 --- a/net/ipv6/inet6_connection_sock.c +++ b/net/ipv6/inet6_connection_sock.c | |||
@@ -32,6 +32,9 @@ int inet6_csk_bind_conflict(const struct sock *sk, | |||
32 | { | 32 | { |
33 | const struct sock *sk2; | 33 | const struct sock *sk2; |
34 | const struct hlist_node *node; | 34 | const struct hlist_node *node; |
35 | int reuse = sk->sk_reuse; | ||
36 | int reuseport = sk->sk_reuseport; | ||
37 | int uid = sock_i_uid((struct sock *)sk); | ||
35 | 38 | ||
36 | /* We must walk the whole port owner list in this case. -DaveM */ | 39 | /* We must walk the whole port owner list in this case. -DaveM */ |
37 | /* | 40 | /* |
@@ -42,11 +45,17 @@ int inet6_csk_bind_conflict(const struct sock *sk, | |||
42 | if (sk != sk2 && | 45 | if (sk != sk2 && |
43 | (!sk->sk_bound_dev_if || | 46 | (!sk->sk_bound_dev_if || |
44 | !sk2->sk_bound_dev_if || | 47 | !sk2->sk_bound_dev_if || |
45 | sk->sk_bound_dev_if == sk2->sk_bound_dev_if) && | 48 | sk->sk_bound_dev_if == sk2->sk_bound_dev_if)) { |
46 | (!sk->sk_reuse || !sk2->sk_reuse || | 49 | if ((!reuse || !sk2->sk_reuse || |
47 | sk2->sk_state == TCP_LISTEN) && | 50 | sk2->sk_state == TCP_LISTEN) && |
48 | ipv6_rcv_saddr_equal(sk, sk2)) | 51 | (!reuseport || !sk2->sk_reuseport || |
49 | break; | 52 | (sk2->sk_state != TCP_TIME_WAIT && |
53 | !uid_eq(uid, | ||
54 | sock_i_uid((struct sock *)sk2))))) { | ||
55 | if (ipv6_rcv_saddr_equal(sk, sk2)) | ||
56 | break; | ||
57 | } | ||
58 | } | ||
50 | } | 59 | } |
51 | 60 | ||
52 | return node != NULL; | 61 | return node != NULL; |