mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/next/linux-next.git
synced 2025-01-07 14:32:23 +00:00
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>
This commit is contained in:
parent
a734eb458a
commit
89e6054836
27
fs/dcache.c
27
fs/dcache.c
@ -582,26 +582,29 @@ static void prune_one_dentry(struct dentry *dentry, struct dentry *parent)
|
|||||||
* Prune ancestors.
|
* Prune ancestors.
|
||||||
*/
|
*/
|
||||||
while (dentry) {
|
while (dentry) {
|
||||||
spin_lock(&dcache_inode_lock);
|
relock:
|
||||||
again:
|
|
||||||
spin_lock(&dentry->d_lock);
|
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))
|
if (IS_ROOT(dentry))
|
||||||
parent = NULL;
|
parent = NULL;
|
||||||
else
|
else
|
||||||
parent = dentry->d_parent;
|
parent = dentry->d_parent;
|
||||||
if (parent && !spin_trylock(&parent->d_lock)) {
|
if (parent && !spin_trylock(&parent->d_lock)) {
|
||||||
spin_unlock(&dentry->d_lock);
|
spin_unlock(&dcache_inode_lock);
|
||||||
goto again;
|
goto relock2;
|
||||||
}
|
}
|
||||||
dentry->d_count--;
|
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;
|
|
||||||
}
|
|
||||||
|
|
||||||
dentry_lru_del(dentry);
|
dentry_lru_del(dentry);
|
||||||
__d_drop(dentry);
|
__d_drop(dentry);
|
||||||
dentry = d_kill(dentry, parent);
|
dentry = d_kill(dentry, parent);
|
||||||
|
Loading…
Reference in New Issue
Block a user