Commit d147ea4a authored by Jaegeuk Kim's avatar Jaegeuk Kim

f2fs: introduce f2fs_gc_control to consolidate f2fs_gc parameters

No functional change.

- remove checkpoint=disable check for f2fs_write_checkpoint
- get sec_freed all the time
Reviewed-by: default avatarChao Yu <chao@kernel.org>
Signed-off-by: default avatarJaegeuk Kim <jaegeuk@kernel.org>
parent 64e3ed0b
...@@ -1265,6 +1265,14 @@ struct atgc_management { ...@@ -1265,6 +1265,14 @@ struct atgc_management {
unsigned long long age_threshold; /* age threshold */ unsigned long long age_threshold; /* age threshold */
}; };
struct f2fs_gc_control {
unsigned int victim_segno; /* target victim segment number */
int init_gc_type; /* FG_GC or BG_GC */
bool no_bg_gc; /* check the space and stop bg_gc */
bool should_migrate_blocks; /* should migrate blocks */
bool err_gc_skipped; /* return EAGAIN if GC skipped */
};
/* For s_flag in struct f2fs_sb_info */ /* For s_flag in struct f2fs_sb_info */
enum { enum {
SBI_IS_DIRTY, /* dirty flag for checkpoint */ SBI_IS_DIRTY, /* dirty flag for checkpoint */
...@@ -3761,8 +3769,7 @@ extern const struct iomap_ops f2fs_iomap_ops; ...@@ -3761,8 +3769,7 @@ extern const struct iomap_ops f2fs_iomap_ops;
int f2fs_start_gc_thread(struct f2fs_sb_info *sbi); int f2fs_start_gc_thread(struct f2fs_sb_info *sbi);
void f2fs_stop_gc_thread(struct f2fs_sb_info *sbi); void f2fs_stop_gc_thread(struct f2fs_sb_info *sbi);
block_t f2fs_start_bidx_of_node(unsigned int node_ofs, struct inode *inode); block_t f2fs_start_bidx_of_node(unsigned int node_ofs, struct inode *inode);
int f2fs_gc(struct f2fs_sb_info *sbi, bool sync, bool background, bool force, int f2fs_gc(struct f2fs_sb_info *sbi, struct f2fs_gc_control *gc_control);
unsigned int segno);
void f2fs_build_gc_manager(struct f2fs_sb_info *sbi); void f2fs_build_gc_manager(struct f2fs_sb_info *sbi);
int f2fs_resize_fs(struct f2fs_sb_info *sbi, __u64 block_count); int f2fs_resize_fs(struct f2fs_sb_info *sbi, __u64 block_count);
int __init f2fs_create_garbage_collection_cache(void); int __init f2fs_create_garbage_collection_cache(void);
......
...@@ -1647,6 +1647,10 @@ static int expand_inode_data(struct inode *inode, loff_t offset, ...@@ -1647,6 +1647,10 @@ static int expand_inode_data(struct inode *inode, loff_t offset,
struct f2fs_map_blocks map = { .m_next_pgofs = NULL, struct f2fs_map_blocks map = { .m_next_pgofs = NULL,
.m_next_extent = NULL, .m_seg_type = NO_CHECK_TYPE, .m_next_extent = NULL, .m_seg_type = NO_CHECK_TYPE,
.m_may_create = true }; .m_may_create = true };
struct f2fs_gc_control gc_control = { .victim_segno = NULL_SEGNO,
.init_gc_type = FG_GC,
.should_migrate_blocks = false,
.err_gc_skipped = true };
pgoff_t pg_start, pg_end; pgoff_t pg_start, pg_end;
loff_t new_size = i_size_read(inode); loff_t new_size = i_size_read(inode);
loff_t off_end; loff_t off_end;
...@@ -1684,7 +1688,7 @@ static int expand_inode_data(struct inode *inode, loff_t offset, ...@@ -1684,7 +1688,7 @@ static int expand_inode_data(struct inode *inode, loff_t offset,
if (has_not_enough_free_secs(sbi, 0, if (has_not_enough_free_secs(sbi, 0,
GET_SEC_FROM_SEG(sbi, overprovision_segments(sbi)))) { GET_SEC_FROM_SEG(sbi, overprovision_segments(sbi)))) {
f2fs_down_write(&sbi->gc_lock); f2fs_down_write(&sbi->gc_lock);
err = f2fs_gc(sbi, true, false, false, NULL_SEGNO); err = f2fs_gc(sbi, &gc_control);
if (err && err != -ENODATA) if (err && err != -ENODATA)
goto out_err; goto out_err;
} }
...@@ -2344,6 +2348,9 @@ static int f2fs_ioc_gc(struct file *filp, unsigned long arg) ...@@ -2344,6 +2348,9 @@ static int f2fs_ioc_gc(struct file *filp, unsigned long arg)
{ {
struct inode *inode = file_inode(filp); struct inode *inode = file_inode(filp);
struct f2fs_sb_info *sbi = F2FS_I_SB(inode); struct f2fs_sb_info *sbi = F2FS_I_SB(inode);
struct f2fs_gc_control gc_control = { .victim_segno = NULL_SEGNO,
.no_bg_gc = false,
.should_migrate_blocks = false };
__u32 sync; __u32 sync;
int ret; int ret;
...@@ -2369,7 +2376,9 @@ static int f2fs_ioc_gc(struct file *filp, unsigned long arg) ...@@ -2369,7 +2376,9 @@ static int f2fs_ioc_gc(struct file *filp, unsigned long arg)
f2fs_down_write(&sbi->gc_lock); f2fs_down_write(&sbi->gc_lock);
} }
ret = f2fs_gc(sbi, sync, true, false, NULL_SEGNO); gc_control.init_gc_type = sync ? FG_GC : BG_GC;
gc_control.err_gc_skipped = sync;
ret = f2fs_gc(sbi, &gc_control);
out: out:
mnt_drop_write_file(filp); mnt_drop_write_file(filp);
return ret; return ret;
...@@ -2378,6 +2387,11 @@ static int f2fs_ioc_gc(struct file *filp, unsigned long arg) ...@@ -2378,6 +2387,11 @@ static int f2fs_ioc_gc(struct file *filp, unsigned long arg)
static int __f2fs_ioc_gc_range(struct file *filp, struct f2fs_gc_range *range) static int __f2fs_ioc_gc_range(struct file *filp, struct f2fs_gc_range *range)
{ {
struct f2fs_sb_info *sbi = F2FS_I_SB(file_inode(filp)); struct f2fs_sb_info *sbi = F2FS_I_SB(file_inode(filp));
struct f2fs_gc_control gc_control = {
.init_gc_type = range->sync ? FG_GC : BG_GC,
.no_bg_gc = false,
.should_migrate_blocks = false,
.err_gc_skipped = range->sync };
u64 end; u64 end;
int ret; int ret;
...@@ -2405,8 +2419,8 @@ static int __f2fs_ioc_gc_range(struct file *filp, struct f2fs_gc_range *range) ...@@ -2405,8 +2419,8 @@ static int __f2fs_ioc_gc_range(struct file *filp, struct f2fs_gc_range *range)
f2fs_down_write(&sbi->gc_lock); f2fs_down_write(&sbi->gc_lock);
} }
ret = f2fs_gc(sbi, range->sync, true, false, gc_control.victim_segno = GET_SEGNO(sbi, range->start);
GET_SEGNO(sbi, range->start)); ret = f2fs_gc(sbi, &gc_control);
if (ret) { if (ret) {
if (ret == -EBUSY) if (ret == -EBUSY)
ret = -EAGAIN; ret = -EAGAIN;
...@@ -2820,6 +2834,10 @@ static int f2fs_ioc_flush_device(struct file *filp, unsigned long arg) ...@@ -2820,6 +2834,10 @@ static int f2fs_ioc_flush_device(struct file *filp, unsigned long arg)
unsigned int start_segno = 0, end_segno = 0; unsigned int start_segno = 0, end_segno = 0;
unsigned int dev_start_segno = 0, dev_end_segno = 0; unsigned int dev_start_segno = 0, dev_end_segno = 0;
struct f2fs_flush_device range; struct f2fs_flush_device range;
struct f2fs_gc_control gc_control = {
.init_gc_type = FG_GC,
.should_migrate_blocks = true,
.err_gc_skipped = true };
int ret; int ret;
if (!capable(CAP_SYS_ADMIN)) if (!capable(CAP_SYS_ADMIN))
...@@ -2863,7 +2881,9 @@ static int f2fs_ioc_flush_device(struct file *filp, unsigned long arg) ...@@ -2863,7 +2881,9 @@ static int f2fs_ioc_flush_device(struct file *filp, unsigned long arg)
sm->last_victim[GC_CB] = end_segno + 1; sm->last_victim[GC_CB] = end_segno + 1;
sm->last_victim[GC_GREEDY] = end_segno + 1; sm->last_victim[GC_GREEDY] = end_segno + 1;
sm->last_victim[ALLOC_NEXT] = end_segno + 1; sm->last_victim[ALLOC_NEXT] = end_segno + 1;
ret = f2fs_gc(sbi, true, true, true, start_segno);
gc_control.victim_segno = start_segno;
ret = f2fs_gc(sbi, &gc_control);
if (ret == -EAGAIN) if (ret == -EAGAIN)
ret = 0; ret = 0;
else if (ret < 0) else if (ret < 0)
......
...@@ -35,6 +35,9 @@ static int gc_thread_func(void *data) ...@@ -35,6 +35,9 @@ static int gc_thread_func(void *data)
wait_queue_head_t *wq = &sbi->gc_thread->gc_wait_queue_head; wait_queue_head_t *wq = &sbi->gc_thread->gc_wait_queue_head;
wait_queue_head_t *fggc_wq = &sbi->gc_thread->fggc_wq; wait_queue_head_t *fggc_wq = &sbi->gc_thread->fggc_wq;
unsigned int wait_ms; unsigned int wait_ms;
struct f2fs_gc_control gc_control = {
.victim_segno = NULL_SEGNO,
.should_migrate_blocks = false };
wait_ms = gc_th->min_sleep_time; wait_ms = gc_th->min_sleep_time;
...@@ -141,8 +144,12 @@ static int gc_thread_func(void *data) ...@@ -141,8 +144,12 @@ static int gc_thread_func(void *data)
if (foreground) if (foreground)
sync_mode = false; sync_mode = false;
gc_control.init_gc_type = sync_mode ? FG_GC : BG_GC;
gc_control.no_bg_gc = foreground;
gc_control.err_gc_skipped = sync_mode;
/* if return value is not zero, no victim was selected */ /* if return value is not zero, no victim was selected */
if (f2fs_gc(sbi, sync_mode, !foreground, false, NULL_SEGNO)) if (f2fs_gc(sbi, &gc_control))
wait_ms = gc_th->no_gc_sleep_time; wait_ms = gc_th->no_gc_sleep_time;
if (foreground) if (foreground)
...@@ -1740,21 +1747,20 @@ static int do_garbage_collect(struct f2fs_sb_info *sbi, ...@@ -1740,21 +1747,20 @@ static int do_garbage_collect(struct f2fs_sb_info *sbi,
return seg_freed; return seg_freed;
} }
int f2fs_gc(struct f2fs_sb_info *sbi, bool sync, int f2fs_gc(struct f2fs_sb_info *sbi, struct f2fs_gc_control *gc_control)
bool background, bool force, unsigned int segno)
{ {
int gc_type = sync ? FG_GC : BG_GC; int gc_type = gc_control->init_gc_type;
unsigned int segno = gc_control->victim_segno;
int sec_freed = 0, seg_freed = 0, total_freed = 0; int sec_freed = 0, seg_freed = 0, total_freed = 0;
int ret = 0; int ret = 0;
struct cp_control cpc; struct cp_control cpc;
unsigned int init_segno = segno;
struct gc_inode_list gc_list = { struct gc_inode_list gc_list = {
.ilist = LIST_HEAD_INIT(gc_list.ilist), .ilist = LIST_HEAD_INIT(gc_list.ilist),
.iroot = RADIX_TREE_INIT(gc_list.iroot, GFP_NOFS), .iroot = RADIX_TREE_INIT(gc_list.iroot, GFP_NOFS),
}; };
unsigned int skipped_round = 0, round = 0; unsigned int skipped_round = 0, round = 0;
trace_f2fs_gc_begin(sbi->sb, sync, background, trace_f2fs_gc_begin(sbi->sb, gc_type, gc_control->no_bg_gc,
get_pages(sbi, F2FS_DIRTY_NODES), get_pages(sbi, F2FS_DIRTY_NODES),
get_pages(sbi, F2FS_DIRTY_DENTS), get_pages(sbi, F2FS_DIRTY_DENTS),
get_pages(sbi, F2FS_DIRTY_IMETA), get_pages(sbi, F2FS_DIRTY_IMETA),
...@@ -1781,8 +1787,7 @@ int f2fs_gc(struct f2fs_sb_info *sbi, bool sync, ...@@ -1781,8 +1787,7 @@ int f2fs_gc(struct f2fs_sb_info *sbi, bool sync,
* threshold, we can make them free by checkpoint. Then, we * threshold, we can make them free by checkpoint. Then, we
* secure free segments which doesn't need fggc any more. * secure free segments which doesn't need fggc any more.
*/ */
if (prefree_segments(sbi) && if (prefree_segments(sbi)) {
!is_sbi_flag_set(sbi, SBI_CP_DISABLED)) {
ret = f2fs_write_checkpoint(sbi, &cpc); ret = f2fs_write_checkpoint(sbi, &cpc);
if (ret) if (ret)
goto stop; goto stop;
...@@ -1792,7 +1797,7 @@ int f2fs_gc(struct f2fs_sb_info *sbi, bool sync, ...@@ -1792,7 +1797,7 @@ int f2fs_gc(struct f2fs_sb_info *sbi, bool sync,
} }
/* f2fs_balance_fs doesn't need to do BG_GC in critical path. */ /* f2fs_balance_fs doesn't need to do BG_GC in critical path. */
if (gc_type == BG_GC && !background) { if (gc_type == BG_GC && gc_control->no_bg_gc) {
ret = -EINVAL; ret = -EINVAL;
goto stop; goto stop;
} }
...@@ -1808,45 +1813,48 @@ int f2fs_gc(struct f2fs_sb_info *sbi, bool sync, ...@@ -1808,45 +1813,48 @@ int f2fs_gc(struct f2fs_sb_info *sbi, bool sync,
goto stop; goto stop;
} }
seg_freed = do_garbage_collect(sbi, segno, &gc_list, gc_type, force); seg_freed = do_garbage_collect(sbi, segno, &gc_list, gc_type,
if (gc_type == FG_GC && gc_control->should_migrate_blocks);
seg_freed == f2fs_usable_segs_in_sec(sbi, segno))
sec_freed++;
total_freed += seg_freed; total_freed += seg_freed;
if (gc_type == FG_GC) { if (seg_freed == f2fs_usable_segs_in_sec(sbi, segno))
if (sbi->skipped_gc_rwsem) sec_freed++;
skipped_round++;
round++;
}
if (gc_type == FG_GC) if (gc_type == FG_GC)
sbi->cur_victim_sec = NULL_SEGNO; sbi->cur_victim_sec = NULL_SEGNO;
if (sync) if (gc_control->init_gc_type == FG_GC)
goto stop; goto stop;
if (!has_not_enough_free_secs(sbi, sec_freed, 0)) if (!has_not_enough_free_secs(sbi,
(gc_type == FG_GC) ? sec_freed : 0, 0))
goto stop; goto stop;
if (skipped_round <= MAX_SKIP_GC_COUNT || skipped_round * 2 < round) { /* FG_GC stops GC by skip_count */
if (gc_type == FG_GC) {
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;
}
}
/* Write checkpoint to reclaim prefree segments */ /* Write checkpoint to reclaim prefree segments */
if (free_sections(sbi) < NR_CURSEG_PERSIST_TYPE && if (free_sections(sbi) < NR_CURSEG_PERSIST_TYPE &&
prefree_segments(sbi) && prefree_segments(sbi)) {
!is_sbi_flag_set(sbi, SBI_CP_DISABLED)) {
ret = f2fs_write_checkpoint(sbi, &cpc); ret = f2fs_write_checkpoint(sbi, &cpc);
if (ret) if (ret)
goto stop; goto stop;
} }
segno = NULL_SEGNO; segno = NULL_SEGNO;
goto gc_more; goto gc_more;
}
if (gc_type == FG_GC && !is_sbi_flag_set(sbi, SBI_CP_DISABLED))
ret = f2fs_write_checkpoint(sbi, &cpc);
stop: stop:
SIT_I(sbi)->last_victim[ALLOC_NEXT] = 0; SIT_I(sbi)->last_victim[ALLOC_NEXT] = 0;
SIT_I(sbi)->last_victim[FLUSH_DEVICE] = init_segno; SIT_I(sbi)->last_victim[FLUSH_DEVICE] = gc_control->victim_segno;
if (gc_type == FG_GC) if (gc_type == FG_GC)
f2fs_unpin_all_sections(sbi, true); f2fs_unpin_all_sections(sbi, true);
...@@ -1864,7 +1872,7 @@ int f2fs_gc(struct f2fs_sb_info *sbi, bool sync, ...@@ -1864,7 +1872,7 @@ int f2fs_gc(struct f2fs_sb_info *sbi, bool sync,
put_gc_inode(&gc_list); put_gc_inode(&gc_list);
if (sync && !ret) if (gc_control->err_gc_skipped && !ret)
ret = sec_freed ? 0 : -EAGAIN; ret = sec_freed ? 0 : -EAGAIN;
return ret; return ret;
} }
......
...@@ -399,8 +399,14 @@ void f2fs_balance_fs(struct f2fs_sb_info *sbi, bool need) ...@@ -399,8 +399,14 @@ void f2fs_balance_fs(struct f2fs_sb_info *sbi, bool need)
io_schedule(); io_schedule();
finish_wait(&sbi->gc_thread->fggc_wq, &wait); finish_wait(&sbi->gc_thread->fggc_wq, &wait);
} else { } else {
struct f2fs_gc_control gc_control = {
.victim_segno = NULL_SEGNO,
.init_gc_type = BG_GC,
.no_bg_gc = true,
.should_migrate_blocks = false,
.err_gc_skipped = false };
f2fs_down_write(&sbi->gc_lock); f2fs_down_write(&sbi->gc_lock);
f2fs_gc(sbi, false, false, false, NULL_SEGNO); f2fs_gc(sbi, &gc_control);
} }
} }
} }
......
...@@ -2076,8 +2076,14 @@ static int f2fs_disable_checkpoint(struct f2fs_sb_info *sbi) ...@@ -2076,8 +2076,14 @@ static int f2fs_disable_checkpoint(struct f2fs_sb_info *sbi)
sbi->gc_mode = GC_URGENT_HIGH; sbi->gc_mode = GC_URGENT_HIGH;
while (!f2fs_time_over(sbi, DISABLE_TIME)) { while (!f2fs_time_over(sbi, DISABLE_TIME)) {
struct f2fs_gc_control gc_control = {
.victim_segno = NULL_SEGNO,
.init_gc_type = FG_GC,
.should_migrate_blocks = false,
.err_gc_skipped = true };
f2fs_down_write(&sbi->gc_lock); f2fs_down_write(&sbi->gc_lock);
err = f2fs_gc(sbi, true, false, false, NULL_SEGNO); err = f2fs_gc(sbi, &gc_control);
if (err == -ENODATA) { if (err == -ENODATA) {
err = 0; err = 0;
break; break;
......
...@@ -644,19 +644,19 @@ TRACE_EVENT(f2fs_background_gc, ...@@ -644,19 +644,19 @@ TRACE_EVENT(f2fs_background_gc,
TRACE_EVENT(f2fs_gc_begin, TRACE_EVENT(f2fs_gc_begin,
TP_PROTO(struct super_block *sb, bool sync, bool background, TP_PROTO(struct super_block *sb, int gc_type, bool no_bg_gc,
long long dirty_nodes, long long dirty_dents, long long dirty_nodes, long long dirty_dents,
long long dirty_imeta, unsigned int free_sec, long long dirty_imeta, unsigned int free_sec,
unsigned int free_seg, int reserved_seg, unsigned int free_seg, int reserved_seg,
unsigned int prefree_seg), unsigned int prefree_seg),
TP_ARGS(sb, sync, background, dirty_nodes, dirty_dents, dirty_imeta, TP_ARGS(sb, gc_type, no_bg_gc, dirty_nodes, dirty_dents, dirty_imeta,
free_sec, free_seg, reserved_seg, prefree_seg), free_sec, free_seg, reserved_seg, prefree_seg),
TP_STRUCT__entry( TP_STRUCT__entry(
__field(dev_t, dev) __field(dev_t, dev)
__field(bool, sync) __field(int, gc_type)
__field(bool, background) __field(bool, no_bg_gc)
__field(long long, dirty_nodes) __field(long long, dirty_nodes)
__field(long long, dirty_dents) __field(long long, dirty_dents)
__field(long long, dirty_imeta) __field(long long, dirty_imeta)
...@@ -668,8 +668,8 @@ TRACE_EVENT(f2fs_gc_begin, ...@@ -668,8 +668,8 @@ TRACE_EVENT(f2fs_gc_begin,
TP_fast_assign( TP_fast_assign(
__entry->dev = sb->s_dev; __entry->dev = sb->s_dev;
__entry->sync = sync; __entry->gc_type = gc_type;
__entry->background = background; __entry->no_bg_gc = no_bg_gc;
__entry->dirty_nodes = dirty_nodes; __entry->dirty_nodes = dirty_nodes;
__entry->dirty_dents = dirty_dents; __entry->dirty_dents = dirty_dents;
__entry->dirty_imeta = dirty_imeta; __entry->dirty_imeta = dirty_imeta;
...@@ -679,12 +679,12 @@ TRACE_EVENT(f2fs_gc_begin, ...@@ -679,12 +679,12 @@ TRACE_EVENT(f2fs_gc_begin,
__entry->prefree_seg = prefree_seg; __entry->prefree_seg = prefree_seg;
), ),
TP_printk("dev = (%d,%d), sync = %d, background = %d, nodes = %lld, " TP_printk("dev = (%d,%d), gc_type = %s, no_background_GC = %d, nodes = %lld, "
"dents = %lld, imeta = %lld, free_sec:%u, free_seg:%u, " "dents = %lld, imeta = %lld, free_sec:%u, free_seg:%u, "
"rsv_seg:%d, prefree_seg:%u", "rsv_seg:%d, prefree_seg:%u",
show_dev(__entry->dev), show_dev(__entry->dev),
__entry->sync, show_gc_type(__entry->gc_type),
__entry->background, (__entry->gc_type == BG_GC) ? __entry->no_bg_gc : -1,
__entry->dirty_nodes, __entry->dirty_nodes,
__entry->dirty_dents, __entry->dirty_dents,
__entry->dirty_imeta, __entry->dirty_imeta,
......
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