Skip to content

Commit 2d3f197

Browse files
author
Jaegeuk Kim
committed
f2fs: refactor f2fs_gc to call checkpoint in urgent condition
The major change is to call checkpoint, if there's not enough space while having some prefree segments in FG_GC case. Reviewed-by: Chao Yu <chao@kernel.org> Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
1 parent 635a52d commit 2d3f197

1 file changed

Lines changed: 13 additions & 14 deletions

File tree

fs/f2fs/gc.c

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1829,7 +1829,10 @@ int f2fs_gc(struct f2fs_sb_info *sbi, struct f2fs_gc_control *gc_control)
18291829
goto stop;
18301830
}
18311831

1832-
if (gc_type == BG_GC && has_not_enough_free_secs(sbi, 0, 0)) {
1832+
/* Let's run FG_GC, if we don't have enough space. */
1833+
if (has_not_enough_free_secs(sbi, 0, 0)) {
1834+
gc_type = FG_GC;
1835+
18331836
/*
18341837
* For example, if there are many prefree_segments below given
18351838
* threshold, we can make them free by checkpoint. Then, we
@@ -1840,8 +1843,6 @@ int f2fs_gc(struct f2fs_sb_info *sbi, struct f2fs_gc_control *gc_control)
18401843
if (ret)
18411844
goto stop;
18421845
}
1843-
if (has_not_enough_free_secs(sbi, 0, 0))
1844-
gc_type = FG_GC;
18451846
}
18461847

18471848
/* f2fs_balance_fs doesn't need to do BG_GC in critical path. */
@@ -1868,19 +1869,15 @@ int f2fs_gc(struct f2fs_sb_info *sbi, struct f2fs_gc_control *gc_control)
18681869
if (seg_freed == f2fs_usable_segs_in_sec(sbi, segno))
18691870
sec_freed++;
18701871

1871-
if (gc_type == FG_GC)
1872+
if (gc_type == FG_GC) {
18721873
sbi->cur_victim_sec = NULL_SEGNO;
18731874

1874-
if (gc_control->init_gc_type == FG_GC ||
1875-
!has_not_enough_free_secs(sbi,
1876-
(gc_type == FG_GC) ? sec_freed : 0, 0)) {
1877-
if (gc_type == FG_GC && sec_freed < gc_control->nr_free_secs)
1878-
goto go_gc_more;
1879-
goto stop;
1880-
}
1881-
1882-
/* FG_GC stops GC by skip_count */
1883-
if (gc_type == FG_GC) {
1875+
if (!has_not_enough_free_secs(sbi, sec_freed, 0)) {
1876+
if (!gc_control->no_bg_gc &&
1877+
sec_freed < gc_control->nr_free_secs)
1878+
goto go_gc_more;
1879+
goto stop;
1880+
}
18841881
if (sbi->skipped_gc_rwsem)
18851882
skipped_round++;
18861883
round++;
@@ -1889,6 +1886,8 @@ int f2fs_gc(struct f2fs_sb_info *sbi, struct f2fs_gc_control *gc_control)
18891886
ret = f2fs_write_checkpoint(sbi, &cpc);
18901887
goto stop;
18911888
}
1889+
} else if (!has_not_enough_free_secs(sbi, 0, 0)) {
1890+
goto stop;
18921891
}
18931892

18941893
__get_secs_required(sbi, NULL, &upper_secs, NULL);

0 commit comments

Comments
 (0)