Commit 43ced84e authored by Chao Yu's avatar Chao Yu Committed by Jaegeuk Kim

f2fs: clean up foreground GC flow

This patch changes to check valid block number of one GCed section
directly instead of checking the number in all segments of section
one by one in order to clean up codes of foreground GC.
Signed-off-by: default avatarChao Yu <yuchao0@huawei.com>
Signed-off-by: default avatarJaegeuk Kim <jaegeuk@kernel.org>
parent 7c4abcbe
...@@ -815,7 +815,7 @@ static int do_garbage_collect(struct f2fs_sb_info *sbi, ...@@ -815,7 +815,7 @@ static int do_garbage_collect(struct f2fs_sb_info *sbi,
struct blk_plug plug; struct blk_plug plug;
unsigned int segno = start_segno; unsigned int segno = start_segno;
unsigned int end_segno = start_segno + sbi->segs_per_sec; unsigned int end_segno = start_segno + sbi->segs_per_sec;
int seg_freed = 0; int sec_freed = 0;
unsigned char type = IS_DATASEG(get_seg_entry(sbi, segno)->type) ? unsigned char type = IS_DATASEG(get_seg_entry(sbi, segno)->type) ?
SUM_TYPE_DATA : SUM_TYPE_NODE; SUM_TYPE_DATA : SUM_TYPE_NODE;
...@@ -871,22 +871,20 @@ static int do_garbage_collect(struct f2fs_sb_info *sbi, ...@@ -871,22 +871,20 @@ static int do_garbage_collect(struct f2fs_sb_info *sbi,
blk_finish_plug(&plug); blk_finish_plug(&plug);
if (gc_type == FG_GC) { if (gc_type == FG_GC &&
while (start_segno < end_segno) get_valid_blocks(sbi, start_segno, sbi->segs_per_sec) == 0)
if (get_valid_blocks(sbi, start_segno++, 1) == 0) sec_freed = 1;
seg_freed++;
}
stat_inc_call_count(sbi->stat_info); stat_inc_call_count(sbi->stat_info);
return seg_freed; return sec_freed;
} }
int f2fs_gc(struct f2fs_sb_info *sbi, bool sync) int f2fs_gc(struct f2fs_sb_info *sbi, bool sync)
{ {
unsigned int segno; unsigned int segno;
int gc_type = sync ? FG_GC : BG_GC; int gc_type = sync ? FG_GC : BG_GC;
int sec_freed = 0, seg_freed; int sec_freed = 0;
int ret = -EINVAL; int ret = -EINVAL;
struct cp_control cpc; struct cp_control cpc;
struct gc_inode_list gc_list = { struct gc_inode_list gc_list = {
...@@ -925,9 +923,8 @@ int f2fs_gc(struct f2fs_sb_info *sbi, bool sync) ...@@ -925,9 +923,8 @@ int f2fs_gc(struct f2fs_sb_info *sbi, bool sync)
goto stop; goto stop;
ret = 0; ret = 0;
seg_freed = do_garbage_collect(sbi, segno, &gc_list, gc_type); if (do_garbage_collect(sbi, segno, &gc_list, gc_type) &&
gc_type == FG_GC)
if (gc_type == FG_GC && seg_freed == sbi->segs_per_sec)
sec_freed++; sec_freed++;
if (gc_type == FG_GC) if (gc_type == FG_GC)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment