ocfs2: fix potential soft lockup during fstrim
authorGang He <ghe@suse.com>
Tue, 13 Oct 2020 23:48:24 +0000 (16:48 -0700)
committerLinus Torvalds <torvalds@linux-foundation.org>
Wed, 14 Oct 2020 01:38:27 +0000 (18:38 -0700)
When we discard unused blocks on a mounted ocfs2 filesystem, fstrim
handles each block goup with locking/unlocking global bitmap meta-file
repeatedly. we should let fstrim thread take a break(if need) between
unlock and lock, this will avoid the potential soft lockup problem,
and also gives the upper applications more IO opportunities, these
applications are not blocked for too long at writing files.

Signed-off-by: Gang He <ghe@suse.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Reviewed-by: Joseph Qi <joseph.qi@linux.alibaba.com>
Cc: Mark Fasheh <mark@fasheh.com>
Cc: Joel Becker <jlbec@evilplan.org>
Cc: Junxiao Bi <junxiao.bi@oracle.com>
Cc: Changwei Ge <gechangwei@live.cn>
Cc: Jun Piao <piaojun@huawei.com>
Link: https://lkml.kernel.org/r/20200927015815.14904-1-ghe@suse.com
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
fs/ocfs2/alloc.c

index 32317ffb9e5cb73cdcb3a4e5ed3aa7bf30ac5f1f..78710788c23703979419296f6d5a7b1071d8097f 100644 (file)
@@ -7654,8 +7654,10 @@ out_mutex:
         * main_bm related locks for avoiding the current IO starve, then go to
         * trim the next group
         */
-       if (ret >= 0 && group <= last_group)
+       if (ret >= 0 && group <= last_group) {
+               cond_resched();
                goto next_group;
+       }
 out:
        range->len = trimmed * sb->s_blocksize;
        return ret;