Skip to content

Commit c81d5ba

Browse files
author
Jaegeuk Kim
committed
f2fs: do not stop GC when requiring a free section
The f2fs_gc uses a bitmap to indicate pinned sections, but when disabling chckpoint, we call f2fs_gc() with NULL_SEGNO which selects the same dirty segment as a victim all the time, resulting in checkpoint=disable failure, for example. Let's pick another one, if we fail to collect it. Reviewed-by: Chao Yu <chao@kernel.org> Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
1 parent c58d7c5 commit c81d5ba

6 files changed

Lines changed: 30 additions & 14 deletions

File tree

fs/f2fs/f2fs.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1271,6 +1271,7 @@ struct f2fs_gc_control {
12711271
bool no_bg_gc; /* check the space and stop bg_gc */
12721272
bool should_migrate_blocks; /* should migrate blocks */
12731273
bool err_gc_skipped; /* return EAGAIN if GC skipped */
1274+
unsigned int nr_free_secs; /* # of free sections to do GC */
12741275
};
12751276

12761277
/* For s_flag in struct f2fs_sb_info */

fs/f2fs/file.c

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1650,7 +1650,8 @@ static int expand_inode_data(struct inode *inode, loff_t offset,
16501650
struct f2fs_gc_control gc_control = { .victim_segno = NULL_SEGNO,
16511651
.init_gc_type = FG_GC,
16521652
.should_migrate_blocks = false,
1653-
.err_gc_skipped = true };
1653+
.err_gc_skipped = true,
1654+
.nr_free_secs = 0 };
16541655
pgoff_t pg_start, pg_end;
16551656
loff_t new_size = i_size_read(inode);
16561657
loff_t off_end;
@@ -2350,7 +2351,8 @@ static int f2fs_ioc_gc(struct file *filp, unsigned long arg)
23502351
struct f2fs_sb_info *sbi = F2FS_I_SB(inode);
23512352
struct f2fs_gc_control gc_control = { .victim_segno = NULL_SEGNO,
23522353
.no_bg_gc = false,
2353-
.should_migrate_blocks = false };
2354+
.should_migrate_blocks = false,
2355+
.nr_free_secs = 0 };
23542356
__u32 sync;
23552357
int ret;
23562358

@@ -2391,7 +2393,8 @@ static int __f2fs_ioc_gc_range(struct file *filp, struct f2fs_gc_range *range)
23912393
.init_gc_type = range->sync ? FG_GC : BG_GC,
23922394
.no_bg_gc = false,
23932395
.should_migrate_blocks = false,
2394-
.err_gc_skipped = range->sync };
2396+
.err_gc_skipped = range->sync,
2397+
.nr_free_secs = 0 };
23952398
u64 end;
23962399
int ret;
23972400

@@ -2837,7 +2840,8 @@ static int f2fs_ioc_flush_device(struct file *filp, unsigned long arg)
28372840
struct f2fs_gc_control gc_control = {
28382841
.init_gc_type = FG_GC,
28392842
.should_migrate_blocks = true,
2840-
.err_gc_skipped = true };
2843+
.err_gc_skipped = true,
2844+
.nr_free_secs = 0 };
28412845
int ret;
28422846

28432847
if (!capable(CAP_SYS_ADMIN))

fs/f2fs/gc.c

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,7 @@ static int gc_thread_func(void *data)
147147

148148
gc_control.init_gc_type = sync_mode ? FG_GC : BG_GC;
149149
gc_control.no_bg_gc = foreground;
150+
gc_control.nr_free_secs = foreground ? 1 : 0;
150151

151152
/* if return value is not zero, no victim was selected */
152153
if (f2fs_gc(sbi, &gc_control))
@@ -1761,6 +1762,7 @@ int f2fs_gc(struct f2fs_sb_info *sbi, struct f2fs_gc_control *gc_control)
17611762
unsigned int skipped_round = 0, round = 0;
17621763

