Skip to content

Commit 19f4e68

Browse files
Hou PengyangJaegeuk Kim
authored andcommitted
f2fs: avoid bggc->fggc when enough free segments are avaliable after cp
We use has_not_enough_free_secs to check if there are enough free segments, (free_sections(sbi) + freed) <= (node_secs + 2 * dent_secs + imeta_secs + reserved_sections(sbi) + needed); Under scenario with large number of dirty nodes, these nodes would be flushed during cp, as a result, right side of the inequality would be decreased, while left side stays unchanged if these nodes are flushed in SSR way, which means there are enough free segments after this cp. For this case, we just do a bggc instead of fggc. Signed-off-by: Hou Pengyang <houpengyang@huawei.com> Reviewed-by: Chao Yu <yuchao0@huawei.com> Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
1 parent d27c3d8 commit 19f4e68

1 file changed

Lines changed: 9 additions & 8 deletions

File tree

‎fs/f2fs/gc.c‎

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -953,21 +953,22 @@ int f2fs_gc(struct f2fs_sb_info *sbi, bool sync, bool background)
953953
goto stop;
954954
}
955955

956-
if (gc_type == BG_GC && has_not_enough_free_secs(sbi, sec_freed, 0)) {
957-
gc_type = FG_GC;
956+
if (gc_type == BG_GC && has_not_enough_free_secs(sbi, 0, 0)) {
958957
/*
959-
* If there is no victim and no prefree segment but still not
960-
* enough free sections, we should flush dent/node blocks and do
961-
* garbage collections.
958+
* For example, if there are many prefree_segments below given
959+
* threshold, we can make them free by checkpoint. Then, we
960+
* secure free segments which doesn't need fggc any more.
962961
*/
963962
ret = write_checkpoint(sbi, &cpc);
964963
if (ret)
965964
goto stop;
966-
} else if (gc_type == BG_GC && !background) {
967-
/* f2fs_balance_fs doesn't need to do BG_GC in critical path. */
968-
goto stop;
965+
if (has_not_enough_free_secs(sbi, 0, 0))
966+
gc_type = FG_GC;
969967
}
970968

969+
/* f2fs_balance_fs doesn't need to do BG_GC in critical path. */
970+
if (gc_type == BG_GC && !background)
971+
goto stop;
971972
if (!__get_victim(sbi, &segno, gc_type))
972973
goto stop;
973974
ret = 0;

0 commit comments

Comments
 (0)