Re: [PATCH 3/4] fs/dcache: Avoid the try_lock loop in d_delete()
From: Peter Zijlstra
Date: Fri Feb 16 2018 - 12:10:24 EST
On Fri, Feb 16, 2018 at 04:09:32PM +0100, John Ogness wrote:
> +static bool dentry_lock_inode(struct dentry *dentry)
> +{
> + struct inode *inode = dentry->d_inode;
> +
> + lockdep_assert_held(&dentry->d_lock);
> +
> + if (unlikely(!spin_trylock(&inode->i_lock))) {
if (likely(spin_trylock(&inode->i_lock)))
return true;
and then unindent by 1 stop the below code:
> + rcu_read_lock();
> + spin_unlock(&dentry->d_lock);
> + spin_lock(&inode->i_lock);
> + spin_lock(&dentry->d_lock);
> + rcu_read_unlock();
> +
> + /*
> + * @dentry->d_inode might have changed after dropping
> + * @dentry->d_lock. If so, release @inode->i_lock and
> + * signal the caller to restart the operation.
> + */
> + if (unlikely(inode != dentry->d_inode)) {
> + spin_unlock(&inode->i_lock);
> + return false;
> + }
> + }
> + return true;
> +}