Skip to content

Commit c27d82f

Browse files
jankaratorvalds
authored andcommitted
fs/drop_caches.c: avoid softlockups in drop_pagecache_sb()
When superblock has lots of inodes without any pagecache (like is the case for /proc), drop_pagecache_sb() will iterate through all of them without dropping sb->s_inode_list_lock which can lead to softlockups (one of our customers hit this). Fix the problem by going to the slow path and doing cond_resched() in case the process needs rescheduling. Link: http://lkml.kernel.org/r/20190114085343.15011-1-jack@suse.cz Signed-off-by: Jan Kara <jack@suse.cz> Acked-by: Michal Hocko <mhocko@suse.com> Reviewed-by: Andrew Morton <akpm@linux-foundation.org> Cc: Al Viro <viro@ZenIV.linux.org.uk> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
1 parent e0a352f commit c27d82f

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

fs/drop_caches.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,15 +21,21 @@ static void drop_pagecache_sb(struct super_block *sb, void *unused)
2121
spin_lock(&sb->s_inode_list_lock);
2222
list_for_each_entry(inode, &sb->s_inodes, i_sb_list) {
2323
spin_lock(&inode->i_lock);
24+
/*
25+
* We must skip inodes in unusual state. We may also skip
26+
* inodes without pages but we deliberately won't in case
27+
* we need to reschedule to avoid softlockups.
28+
*/
2429
if ((inode->i_state & (I_FREEING|I_WILL_FREE|I_NEW)) ||
25-
(inode->i_mapping->nrpages == 0)) {
30+
(inode->i_mapping->nrpages == 0 && !need_resched())) {
2631
spin_unlock(&inode->i_lock);
2732
continue;
2833
}
2934
__iget(inode);
3035
spin_unlock(&inode->i_lock);
3136
spin_unlock(&sb->s_inode_list_lock);
3237

38+
cond_resched();
3339
invalidate_mapping_pages(inode->i_mapping, 0, -1);
3440
iput(toput_inode);
3541
toput_inode = inode;

0 commit comments

Comments
 (0)