Skip to content

Commit

Permalink
fs/dcache.c: Save one 32-bit multiply in dcache lookup
Browse files Browse the repository at this point in the history
Noe that we're mixing in the parent pointer earlier, we
don't need to use hash_32() to mix its bits.  Instead, we can
just take the msbits of the hash value directly.

For those applications which use the partial_name_hash(),
move the multiply to end_name_hash.

Signed-off-by: George Spelvin <[email protected]>
Signed-off-by: Linus Torvalds <[email protected]>
  • Loading branch information
George Spelvin authored and torvalds committed Jun 11, 2016
1 parent 8387ff2 commit 703b5fa
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
2 changes: 1 addition & 1 deletion fs/dcache.c
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ static struct hlist_bl_head *dentry_hashtable __read_mostly;

static inline struct hlist_bl_head *d_hash(unsigned int hash)
{
return dentry_hashtable + hash_32(hash, d_hash_shift);
return dentry_hashtable + (hash >> (32 - d_hash_shift));
}

#define IN_LOOKUP_SHIFT 10
Expand Down
6 changes: 4 additions & 2 deletions include/linux/stringhash.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

#include <linux/compiler.h> /* For __pure */
#include <linux/types.h> /* For u32, u64 */
#include <linux/hash.h>

/*
* Routines for hashing strings of bytes to a 32-bit hash value.
Expand Down Expand Up @@ -45,11 +46,12 @@ partial_name_hash(unsigned long c, unsigned long prevhash)

/*
* Finally: cut down the number of bits to a int value (and try to avoid
* losing bits)
* losing bits). This also has the property (wanted by the dcache)
* that the msbits make a good hash table index.
*/
static inline unsigned long end_name_hash(unsigned long hash)
{
return (unsigned int)hash;
return __hash_32((unsigned int)hash);
}

/*
Expand Down

0 comments on commit 703b5fa

Please sign in to comment.