From: Eric Dumazet <dada1@cosmosbay.com>
To: "David S. Miller" <davem@davemloft.net>
Cc: Linux Netdev List <netdev@vger.kernel.org>
Subject: [PATCH] net: udp_unhash() can test if sk is hashed
Date: Tue, 25 Nov 2008 21:25:55 +0100 [thread overview]
Message-ID: <492C5F53.2090901@cosmosbay.com> (raw)
[-- Attachment #1: Type: text/plain, Size: 324 bytes --]
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>
---
net/ipv4/udp.c | 18 ++++++++++--------
1 files changed, 10 insertions(+), 8 deletions(-)
[-- Attachment #2: udp_unhash.patch --]
[-- Type: text/plain, Size: 1010 bytes --]
diff --git a/net/ipv4/udp.c b/net/ipv4/udp.c
index da869ce..e2ab258 100644
--- a/net/ipv4/udp.c
+++ b/net/ipv4/udp.c
@@ -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);
next reply other threads:[~2008-11-25 20:26 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-11-25 20:25 Eric Dumazet [this message]
2008-11-25 21:55 ` [PATCH] net: udp_unhash() can test if sk is hashed David Miller
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=492C5F53.2090901@cosmosbay.com \
--to=dada1@cosmosbay.com \
--cc=davem@davemloft.net \
--cc=netdev@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.