Skip to content

Commit

Permalink
f2fs: do checkpoint when there's not enough free sections
Browse files Browse the repository at this point in the history
We didn't do checkpoint in FG_GC case, which may cause losing to reclaim prefree
sctions in time.

Fixes: 6f8d445 ("f2fs: avoid fi->i_gc_rwsem[WRITE] lock in f2fs_gc")
Signed-off-by: Chao Yu <chao@kernel.org>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
  • Loading branch information
Jaegeuk Kim committed Apr 5, 2023
1 parent 8df3756 commit fecc894
Showing 1 changed file with 11 additions and 13 deletions.
24 changes: 11 additions & 13 deletions fs/f2fs/gc.c
Expand Up @@ -1806,6 +1806,7 @@ int f2fs_gc(struct f2fs_sb_info *sbi, struct f2fs_gc_control *gc_control)
};
unsigned int skipped_round = 0, round = 0;
unsigned int upper_secs;
bool stop_gc = false;

trace_f2fs_gc_begin(sbi->sb, gc_type, gc_control->no_bg_gc,
gc_control->nr_free_secs,
Expand Down Expand Up @@ -1876,19 +1877,15 @@ int f2fs_gc(struct f2fs_sb_info *sbi, struct f2fs_gc_control *gc_control)
(gc_type == FG_GC) ? sec_freed : 0, 0)) {
if (gc_type == FG_GC && sec_freed < gc_control->nr_free_secs)
goto go_gc_more;
goto stop;
}

/* FG_GC stops GC by skip_count */
if (gc_type == FG_GC) {
stop_gc = true;
} else if (gc_type == FG_GC) {
/* FG_GC stops GC by skip_count */
if (sbi->skipped_gc_rwsem)
skipped_round++;
round++;
if (skipped_round > MAX_SKIP_GC_COUNT &&
skipped_round * 2 >= round) {
ret = f2fs_write_checkpoint(sbi, &cpc);
goto stop;
}
skipped_round * 2 >= round)
stop_gc = true;
}

__get_secs_required(sbi, NULL, &upper_secs, NULL);
Expand All @@ -1901,12 +1898,13 @@ int f2fs_gc(struct f2fs_sb_info *sbi, struct f2fs_gc_control *gc_control)
prefree_segments(sbi)) {
ret = f2fs_write_checkpoint(sbi, &cpc);
if (ret)
goto stop;
stop_gc = true;
}
go_gc_more:
segno = NULL_SEGNO;
goto gc_more;

if (!stop_gc) {
segno = NULL_SEGNO;
goto gc_more;
}
stop:
SIT_I(sbi)->last_victim[ALLOC_NEXT] = 0;
SIT_I(sbi)->last_victim[FLUSH_DEVICE] = gc_control->victim_segno;
Expand Down

0 comments on commit fecc894

Please sign in to comment.