Skip to content

Commit 04646ae

Browse files
Eric SandeenAl Viro
authored andcommitted
fs: avoid softlockups in s_inodes iterators
Anything that walks all inodes on sb->s_inodes list without rescheduling risks softlockups. Previous efforts were made in 2 functions, see: c27d82f fs/drop_caches.c: avoid softlockups in drop_pagecache_sb() ac05fbb inode: don't softlockup when evicting inodes but there hasn't been an audit of all walkers, so do that now. This also consistently moves the cond_resched() calls to the bottom of each loop in cases where it already exists. One loop remains: remove_dquot_ref(), because I'm not quite sure how to deal with that one w/o taking the i_lock. Signed-off-by: Eric Sandeen <[email protected]> Reviewed-by: Jan Kara <[email protected]> Signed-off-by: Al Viro <[email protected]>
1 parent e0ff126 commit 04646ae

File tree

4 files changed

+10
-1
lines changed

4 files changed

+10
-1
lines changed

fs/drop_caches.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,11 @@ static void drop_pagecache_sb(struct super_block *sb, void *unused)
3535
spin_unlock(&inode->i_lock);
3636
spin_unlock(&sb->s_inode_list_lock);
3737

38-
cond_resched();
3938
invalidate_mapping_pages(inode->i_mapping, 0, -1);
4039
iput(toput_inode);
4140
toput_inode = inode;
4241

42+
cond_resched();
4343
spin_lock(&sb->s_inode_list_lock);
4444
}
4545
spin_unlock(&sb->s_inode_list_lock);

fs/inode.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -676,6 +676,7 @@ int invalidate_inodes(struct super_block *sb, bool kill_dirty)
676676
struct inode *inode, *next;
677677
LIST_HEAD(dispose);
678678

679+
again:
679680
spin_lock(&sb->s_inode_list_lock);
680681
list_for_each_entry_safe(inode, next, &sb->s_inodes, i_sb_list) {
681682
spin_lock(&inode->i_lock);
@@ -698,6 +699,12 @@ int invalidate_inodes(struct super_block *sb, bool kill_dirty)
698699
inode_lru_list_del(inode);
699700
spin_unlock(&inode->i_lock);
700701
list_add(&inode->i_lru, &dispose);
702+
if (need_resched()) {
703+
spin_unlock(&sb->s_inode_list_lock);
704+
cond_resched();
705+
dispose_list(&dispose);
706+
goto again;
707+
}
701708
}
702709
spin_unlock(&sb->s_inode_list_lock);
703710

fs/notify/fsnotify.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ static void fsnotify_unmount_inodes(struct super_block *sb)
7777

7878
iput_inode = inode;
7979

80+
cond_resched();
8081
spin_lock(&sb->s_inode_list_lock);
8182
}
8283
spin_unlock(&sb->s_inode_list_lock);

fs/quota/dquot.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -984,6 +984,7 @@ static int add_dquot_ref(struct super_block *sb, int type)
984984
* later.
985985
*/
986986
old_inode = inode;
987+
cond_resched();
987988
spin_lock(&sb->s_inode_list_lock);
988989
}
989990
spin_unlock(&sb->s_inode_list_lock);

0 commit comments

Comments
 (0)