diff options
author | Eric Dumazet <dada1@cosmosbay.com> | 2005-10-03 17:13:38 -0400 |
---|---|---|
committer | David S. Miller <davem@davemloft.net> | 2005-10-03 17:13:38 -0400 |
commit | 81c3d5470ecc70564eb9209946730fe2be93ad06 (patch) | |
tree | 1efa553c305a6453769dacfaf580bc6ccf146d82 | |
parent | 399de50bbbb2501a6db43daaa8a2dafbc9bcfe0c (diff) |
[INET]: speedup inet (tcp/dccp) lookups
Arnaldo and I agreed it could be applied now, because I have other
pending patches depending on this one (Thank you Arnaldo)
(The other important patch moves skc_refcnt in a separate cache line,
so that the SMP/NUMA performance doesnt suffer from cache line ping pongs)
1) First some performance data :
--------------------------------
tcp_v4_rcv() wastes a *lot* of time in __inet_lookup_established()
The most time critical code is :
sk_for_each(sk, node, &head->chain) {
if (INET_MATCH(sk, acookie, saddr, daddr, ports, dif))
goto hit; /* You sunk my battleship! */
}
The sk_for_each() does use prefetch() hints but only the begining of
"struct sock" is prefetched.
As INET_MATCH first comparison uses inet_sk(__sk)->daddr, wich is far
away from the begining of "struct sock", it has to bring into CPU
cache cold cache line. Each iteration has to use at least 2 cache
lines.
This can be problematic if some chains are very long.
2) The goal
-----------
The idea I had is to change things so that INET_MATCH() may return
FALSE in 99% of cases only using the data already in the CPU cache,
using one cache line per iteration.
3) Description of the patch
---------------------------
Adds a new 'unsigned int skc_hash' field in 'struct sock_common',
filling a 32 bits hole on 64 bits platform.
struct sock_common {
unsigned short skc_family;
volatile unsigned char skc_state;
unsigned char skc_reuse;
int skc_bound_dev_if;
struct hlist_node skc_node;
struct hlist_node skc_bind_node;
atomic_t skc_refcnt;
+ unsigned int skc_hash;
struct proto *skc_prot;
};
Store in this 32 bits field the full hash, not masked by (ehash_size -
1) Using this full hash as the first comparison done in INET_MATCH
permits us immediatly skip the element without touching a second cache
line in case of a miss.
Suppress the sk_hashent/tw_hashent fields since skc_hash (aliased to
sk_hash and tw_hash) already contains the slot number if we mask with
(ehash_size - 1)
File include/net/inet_hashtables.h
64 bits platforms :
#define INET_MATCH(__sk, __hash, __cookie, __saddr, __daddr, __ports, __dif)\
(((__sk)->sk_hash == (__hash))
((*((__u64 *)&(inet_sk(__sk)->daddr)))== (__cookie)) && \
((*((__u32 *)&(inet_sk(__sk)->dport))) == (__ports)) && \
(!((__sk)->sk_bound_dev_if) || ((__sk)->sk_bound_dev_if == (__dif))))
32bits platforms:
#define TCP_IPV4_MATCH(__sk, __hash, __cookie, __saddr, __daddr, __ports, __dif)\
(((__sk)->sk_hash == (__hash)) && \
(inet_sk(__sk)->daddr == (__saddr)) && \
(inet_sk(__sk)->rcv_saddr == (__daddr)) && \
(!((__sk)->sk_bound_dev_if) || ((__sk)->sk_bound_dev_if == (__dif))))
- Adds a prefetch(head->chain.first) in
__inet_lookup_established()/__tcp_v4_check_established() and
__inet6_lookup_established()/__tcp_v6_check_established() and
__dccp_v4_check_established() to bring into cache the first element of the
list, before the {read|write}_lock(&head->lock);
Signed-off-by: Eric Dumazet <dada1@cosmosbay.com>
Acked-by: Arnaldo Carvalho de Melo <acme@ghostprotocols.net>
Signed-off-by: David S. Miller <davem@davemloft.net>
-rw-r--r-- | include/linux/ipv6.h | 5 | ||||
-rw-r--r-- | include/linux/tc_ematch/tc_em_meta.h | 2 | ||||
-rw-r--r-- | include/net/inet6_hashtables.h | 21 | ||||
-rw-r--r-- | include/net/inet_hashtables.h | 64 | ||||
-rw-r--r-- | include/net/inet_timewait_sock.h | 2 | ||||
-rw-r--r-- | include/net/sock.h | 5 | ||||
-rw-r--r-- | net/atm/common.c | 2 | ||||
-rw-r--r-- | net/dccp/ipv4.c | 12 | ||||
-rw-r--r-- | net/ipv4/inet_timewait_sock.c | 6 | ||||
-rw-r--r-- | net/ipv4/tcp_ipv4.c | 11 | ||||
-rw-r--r-- | net/ipv6/tcp_ipv6.c | 18 | ||||
-rw-r--r-- | net/sched/em_meta.c | 6 |
12 files changed, 85 insertions, 69 deletions
diff --git a/include/linux/ipv6.h b/include/linux/ipv6.h index bb6f88e14061..e0b922785d98 100644 --- a/include/linux/ipv6.h +++ b/include/linux/ipv6.h | |||
@@ -372,8 +372,9 @@ static inline struct raw6_sock *raw6_sk(const struct sock *sk) | |||
372 | #define inet_v6_ipv6only(__sk) 0 | 372 | #define inet_v6_ipv6only(__sk) 0 |
373 | #endif /* defined(CONFIG_IPV6) || defined(CONFIG_IPV6_MODULE) */ | 373 | #endif /* defined(CONFIG_IPV6) || defined(CONFIG_IPV6_MODULE) */ |
374 | 374 | ||
375 | #define INET6_MATCH(__sk, __saddr, __daddr, __ports, __dif) \ | 375 | #define INET6_MATCH(__sk, __hash, __saddr, __daddr, __ports, __dif)\ |
376 | (((*((__u32 *)&(inet_sk(__sk)->dport))) == (__ports)) && \ | 376 | (((__sk)->sk_hash == (__hash)) && \ |
377 | ((*((__u32 *)&(inet_sk(__sk)->dport))) == (__ports)) && \ | ||
377 | ((__sk)->sk_family == AF_INET6) && \ | 378 | ((__sk)->sk_family == AF_INET6) && \ |
378 | ipv6_addr_equal(&inet6_sk(__sk)->daddr, (__saddr)) && \ | 379 | ipv6_addr_equal(&inet6_sk(__sk)->daddr, (__saddr)) && \ |
379 | ipv6_addr_equal(&inet6_sk(__sk)->rcv_saddr, (__daddr)) && \ | 380 | ipv6_addr_equal(&inet6_sk(__sk)->rcv_saddr, (__daddr)) && \ |
diff --git a/include/linux/tc_ematch/tc_em_meta.h b/include/linux/tc_ematch/tc_em_meta.h index 081b1ee8516e..e21937cf91d0 100644 --- a/include/linux/tc_ematch/tc_em_meta.h +++ b/include/linux/tc_ematch/tc_em_meta.h | |||
@@ -71,7 +71,7 @@ enum | |||
71 | TCF_META_ID_SK_SNDBUF, | 71 | TCF_META_ID_SK_SNDBUF, |
72 | TCF_META_ID_SK_ALLOCS, | 72 | TCF_META_ID_SK_ALLOCS, |
73 | TCF_META_ID_SK_ROUTE_CAPS, | 73 | TCF_META_ID_SK_ROUTE_CAPS, |
74 | TCF_META_ID_SK_HASHENT, | 74 | TCF_META_ID_SK_HASH, |
75 | TCF_META_ID_SK_LINGERTIME, | 75 | TCF_META_ID_SK_LINGERTIME, |
76 | TCF_META_ID_SK_ACK_BACKLOG, | 76 | TCF_META_ID_SK_ACK_BACKLOG, |
77 | TCF_META_ID_SK_MAX_ACK_BACKLOG, | 77 | TCF_META_ID_SK_MAX_ACK_BACKLOG, |
diff --git a/include/net/inet6_hashtables.h b/include/net/inet6_hashtables.h index 03df3b157960..5a2beed5a770 100644 --- a/include/net/inet6_hashtables.h +++ b/include/net/inet6_hashtables.h | |||
@@ -26,19 +26,18 @@ | |||
26 | struct inet_hashinfo; | 26 | struct inet_hashinfo; |
27 | 27 | ||
28 | /* I have no idea if this is a good hash for v6 or not. -DaveM */ | 28 | /* I have no idea if this is a good hash for v6 or not. -DaveM */ |
29 | static inline int inet6_ehashfn(const struct in6_addr *laddr, const u16 lport, | 29 | static inline unsigned int inet6_ehashfn(const struct in6_addr *laddr, const u16 lport, |
30 | const struct in6_addr *faddr, const u16 fport, | 30 | const struct in6_addr *faddr, const u16 fport) |
31 | const int ehash_size) | ||
32 | { | 31 | { |
33 | int hashent = (lport ^ fport); | 32 | unsigned int hashent = (lport ^ fport); |
34 | 33 | ||
35 | hashent ^= (laddr->s6_addr32[3] ^ faddr->s6_addr32[3]); | 34 | hashent ^= (laddr->s6_addr32[3] ^ faddr->s6_addr32[3]); |
36 | hashent ^= hashent >> 16; | 35 | hashent ^= hashent >> 16; |
37 | hashent ^= hashent >> 8; | 36 | hashent ^= hashent >> 8; |
38 | return (hashent & (ehash_size - 1)); | 37 | return hashent; |
39 | } | 38 | } |
40 | 39 | ||
41 | static inline int inet6_sk_ehashfn(const struct sock *sk, const int ehash_size) | 40 | static inline int inet6_sk_ehashfn(const struct sock *sk) |
42 | { | 41 | { |
43 | const struct inet_sock *inet = inet_sk(sk); | 42 | const struct inet_sock *inet = inet_sk(sk); |
44 | const struct ipv6_pinfo *np = inet6_sk(sk); | 43 | const struct ipv6_pinfo *np = inet6_sk(sk); |
@@ -46,7 +45,7 @@ static inline int inet6_sk_ehashfn(const struct sock *sk, const int ehash_size) | |||
46 | const struct in6_addr *faddr = &np->daddr; | 45 | const struct in6_addr *faddr = &np->daddr; |
47 | const __u16 lport = inet->num; | 46 | const __u16 lport = inet->num; |
48 | const __u16 fport = inet->dport; | 47 | const __u16 fport = inet->dport; |
49 | return inet6_ehashfn(laddr, lport, faddr, fport, ehash_size); | 48 | return inet6_ehashfn(laddr, lport, faddr, fport); |
50 | } | 49 | } |
51 | 50 | ||
52 | /* | 51 | /* |
@@ -69,14 +68,14 @@ static inline struct sock * | |||
69 | /* Optimize here for direct hit, only listening connections can | 68 | /* Optimize here for direct hit, only listening connections can |
70 | * have wildcards anyways. | 69 | * have wildcards anyways. |
71 | */ | 70 | */ |
72 | const int hash = inet6_ehashfn(daddr, hnum, saddr, sport, | 71 | unsigned int hash = inet6_ehashfn(daddr, hnum, saddr, sport); |
73 | hashinfo->ehash_size); | 72 | struct inet_ehash_bucket *head = inet_ehash_bucket(hashinfo, hash); |
74 | struct inet_ehash_bucket *head = &hashinfo->ehash[hash]; | ||
75 | 73 | ||
74 | prefetch(head->chain.first); | ||
76 | read_lock(&head->lock); | 75 | read_lock(&head->lock); |
77 | sk_for_each(sk, node, &head->chain) { | 76 | sk_for_each(sk, node, &head->chain) { |
78 | /* For IPV6 do the cheaper port and family tests first. */ | 77 | /* For IPV6 do the cheaper port and family tests first. */ |
79 | if (INET6_MATCH(sk, saddr, daddr, ports, dif)) | 78 | if (INET6_MATCH(sk, hash, saddr, daddr, ports, dif)) |
80 | goto hit; /* You sunk my battleship! */ | 79 | goto hit; /* You sunk my battleship! */ |
81 | } | 80 | } |
82 | /* Must check for a TIME_WAIT'er before going to listener hash. */ | 81 | /* Must check for a TIME_WAIT'er before going to listener hash. */ |
diff --git a/include/net/inet_hashtables.h b/include/net/inet_hashtables.h index 646b6ea7fe26..35f49e65e295 100644 --- a/include/net/inet_hashtables.h +++ b/include/net/inet_hashtables.h | |||
@@ -108,7 +108,7 @@ struct inet_hashinfo { | |||
108 | struct inet_bind_hashbucket *bhash; | 108 | struct inet_bind_hashbucket *bhash; |
109 | 109 | ||
110 | int bhash_size; | 110 | int bhash_size; |
111 | int ehash_size; | 111 | unsigned int ehash_size; |
112 | 112 | ||
113 | /* All sockets in TCP_LISTEN state will be in here. This is the only | 113 | /* All sockets in TCP_LISTEN state will be in here. This is the only |
114 | * table where wildcard'd TCP sockets can exist. Hash function here | 114 | * table where wildcard'd TCP sockets can exist. Hash function here |
@@ -130,17 +130,16 @@ struct inet_hashinfo { | |||
130 | int port_rover; | 130 | int port_rover; |
131 | }; | 131 | }; |
132 | 132 | ||
133 | static inline int inet_ehashfn(const __u32 laddr, const __u16 lport, | 133 | static inline unsigned int inet_ehashfn(const __u32 laddr, const __u16 lport, |
134 | const __u32 faddr, const __u16 fport, | 134 | const __u32 faddr, const __u16 fport) |
135 | const int ehash_size) | ||
136 | { | 135 | { |
137 | int h = (laddr ^ lport) ^ (faddr ^ fport); | 136 | unsigned int h = (laddr ^ lport) ^ (faddr ^ fport); |
138 | h ^= h >> 16; | 137 | h ^= h >> 16; |
139 | h ^= h >> 8; | 138 | h ^= h >> 8; |
140 | return h & (ehash_size - 1); | 139 | return h; |
141 | } | 140 | } |
142 | 141 | ||
143 | static inline int inet_sk_ehashfn(const struct sock *sk, const int ehash_size) | 142 | static inline int inet_sk_ehashfn(const struct sock *sk) |
144 | { | 143 | { |
145 | const struct inet_sock *inet = inet_sk(sk); | 144 | const struct inet_sock *inet = inet_sk(sk); |
146 | const __u32 laddr = inet->rcv_saddr; | 145 | const __u32 laddr = inet->rcv_saddr; |
@@ -148,7 +147,14 @@ static inline int inet_sk_ehashfn(const struct sock *sk, const int ehash_size) | |||
148 | const __u32 faddr = inet->daddr; | 147 | const __u32 faddr = inet->daddr; |
149 | const __u16 fport = inet->dport; | 148 | const __u16 fport = inet->dport; |
150 | 149 | ||
151 | return inet_ehashfn(laddr, lport, faddr, fport, ehash_size); | 150 | return inet_ehashfn(laddr, lport, faddr, fport); |
151 | } | ||
152 | |||
153 | static inline struct inet_ehash_bucket *inet_ehash_bucket( | ||
154 | struct inet_hashinfo *hashinfo, | ||
155 | unsigned int hash) | ||
156 | { | ||
157 | return &hashinfo->ehash[hash & (hashinfo->ehash_size - 1)]; | ||
152 | } | 158 | } |
153 | 159 | ||
154 | extern struct inet_bind_bucket * | 160 | extern struct inet_bind_bucket * |
@@ -235,9 +241,11 @@ static inline void __inet_hash(struct inet_hashinfo *hashinfo, | |||
235 | lock = &hashinfo->lhash_lock; | 241 | lock = &hashinfo->lhash_lock; |
236 | inet_listen_wlock(hashinfo); | 242 | inet_listen_wlock(hashinfo); |
237 | } else { | 243 | } else { |
238 | sk->sk_hashent = inet_sk_ehashfn(sk, hashinfo->ehash_size); | 244 | struct inet_ehash_bucket *head; |
239 | list = &hashinfo->ehash[sk->sk_hashent].chain; | 245 | sk->sk_hash = inet_sk_ehashfn(sk); |
240 | lock = &hashinfo->ehash[sk->sk_hashent].lock; | 246 | head = inet_ehash_bucket(hashinfo, sk->sk_hash); |
247 | list = &head->chain; | ||
248 | lock = &head->lock; | ||
241 | write_lock(lock); | 249 | write_lock(lock); |
242 | } | 250 | } |
243 | __sk_add_node(sk, list); | 251 | __sk_add_node(sk, list); |
@@ -268,9 +276,8 @@ static inline void inet_unhash(struct inet_hashinfo *hashinfo, struct sock *sk) | |||
268 | inet_listen_wlock(hashinfo); | 276 | inet_listen_wlock(hashinfo); |
269 | lock = &hashinfo->lhash_lock; | 277 | lock = &hashinfo->lhash_lock; |
270 | } else { | 278 | } else { |
271 | struct inet_ehash_bucket *head = &hashinfo->ehash[sk->sk_hashent]; | 279 | lock = &inet_ehash_bucket(hashinfo, sk->sk_hash)->lock; |
272 | lock = &head->lock; | 280 | write_lock_bh(lock); |
273 | write_lock_bh(&head->lock); | ||
274 | } | 281 | } |
275 | 282 | ||
276 | if (__sk_del_node_init(sk)) | 283 | if (__sk_del_node_init(sk)) |
@@ -337,23 +344,27 @@ sherry_cache: | |||
337 | #define INET_ADDR_COOKIE(__name, __saddr, __daddr) \ | 344 | #define INET_ADDR_COOKIE(__name, __saddr, __daddr) \ |
338 | const __u64 __name = (((__u64)(__daddr)) << 32) | ((__u64)(__saddr)); | 345 | const __u64 __name = (((__u64)(__daddr)) << 32) | ((__u64)(__saddr)); |
339 | #endif /* __BIG_ENDIAN */ | 346 | #endif /* __BIG_ENDIAN */ |
340 | #define INET_MATCH(__sk, __cookie, __saddr, __daddr, __ports, __dif)\ | 347 | #define INET_MATCH(__sk, __hash, __cookie, __saddr, __daddr, __ports, __dif)\ |
341 | (((*((__u64 *)&(inet_sk(__sk)->daddr))) == (__cookie)) && \ | 348 | (((__sk)->sk_hash == (__hash)) && \ |
349 | ((*((__u64 *)&(inet_sk(__sk)->daddr))) == (__cookie)) && \ | ||
342 | ((*((__u32 *)&(inet_sk(__sk)->dport))) == (__ports)) && \ | 350 | ((*((__u32 *)&(inet_sk(__sk)->dport))) == (__ports)) && \ |
343 | (!((__sk)->sk_bound_dev_if) || ((__sk)->sk_bound_dev_if == (__dif)))) | 351 | (!((__sk)->sk_bound_dev_if) || ((__sk)->sk_bound_dev_if == (__dif)))) |
344 | #define INET_TW_MATCH(__sk, __cookie, __saddr, __daddr, __ports, __dif)\ | 352 | #define INET_TW_MATCH(__sk, __hash, __cookie, __saddr, __daddr, __ports, __dif)\ |
345 | (((*((__u64 *)&(inet_twsk(__sk)->tw_daddr))) == (__cookie)) && \ | 353 | (((__sk)->sk_hash == (__hash)) && \ |
354 | ((*((__u64 *)&(inet_twsk(__sk)->tw_daddr))) == (__cookie)) && \ | ||
346 | ((*((__u32 *)&(inet_twsk(__sk)->tw_dport))) == (__ports)) && \ | 355 | ((*((__u32 *)&(inet_twsk(__sk)->tw_dport))) == (__ports)) && \ |
347 | (!((__sk)->sk_bound_dev_if) || ((__sk)->sk_bound_dev_if == (__dif)))) | 356 | (!((__sk)->sk_bound_dev_if) || ((__sk)->sk_bound_dev_if == (__dif)))) |
348 | #else /* 32-bit arch */ | 357 | #else /* 32-bit arch */ |
349 | #define INET_ADDR_COOKIE(__name, __saddr, __daddr) | 358 | #define INET_ADDR_COOKIE(__name, __saddr, __daddr) |
350 | #define INET_MATCH(__sk, __cookie, __saddr, __daddr, __ports, __dif) \ | 359 | #define INET_MATCH(__sk, __hash, __cookie, __saddr, __daddr, __ports, __dif) \ |
351 | ((inet_sk(__sk)->daddr == (__saddr)) && \ | 360 | (((__sk)->sk_hash == (__hash)) && \ |
361 | (inet_sk(__sk)->daddr == (__saddr)) && \ | ||
352 | (inet_sk(__sk)->rcv_saddr == (__daddr)) && \ | 362 | (inet_sk(__sk)->rcv_saddr == (__daddr)) && \ |
353 | ((*((__u32 *)&(inet_sk(__sk)->dport))) == (__ports)) && \ | 363 | ((*((__u32 *)&(inet_sk(__sk)->dport))) == (__ports)) && \ |
354 | (!((__sk)->sk_bound_dev_if) || ((__sk)->sk_bound_dev_if == (__dif)))) | 364 | (!((__sk)->sk_bound_dev_if) || ((__sk)->sk_bound_dev_if == (__dif)))) |
355 | #define INET_TW_MATCH(__sk, __cookie, __saddr, __daddr, __ports, __dif) \ | 365 | #define INET_TW_MATCH(__sk, __hash,__cookie, __saddr, __daddr, __ports, __dif) \ |
356 | ((inet_twsk(__sk)->tw_daddr == (__saddr)) && \ | 366 | (((__sk)->sk_hash == (__hash)) && \ |
367 | (inet_twsk(__sk)->tw_daddr == (__saddr)) && \ | ||
357 | (inet_twsk(__sk)->tw_rcv_saddr == (__daddr)) && \ | 368 | (inet_twsk(__sk)->tw_rcv_saddr == (__daddr)) && \ |
358 | ((*((__u32 *)&(inet_twsk(__sk)->tw_dport))) == (__ports)) && \ | 369 | ((*((__u32 *)&(inet_twsk(__sk)->tw_dport))) == (__ports)) && \ |
359 | (!((__sk)->sk_bound_dev_if) || ((__sk)->sk_bound_dev_if == (__dif)))) | 370 | (!((__sk)->sk_bound_dev_if) || ((__sk)->sk_bound_dev_if == (__dif)))) |
@@ -378,18 +389,19 @@ static inline struct sock * | |||
378 | /* Optimize here for direct hit, only listening connections can | 389 | /* Optimize here for direct hit, only listening connections can |
379 | * have wildcards anyways. | 390 | * have wildcards anyways. |
380 | */ | 391 | */ |
381 | const int hash = inet_ehashfn(daddr, hnum, saddr, sport, hashinfo->ehash_size); | 392 | unsigned int hash = inet_ehashfn(daddr, hnum, saddr, sport); |
382 | struct inet_ehash_bucket *head = &hashinfo->ehash[hash]; | 393 | struct inet_ehash_bucket *head = inet_ehash_bucket(hashinfo, hash); |
383 | 394 | ||
395 | prefetch(head->chain.first); | ||
384 | read_lock(&head->lock); | 396 | read_lock(&head->lock); |
385 | sk_for_each(sk, node, &head->chain) { | 397 | sk_for_each(sk, node, &head->chain) { |
386 | if (INET_MATCH(sk, acookie, saddr, daddr, ports, dif)) | 398 | if (INET_MATCH(sk, hash, acookie, saddr, daddr, ports, dif)) |
387 | goto hit; /* You sunk my battleship! */ | 399 | goto hit; /* You sunk my battleship! */ |
388 | } | 400 | } |
389 | 401 | ||
390 | /* Must check for a TIME_WAIT'er before going to listener hash. */ | 402 | /* Must check for a TIME_WAIT'er before going to listener hash. */ |
391 | sk_for_each(sk, node, &(head + hashinfo->ehash_size)->chain) { | 403 | sk_for_each(sk, node, &(head + hashinfo->ehash_size)->chain) { |
392 | if (INET_TW_MATCH(sk, acookie, saddr, daddr, ports, dif)) | 404 | if (INET_TW_MATCH(sk, hash, acookie, saddr, daddr, ports, dif)) |
393 | goto hit; | 405 | goto hit; |
394 | } | 406 | } |
395 | sk = NULL; | 407 | sk = NULL; |
diff --git a/include/net/inet_timewait_sock.h b/include/net/inet_timewait_sock.h index 3b070352e869..4ade56ef3a4d 100644 --- a/include/net/inet_timewait_sock.h +++ b/include/net/inet_timewait_sock.h | |||
@@ -112,6 +112,7 @@ struct inet_timewait_sock { | |||
112 | #define tw_node __tw_common.skc_node | 112 | #define tw_node __tw_common.skc_node |
113 | #define tw_bind_node __tw_common.skc_bind_node | 113 | #define tw_bind_node __tw_common.skc_bind_node |
114 | #define tw_refcnt __tw_common.skc_refcnt | 114 | #define tw_refcnt __tw_common.skc_refcnt |
115 | #define tw_hash __tw_common.skc_hash | ||
115 | #define tw_prot __tw_common.skc_prot | 116 | #define tw_prot __tw_common.skc_prot |
116 | volatile unsigned char tw_substate; | 117 | volatile unsigned char tw_substate; |
117 | /* 3 bits hole, try to pack */ | 118 | /* 3 bits hole, try to pack */ |
@@ -126,7 +127,6 @@ struct inet_timewait_sock { | |||
126 | /* And these are ours. */ | 127 | /* And these are ours. */ |
127 | __u8 tw_ipv6only:1; | 128 | __u8 tw_ipv6only:1; |
128 | /* 31 bits hole, try to pack */ | 129 | /* 31 bits hole, try to pack */ |
129 | int tw_hashent; | ||
130 | int tw_timeout; | 130 | int tw_timeout; |
131 | unsigned long tw_ttd; | 131 | unsigned long tw_ttd; |
132 | struct inet_bind_bucket *tw_tb; | 132 | struct inet_bind_bucket *tw_tb; |
diff --git a/include/net/sock.h b/include/net/sock.h index 8c48fbecb7cf..b6440805c420 100644 --- a/include/net/sock.h +++ b/include/net/sock.h | |||
@@ -99,6 +99,7 @@ struct proto; | |||
99 | * @skc_node: main hash linkage for various protocol lookup tables | 99 | * @skc_node: main hash linkage for various protocol lookup tables |
100 | * @skc_bind_node: bind hash linkage for various protocol lookup tables | 100 | * @skc_bind_node: bind hash linkage for various protocol lookup tables |
101 | * @skc_refcnt: reference count | 101 | * @skc_refcnt: reference count |
102 | * @skc_hash: hash value used with various protocol lookup tables | ||
102 | * @skc_prot: protocol handlers inside a network family | 103 | * @skc_prot: protocol handlers inside a network family |
103 | * | 104 | * |
104 | * This is the minimal network layer representation of sockets, the header | 105 | * This is the minimal network layer representation of sockets, the header |
@@ -112,6 +113,7 @@ struct sock_common { | |||
112 | struct hlist_node skc_node; | 113 | struct hlist_node skc_node; |
113 | struct hlist_node skc_bind_node; | 114 | struct hlist_node skc_bind_node; |
114 | atomic_t skc_refcnt; | 115 | atomic_t skc_refcnt; |
116 | unsigned int skc_hash; | ||
115 | struct proto *skc_prot; | 117 | struct proto *skc_prot; |
116 | }; | 118 | }; |
117 | 119 | ||
@@ -139,7 +141,6 @@ struct sock_common { | |||
139 | * @sk_no_check: %SO_NO_CHECK setting, wether or not checkup packets | 141 | * @sk_no_check: %SO_NO_CHECK setting, wether or not checkup packets |
140 | * @sk_route_caps: route capabilities (e.g. %NETIF_F_TSO) | 142 | * @sk_route_caps: route capabilities (e.g. %NETIF_F_TSO) |
141 | * @sk_lingertime: %SO_LINGER l_linger setting | 143 | * @sk_lingertime: %SO_LINGER l_linger setting |
142 | * @sk_hashent: hash entry in several tables (e.g. inet_hashinfo.ehash) | ||
143 | * @sk_backlog: always used with the per-socket spinlock held | 144 | * @sk_backlog: always used with the per-socket spinlock held |
144 | * @sk_callback_lock: used with the callbacks in the end of this struct | 145 | * @sk_callback_lock: used with the callbacks in the end of this struct |
145 | * @sk_error_queue: rarely used | 146 | * @sk_error_queue: rarely used |
@@ -186,6 +187,7 @@ struct sock { | |||
186 | #define sk_node __sk_common.skc_node | 187 | #define sk_node __sk_common.skc_node |
187 | #define sk_bind_node __sk_common.skc_bind_node | 188 | #define sk_bind_node __sk_common.skc_bind_node |
188 | #define sk_refcnt __sk_common.skc_refcnt | 189 | #define sk_refcnt __sk_common.skc_refcnt |
190 | #define sk_hash __sk_common.skc_hash | ||
189 | #define sk_prot __sk_common.skc_prot | 191 | #define sk_prot __sk_common.skc_prot |
190 | unsigned char sk_shutdown : 2, | 192 | unsigned char sk_shutdown : 2, |
191 | sk_no_check : 2, | 193 | sk_no_check : 2, |
@@ -208,7 +210,6 @@ struct sock { | |||
208 | unsigned int sk_allocation; | 210 | unsigned int sk_allocation; |
209 | int sk_sndbuf; | 211 | int sk_sndbuf; |
210 | int sk_route_caps; | 212 | int sk_route_caps; |
211 | int sk_hashent; | ||
212 | unsigned long sk_flags; | 213 | unsigned long sk_flags; |
213 | unsigned long sk_lingertime; | 214 | unsigned long sk_lingertime; |
214 | /* | 215 | /* |
diff --git a/net/atm/common.c b/net/atm/common.c index 801a5813ec60..63feea49fb13 100644 --- a/net/atm/common.c +++ b/net/atm/common.c | |||
@@ -46,7 +46,7 @@ static void __vcc_insert_socket(struct sock *sk) | |||
46 | struct atm_vcc *vcc = atm_sk(sk); | 46 | struct atm_vcc *vcc = atm_sk(sk); |
47 | struct hlist_head *head = &vcc_hash[vcc->vci & | 47 | struct hlist_head *head = &vcc_hash[vcc->vci & |
48 | (VCC_HTABLE_SIZE - 1)]; | 48 | (VCC_HTABLE_SIZE - 1)]; |
49 | sk->sk_hashent = vcc->vci & (VCC_HTABLE_SIZE - 1); | 49 | sk->sk_hash = vcc->vci & (VCC_HTABLE_SIZE - 1); |
50 | sk_add_node(sk, head); | 50 | sk_add_node(sk, head); |
51 | } | 51 | } |
52 | 52 | ||
diff --git a/net/dccp/ipv4.c b/net/dccp/ipv4.c index 40fe6afacde6..ae088d1347af 100644 --- a/net/dccp/ipv4.c +++ b/net/dccp/ipv4.c | |||
@@ -62,27 +62,27 @@ static int __dccp_v4_check_established(struct sock *sk, const __u16 lport, | |||
62 | const int dif = sk->sk_bound_dev_if; | 62 | const int dif = sk->sk_bound_dev_if; |
63 | INET_ADDR_COOKIE(acookie, saddr, daddr) | 63 | INET_ADDR_COOKIE(acookie, saddr, daddr) |
64 | const __u32 ports = INET_COMBINED_PORTS(inet->dport, lport); | 64 | const __u32 ports = INET_COMBINED_PORTS(inet->dport, lport); |
65 | const int hash = inet_ehashfn(daddr, lport, saddr, inet->dport, | 65 | unsigned int hash = inet_ehashfn(daddr, lport, saddr, inet->dport); |
66 | dccp_hashinfo.ehash_size); | 66 | struct inet_ehash_bucket *head = inet_ehash_bucket(&dccp_hashinfo, hash); |
67 | struct inet_ehash_bucket *head = &dccp_hashinfo.ehash[hash]; | ||
68 | const struct sock *sk2; | 67 | const struct sock *sk2; |
69 | const struct hlist_node *node; | 68 | const struct hlist_node *node; |
70 | struct inet_timewait_sock *tw; | 69 | struct inet_timewait_sock *tw; |
71 | 70 | ||
71 | prefetch(head->chain.first); | ||
72 | write_lock(&head->lock); | 72 | write_lock(&head->lock); |
73 | 73 | ||
74 | /* Check TIME-WAIT sockets first. */ | 74 | /* Check TIME-WAIT sockets first. */ |
75 | sk_for_each(sk2, node, &(head + dccp_hashinfo.ehash_size)->chain) { | 75 | sk_for_each(sk2, node, &(head + dccp_hashinfo.ehash_size)->chain) { |
76 | tw = inet_twsk(sk2); | 76 | tw = inet_twsk(sk2); |
77 | 77 | ||
78 | if (INET_TW_MATCH(sk2, acookie, saddr, daddr, ports, dif)) | 78 | if (INET_TW_MATCH(sk2, hash, acookie, saddr, daddr, ports, dif)) |
79 | goto not_unique; | 79 | goto not_unique; |
80 | } | 80 | } |
81 | tw = NULL; | 81 | tw = NULL; |
82 | 82 | ||
83 | /* And established part... */ | 83 | /* And established part... */ |
84 | sk_for_each(sk2, node, &head->chain) { | 84 | sk_for_each(sk2, node, &head->chain) { |
85 | if (INET_MATCH(sk2, acookie, saddr, daddr, ports, dif)) | 85 | if (INET_MATCH(sk2, hash, acookie, saddr, daddr, ports, dif)) |
86 | goto not_unique; | 86 | goto not_unique; |
87 | } | 87 | } |
88 | 88 | ||
@@ -90,7 +90,7 @@ static int __dccp_v4_check_established(struct sock *sk, const __u16 lport, | |||
90 | * in hash table socket with a funny identity. */ | 90 | * in hash table socket with a funny identity. */ |
91 | inet->num = lport; | 91 | inet->num = lport; |
92 | inet->sport = htons(lport); | 92 | inet->sport = htons(lport); |
93 | sk->sk_hashent = hash; | 93 | sk->sk_hash = hash; |
94 | BUG_TRAP(sk_unhashed(sk)); | 94 | BUG_TRAP(sk_unhashed(sk)); |
95 | __sk_add_node(sk, &head->chain); | 95 | __sk_add_node(sk, &head->chain); |
96 | sock_prot_inc_use(sk->sk_prot); | 96 | sock_prot_inc_use(sk->sk_prot); |
diff --git a/net/ipv4/inet_timewait_sock.c b/net/ipv4/inet_timewait_sock.c index 4d1502a49852..f9076ef3a1a8 100644 --- a/net/ipv4/inet_timewait_sock.c +++ b/net/ipv4/inet_timewait_sock.c | |||
@@ -20,7 +20,7 @@ void __inet_twsk_kill(struct inet_timewait_sock *tw, struct inet_hashinfo *hashi | |||
20 | struct inet_bind_hashbucket *bhead; | 20 | struct inet_bind_hashbucket *bhead; |
21 | struct inet_bind_bucket *tb; | 21 | struct inet_bind_bucket *tb; |
22 | /* Unlink from established hashes. */ | 22 | /* Unlink from established hashes. */ |
23 | struct inet_ehash_bucket *ehead = &hashinfo->ehash[tw->tw_hashent]; | 23 | struct inet_ehash_bucket *ehead = inet_ehash_bucket(hashinfo, tw->tw_hash); |
24 | 24 | ||
25 | write_lock(&ehead->lock); | 25 | write_lock(&ehead->lock); |
26 | if (hlist_unhashed(&tw->tw_node)) { | 26 | if (hlist_unhashed(&tw->tw_node)) { |
@@ -60,7 +60,7 @@ void __inet_twsk_hashdance(struct inet_timewait_sock *tw, struct sock *sk, | |||
60 | { | 60 | { |
61 | const struct inet_sock *inet = inet_sk(sk); | 61 | const struct inet_sock *inet = inet_sk(sk); |
62 | const struct inet_connection_sock *icsk = inet_csk(sk); | 62 | const struct inet_connection_sock *icsk = inet_csk(sk); |
63 | struct inet_ehash_bucket *ehead = &hashinfo->ehash[sk->sk_hashent]; | 63 | struct inet_ehash_bucket *ehead = inet_ehash_bucket(hashinfo, sk->sk_hash); |
64 | struct inet_bind_hashbucket *bhead; | 64 | struct inet_bind_hashbucket *bhead; |
65 | /* Step 1: Put TW into bind hash. Original socket stays there too. | 65 | /* Step 1: Put TW into bind hash. Original socket stays there too. |
66 | Note, that any socket with inet->num != 0 MUST be bound in | 66 | Note, that any socket with inet->num != 0 MUST be bound in |
@@ -106,7 +106,7 @@ struct inet_timewait_sock *inet_twsk_alloc(const struct sock *sk, const int stat | |||
106 | tw->tw_dport = inet->dport; | 106 | tw->tw_dport = inet->dport; |
107 | tw->tw_family = sk->sk_family; | 107 | tw->tw_family = sk->sk_family; |
108 | tw->tw_reuse = sk->sk_reuse; | 108 | tw->tw_reuse = sk->sk_reuse; |
109 | tw->tw_hashent = sk->sk_hashent; | 109 | tw->tw_hash = sk->sk_hash; |
110 | tw->tw_ipv6only = 0; | 110 | tw->tw_ipv6only = 0; |
111 | tw->tw_prot = sk->sk_prot_creator; | 111 | tw->tw_prot = sk->sk_prot_creator; |
112 | atomic_set(&tw->tw_refcnt, 1); | 112 | atomic_set(&tw->tw_refcnt, 1); |
diff --git a/net/ipv4/tcp_ipv4.c b/net/ipv4/tcp_ipv4.c index 13dfb391cdf1..c85819d8474b 100644 --- a/net/ipv4/tcp_ipv4.c +++ b/net/ipv4/tcp_ipv4.c | |||
@@ -130,19 +130,20 @@ static int __tcp_v4_check_established(struct sock *sk, __u16 lport, | |||
130 | int dif = sk->sk_bound_dev_if; | 130 | int dif = sk->sk_bound_dev_if; |
131 | INET_ADDR_COOKIE(acookie, saddr, daddr) | 131 | INET_ADDR_COOKIE(acookie, saddr, daddr) |
132 | const __u32 ports = INET_COMBINED_PORTS(inet->dport, lport); | 132 | const __u32 ports = INET_COMBINED_PORTS(inet->dport, lport); |
133 | const int hash = inet_ehashfn(daddr, lport, saddr, inet->dport, tcp_hashinfo.ehash_size); | 133 | unsigned int hash = inet_ehashfn(daddr, lport, saddr, inet->dport); |
134 | struct inet_ehash_bucket *head = &tcp_hashinfo.ehash[hash]; | 134 | struct inet_ehash_bucket *head = inet_ehash_bucket(&tcp_hashinfo, hash); |
135 | struct sock *sk2; | 135 | struct sock *sk2; |
136 | const struct hlist_node *node; | 136 | const struct hlist_node *node; |
137 | struct inet_timewait_sock *tw; | 137 | struct inet_timewait_sock *tw; |
138 | 138 | ||
139 | prefetch(head->chain.first); | ||
139 | write_lock(&head->lock); | 140 | write_lock(&head->lock); |
140 | 141 | ||
141 | /* Check TIME-WAIT sockets first. */ | 142 | /* Check TIME-WAIT sockets first. */ |
142 | sk_for_each(sk2, node, &(head + tcp_hashinfo.ehash_size)->chain) { | 143 | sk_for_each(sk2, node, &(head + tcp_hashinfo.ehash_size)->chain) { |
143 | tw = inet_twsk(sk2); | 144 | tw = inet_twsk(sk2); |
144 | 145 | ||
145 | if (INET_TW_MATCH(sk2, acookie, saddr, daddr, ports, dif)) { | 146 | if (INET_TW_MATCH(sk2, hash, acookie, saddr, daddr, ports, dif)) { |
146 | const struct tcp_timewait_sock *tcptw = tcp_twsk(sk2); | 147 | const struct tcp_timewait_sock *tcptw = tcp_twsk(sk2); |
147 | struct tcp_sock *tp = tcp_sk(sk); | 148 | struct tcp_sock *tp = tcp_sk(sk); |
148 | 149 | ||
@@ -179,7 +180,7 @@ static int __tcp_v4_check_established(struct sock *sk, __u16 lport, | |||
179 | 180 | ||
180 | /* And established part... */ | 181 | /* And established part... */ |
181 | sk_for_each(sk2, node, &head->chain) { | 182 | sk_for_each(sk2, node, &head->chain) { |
182 | if (INET_MATCH(sk2, acookie, saddr, daddr, ports, dif)) | 183 | if (INET_MATCH(sk2, hash, acookie, saddr, daddr, ports, dif)) |
183 | goto not_unique; | 184 | goto not_unique; |
184 | } | 185 | } |
185 | 186 | ||
@@ -188,7 +189,7 @@ unique: | |||
188 | * in hash table socket with a funny identity. */ | 189 | * in hash table socket with a funny identity. */ |
189 | inet->num = lport; | 190 | inet->num = lport; |
190 | inet->sport = htons(lport); | 191 | inet->sport = htons(lport); |
191 | sk->sk_hashent = hash; | 192 | sk->sk_hash = hash; |
192 | BUG_TRAP(sk_unhashed(sk)); | 193 | BUG_TRAP(sk_unhashed(sk)); |
193 | __sk_add_node(sk, &head->chain); | 194 | __sk_add_node(sk, &head->chain); |
194 | sock_prot_inc_use(sk->sk_prot); | 195 | sock_prot_inc_use(sk->sk_prot); |
diff --git a/net/ipv6/tcp_ipv6.c b/net/ipv6/tcp_ipv6.c index 80643e6b346b..d693cb988b78 100644 --- a/net/ipv6/tcp_ipv6.c +++ b/net/ipv6/tcp_ipv6.c | |||
@@ -209,9 +209,11 @@ static __inline__ void __tcp_v6_hash(struct sock *sk) | |||
209 | lock = &tcp_hashinfo.lhash_lock; | 209 | lock = &tcp_hashinfo.lhash_lock; |
210 | inet_listen_wlock(&tcp_hashinfo); | 210 | inet_listen_wlock(&tcp_hashinfo); |
211 | } else { | 211 | } else { |
212 | sk->sk_hashent = inet6_sk_ehashfn(sk, tcp_hashinfo.ehash_size); | 212 | unsigned int hash; |
213 | list = &tcp_hashinfo.ehash[sk->sk_hashent].chain; | 213 | sk->sk_hash = hash = inet6_sk_ehashfn(sk); |
214 | lock = &tcp_hashinfo.ehash[sk->sk_hashent].lock; | 214 | hash &= (tcp_hashinfo.ehash_size - 1); |
215 | list = &tcp_hashinfo.ehash[hash].chain; | ||
216 | lock = &tcp_hashinfo.ehash[hash].lock; | ||
215 | write_lock(lock); | 217 | write_lock(lock); |
216 | } | 218 | } |
217 | 219 | ||
@@ -322,13 +324,13 @@ static int __tcp_v6_check_established(struct sock *sk, const __u16 lport, | |||
322 | const struct in6_addr *saddr = &np->daddr; | 324 | const struct in6_addr *saddr = &np->daddr; |
323 | const int dif = sk->sk_bound_dev_if; | 325 | const int dif = sk->sk_bound_dev_if; |
324 | const u32 ports = INET_COMBINED_PORTS(inet->dport, lport); | 326 | const u32 ports = INET_COMBINED_PORTS(inet->dport, lport); |
325 | const int hash = inet6_ehashfn(daddr, inet->num, saddr, inet->dport, | 327 | unsigned int hash = inet6_ehashfn(daddr, inet->num, saddr, inet->dport); |
326 | tcp_hashinfo.ehash_size); | 328 | struct inet_ehash_bucket *head = inet_ehash_bucket(&tcp_hashinfo, hash); |
327 | struct inet_ehash_bucket *head = &tcp_hashinfo.ehash[hash]; | ||
328 | struct sock *sk2; | 329 | struct sock *sk2; |
329 | const struct hlist_node *node; | 330 | const struct hlist_node *node; |
330 | struct inet_timewait_sock *tw; | 331 | struct inet_timewait_sock *tw; |
331 | 332 | ||
333 | prefetch(head->chain.first); | ||
332 | write_lock(&head->lock); | 334 | write_lock(&head->lock); |
333 | 335 | ||
334 | /* Check TIME-WAIT sockets first. */ | 336 | /* Check TIME-WAIT sockets first. */ |
@@ -365,14 +367,14 @@ static int __tcp_v6_check_established(struct sock *sk, const __u16 lport, | |||
365 | 367 | ||
366 | /* And established part... */ | 368 | /* And established part... */ |
367 | sk_for_each(sk2, node, &head->chain) { | 369 | sk_for_each(sk2, node, &head->chain) { |
368 | if (INET6_MATCH(sk2, saddr, daddr, ports, dif)) | 370 | if (INET6_MATCH(sk2, hash, saddr, daddr, ports, dif)) |
369 | goto not_unique; | 371 | goto not_unique; |
370 | } | 372 | } |
371 | 373 | ||
372 | unique: | 374 | unique: |
373 | BUG_TRAP(sk_unhashed(sk)); | 375 | BUG_TRAP(sk_unhashed(sk)); |
374 | __sk_add_node(sk, &head->chain); | 376 | __sk_add_node(sk, &head->chain); |
375 | sk->sk_hashent = hash; | 377 | sk->sk_hash = hash; |
376 | sock_prot_inc_use(sk->sk_prot); | 378 | sock_prot_inc_use(sk->sk_prot); |
377 | write_unlock(&head->lock); | 379 | write_unlock(&head->lock); |
378 | 380 | ||
diff --git a/net/sched/em_meta.c b/net/sched/em_meta.c index 00eae5f9a01a..cf68a59fdc5a 100644 --- a/net/sched/em_meta.c +++ b/net/sched/em_meta.c | |||
@@ -393,10 +393,10 @@ META_COLLECTOR(int_sk_route_caps) | |||
393 | dst->value = skb->sk->sk_route_caps; | 393 | dst->value = skb->sk->sk_route_caps; |
394 | } | 394 | } |
395 | 395 | ||
396 | META_COLLECTOR(int_sk_hashent) | 396 | META_COLLECTOR(int_sk_hash) |
397 | { | 397 | { |
398 | SKIP_NONLOCAL(skb); | 398 | SKIP_NONLOCAL(skb); |
399 | dst->value = skb->sk->sk_hashent; | 399 | dst->value = skb->sk->sk_hash; |
400 | } | 400 | } |
401 | 401 | ||
402 | META_COLLECTOR(int_sk_lingertime) | 402 | META_COLLECTOR(int_sk_lingertime) |
@@ -515,7 +515,7 @@ static struct meta_ops __meta_ops[TCF_META_TYPE_MAX+1][TCF_META_ID_MAX+1] = { | |||
515 | [META_ID(SK_FORWARD_ALLOCS)] = META_FUNC(int_sk_fwd_alloc), | 515 | [META_ID(SK_FORWARD_ALLOCS)] = META_FUNC(int_sk_fwd_alloc), |
516 | [META_ID(SK_ALLOCS)] = META_FUNC(int_sk_alloc), | 516 | [META_ID(SK_ALLOCS)] = META_FUNC(int_sk_alloc), |
517 | [META_ID(SK_ROUTE_CAPS)] = META_FUNC(int_sk_route_caps), | 517 | [META_ID(SK_ROUTE_CAPS)] = META_FUNC(int_sk_route_caps), |
518 | [META_ID(SK_HASHENT)] = META_FUNC(int_sk_hashent), | 518 | [META_ID(SK_HASH)] = META_FUNC(int_sk_hash), |
519 | [META_ID(SK_LINGERTIME)] = META_FUNC(int_sk_lingertime), | 519 | [META_ID(SK_LINGERTIME)] = META_FUNC(int_sk_lingertime), |
520 | [META_ID(SK_ACK_BACKLOG)] = META_FUNC(int_sk_ack_bl), | 520 | [META_ID(SK_ACK_BACKLOG)] = META_FUNC(int_sk_ack_bl), |
521 | [META_ID(SK_MAX_ACK_BACKLOG)] = META_FUNC(int_sk_max_ack_bl), | 521 | [META_ID(SK_MAX_ACK_BACKLOG)] = META_FUNC(int_sk_max_ack_bl), |