netdev: fold name hash properly (v3)
Subsystems (2)
PATCH 1/1 netdev: fold name hash properly (v3)
The full_name_hash function does not produce well distributed values in the lower bits, so most code uses hash_32() to fold it. This is really a bug introduced when name hashing was added, back in 2.5 when I added name hashing.
hash_32 is all that is needed since full_name_hash returns unsigned int which is only 32 bits on 64 bit platforms.
Also, there is no point in using hash_32 on ifindex, because the is naturally sequential and usually well distributed.
---
Patch against net-next-2.6
net/core/dev.c +2 -1
@@ -79,6 +79,7 @@#include <linux/cpu.h> #include <linux/types.h> #include <linux/kernel.h> +#include <linux/hash.h> #include <linux/sched.h> #include <linux/mutex.h> #include <linux/string.h>
@@ -196,7 +197,7 @@ EXPORT_SYMBOL(dev_base_lock);static inline struct hlist_head *dev_name_hash (struct net *net,const char *name) {unsigned hash =full_name_hash (name,strnlen (name,IFNAMSIZ )); -return &net->dev_name_head[hash & (NETDEV_HASHENTRIES -1 )]; +return &net->dev_name_head[hash_32 (hash,NETDEV_HASHBITS )]; }static inline struct hlist_head *dev_index_hash (struct net *net,int ifindex)
Quoted 5 lines · Stephen Hemminger
The
full_name_hashfunction does not produce well distributed values in the lower bits, so most code useshash_32()to fold it. This is really a bug introduced when name hashing was added, back in 2.5 when I added name hashing.
Quoted 8 lines
hash_32is all that is needed sincefull_name_hashreturns unsigned int which is only 32 bits on 64 bit platforms.Also, there is no point in using
hash_32on ifindex, because the is naturally sequential and usually well distributed.Signed-off-by Stephen Hemminger <[email protected]>
Thanks Stephen
From: Eric Dumazet <[email protected]>
Date: Tue, 10 Nov 2009 18:37:11 +0100
Quoted 9 lines
Quoted 8 lines · Stephen Hemminger
The
full_name_hashfunction does not produce well distributed values in the lower bits, so most code useshash_32()to fold it. This is really a bug introduced when name hashing was added, back in 2.5 when I added name hashing.
hash_32is all that is needed sincefull_name_hashreturns unsigned int which is only 32 bits on 64 bit platforms.
Quoted 7 lines
Quoted 5 lines
Also, there is no point in using
hash_32on ifindex, because the is naturally sequential and usually well distributed.Signed-off-by Stephen Hemminger <[email protected]>Signed-off-by Eric Dumazet <[email protected]>
Applied, thanks.