mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git
synced 2024-09-12 13:55:32 +00:00
udp: inuse checks can quit early for reuseport
UDP lib inuse checks will walk the entire hash bucket to check if the portaddr is in use. In the case of reuseport we can stop searching when we find a matching reuseport. On a 16-core VM a test program that spawns 16 threads that each bind to 1024 sockets (one per 10ms) takes 1m45s. With this change it takes 11s. Also add a cond_resched() when the port is not specified. Signed-off-by: Eric Garver <e@erig.me> Signed-off-by: David S. Miller <davem@davemloft.net>
This commit is contained in:
parent
89eb9835b2
commit
df560056d9
1 changed files with 19 additions and 10 deletions
|
@ -153,13 +153,18 @@ static int udp_lib_lport_inuse(struct net *net, __u16 num,
|
|||
(!sk2->sk_reuse || !sk->sk_reuse) &&
|
||||
(!sk2->sk_bound_dev_if || !sk->sk_bound_dev_if ||
|
||||
sk2->sk_bound_dev_if == sk->sk_bound_dev_if) &&
|
||||
(!sk2->sk_reuseport || !sk->sk_reuseport ||
|
||||
rcu_access_pointer(sk->sk_reuseport_cb) ||
|
||||
!uid_eq(uid, sock_i_uid(sk2))) &&
|
||||
saddr_comp(sk, sk2, true)) {
|
||||
if (sk2->sk_reuseport && sk->sk_reuseport &&
|
||||
!rcu_access_pointer(sk->sk_reuseport_cb) &&
|
||||
uid_eq(uid, sock_i_uid(sk2))) {
|
||||
if (!bitmap)
|
||||
return 0;
|
||||
} else {
|
||||
if (!bitmap)
|
||||
return 1;
|
||||
__set_bit(udp_sk(sk2)->udp_port_hash >> log, bitmap);
|
||||
__set_bit(udp_sk(sk2)->udp_port_hash >> log,
|
||||
bitmap);
|
||||
}
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
|
@ -188,11 +193,14 @@ static int udp_lib_lport_inuse2(struct net *net, __u16 num,
|
|||
(!sk2->sk_reuse || !sk->sk_reuse) &&
|
||||
(!sk2->sk_bound_dev_if || !sk->sk_bound_dev_if ||
|
||||
sk2->sk_bound_dev_if == sk->sk_bound_dev_if) &&
|
||||
(!sk2->sk_reuseport || !sk->sk_reuseport ||
|
||||
rcu_access_pointer(sk->sk_reuseport_cb) ||
|
||||
!uid_eq(uid, sock_i_uid(sk2))) &&
|
||||
saddr_comp(sk, sk2, true)) {
|
||||
if (sk2->sk_reuseport && sk->sk_reuseport &&
|
||||
!rcu_access_pointer(sk->sk_reuseport_cb) &&
|
||||
uid_eq(uid, sock_i_uid(sk2))) {
|
||||
res = 0;
|
||||
} else {
|
||||
res = 1;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -285,6 +293,7 @@ int udp_lib_get_port(struct sock *sk, unsigned short snum,
|
|||
snum += rand;
|
||||
} while (snum != first);
|
||||
spin_unlock_bh(&hslot->lock);
|
||||
cond_resched();
|
||||
} while (++first != last);
|
||||
goto fail;
|
||||
} else {
|
||||
|
|
Loading…
Reference in a new issue