Skip to content

Commit b4cc073

Browse files
author
Al Viro
committed
d_prune_aliases(): use a shrink list
Instead of dropping aliases one by one, restarting, etc., just collect them into a shrink list and kill them off in one pass. We don't really need the restarts - one alias can't pin another (directory has only one alias, and couldn't be its own ancestor anyway), so collecting everything that is not busy and taking it out would take care of everything evictable that had been there as we entered the function. And new aliases added while we'd been dropping old ones could just as easily have appeared right as we return to caller... Reviewed-by: Christian Brauner <brauner@kernel.org> Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
1 parent f5c8a8a commit b4cc073

File tree

1 file changed

+5
-25
lines changed

1 file changed

+5
-25
lines changed

fs/dcache.c

Lines changed: 5 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -647,20 +647,6 @@ static struct dentry *__lock_parent(struct dentry *dentry)
647647
return parent;
648648
}
649649

650-
static inline struct dentry *lock_parent(struct dentry *dentry)
651-
{
652-
struct dentry *parent = dentry->d_parent;
653-
if (IS_ROOT(dentry))
654-
return NULL;
655-
if (likely(spin_trylock(&parent->d_lock)))
656-
return parent;
657-
rcu_read_lock();
658-
spin_unlock(&dentry->d_lock);
659-
parent = __lock_parent(dentry);
660-
rcu_read_unlock();
661-
return parent;
662-
}
663-
664650
/*
665651
* Lock a dentry for feeding it to __dentry_kill().
666652
* Called under rcu_read_lock() and dentry->d_lock; the former
@@ -1090,24 +1076,18 @@ struct dentry *d_find_alias_rcu(struct inode *inode)
10901076
*/
10911077
void d_prune_aliases(struct inode *inode)
10921078
{
1079+
LIST_HEAD(dispose);
10931080
struct dentry *dentry;
1094-
restart:
1081+
10951082
spin_lock(&inode->i_lock);
10961083
hlist_for_each_entry(dentry, &inode->i_dentry, d_u.d_alias) {
10971084
spin_lock(&dentry->d_lock);
1098-
if (!dentry->d_lockref.count) {
1099-
struct dentry *parent = lock_parent(dentry);
1100-
if (likely(!dentry->d_lockref.count)) {
1101-
__dentry_kill(dentry);
1102-
dput(parent);
1103-
goto restart;
1104-
}
1105-
if (parent)
1106-
spin_unlock(&parent->d_lock);
1107-
}
1085+
if (!dentry->d_lockref.count)
1086+
to_shrink_list(dentry, &dispose);
11081087
spin_unlock(&dentry->d_lock);
11091088
}
11101089
spin_unlock(&inode->i_lock);
1090+
shrink_dentry_list(&dispose);
11111091
}
11121092
EXPORT_SYMBOL(d_prune_aliases);
11131093

0 commit comments

Comments
 (0)