]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
f2fs: fix to freeze GC and discard threads quickly
authorDaeho Jeong <daehojeong@google.com>
Mon, 16 Mar 2026 18:59:54 +0000 (11:59 -0700)
committerJaegeuk Kim <jaegeuk@kernel.org>
Thu, 2 Apr 2026 16:24:20 +0000 (16:24 +0000)
Suspend can fail if kernel threads do not freeze for a while.
f2fs_gc and f2fs_discard threads can perform long-running operations
that prevent them from reaching a freeze point in a timely manner.

This patch adds explicit freezing checks in the following locations:
1. f2fs_gc: Added a check at the 'retry' label to exit the loop quickly
   if freezing is requested, especially during heavy GC rounds.
2. __issue_discard_cmd: Added a 'suspended' flag to break both inner and
   outer loops during discard command issuance if freezing is detected
   after at least one command has been issued.
3. __issue_discard_cmd_orderly: Added a similar check for orderly discard
   to ensure responsiveness.

These checks ensure that the threads release locks safely and enter the
frozen state.

Signed-off-by: Daeho Jeong <daehojeong@google.com>
Reviewed-by: Chao Yu <chao@kernel.org>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
fs/f2fs/gc.c
fs/f2fs/segment.c

index 4bfc4452f2997cd566da7604f35410ecde713678..e60c1106f70bd2f1ac6bcab8ba6e1d5ab1699b0c 100644 (file)
@@ -1895,12 +1895,18 @@ freed:
                                sbi->next_victim_seg[gc_type] =
                                        (cur_segno + 1 < sec_end_segno) ?
                                        cur_segno + 1 : NULL_SEGNO;
+
+                       if (unlikely(freezing(current))) {
+                               folio_put_refs(sum_folio, 2);
+                               goto stop;
+                       }
                }
 next_block:
                folio_put_refs(sum_folio, 2);
                segno = block_end_segno;
        }
 
+stop:
        if (submitted)
                f2fs_submit_merged_write(sbi, data_type);
 
@@ -1974,6 +1980,10 @@ gc_more:
                goto stop;
        }
 retry:
+       if (unlikely(freezing(current))) {
+               ret = 0;
+               goto stop;
+       }
        ret = __get_victim(sbi, &segno, gc_type, gc_control->one_time);
        if (ret) {
                /* allow to search victim from sections has pinned data */
index 0bf25786667fcb143a4745e8bd6ca4469b768519..788f8b05024927cec89e379fc7fab2dce7b006e8 100644 (file)
@@ -1606,6 +1606,9 @@ static void __issue_discard_cmd_orderly(struct f2fs_sb_info *sbi,
                if (dc->state != D_PREP)
                        goto next;
 
+               if (*issued > 0 && unlikely(freezing(current)))
+                       break;
+
                if (dpolicy->io_aware && !is_idle(sbi, DISCARD_TIME)) {
                        io_interrupted = true;
                        break;
@@ -1645,6 +1648,7 @@ static int __issue_discard_cmd(struct f2fs_sb_info *sbi,
        struct blk_plug plug;
        int i, issued;
        bool io_interrupted = false;
+       bool suspended = false;
 
        if (dpolicy->timeout)
                f2fs_update_time(sbi, UMOUNT_DISCARD_TIMEOUT);
@@ -1675,6 +1679,11 @@ retry:
                list_for_each_entry_safe(dc, tmp, pend_list, list) {
                        f2fs_bug_on(sbi, dc->state != D_PREP);
 
+                       if (issued > 0 && unlikely(freezing(current))) {
+                               suspended = true;
+                               break;
+                       }
+
                        if (dpolicy->timeout &&
                                f2fs_time_over(sbi, UMOUNT_DISCARD_TIMEOUT))
                                break;
@@ -1694,7 +1703,8 @@ retry:
 next:
                mutex_unlock(&dcc->cmd_lock);
 
-               if (issued >= dpolicy->max_requests || io_interrupted)
+               if (issued >= dpolicy->max_requests || io_interrupted ||
+                                       suspended)
                        break;
        }