Skip to content

Commit e6d5e78

Browse files
Daeho JeongJaegeuk Kim
authored andcommitted
f2fs: ignore valid ratio when free section count is low
Otherwise F2FS will not do GC in background in low free section. Signed-off-by: Daeho Jeong <[email protected]> Reviewed-by: Chao Yu <[email protected]> Signed-off-by: Jaegeuk Kim <[email protected]>
1 parent f0a7adf commit e6d5e78

File tree

1 file changed

+12
-6
lines changed

1 file changed

+12
-6
lines changed

fs/f2fs/gc.c

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -384,14 +384,15 @@ static unsigned int get_cb_cost(struct f2fs_sb_info *sbi, unsigned int segno)
384384
}
385385

386386
static inline unsigned int get_gc_cost(struct f2fs_sb_info *sbi,
387-
unsigned int segno, struct victim_sel_policy *p)
387+
unsigned int segno, struct victim_sel_policy *p,
388+
unsigned int valid_thresh_ratio)
388389
{
389390
if (p->alloc_mode == SSR)
390391
return get_seg_entry(sbi, segno)->ckpt_valid_blocks;
391392

392-
if (p->one_time_gc && (get_valid_blocks(sbi, segno, true) >=
393-
CAP_BLKS_PER_SEC(sbi) * sbi->gc_thread->valid_thresh_ratio /
394-
100))
393+
if (p->one_time_gc && (valid_thresh_ratio < 100) &&
394+
(get_valid_blocks(sbi, segno, true) >=
395+
CAP_BLKS_PER_SEC(sbi) * valid_thresh_ratio / 100))
395396
return UINT_MAX;
396397

397398
/* alloc_mode == LFS */
@@ -772,6 +773,7 @@ int f2fs_get_victim(struct f2fs_sb_info *sbi, unsigned int *result,
772773
unsigned int secno, last_victim;
773774
unsigned int last_segment;
774775
unsigned int nsearched;
776+
unsigned int valid_thresh_ratio = 100;
775777
bool is_atgc;
776778
int ret = 0;
777779

@@ -781,7 +783,11 @@ int f2fs_get_victim(struct f2fs_sb_info *sbi, unsigned int *result,
781783
p.alloc_mode = alloc_mode;
782784
p.age = age;
783785
p.age_threshold = sbi->am.age_threshold;
784-
p.one_time_gc = one_time;
786+
if (one_time) {
787+
p.one_time_gc = one_time;
788+
if (has_enough_free_secs(sbi, 0, NR_PERSISTENT_LOG))
789+
valid_thresh_ratio = sbi->gc_thread->valid_thresh_ratio;
790+
}
785791

786792
retry:
787793
select_policy(sbi, gc_type, type, &p);
@@ -907,7 +913,7 @@ int f2fs_get_victim(struct f2fs_sb_info *sbi, unsigned int *result,
907913
goto next;
908914
}
909915

910-
cost = get_gc_cost(sbi, segno, &p);
916+
cost = get_gc_cost(sbi, segno, &p, valid_thresh_ratio);
911917

912918
if (p.min_cost > cost) {
913919
p.min_segno = segno;

0 commit comments

Comments
 (0)