soreuseport: TCP/IPv4 implementation
Allow multiple listener sockets to bind to the same port. Motivation for soresuseport 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>
This commit is contained in:

committed by
David S. Miller

parent
055dc21a1d
commit
da5e36308d
@@ -81,7 +81,9 @@ struct inet_bind_bucket {
|
||||
struct net *ib_net;
|
||||
#endif
|
||||
unsigned short port;
|
||||
signed short fastreuse;
|
||||
signed char fastreuse;
|
||||
signed char fastreuseport;
|
||||
kuid_t fastuid;
|
||||
int num_owners;
|
||||
struct hlist_node node;
|
||||
struct hlist_head owners;
|
||||
@@ -257,15 +259,19 @@ extern void inet_unhash(struct sock *sk);
|
||||
|
||||
extern struct sock *__inet_lookup_listener(struct net *net,
|
||||
struct inet_hashinfo *hashinfo,
|
||||
const __be32 saddr,
|
||||
const __be16 sport,
|
||||
const __be32 daddr,
|
||||
const unsigned short hnum,
|
||||
const int dif);
|
||||
|
||||
static inline struct sock *inet_lookup_listener(struct net *net,
|
||||
struct inet_hashinfo *hashinfo,
|
||||
__be32 saddr, __be16 sport,
|
||||
__be32 daddr, __be16 dport, int dif)
|
||||
{
|
||||
return __inet_lookup_listener(net, hashinfo, daddr, ntohs(dport), dif);
|
||||
return __inet_lookup_listener(net, hashinfo, saddr, sport,
|
||||
daddr, ntohs(dport), dif);
|
||||
}
|
||||
|
||||
/* Socket demux engine toys. */
|
||||
@@ -358,7 +364,8 @@ static inline struct sock *__inet_lookup(struct net *net,
|
||||
struct sock *sk = __inet_lookup_established(net, hashinfo,
|
||||
saddr, sport, daddr, hnum, dif);
|
||||
|
||||
return sk ? : __inet_lookup_listener(net, hashinfo, daddr, hnum, dif);
|
||||
return sk ? : __inet_lookup_listener(net, hashinfo, saddr, sport,
|
||||
daddr, hnum, dif);
|
||||
}
|
||||
|
||||
static inline struct sock *inet_lookup(struct net *net,
|
||||
|
Reference in New Issue
Block a user