aboutsummaryrefslogtreecommitdiff
path: root/fs/dcache.c
diff options
context:
space:
mode:
authorNick Piggin <npiggin@kernel.dk>2011-01-07 17:49:45 +1100
committerNick Piggin <npiggin@kernel.dk>2011-01-07 17:50:25 +1100
commit89e6054836a7b1e7500cd70a14b5579e752c9250 (patch)
treeb74d2ecd1ac2a571d289e5525a0dc067ec1f35eb /fs/dcache.c
parenta734eb458ab2bd11479a27dd54f48e1b26a55845 (diff)
fs: dcache reduce prune_one_dentry locking
prune_one_dentry can avoid quite a bit of locking in the common case where ancestors have an elevated refcount. Alternatively, we could have gone the other way and made fewer trylocks in the case where d_count goes to zero, but is probably less common. Signed-off-by: Nick Piggin <npiggin@kernel.dk>
Diffstat (limited to 'fs/dcache.c')
-rw-r--r--fs/dcache.c27
1 files changed, 15 insertions, 12 deletions
diff --git a/fs/dcache.c b/fs/dcache.c
index a8f89765d60..19570637469 100644
--- a/fs/dcache.c
+++ b/fs/dcache.c
@@ -582,26 +582,29 @@ static void prune_one_dentry(struct dentry *dentry, struct dentry *parent)
* Prune ancestors.
*/
while (dentry) {
- spin_lock(&dcache_inode_lock);
-again:
+relock:
spin_lock(&dentry->d_lock);
+ if (dentry->d_count > 1) {
+ dentry->d_count--;
+ spin_unlock(&dentry->d_lock);
+ return;
+ }
+ if (!spin_trylock(&dcache_inode_lock)) {
+relock2:
+ spin_unlock(&dentry->d_lock);
+ cpu_relax();
+ goto relock;
+ }
+
if (IS_ROOT(dentry))
parent = NULL;
else
parent = dentry->d_parent;
if (parent && !spin_trylock(&parent->d_lock)) {
- spin_unlock(&dentry->d_lock);
- goto again;
- }
- dentry->d_count--;
- if (dentry->d_count) {
- if (parent)
- spin_unlock(&parent->d_lock);
- spin_unlock(&dentry->d_lock);
spin_unlock(&dcache_inode_lock);
- return;
+ goto relock2;
}
-
+ dentry->d_count--;
dentry_lru_del(dentry);
__d_drop(dentry);
dentry = d_kill(dentry, parent);