aboutsummaryrefslogtreecommitdiffstats
path: root/include
diff options
context:
space:
mode:
authorDavid S. Miller <davem@davemloft.net>2008-03-04 17:28:41 -0500
committerDavid S. Miller <davem@davemloft.net>2008-03-04 17:28:41 -0500
commit7adc3830f90df04a13366914d80a3ed407db5381 (patch)
tree811ce5e53634034a16d81bd34a8c80965abc28c7 /include
parentd9452e9f81e997cbd0c9bface8d2c2a4b064cc3e (diff)
[TCP]: Improve ipv4 established hash function.
If all of the entropy is in the local and foreign addresses, but xor'ing together would cancel out that entropy, the current hash performs poorly. Suggested by Cosmin Ratiu: Basically, the situation is as follows: There is a client machine and a server machine. Both create 15000 virtual interfaces, open up a socket for each pair of interfaces and do SIP traffic. By profiling I noticed that there is a lot of time spent walking the established hash chains with this particular setup. The addresses were distributed like this: client interfaces were 198.18.0.1/16 with increments of 1 and server interfaces were 198.18.128.1/16 with increments of 1. As I said, there were 15000 interfaces. Source and destination ports were 5060 for each connection. So in this case, ports don't matter for hashing purposes, and the bits from the address pairs used cancel each other, meaning there are no differences in the whole lot of pairs, so they all end up in the same hash chain. Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'include')
-rw-r--r--include/net/inet_sock.h3
1 files changed, 2 insertions, 1 deletions
diff --git a/include/net/inet_sock.h b/include/net/inet_sock.h
index 70013c5f4e59..89cd011edb99 100644
--- a/include/net/inet_sock.h
+++ b/include/net/inet_sock.h
@@ -175,7 +175,8 @@ extern void build_ehash_secret(void);
175static inline unsigned int inet_ehashfn(const __be32 laddr, const __u16 lport, 175static inline unsigned int inet_ehashfn(const __be32 laddr, const __u16 lport,
176 const __be32 faddr, const __be16 fport) 176 const __be32 faddr, const __be16 fport)
177{ 177{
178 return jhash_2words((__force __u32) laddr ^ (__force __u32) faddr, 178 return jhash_3words((__force __u32) laddr,
179 (__force __u32) faddr,
179 ((__u32) lport) << 16 | (__force __u32)fport, 180 ((__u32) lport) << 16 | (__force __u32)fport,
180 inet_ehash_secret); 181 inet_ehash_secret);
181} 182}