Skip to content

Commit 9bf1dcb

Browse files
chaseyuJaegeuk Kim
authored andcommitted
f2fs: fix to account gc stats correctly
As reported, status debugfs entry shows inconsistent GC stats as below: GC calls: 6008 (BG: 6161) - data segments : 3053 (BG: 3053) - node segments : 2955 (BG: 2955) Total GC calls is larger than BGGC calls, the reason is: - f2fs_stat_info.call_count accounts total migrated section count by f2fs_gc() - f2fs_stat_info.bg_gc accounts total call times of f2fs_gc() from background gc_thread Another issue is gc_foreground_calls sysfs entry shows total GC call count rather than FGGC call count. This patch changes as below for fix: - account GC calls and migrated segment count separately - support to account migrated section count if it enables large section mode - fix to show correct value in gc_foreground_calls sysfs entry Fixes: fc7100e ("f2fs: Add f2fs stats to sysfs") Signed-off-by: Chao Yu <chao@kernel.org> Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
1 parent bc3994f commit 9bf1dcb

File tree

7 files changed

+54
-35
lines changed

7 files changed

+54
-35
lines changed

fs/f2fs/debug.c

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -511,12 +511,24 @@ static int stat_show(struct seq_file *s, void *v)
511511
seq_printf(s, " - Total : %4d\n", si->nr_total_ckpt);
512512
seq_printf(s, " - Cur time : %4d(ms)\n", si->cur_ckpt_time);
513513
seq_printf(s, " - Peak time : %4d(ms)\n", si->peak_ckpt_time);
514-
seq_printf(s, "GC calls: %d (BG: %d)\n",
515-
si->call_count, si->bg_gc);
516-
seq_printf(s, " - data segments : %d (%d)\n",
517-
si->data_segs, si->bg_data_segs);
518-
seq_printf(s, " - node segments : %d (%d)\n",
519-
si->node_segs, si->bg_node_segs);
514+
seq_printf(s, "GC calls: %d (gc_thread: %d)\n",
515+
si->gc_call_count[BACKGROUND] +
516+
si->gc_call_count[FOREGROUND],
517+
si->gc_call_count[BACKGROUND]);
518+
if (__is_large_section(sbi)) {
519+
seq_printf(s, " - data sections : %d (BG: %d)\n",
520+
si->gc_secs[DATA][BG_GC] + si->gc_secs[DATA][FG_GC],
521+
si->gc_secs[DATA][BG_GC]);
522+
seq_printf(s, " - node sections : %d (BG: %d)\n",
523+
si->gc_secs[NODE][BG_GC] + si->gc_secs[NODE][FG_GC],
524+
si->gc_secs[NODE][BG_GC]);
525+
}
526+
seq_printf(s, " - data segments : %d (BG: %d)\n",
527+
si->gc_segs[DATA][BG_GC] + si->gc_segs[DATA][FG_GC],
528+
si->gc_segs[DATA][BG_GC]);
529+
seq_printf(s, " - node segments : %d (BG: %d)\n",
530+
si->gc_segs[NODE][BG_GC] + si->gc_segs[NODE][FG_GC],
531+
si->gc_segs[NODE][BG_GC]);
520532
seq_puts(s, " - Reclaimed segs :\n");
521533
seq_printf(s, " - Normal : %d\n", sbi->gc_reclaimed_segs[GC_NORMAL]);
522534
seq_printf(s, " - Idle CB : %d\n", sbi->gc_reclaimed_segs[GC_IDLE_CB]);

