summaryrefslogtreecommitdiffstats
path: root/fs/dcache.c
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@linux-foundation.org>2016-06-10 10:51:30 -0400
committerLinus Torvalds <torvalds@linux-foundation.org>2016-06-10 23:21:46 -0400
commit8387ff2577eb9ed245df9a39947f66976c6bcd02 (patch)
tree79fafcb5777f16e520d1c39e9389039f866b4c6d /fs/dcache.c
parent147d9e7bcad3b8d5465f6eea6292731e7f35dee8 (diff)
vfs: make the string hashes salt the hash
We always mixed in the parent pointer into the dentry name hash, but we did it late at lookup time. It turns out that we can simplify that lookup-time action by salting the hash with the parent pointer early instead of late. A few other users of our string hashes also wanted to mix in their own pointers into the hash, and those are updated to use the same mechanism. Hash users that don't have any particular initial salt can just use the NULL pointer as a no-salt. Cc: Vegard Nossum <vegard.nossum@oracle.com> Cc: George Spelvin <linux@sciencehorizons.net> Cc: Al Viro <viro@zeniv.linux.org.uk> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'fs/dcache.c')
-rw-r--r--fs/dcache.c21
1 files changed, 9 insertions, 12 deletions
diff --git a/fs/dcache.c b/fs/dcache.c
index 817c243c1ff1..9522b8b63871 100644
--- a/fs/dcache.c
+++ b/fs/dcache.c
@@ -104,10 +104,8 @@ static unsigned int d_hash_shift __read_mostly;
104 104
105static struct hlist_bl_head *dentry_hashtable __read_mostly; 105static struct hlist_bl_head *dentry_hashtable __read_mostly;
106 106
107static inline struct hlist_bl_head *d_hash(const struct dentry *parent, 107static inline struct hlist_bl_head *d_hash(unsigned int hash)
108 unsigned int hash)
109{ 108{
110 hash += (unsigned long) parent / L1_CACHE_BYTES;
111 return dentry_hashtable + hash_32(hash, d_hash_shift); 109 return dentry_hashtable + hash_32(hash, d_hash_shift);
112} 110}
113 111
@@ -488,7 +486,7 @@ void __d_drop(struct dentry *dentry)
488 if (unlikely(IS_ROOT(dentry))) 486 if (unlikely(IS_ROOT(dentry)))
489 b = &dentry->d_sb->s_anon; 487 b = &dentry->d_sb->s_anon;
490 else 488 else
491 b = d_hash(dentry->d_parent, dentry->d_name.hash); 489 b = d_hash(dentry->d_name.hash);
492 490
493 hlist_bl_lock(b); 491 hlist_bl_lock(b);
494 __hlist_bl_del(&dentry->d_hash); 492 __hlist_bl_del(&dentry->d_hash);
@@ -1670,7 +1668,7 @@ struct dentry *d_alloc_name(struct dentry *parent, const char *name)
1670 struct qstr q; 1668 struct qstr q;
1671 1669
1672 q.name = name; 1670 q.name = name;
1673 q.hash_len = hashlen_string(name); 1671 q.hash_len = hashlen_string(parent, name);
1674 return d_alloc(parent, &q); 1672 return d_alloc(parent, &q);
1675} 1673}
1676EXPORT_SYMBOL(d_alloc_name); 1674EXPORT_SYMBOL(d_alloc_name);
@@ -2094,7 +2092,7 @@ struct dentry *__d_lookup_rcu(const struct dentry *parent,
2094{ 2092{
2095 u64 hashlen = name->hash_len; 2093 u64 hashlen = name->hash_len;
2096 const unsigned char *str = name->name; 2094 const unsigned char *str = name->name;
2097 struct hlist_bl_head *b = d_hash(parent, hashlen_hash(hashlen)); 2095 struct hlist_bl_head *b = d_hash(hashlen_hash(hashlen));
2098 struct hlist_bl_node *node; 2096 struct hlist_bl_node *node;
2099 struct dentry *dentry; 2097 struct dentry *dentry;
2100 2098
@@ -2211,7 +2209,7 @@ struct dentry *__d_lookup(const struct dentry *parent, const struct qstr *name)
2211 unsigned int len = name->len; 2209 unsigned int len = name->len;
2212 unsigned int hash = name->hash; 2210 unsigned int hash = name->hash;
2213 const unsigned char *str = name->name; 2211 const unsigned char *str = name->name;
2214 struct hlist_bl_head *b = d_hash(parent, hash); 2212 struct hlist_bl_head *b = d_hash(hash);
2215 struct hlist_bl_node *node; 2213 struct hlist_bl_node *node;
2216 struct dentry *found = NULL; 2214 struct dentry *found = NULL;
2217 struct dentry *dentry; 2215 struct dentry *dentry;
@@ -2291,7 +2289,7 @@ struct dentry *d_hash_and_lookup(struct dentry *dir, struct qstr *name)
2291 * calculate the standard hash first, as the d_op->d_hash() 2289 * calculate the standard hash first, as the d_op->d_hash()
2292 * routine may choose to leave the hash value unchanged. 2290 * routine may choose to leave the hash value unchanged.
2293 */ 2291 */
2294 name->hash = full_name_hash(name->name, name->len); 2292 name->hash = full_name_hash(dir, name->name, name->len);
2295 if (dir->d_flags & DCACHE_OP_HASH) { 2293 if (dir->d_flags & DCACHE_OP_HASH) {
2296 int err = dir->d_op->d_hash(dir, name); 2294 int err = dir->d_op->d_hash(dir, name);
2297 if (unlikely(err < 0)) 2295 if (unlikely(err < 0))
@@ -2364,7 +2362,7 @@ static void __d_rehash(struct dentry * entry, struct hlist_bl_head *b)
2364 2362
2365static void _d_rehash(struct dentry * entry) 2363static void _d_rehash(struct dentry * entry)
2366{ 2364{
2367 __d_rehash(entry, d_hash(entry->d_parent, entry->d_name.hash)); 2365 __d_rehash(entry, d_hash(entry->d_name.hash));
2368} 2366}
2369 2367
2370/** 2368/**
@@ -2821,7 +2819,7 @@ static void __d_move(struct dentry *dentry, struct dentry *target,
2821 * for the same hash queue because of how unlikely it is. 2819 * for the same hash queue because of how unlikely it is.
2822 */ 2820 */
2823 __d_drop(dentry); 2821 __d_drop(dentry);
2824 __d_rehash(dentry, d_hash(target->d_parent, target->d_name.hash)); 2822 __d_rehash(dentry, d_hash(target->d_name.hash));
2825 2823
2826 /* 2824 /*
2827 * Unhash the target (d_delete() is not usable here). If exchanging 2825 * Unhash the target (d_delete() is not usable here). If exchanging
@@ -2829,8 +2827,7 @@ static void __d_move(struct dentry *dentry, struct dentry *target,
2829 */ 2827 */
2830 __d_drop(target); 2828 __d_drop(target);
2831 if (exchange) { 2829 if (exchange) {
2832 __d_rehash(target, 2830 __d_rehash(target, d_hash(dentry->d_name.hash));
2833 d_hash(dentry->d_parent, dentry->d_name.hash));
2834 } 2831 }
2835 2832
2836 /* Switch the names.. */ 2833 /* Switch the names.. */