mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git
synced 2024-09-15 15:15:47 +00:00
fs: dcache reduce dput locking
It is possible to run dput without taking data structure locks up-front. In many cases where we don't kill the dentry anyway, these locks are not required. Signed-off-by: Nick Piggin <npiggin@kernel.dk>
This commit is contained in:
parent
58db63d086
commit
61f3dee4af
1 changed files with 23 additions and 29 deletions
52
fs/dcache.c
52
fs/dcache.c
|
@ -323,35 +323,16 @@ void dput(struct dentry *dentry)
|
||||||
if (dentry->d_count == 1)
|
if (dentry->d_count == 1)
|
||||||
might_sleep();
|
might_sleep();
|
||||||
spin_lock(&dentry->d_lock);
|
spin_lock(&dentry->d_lock);
|
||||||
if (IS_ROOT(dentry))
|
BUG_ON(!dentry->d_count);
|
||||||
parent = NULL;
|
if (dentry->d_count > 1) {
|
||||||
else
|
dentry->d_count--;
|
||||||
parent = dentry->d_parent;
|
|
||||||
if (dentry->d_count == 1) {
|
|
||||||
if (!spin_trylock(&dcache_inode_lock)) {
|
|
||||||
drop2:
|
|
||||||
spin_unlock(&dentry->d_lock);
|
|
||||||
goto repeat;
|
|
||||||
}
|
|
||||||
if (parent && !spin_trylock(&parent->d_lock)) {
|
|
||||||
spin_unlock(&dcache_inode_lock);
|
|
||||||
goto drop2;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
dentry->d_count--;
|
|
||||||
if (dentry->d_count) {
|
|
||||||
spin_unlock(&dentry->d_lock);
|
spin_unlock(&dentry->d_lock);
|
||||||
if (parent)
|
|
||||||
spin_unlock(&parent->d_lock);
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
* AV: ->d_delete() is _NOT_ allowed to block now.
|
|
||||||
*/
|
|
||||||
if (dentry->d_op && dentry->d_op->d_delete) {
|
if (dentry->d_op && dentry->d_op->d_delete) {
|
||||||
if (dentry->d_op->d_delete(dentry))
|
if (dentry->d_op->d_delete(dentry))
|
||||||
goto unhash_it;
|
goto kill_it;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Unreachable? Get rid of it */
|
/* Unreachable? Get rid of it */
|
||||||
|
@ -362,17 +343,30 @@ void dput(struct dentry *dentry)
|
||||||
dentry->d_flags |= DCACHE_REFERENCED;
|
dentry->d_flags |= DCACHE_REFERENCED;
|
||||||
dentry_lru_add(dentry);
|
dentry_lru_add(dentry);
|
||||||
|
|
||||||
spin_unlock(&dentry->d_lock);
|
dentry->d_count--;
|
||||||
if (parent)
|
spin_unlock(&dentry->d_lock);
|
||||||
spin_unlock(&parent->d_lock);
|
|
||||||
spin_unlock(&dcache_inode_lock);
|
|
||||||
return;
|
return;
|
||||||
|
|
||||||
unhash_it:
|
|
||||||
__d_drop(dentry);
|
|
||||||
kill_it:
|
kill_it:
|
||||||
|
if (!spin_trylock(&dcache_inode_lock)) {
|
||||||
|
relock:
|
||||||
|
spin_unlock(&dentry->d_lock);
|
||||||
|
cpu_relax();
|
||||||
|
goto repeat;
|
||||||
|
}
|
||||||
|
if (IS_ROOT(dentry))
|
||||||
|
parent = NULL;
|
||||||
|
else
|
||||||
|
parent = dentry->d_parent;
|
||||||
|
if (parent && !spin_trylock(&parent->d_lock)) {
|
||||||
|
spin_unlock(&dcache_inode_lock);
|
||||||
|
goto relock;
|
||||||
|
}
|
||||||
|
dentry->d_count--;
|
||||||
/* if dentry was on the d_lru list delete it from there */
|
/* if dentry was on the d_lru list delete it from there */
|
||||||
dentry_lru_del(dentry);
|
dentry_lru_del(dentry);
|
||||||
|
/* if it was on the hash (d_delete case), then remove it */
|
||||||
|
__d_drop(dentry);
|
||||||
dentry = d_kill(dentry, parent);
|
dentry = d_kill(dentry, parent);
|
||||||
if (dentry)
|
if (dentry)
|
||||||
goto repeat;
|
goto repeat;
|
||||||
|
|
Loading…
Reference in a new issue