summaryrefslogtreecommitdiff
path: root/fs/notify/fsnotify.c
diff options
context:
space:
mode:
authorKent Overstreet <kent.overstreet@linux.dev>2024-09-28 21:31:10 -0400
committerKent Overstreet <kent.overstreet@linux.dev>2024-10-01 19:40:47 -0400
commit9ec9b917b3f6cf676226f074fdcdeceebe1a0b29 (patch)
tree7c71ca81faa20a1e44624f7489fae1264db8e269 /fs/notify/fsnotify.c
parent32cb8103ecfacdd5ed8e1eb390221c3f8339de6f (diff)
vfs: use fast_list for superblock's inode listfast_list
Use the new fast_list for super_block.s_inodes. This gives similar performance to Dave's dlock list approach [1]; lock contention is now moved to the lru_list locks. Iteration is now fully lockless - instead we iterate using rcu_read_lock(), which means we must take care for racing with removal. Generally this is already handled - code that iterates over s_inodes takes i_lock and checks i_state, skipping inodes that are I_WILL_FREE|I_FREEING. However, code may also check for nonzero i_sb_list_idx if it wishes to iterate over precisely the inodes that are on the s_inodes list. [1]: https://lore.kernel.org/linux-fsdevel/20231206060629.2827226-4-david@fromorbit.com/ Cc: Christian Brauner <brauner@kernel.org> Cc: Dave Chinner <dchinner@redhat.com> Cc: Waiman Long <longman@redhat.com> Cc: Alexander Viro <viro@zeniv.linux.org.uk> Cc: Linus Torvalds <torvalds@linux-foundation.org> Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
Diffstat (limited to 'fs/notify/fsnotify.c')
-rw-r--r--fs/notify/fsnotify.c25
1 files changed, 13 insertions, 12 deletions
diff --git a/fs/notify/fsnotify.c b/fs/notify/fsnotify.c
index 272c8a1dab3c..9a8da7a02a6f 100644
--- a/fs/notify/fsnotify.c
+++ b/fs/notify/fsnotify.c
@@ -33,14 +33,19 @@ void __fsnotify_vfsmount_delete(struct vfsmount *mnt)
* @sb: superblock being unmounted.
*
* Called during unmount with no locks held, so needs to be safe against
- * concurrent modifiers. We temporarily drop sb->s_inode_list_lock and CAN block.
+ * concurrent modifiers. Can block.
*/
static void fsnotify_unmount_inodes(struct super_block *sb)
{
- struct inode *inode, *iput_inode = NULL;
+ struct genradix_iter iter;
+ void **i;
+
+ rcu_read_lock();
+ genradix_for_each(&sb->s_inodes.items, iter, i) {
+ struct inode *inode = *((struct inode **) i);
+ if (!inode)
+ continue;
- spin_lock(&sb->s_inode_list_lock);
- list_for_each_entry(inode, &sb->s_inodes, i_sb_list) {
/*
* We cannot __iget() an inode in state I_FREEING,
* I_WILL_FREE, or I_NEW which is fine because by that point
@@ -68,23 +73,19 @@ static void fsnotify_unmount_inodes(struct super_block *sb)
__iget(inode);
spin_unlock(&inode->i_lock);
- spin_unlock(&sb->s_inode_list_lock);
-
- iput(iput_inode);
+ rcu_read_unlock();
/* for each watch, send FS_UNMOUNT and then remove it */
fsnotify_inode(inode, FS_UNMOUNT);
fsnotify_inode_delete(inode);
- iput_inode = inode;
+ iput(inode);
cond_resched();
- spin_lock(&sb->s_inode_list_lock);
+ rcu_read_lock();
}
- spin_unlock(&sb->s_inode_list_lock);
-
- iput(iput_inode);
+ rcu_read_unlock();
}
void fsnotify_sb_delete(struct super_block *sb)