17631764
trace_f2fs_gc_begin(sbi->sb, gc_type, gc_control->no_bg_gc,
1765+
gc_control->nr_free_secs,
17641766
get_pages(sbi, F2FS_DIRTY_NODES),
17651767
get_pages(sbi, F2FS_DIRTY_DENTS),
17661768
get_pages(sbi, F2FS_DIRTY_IMETA),
@@ -1823,12 +1825,13 @@ int f2fs_gc(struct f2fs_sb_info *sbi, struct f2fs_gc_control *gc_control)
18231825
if (gc_type == FG_GC)
18241826
sbi->cur_victim_sec = NULL_SEGNO;
18251827

1826-
if (gc_control->init_gc_type == FG_GC)
1827-
goto stop;
1828-
1829-
if (!has_not_enough_free_secs(sbi,
1830-
(gc_type == FG_GC) ? sec_freed : 0, 0))
1828+
if (gc_control->init_gc_type == FG_GC ||
1829+
!has_not_enough_free_secs(sbi,
1830+
(gc_type == FG_GC) ? sec_freed : 0, 0)) {
1831+
if (gc_type == FG_GC && sec_freed < gc_control->nr_free_secs)
1832+
goto go_gc_more;
18311833
goto stop;
1834+
}
18321835

18331836
/* FG_GC stops GC by skip_count */
18341837
if (gc_type == FG_GC) {
@@ -1849,6 +1852,7 @@ int f2fs_gc(struct f2fs_sb_info *sbi, struct f2fs_gc_control *gc_control)
18491852
if (ret)
18501853
goto stop;
18511854
}
1855+
go_gc_more:
18521856
segno = NULL_SEGNO;
18531857
goto gc_more;
18541858

fs/f2fs/segment.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -404,7 +404,8 @@ void f2fs_balance_fs(struct f2fs_sb_info *sbi, bool need)
404404
.init_gc_type = BG_GC,
405405
.no_bg_gc = true,
406406
.should_migrate_blocks = false,
407-
.err_gc_skipped = false };
407+
.err_gc_skipped = false,
408+
.nr_free_secs = 1 };
408409
f2fs_down_write(&sbi->gc_lock);
409410
f2fs_gc(sbi, &gc_control);
410411
}

fs/f2fs/super.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2080,7 +2080,8 @@ static int f2fs_disable_checkpoint(struct f2fs_sb_info *sbi)
20802080
.victim_segno = NULL_SEGNO,
20812081
.init_gc_type = FG_GC,
20822082
.should_migrate_blocks = false,
2083-
.err_gc_skipped = true };
2083+
.err_gc_skipped = true,
2084+
.nr_free_secs = 1 };
20842085

20852086
f2fs_down_write(&sbi->gc_lock);
20862087
err = f2fs_gc(sbi, &gc_control);

include/trace/events/f2fs.h

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -645,18 +645,21 @@ TRACE_EVENT(f2fs_background_gc,
645645
TRACE_EVENT(f2fs_gc_begin,
646646

647647
TP_PROTO(struct super_block *sb, int gc_type, bool no_bg_gc,
648+
unsigned int nr_free_secs,
648649
long long dirty_nodes, long long dirty_dents,
649650
long long dirty_imeta, unsigned int free_sec,
650651
unsigned int free_seg, int reserved_seg,
651652
unsigned int prefree_seg),
652653

653-
TP_ARGS(sb, gc_type, no_bg_gc, dirty_nodes, dirty_dents, dirty_imeta,
654+
TP_ARGS(sb, gc_type, no_bg_gc, nr_free_secs, dirty_nodes,
655+
dirty_dents, dirty_imeta,
654656
free_sec, free_seg, reserved_seg, prefree_seg),
655657

656658
TP_STRUCT__entry(
657659
__field(dev_t, dev)
658660
__field(int, gc_type)
659661
__field(bool, no_bg_gc)
662+
__field(unsigned int, nr_free_secs)
660663
__field(long long, dirty_nodes)
661664
__field(long long, dirty_dents)
662665
__field(long long, dirty_imeta)
@@ -670,6 +673,7 @@ TRACE_EVENT(f2fs_gc_begin,
670673
__entry->dev = sb->s_dev;
671674
__entry->gc_type = gc_type;
672675
__entry->no_bg_gc = no_bg_gc;
676+
__entry->nr_free_secs = nr_free_secs;
673677
__entry->dirty_nodes = dirty_nodes;
674678
__entry->dirty_dents = dirty_dents;
675679
__entry->dirty_imeta = dirty_imeta;
@@ -679,12 +683,13 @@ TRACE_EVENT(f2fs_gc_begin,
679683
__entry->prefree_seg = prefree_seg;
680684
),
681685

682-
TP_printk("dev = (%d,%d), gc_type = %s, no_background_GC = %d, nodes = %lld, "
683-
"dents = %lld, imeta = %lld, free_sec:%u, free_seg:%u, "
686+
TP_printk("dev = (%d,%d), gc_type = %s, no_background_GC = %d, nr_free_secs = %u, "
687+
"nodes = %lld, dents = %lld, imeta = %lld, free_sec:%u, free_seg:%u, "
684688
"rsv_seg:%d, prefree_seg:%u",
685689
show_dev(__entry->dev),
686690
show_gc_type(__entry->gc_type),
687691
(__entry->gc_type == BG_GC) ? __entry->no_bg_gc : -1,
692+
__entry->nr_free_secs,
688693
__entry->dirty_nodes,
689694
__entry->dirty_dents,
690695
__entry->dirty_imeta,

0 commit comments

Comments
 (0)