* [PATCH net] udp: inuse checks can quit early for reuseport
@ 2017-01-06 1:22 Eric Garver
2017-01-07 1:57 ` David Miller
0 siblings, 1 reply; 2+ messages in thread
From: Eric Garver @ 2017-01-06 1:22 UTC (permalink / raw)
To: davem; +Cc: netdev
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>
---
net/ipv4/udp.c | 29 +++++++++++++++++++----------
1 file changed, 19 insertions(+), 10 deletions(-)
diff --git a/net/ipv4/udp.c b/net/ipv4/udp.c
index 1307a7c2e544..4318d72e0248 100644
--- a/net/ipv4/udp.c
+++ b/net/ipv4/udp.c
@@ -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 (!bitmap)
- return 1;
- __set_bit(udp_sk(sk2)->udp_port_hash >> log, bitmap);
+ 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);
+ }
}
}
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)) {
- res = 1;
+ 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 {
--
2.10.0
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH net] udp: inuse checks can quit early for reuseport
2017-01-06 1:22 [PATCH net] udp: inuse checks can quit early for reuseport Eric Garver
@ 2017-01-07 1:57 ` David Miller
0 siblings, 0 replies; 2+ messages in thread
From: David Miller @ 2017-01-07 1:57 UTC (permalink / raw)
To: e; +Cc: netdev
From: Eric Garver <e@erig.me>
Date: Thu, 5 Jan 2017 20:22:36 -0500
> 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>
Applied to net-next.
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2017-01-07 1:57 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-01-06 1:22 [PATCH net] udp: inuse checks can quit early for reuseport Eric Garver
2017-01-07 1:57 ` David Miller
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).