From: Eric Dumazet <dada1@cosmosbay.com>
To: David Miller <davem@davemloft.net>
Cc: netdev@vger.kernel.org
Subject: [PATCH] NET : UDP can use sk_hash to speedup lookups
Date: Fri, 9 Feb 2007 18:44:16 +0100 [thread overview]
Message-ID: <200702091844.16803.dada1@cosmosbay.com> (raw)
In-Reply-To: <20070209.014344.63999119.davem@davemloft.net>
[-- Attachment #1: Type: text/plain, Size: 609 bytes --]
In a prior patch, I introduced a sk_hash field (__sk_common.skc_hash) to let
tcp lookups use one cache line per unmatched entry instead of two.
We can also use sk_hash to speedup UDP part as well. We store in sk_hash the
hnum value, and use sk->sk_hash (same cache line than 'next' pointer),
instead of inet->num (different cache line)
Note : We still have a false sharing problem for SMP machines, because
sock_hold(sock) dirties the cache line containing the 'next' pointer. Not
counting the udp_hash_lock rwlock. (did someone mentioned RCU ? :) )
Signed-off-by: Eric Dumazet <dada1@cosmosbay.com>
[-- Attachment #2: udp_can_use_sk_hash.patch --]
[-- Type: text/plain, Size: 2586 bytes --]
--- linux-2.6.20/net/ipv4/udp.c 2007-02-09 19:17:28.000000000 +0100
+++ linux-2.6.20-ed/net/ipv4/udp.c 2007-02-09 19:21:07.000000000 +0100
@@ -120,7 +120,7 @@ static inline int __udp_lib_lport_inuse(
struct hlist_node *node;
sk_for_each(sk, node, &udptable[num & (UDP_HTABLE_SIZE - 1)])
- if (inet_sk(sk)->num == num)
+ if (sk->sk_hash == num)
return 1;
return 0;
}
@@ -191,7 +191,7 @@ gotit:
head = &udptable[snum & (UDP_HTABLE_SIZE - 1)];
sk_for_each(sk2, node, head)
- if (inet_sk(sk2)->num == snum &&
+ if (sk2->sk_hash == snum &&
sk2 != sk &&
(!sk2->sk_reuse || !sk->sk_reuse) &&
(!sk2->sk_bound_dev_if || !sk->sk_bound_dev_if
@@ -200,6 +200,7 @@ gotit:
goto fail;
}
inet_sk(sk)->num = snum;
+ sk->sk_hash = snum;
if (sk_unhashed(sk)) {
head = &udptable[snum & (UDP_HTABLE_SIZE - 1)];
sk_add_node(sk, head);
@@ -247,7 +248,7 @@ static struct sock *__udp4_lib_lookup(__
sk_for_each(sk, node, &udptable[hnum & (UDP_HTABLE_SIZE - 1)]) {
struct inet_sock *inet = inet_sk(sk);
- if (inet->num == hnum && !ipv6_only_sock(sk)) {
+ if (sk->sk_hash == hnum && !ipv6_only_sock(sk)) {
int score = (sk->sk_family == PF_INET ? 1 : 0);
if (inet->rcv_saddr) {
if (inet->rcv_saddr != daddr)
@@ -296,7 +297,7 @@ static inline struct sock *udp_v4_mcast_
sk_for_each_from(s, node) {
struct inet_sock *inet = inet_sk(s);
- if (inet->num != hnum ||
+ if (s->sk_hash != hnum ||
(inet->daddr && inet->daddr != rmt_addr) ||
(inet->dport != rmt_port && inet->dport) ||
(inet->rcv_saddr && inet->rcv_saddr != loc_addr) ||
--- linux-2.6.20/net/ipv6/udp.c 2007-02-09 19:17:28.000000000 +0100
+++ linux-2.6.20-ed/net/ipv6/udp.c 2007-02-09 19:17:28.000000000 +0100
@@ -71,7 +71,7 @@ static struct sock *__udp6_lib_lookup(st
sk_for_each(sk, node, &udptable[hnum & (UDP_HTABLE_SIZE - 1)]) {
struct inet_sock *inet = inet_sk(sk);
- if (inet->num == hnum && sk->sk_family == PF_INET6) {
+ if (sk->sk_hash == hnum && sk->sk_family == PF_INET6) {
struct ipv6_pinfo *np = inet6_sk(sk);
int score = 0;
if (inet->dport) {
@@ -309,7 +309,7 @@ static struct sock *udp_v6_mcast_next(st
sk_for_each_from(s, node) {
struct inet_sock *inet = inet_sk(s);
- if (inet->num == num && s->sk_family == PF_INET6) {
+ if (s->sk_hash == num && s->sk_family == PF_INET6) {
struct ipv6_pinfo *np = inet6_sk(s);
if (inet->dport) {
if (inet->dport != rmt_port)
next prev parent reply other threads:[~2007-02-09 17:44 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2006-12-19 8:56 [PATCH] irlan: handle out of memory errors Akinobu Mita
2006-12-19 22:47 ` Samuel Ortiz
2007-02-07 8:12 ` David Miller
2007-02-07 10:59 ` [PATCH] NET : change layout of ehash table Eric Dumazet
2007-02-08 22:56 ` David Miller
2007-02-09 9:18 ` Andi Kleen
2007-02-09 8:40 ` David Miller
2007-02-09 8:57 ` Andi Kleen
2007-02-09 9:06 ` Eric Dumazet
2007-02-09 9:15 ` David Miller
2007-02-09 9:36 ` Eric Dumazet
2007-02-09 9:43 ` David Miller
2007-02-09 10:10 ` Andi Kleen
2007-02-09 17:44 ` Eric Dumazet [this message]
2007-02-09 23:45 ` [PATCH] NET : UDP can use sk_hash to speedup lookups 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=200702091844.16803.dada1@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.