summaryrefslogtreecommitdiffstats
path: root/include/linux/hash.h
diff options
context:
space:
mode:
authorPavel Emelyanov <xemul@parallels.com>2012-08-08 21:52:28 +0000
committerDavid S. Miller <davem@davemloft.net>2012-08-09 16:18:06 -0700
commitb14f243a42c7aa43de71f878641acd003f223022 (patch)
tree13d052f3d3eab915c26eadd9a1f6997aef168998 /include/linux/hash.h
parenta399a8053164ec8bcb06fed52be9941a26ecde11 (diff)
downloadlinux-b14f243a42c7aa43de71f878641acd003f223022.tar.gz
linux-b14f243a42c7aa43de71f878641acd003f223022.tar.bz2
linux-b14f243a42c7aa43de71f878641acd003f223022.zip
net: Dont use ifindices in hash fns
Eric noticed, that when there will be devices with equal indices, some hash functions that use them will become less effective as they could. Fix this in advance by mixing the net_device address into the hash value instead of the device index. This is true for arp and ndisc hash fns. The netlabel, can and llc ones are also ifindex-based, but that three are init_net-only, thus will not be affected. Many thanks to David and Eric for the hash32_ptr implementation! Signed-off-by: Pavel Emelyanov <xemul@parallels.com> Signed-off-by: Eric Dumazet <edumazet@google.com> Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'include/linux/hash.h')
-rw-r--r--include/linux/hash.h10
1 files changed, 10 insertions, 0 deletions
diff --git a/include/linux/hash.h b/include/linux/hash.h
index b80506bdd733..24df9e70406f 100644
--- a/include/linux/hash.h
+++ b/include/linux/hash.h
@@ -67,4 +67,14 @@ static inline unsigned long hash_ptr(const void *ptr, unsigned int bits)
{
return hash_long((unsigned long)ptr, bits);
}
+
+static inline u32 hash32_ptr(const void *ptr)
+{
+ unsigned long val = (unsigned long)ptr;
+
+#if BITS_PER_LONG == 64
+ val ^= (val >> 32);
+#endif
+ return (u32)val;
+}
#endif /* _LINUX_HASH_H */