Skip to content

Commit eb7e453

Browse files
mjguzikbrauner
authored andcommitted
fs: drop the lock trip around I_NEW wake up in evict()
The unhashed state check in __wait_on_freeing_inode() performed with ->i_lock held against remove_hash_inode() also holding the lock makes another lock acquire in evict() completely spurious -- all potential sleepers already dropped the lock before remove_hash_inode() acquired it or they found the inode to be unhashed and aborted. Note there is no trickery here: the usual cost of both sides taking locks is still being paid, it just stops being paid twice. Signed-off-by: Mateusz Guzik <mjguzik@gmail.com> Link: https://lore.kernel.org/r/20250317160707.1694135-1-mjguzik@gmail.com Signed-off-by: Christian Brauner <brauner@kernel.org>
1 parent 008a746 commit eb7e453

1 file changed

Lines changed: 6 additions & 13 deletions

File tree

fs/inode.c

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -816,23 +816,16 @@ static void evict(struct inode *inode)
816816
/*
817817
* Wake up waiters in __wait_on_freeing_inode().
818818
*
819-
* Lockless hash lookup may end up finding the inode before we removed
820-
* it above, but only lock it *after* we are done with the wakeup below.
821-
* In this case the potential waiter cannot safely block.
819+
* It is an invariant that any thread we need to wake up is already
820+
* accounted for before remove_inode_hash() acquires ->i_lock -- both
821+
* sides take the lock and sleep is aborted if the inode is found
822+
* unhashed. Thus either the sleeper wins and goes off CPU, or removal
823+
* wins and the sleeper aborts after testing with the lock.
822824
*
823-
* The inode being unhashed after the call to remove_inode_hash() is
824-
* used as an indicator whether blocking on it is safe.
825+
* This also means we don't need any fences for the call below.
825826
*/
826-
spin_lock(&inode->i_lock);
827-
/*
828-
* Pairs with the barrier in prepare_to_wait_event() to make sure
829-
* ___wait_var_event() either sees the bit cleared or
830-
* waitqueue_active() check in wake_up_var() sees the waiter.
831-
*/
832-
smp_mb__after_spinlock();
833827
inode_wake_up_bit(inode, __I_NEW);
834828
BUG_ON(inode->i_state != (I_FREEING | I_CLEAR));
835-
spin_unlock(&inode->i_lock);
836829

837830
destroy_inode(inode);
838831
}

0 commit comments

Comments
 (0)