Skip to content

Commit

Permalink
net: udp_unhash() can test if sk is hashed
Browse files Browse the repository at this point in the history
Impact: Optimization

Like done in inet_unhash(), we can avoid taking a chain lock if
socket is not hashed in udp_unhash()

Triggered by close(socket(AF_INET, SOCK_DGRAM, 0));

Signed-off-by: Eric Dumazet <dada1@cosmosbay.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
  • Loading branch information
Eric Dumazet authored and David S. Miller committed Nov 25, 2008
1 parent 5bc0b3b commit 723b461
Showing 1 changed file with 10 additions and 8 deletions.
18 changes: 10 additions & 8 deletions net/ipv4/udp.c
Original file line number Diff line number Diff line change
Expand Up @@ -970,16 +970,18 @@ int udp_disconnect(struct sock *sk, int flags)

void udp_lib_unhash(struct sock *sk)
{
struct udp_table *udptable = sk->sk_prot->h.udp_table;
unsigned int hash = udp_hashfn(sock_net(sk), sk->sk_hash);
struct udp_hslot *hslot = &udptable->hash[hash];
if (sk_hashed(sk)) {
struct udp_table *udptable = sk->sk_prot->h.udp_table;
unsigned int hash = udp_hashfn(sock_net(sk), sk->sk_hash);
struct udp_hslot *hslot = &udptable->hash[hash];

spin_lock_bh(&hslot->lock);
if (sk_nulls_del_node_init_rcu(sk)) {
inet_sk(sk)->num = 0;
sock_prot_inuse_add(sock_net(sk), sk->sk_prot, -1);
spin_lock_bh(&hslot->lock);
if (sk_nulls_del_node_init_rcu(sk)) {
inet_sk(sk)->num = 0;
sock_prot_inuse_add(sock_net(sk), sk->sk_prot, -1);
}
spin_unlock_bh(&hslot->lock);
}
spin_unlock_bh(&hslot->lock);
}
EXPORT_SYMBOL(udp_lib_unhash);

Expand Down

0 comments on commit 723b461

Please sign in to comment.