Skip to content

Commit 9748c2d

Browse files
Daeho JeongJaegeuk Kim
authored andcommitted
f2fs: do FG_GC when GC boosting is required for zoned devices
Under low free section count, we need to use FG_GC instead of BG_GC to recover free sections. Signed-off-by: Daeho Jeong <[email protected]> Reviewed-by: Chao Yu <[email protected]> Signed-off-by: Jaegeuk Kim <[email protected]>
1 parent 2223fe6 commit 9748c2d

File tree

2 files changed

+18
-7
lines changed

2 files changed

+18
-7
lines changed

fs/f2fs/f2fs.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1300,6 +1300,7 @@ struct f2fs_gc_control {
13001300
bool no_bg_gc; /* check the space and stop bg_gc */
13011301
bool should_migrate_blocks; /* should migrate blocks */
13021302
bool err_gc_skipped; /* return EAGAIN if GC skipped */
1303+
bool one_time; /* require one time GC in one migration unit */
13031304
unsigned int nr_free_secs; /* # of free sections to do GC */
13041305
};
13051306

fs/f2fs/gc.c

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,8 @@ static int gc_thread_func(void *data)
8181
continue;
8282
}
8383

84+
gc_control.one_time = false;
85+
8486
/*
8587
* [GC triggering condition]
8688
* 0. GC is not conducted currently.
@@ -126,15 +128,19 @@ static int gc_thread_func(void *data)
126128
wait_ms = gc_th->max_sleep_time;
127129
}
128130

129-
if (need_to_boost_gc(sbi))
131+
if (need_to_boost_gc(sbi)) {
130132
decrease_sleep_time(gc_th, &wait_ms);
131-
else
133+
if (f2fs_sb_has_blkzoned(sbi))
134+
gc_control.one_time = true;
135+
} else {
132136
increase_sleep_time(gc_th, &wait_ms);
137+
}
133138
do_gc:
134139
stat_inc_gc_call_count(sbi, foreground ?
135140
FOREGROUND : BACKGROUND);
136141

137-
sync_mode = F2FS_OPTION(sbi).bggc_mode == BGGC_MODE_SYNC;
142+
sync_mode = (F2FS_OPTION(sbi).bggc_mode == BGGC_MODE_SYNC) ||
143+
gc_control.one_time;
138144

139145
/* foreground GC was been triggered via f2fs_balance_fs() */
140146
if (foreground)
@@ -1701,7 +1707,7 @@ static int __get_victim(struct f2fs_sb_info *sbi, unsigned int *victim,
17011707
static int do_garbage_collect(struct f2fs_sb_info *sbi,
17021708
unsigned int start_segno,
17031709
struct gc_inode_list *gc_list, int gc_type,
1704-
bool force_migrate)
1710+
bool force_migrate, bool one_time)
17051711
{
17061712
struct page *sum_page;
17071713
struct f2fs_summary_block *sum;
@@ -1728,7 +1734,7 @@ static int do_garbage_collect(struct f2fs_sb_info *sbi,
17281734
sec_end_segno -= SEGS_PER_SEC(sbi) -
17291735
f2fs_usable_segs_in_sec(sbi, segno);
17301736

1731-
if (gc_type == BG_GC) {
1737+
if (gc_type == BG_GC || one_time) {
17321738
unsigned int window_granularity =
17331739
sbi->migration_window_granularity;
17341740

@@ -1911,7 +1917,8 @@ int f2fs_gc(struct f2fs_sb_info *sbi, struct f2fs_gc_control *gc_control)
19111917
}
19121918

19131919
seg_freed = do_garbage_collect(sbi, segno, &gc_list, gc_type,
1914-
gc_control->should_migrate_blocks);
1920+
gc_control->should_migrate_blocks,
1921+
gc_control->one_time);
19151922
if (seg_freed < 0)
19161923
goto stop;
19171924

@@ -1922,6 +1929,9 @@ int f2fs_gc(struct f2fs_sb_info *sbi, struct f2fs_gc_control *gc_control)
19221929
total_sec_freed++;
19231930
}
19241931

1932+
if (gc_control->one_time)
1933+
goto stop;
1934+
19251935
if (gc_type == FG_GC) {
19261936
sbi->cur_victim_sec = NULL_SEGNO;
19271937

@@ -2047,7 +2057,7 @@ int f2fs_gc_range(struct f2fs_sb_info *sbi,
20472057
};
20482058

20492059
do_garbage_collect(sbi, segno, &gc_list, FG_GC,
2050-
dry_run_sections == 0);
2060+
dry_run_sections == 0, false);
20512061
put_gc_inode(&gc_list);
20522062

20532063
if (!dry_run && get_valid_blocks(sbi, segno, true))

0 commit comments

Comments
 (0)