Skip to content

Commit 02d9139

Browse files
Daeho JeongJaegeuk Kim
authored andcommitted
f2fs: fix to freeze GC and discard threads quickly
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 <[email protected]> Reviewed-by: Chao Yu <[email protected]> Signed-off-by: Jaegeuk Kim <[email protected]>
1 parent 7b9161a commit 02d9139

2 files changed

Lines changed: 21 additions & 1 deletion

File tree

fs/f2fs/gc.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1895,12 +1895,18 @@ static int do_garbage_collect(struct f2fs_sb_info *sbi,
18951895
sbi->next_victim_seg[gc_type] =
18961896
(cur_segno + 1 < sec_end_segno) ?
18971897
cur_segno + 1 : NULL_SEGNO;
1898+
1899+
if (unlikely(freezing(current))) {
1900+
folio_put_refs(sum_folio, 2);
1901+
goto stop;
1902+
}
18981903
}
18991904
next_block:
19001905
folio_put_refs(sum_folio, 2);
19011906
segno = block_end_segno;
19021907
}
19031908

1909+
stop:
19041910
if (submitted)
19051911
f2fs_submit_merged_write(sbi, data_type);
19061912

@@ -1974,6 +1980,10 @@ int f2fs_gc(struct f2fs_sb_info *sbi, struct f2fs_gc_control *gc_control)
19741980
goto stop;
19751981
}
19761982
retry:
1983+
if (unlikely(freezing(current))) {
1984+
ret = 0;
1985+
goto stop;
1986+
}
19771987
ret = __get_victim(sbi, &segno, gc_type, gc_control->one_time);
19781988
if (ret) {
19791989
/* allow to search victim from sections has pinned data */

fs/f2fs/segment.c

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1606,6 +1606,9 @@ static void __issue_discard_cmd_orderly(struct f2fs_sb_info *sbi,
16061606
if (dc->state != D_PREP)
16071607
goto next;
16081608

1609+
if (*issued > 0 && unlikely(freezing(current)))
1610+
break;
1611+
16091612
if (dpolicy->io_aware && !is_idle(sbi, DISCARD_TIME)) {
16101613
io_interrupted = true;
16111614
break;
@@ -1645,6 +1648,7 @@ static int __issue_discard_cmd(struct f2fs_sb_info *sbi,
16451648
struct blk_plug plug;
16461649
int i, issued;
16471650
bool io_interrupted = false;
1651+
bool suspended = false;
16481652

16491653
if (dpolicy->timeout)
16501654
f2fs_update_time(sbi, UMOUNT_DISCARD_TIMEOUT);
@@ -1675,6 +1679,11 @@ static int __issue_discard_cmd(struct f2fs_sb_info *sbi,
16751679
list_for_each_entry_safe(dc, tmp, pend_list, list) {
16761680
f2fs_bug_on(sbi, dc->state != D_PREP);
16771681

1682+
if (issued > 0 && unlikely(freezing(current))) {
1683+
suspended = true;
1684+
break;
1685+
}
1686+
16781687
if (dpolicy->timeout &&
16791688
f2fs_time_over(sbi, UMOUNT_DISCARD_TIMEOUT))
16801689
break;
@@ -1694,7 +1703,8 @@ static int __issue_discard_cmd(struct f2fs_sb_info *sbi,
16941703
next:
16951704
mutex_unlock(&dcc->cmd_lock);
16961705

1697-
if (issued >= dpolicy->max_requests || io_interrupted)
1706+
if (issued >= dpolicy->max_requests || io_interrupted ||
1707+
suspended)
16981708
break;
16991709
}
17001710

0 commit comments

Comments
 (0)