fs/f2fs/f2fs.h

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -3860,6 +3860,12 @@ void f2fs_destroy_recovery_cache(void);
38603860
/*
38613861
* debug.c
38623862
*/
3863+
enum {
3864+
BACKGROUND,
3865+
FOREGROUND,
3866+
MAX_CALL_TYPE
3867+
};
3868+
38633869
#ifdef CONFIG_F2FS_STAT_FS
38643870
struct f2fs_stat_info {
38653871
struct list_head stat_list;
@@ -3885,7 +3891,7 @@ struct f2fs_stat_info {
38853891
int nats, dirty_nats, sits, dirty_sits;
38863892
int free_nids, avail_nids, alloc_nids;
38873893
int total_count, utilization;
3888-
int bg_gc, nr_wb_cp_data, nr_wb_data;
3894+
int nr_wb_cp_data, nr_wb_data;
38893895
int nr_rd_data, nr_rd_node, nr_rd_meta;
38903896
int nr_dio_read, nr_dio_write;
38913897
unsigned int io_skip_bggc, other_skip_bggc;
@@ -3905,9 +3911,11 @@ struct f2fs_stat_info {
39053911
int rsvd_segs, overp_segs;
39063912
int dirty_count, node_pages, meta_pages, compress_pages;
39073913
int compress_page_hit;
3908-
int prefree_count, call_count, cp_count, bg_cp_count;
3909-
int tot_segs, node_segs, data_segs, free_segs, free_secs;
3910-
int bg_node_segs, bg_data_segs;
3914+
int prefree_count, free_segs, free_secs;
3915+
int cp_count, bg_cp_count;
3916+
int gc_call_count[MAX_CALL_TYPE];
3917+
int gc_segs[2][2];
3918+
int gc_secs[2][2];
39113919
int tot_blks, data_blks, node_blks;
39123920
int bg_data_blks, bg_node_blks;
39133921
int curseg[NR_CURSEG_TYPE];
@@ -3931,8 +3939,6 @@ static inline struct f2fs_stat_info *F2FS_STAT(struct f2fs_sb_info *sbi)
39313939

39323940
#define stat_inc_cp_count(si) ((si)->cp_count++)
39333941
#define stat_inc_bg_cp_count(si) ((si)->bg_cp_count++)
3934-
#define stat_inc_call_count(si) ((si)->call_count++)
3935-
#define stat_inc_bggc_count(si) ((si)->bg_gc++)
39363942
#define stat_io_skip_bggc_count(sbi) ((sbi)->io_skip_bggc++)
39373943
#define stat_other_skip_bggc_count(sbi) ((sbi)->other_skip_bggc++)
39383944
#define stat_inc_dirty_inode(sbi, type) ((sbi)->ndirty_inode[type]++)
@@ -4017,18 +4023,12 @@ static inline struct f2fs_stat_info *F2FS_STAT(struct f2fs_sb_info *sbi)
40174023
if (cur > max) \
40184024
atomic_set(&F2FS_I_SB(inode)->max_aw_cnt, cur); \
40194025
} while (0)
4020-
#define stat_inc_seg_count(sbi, type, gc_type) \
4021-
do { \
4022-
struct f2fs_stat_info *si = F2FS_STAT(sbi); \
4023-
si->tot_segs++; \
4024-
if ((type) == SUM_TYPE_DATA) { \
4025-
si->data_segs++; \
4026-
si->bg_data_segs += (gc_type == BG_GC) ? 1 : 0; \
4027-
} else { \
4028-
si->node_segs++; \
4029-
si->bg_node_segs += (gc_type == BG_GC) ? 1 : 0; \
4030-
} \
4031-
} while (0)
4026+
#define stat_inc_gc_call_count(sbi, foreground) \
4027+
(F2FS_STAT(sbi)->gc_call_count[(foreground)]++)
4028+
#define stat_inc_gc_sec_count(sbi, type, gc_type) \
4029+
(F2FS_STAT(sbi)->gc_secs[(type)][(gc_type)]++)
4030+
#define stat_inc_gc_seg_count(sbi, type, gc_type) \
4031+
(F2FS_STAT(sbi)->gc_segs[(type)][(gc_type)]++)
40324032

40334033
#define stat_inc_tot_blk_count(si, blks) \
40344034
((si)->tot_blks += (blks))
@@ -4057,8 +4057,6 @@ void f2fs_update_sit_info(struct f2fs_sb_info *sbi);
40574057
#else
40584058
#define stat_inc_cp_count(si) do { } while (0)
40594059
#define stat_inc_bg_cp_count(si) do { } while (0)
4060-
#define stat_inc_call_count(si) do { } while (0)
4061-
#define stat_inc_bggc_count(si) do { } while (0)
40624060
#define stat_io_skip_bggc_count(sbi) do { } while (0)
40634061
#define stat_other_skip_bggc_count(sbi) do { } while (0)
40644062
#define stat_inc_dirty_inode(sbi, type) do { } while (0)
@@ -4086,7 +4084,9 @@ void f2fs_update_sit_info(struct f2fs_sb_info *sbi);
40864084
#define stat_inc_seg_type(sbi, curseg) do { } while (0)
40874085
#define stat_inc_block_count(sbi, curseg) do { } while (0)
40884086
#define stat_inc_inplace_blocks(sbi) do { } while (0)
4089-
#define stat_inc_seg_count(sbi, type, gc_type) do { } while (0)
4087+
#define stat_inc_gc_call_count(sbi, foreground) do { } while (0)
4088+
#define stat_inc_gc_sec_count(sbi, type, gc_type) do { } while (0)
4089+
#define stat_inc_gc_seg_count(sbi, type, gc_type) do { } while (0)
40904090
#define stat_inc_tot_blk_count(si, blks) do { } while (0)
40914091
#define stat_inc_data_blk_count(sbi, blks, gc_type) do { } while (0)
40924092
#define stat_inc_node_blk_count(sbi, blks, gc_type) do { } while (0)

fs/f2fs/file.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1728,6 +1728,7 @@ static int f2fs_expand_inode_data(struct inode *inode, loff_t offset,
17281728
if (has_not_enough_free_secs(sbi, 0,
17291729
GET_SEC_FROM_SEG(sbi, overprovision_segments(sbi)))) {
17301730
f2fs_down_write(&sbi->gc_lock);
1731+
stat_inc_gc_call_count(sbi, FOREGROUND);
17311732
err = f2fs_gc(sbi, &gc_control);
17321733
if (err && err != -ENODATA)
17331734
goto out_err;
@@ -2476,6 +2477,7 @@ static int f2fs_ioc_gc(struct file *filp, unsigned long arg)
24762477

24772478
gc_control.init_gc_type = sync ? FG_GC : BG_GC;
24782479
gc_control.err_gc_skipped = sync;
2480+
stat_inc_gc_call_count(sbi, FOREGROUND);
24792481
ret = f2fs_gc(sbi, &gc_control);
24802482
out:
24812483
mnt_drop_write_file(filp);
@@ -2519,6 +2521,7 @@ static int __f2fs_ioc_gc_range(struct file *filp, struct f2fs_gc_range *range)
25192521
}
25202522

25212523
gc_control.victim_segno = GET_SEGNO(sbi, range->start);
2524+
stat_inc_gc_call_count(sbi, FOREGROUND);
25222525
ret = f2fs_gc(sbi, &gc_control);
25232526
if (ret) {
25242527
if (ret == -EBUSY)
@@ -3001,6 +3004,7 @@ static int f2fs_ioc_flush_device(struct file *filp, unsigned long arg)
30013004
sm->last_victim[ALLOC_NEXT] = end_segno + 1;
30023005

30033006
gc_control.victim_segno = start_segno;
3007+
stat_inc_gc_call_count(sbi, FOREGROUND);
30043008
ret = f2fs_gc(sbi, &gc_control);
30053009
if (ret == -EAGAIN)
30063010
ret = 0;

fs/f2fs/gc.c

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -121,8 +121,8 @@ static int gc_thread_func(void *data)
121121
else
122122
increase_sleep_time(gc_th, &wait_ms);
123123
do_gc:
124-
if (!foreground)
125-
stat_inc_bggc_count(sbi->stat_info);
124+
stat_inc_gc_call_count(sbi, foreground ?
125+
FOREGROUND : BACKGROUND);
126126

127127
sync_mode = F2FS_OPTION(sbi).bggc_mode == BGGC_MODE_SYNC;
128128

@@ -1685,6 +1685,7 @@ static int do_garbage_collect(struct f2fs_sb_info *sbi,
16851685
int seg_freed = 0, migrated = 0;
16861686
unsigned char type = IS_DATASEG(get_seg_entry(sbi, segno)->type) ?
16871687
SUM_TYPE_DATA : SUM_TYPE_NODE;
1688+
unsigned char data_type = (type == SUM_TYPE_DATA) ? DATA : NODE;
16881689
int submitted = 0;
16891690

16901691
if (__is_large_section(sbi))
@@ -1766,7 +1767,7 @@ static int do_garbage_collect(struct f2fs_sb_info *sbi,
17661767
segno, gc_type,
17671768
force_migrate);
17681769

1769-
stat_inc_seg_count(sbi, type, gc_type);
1770+
stat_inc_gc_seg_count(sbi, data_type, gc_type);
17701771
sbi->gc_reclaimed_segs[sbi->gc_mode]++;
17711772
migrated++;
17721773

@@ -1783,12 +1784,12 @@ static int do_garbage_collect(struct f2fs_sb_info *sbi,
17831784
}
17841785

17851786
if (submitted)
1786-
f2fs_submit_merged_write(sbi,
1787-
(type == SUM_TYPE_NODE) ? NODE : DATA);
1787+
f2fs_submit_merged_write(sbi, data_type);
17881788

17891789
blk_finish_plug(&plug);
17901790

1791-
stat_inc_call_count(sbi->stat_info);
1791+
if (migrated)
1792+
stat_inc_gc_sec_count(sbi, data_type, gc_type);
17921793

17931794
return seg_freed;
17941795
}

fs/f2fs/segment.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -435,6 +435,7 @@ void f2fs_balance_fs(struct f2fs_sb_info *sbi, bool need)
435435
.err_gc_skipped = false,
436436
.nr_free_secs = 1 };
437437
f2fs_down_write(&sbi->gc_lock);
438+
stat_inc_gc_call_count(sbi, FOREGROUND);
438439
f2fs_gc(sbi, &gc_control);
439440
}
440441
}

fs/f2fs/super.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2206,6 +2206,7 @@ static int f2fs_disable_checkpoint(struct f2fs_sb_info *sbi)
22062206
.nr_free_secs = 1 };
22072207

22082208
f2fs_down_write(&sbi->gc_lock);
2209+
stat_inc_gc_call_count(sbi, FOREGROUND);
22092210
err = f2fs_gc(sbi, &gc_control);
22102211
if (err == -ENODATA) {
22112212
err = 0;

fs/f2fs/sysfs.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -974,8 +974,8 @@ F2FS_SBI_GENERAL_RO_ATTR(unusable_blocks_per_sec);
974974
#ifdef CONFIG_F2FS_STAT_FS
975975
STAT_INFO_RO_ATTR(cp_foreground_calls, cp_count);
976976
STAT_INFO_RO_ATTR(cp_background_calls, bg_cp_count);
977-
STAT_INFO_RO_ATTR(gc_foreground_calls, call_count);
978-
STAT_INFO_RO_ATTR(gc_background_calls, bg_gc);
977+
STAT_INFO_RO_ATTR(gc_foreground_calls, gc_call_count[FOREGROUND]);
978+
STAT_INFO_RO_ATTR(gc_background_calls, gc_call_count[BACKGROUND]);
979979
#endif
980980

981981
/* FAULT_INFO ATTR */

0 commit comments

Comments
 (0)