Skip to content

Commit eb61c2c

Browse files
chaseyuJaegeuk Kim
authored andcommitted
f2fs: fix to account cp stats correctly
cp_foreground_calls sysfs entry shows total CP call count rather than foreground CP call count, fix it. 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 9bf1dcb commit eb61c2c

File tree

8 files changed

+50
-17
lines changed

8 files changed

+50
-17
lines changed

fs/f2fs/checkpoint.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1701,9 +1701,9 @@ int f2fs_write_checkpoint(struct f2fs_sb_info *sbi, struct cp_control *cpc)
17011701
}
17021702

17031703
f2fs_restore_inmem_curseg(sbi);
1704+
stat_inc_cp_count(sbi);
17041705
stop:
17051706
unblock_operations(sbi);
1706-
stat_inc_cp_count(sbi->stat_info);
17071707

17081708
if (cpc->reason & CP_RECOVERY)
17091709
f2fs_notice(sbi, "checkpoint: version = %llx", ckpt_ver);

fs/f2fs/debug.c

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,9 @@ static void update_general_status(struct f2fs_sb_info *sbi)
215215
si->valid_blks[type] += blks;
216216
}
217217

218+
for (i = 0; i < MAX_CALL_TYPE; i++)
219+
si->cp_call_count[i] = atomic_read(&sbi->cp_call_count[i]);
220+
218221
for (i = 0; i < 2; i++) {
219222
si->segment_count[i] = sbi->segment_count[i];
220223
si->block_count[i] = sbi->block_count[i];
@@ -497,7 +500,9 @@ static int stat_show(struct seq_file *s, void *v)
497500
seq_printf(s, " - Prefree: %d\n - Free: %d (%d)\n\n",
498501
si->prefree_count, si->free_segs, si->free_secs);
499502
seq_printf(s, "CP calls: %d (BG: %d)\n",
500-
si->cp_count, si->bg_cp_count);
503+
si->cp_call_count[TOTAL_CALL],
504+
si->cp_call_count[BACKGROUND]);
505+
seq_printf(s, "CP count: %d\n", si->cp_count);
501506
seq_printf(s, " - cp blocks : %u\n", si->meta_count[META_CP]);
502507
seq_printf(s, " - sit blocks : %u\n",
503508
si->meta_count[META_SIT]);
@@ -699,6 +704,8 @@ int f2fs_build_stats(struct f2fs_sb_info *sbi)
699704
atomic_set(&sbi->inplace_count, 0);
700705
for (i = META_CP; i < META_MAX; i++)
701706
atomic_set(&sbi->meta_count[i], 0);
707+
for (i = 0; i < MAX_CALL_TYPE; i++)
708+
atomic_set(&sbi->cp_call_count[i], 0);
702709

703710
atomic_set(&sbi->max_aw_cnt, 0);
704711

fs/f2fs/f2fs.h

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1383,6 +1383,13 @@ enum errors_option {
13831383
MOUNT_ERRORS_PANIC, /* panic on errors */
13841384
};
13851385

1386+
enum {
1387+
BACKGROUND,
1388+
FOREGROUND,
1389+
MAX_CALL_TYPE,
1390+
TOTAL_CALL = FOREGROUND,
1391+
};
1392+
13861393
static inline int f2fs_test_bit(unsigned int nr, char *addr);
13871394
static inline void f2fs_set_bit(unsigned int nr, char *addr);
13881395
static inline void f2fs_clear_bit(unsigned int nr, char *addr);
@@ -1695,6 +1702,7 @@ struct f2fs_sb_info {
16951702
unsigned int io_skip_bggc; /* skip background gc for in-flight IO */
16961703
unsigned int other_skip_bggc; /* skip background gc for other reasons */
16971704
unsigned int ndirty_inode[NR_INODE_TYPE]; /* # of dirty inodes */
1705+
atomic_t cp_call_count[MAX_CALL_TYPE]; /* # of cp call */
16981706
#endif
16991707
spinlock_t stat_lock; /* lock for stat operations */
17001708

@@ -3860,12 +3868,6 @@ void f2fs_destroy_recovery_cache(void);
38603868
/*
38613869
* debug.c
38623870
*/
3863-
enum {
3864-
BACKGROUND,
3865-
FOREGROUND,
3866-
MAX_CALL_TYPE
3867-
};
3868-
38693871
#ifdef CONFIG_F2FS_STAT_FS
38703872
struct f2fs_stat_info {
38713873
struct list_head stat_list;
@@ -3912,7 +3914,7 @@ struct f2fs_stat_info {
39123914
int dirty_count, node_pages, meta_pages, compress_pages;
39133915
int compress_page_hit;
39143916
int prefree_count, free_segs, free_secs;
3915-
int cp_count, bg_cp_count;
3917+
int cp_call_count[MAX_CALL_TYPE], cp_count;
39163918
int gc_call_count[MAX_CALL_TYPE];
39173919
int gc_segs[2][2];
39183920
int gc_secs[2][2];
@@ -3937,8 +3939,9 @@ static inline struct f2fs_stat_info *F2FS_STAT(struct f2fs_sb_info *sbi)
39373939
return (struct f2fs_stat_info *)sbi->stat_info;
39383940
}
39393941

3940-
#define stat_inc_cp_count(si) ((si)->cp_count++)
3941-
#define stat_inc_bg_cp_count(si) ((si)->bg_cp_count++)
3942+
#define stat_inc_cp_call_count(sbi, foreground) \
3943+
atomic_inc(&sbi->cp_call_count[(foreground)])
3944+
#define stat_inc_cp_count(si) (F2FS_STAT(sbi)->cp_count++)
39423945
#define stat_io_skip_bggc_count(sbi) ((sbi)->io_skip_bggc++)
39433946
#define stat_other_skip_bggc_count(sbi) ((sbi)->other_skip_bggc++)
39443947
#define stat_inc_dirty_inode(sbi, type) ((sbi)->ndirty_inode[type]++)
@@ -4055,8 +4058,8 @@ void __init f2fs_create_root_stats(void);
40554058
void f2fs_destroy_root_stats(void);
40564059
void f2fs_update_sit_info(struct f2fs_sb_info *sbi);
40574060
#else
4058-
#define stat_inc_cp_count(si) do { } while (0)
4059-
#define stat_inc_bg_cp_count(si) do { } while (0)
4061+
#define stat_inc_cp_call_count(sbi, foreground) do { } while (0)
4062+
#define stat_inc_cp_count(sbi) do { } while (0)
40604063
#define stat_io_skip_bggc_count(sbi) do { } while (0)
40614064
#define stat_other_skip_bggc_count(sbi) do { } while (0)
40624065
#define stat_inc_dirty_inode(sbi, type) do { } while (0)

fs/f2fs/gc.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1840,6 +1840,7 @@ int f2fs_gc(struct f2fs_sb_info *sbi, struct f2fs_gc_control *gc_control)
18401840
* secure free segments which doesn't need fggc any more.
18411841
*/
18421842
if (prefree_segments(sbi)) {
1843+
stat_inc_cp_call_count(sbi, TOTAL_CALL);
18431844
ret = f2fs_write_checkpoint(sbi, &cpc);
18441845
if (ret)
18451846
goto stop;
@@ -1888,6 +1889,7 @@ int f2fs_gc(struct f2fs_sb_info *sbi, struct f2fs_gc_control *gc_control)
18881889
round++;
18891890
if (skipped_round > MAX_SKIP_GC_COUNT &&
18901891
skipped_round * 2 >= round) {
1892+
stat_inc_cp_call_count(sbi, TOTAL_CALL);
18911893
ret = f2fs_write_checkpoint(sbi, &cpc);
18921894
goto stop;
18931895
}
@@ -1903,6 +1905,7 @@ int f2fs_gc(struct f2fs_sb_info *sbi, struct f2fs_gc_control *gc_control)
19031905
*/
19041906
if (free_sections(sbi) <= upper_secs + NR_GC_CHECKPOINT_SECS &&
19051907
prefree_segments(sbi)) {
1908+
stat_inc_cp_call_count(sbi, TOTAL_CALL);
19061909
ret = f2fs_write_checkpoint(sbi, &cpc);
19071910
if (ret)
19081911
goto stop;
@@ -2030,6 +2033,7 @@ static int free_segment_range(struct f2fs_sb_info *sbi,
20302033
if (gc_only)
20312034
goto out;
20322035

2036+
stat_inc_cp_call_count(sbi, TOTAL_CALL);
20332037
err = f2fs_write_checkpoint(sbi, &cpc);
20342038
if (err)
20352039
goto out;
@@ -2222,6 +2226,7 @@ int f2fs_resize_fs(struct file *filp, __u64 block_count)
22222226
clear_sbi_flag(sbi, SBI_IS_RESIZEFS);
22232227
set_sbi_flag(sbi, SBI_IS_DIRTY);
22242228

2229+
stat_inc_cp_call_count(sbi, TOTAL_CALL);
22252230
err = f2fs_write_checkpoint(sbi, &cpc);
22262231
if (err) {
22272232
update_fs_metadata(sbi, secs);

fs/f2fs/recovery.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -924,6 +924,7 @@ int f2fs_recover_fsync_data(struct f2fs_sb_info *sbi, bool check_only)
924924
struct cp_control cpc = {
925925
.reason = CP_RECOVERY,
926926
};
927+
stat_inc_cp_call_count(sbi, TOTAL_CALL);
927928
err = f2fs_write_checkpoint(sbi, &cpc);
928929
}
929930
}

fs/f2fs/segment.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -513,8 +513,8 @@ void f2fs_balance_fs_bg(struct f2fs_sb_info *sbi, bool from_bg)
513513

514514
mutex_unlock(&sbi->flush_lock);
515515
}
516+
stat_inc_cp_call_count(sbi, BACKGROUND);
516517
f2fs_sync_fs(sbi->sb, 1);
517-
stat_inc_bg_cp_count(sbi->stat_info);
518518
}
519519

520520
static int __submit_flush_wait(struct f2fs_sb_info *sbi,
@@ -3248,6 +3248,7 @@ int f2fs_trim_fs(struct f2fs_sb_info *sbi, struct fstrim_range *range)
32483248
goto out;
32493249

32503250
f2fs_down_write(&sbi->gc_lock);
3251+
stat_inc_cp_call_count(sbi, TOTAL_CALL);
32513252
err = f2fs_write_checkpoint(sbi, &cpc);
32523253
f2fs_up_write(&sbi->gc_lock);
32533254
if (err)

fs/f2fs/super.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1601,6 +1601,7 @@ static void f2fs_put_super(struct super_block *sb)
16011601
struct cp_control cpc = {
16021602
.reason = CP_UMOUNT,
16031603
};
1604+
stat_inc_cp_call_count(sbi, TOTAL_CALL);
16041605
err = f2fs_write_checkpoint(sbi, &cpc);
16051606
}
16061607

@@ -1610,6 +1611,7 @@ static void f2fs_put_super(struct super_block *sb)
16101611
struct cp_control cpc = {
16111612
.reason = CP_UMOUNT | CP_TRIMMED,
16121613
};
1614+
stat_inc_cp_call_count(sbi, TOTAL_CALL);
16131615
err = f2fs_write_checkpoint(sbi, &cpc);
16141616
}
16151617

@@ -1706,8 +1708,10 @@ int f2fs_sync_fs(struct super_block *sb, int sync)
17061708
if (unlikely(is_sbi_flag_set(sbi, SBI_POR_DOING)))
17071709
return -EAGAIN;
17081710

1709-
if (sync)
1711+
if (sync) {
1712+
stat_inc_cp_call_count(sbi, TOTAL_CALL);
17101713
err = f2fs_issue_checkpoint(sbi);
1714+
}
17111715

17121716
return err;
17131717
}
@@ -2232,6 +2236,7 @@ static int f2fs_disable_checkpoint(struct f2fs_sb_info *sbi)
22322236
f2fs_down_write(&sbi->gc_lock);
22332237
cpc.reason = CP_PAUSE;
22342238
set_sbi_flag(sbi, SBI_CP_DISABLED);
2239+
stat_inc_cp_call_count(sbi, TOTAL_CALL);
22352240
err = f2fs_write_checkpoint(sbi, &cpc);
22362241
if (err)
22372242
goto out_unlock;
@@ -4868,6 +4873,7 @@ static void kill_f2fs_super(struct super_block *sb)
48684873
struct cp_control cpc = {
48694874
.reason = CP_UMOUNT,
48704875
};
4876+
stat_inc_cp_call_count(sbi, TOTAL_CALL);
48714877
f2fs_write_checkpoint(sbi, &cpc);
48724878
}
48734879

fs/f2fs/sysfs.c

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -356,6 +356,16 @@ static ssize_t f2fs_sbi_show(struct f2fs_attr *a,
356356
if (!strcmp(a->attr.name, "revoked_atomic_block"))
357357
return sysfs_emit(buf, "%llu\n", sbi->revoked_atomic_block);
358358

359+
#ifdef CONFIG_F2FS_STAT_FS
360+
if (!strcmp(a->attr.name, "cp_foreground_calls"))
361+
return sysfs_emit(buf, "%d\n",
362+
atomic_read(&sbi->cp_call_count[TOTAL_CALL]) -
363+
atomic_read(&sbi->cp_call_count[BACKGROUND]));
364+
if (!strcmp(a->attr.name, "cp_background_calls"))
365+
return sysfs_emit(buf, "%d\n",
366+
atomic_read(&sbi->cp_call_count[BACKGROUND]));
367+
#endif
368+
359369
ui = (unsigned int *)(ptr + a->offset);
360370

361371
return sysfs_emit(buf, "%u\n", *ui);
@@ -972,8 +982,8 @@ F2FS_SBI_GENERAL_RO_ATTR(unusable_blocks_per_sec);
972982

973983
/* STAT_INFO ATTR */
974984
#ifdef CONFIG_F2FS_STAT_FS
975-
STAT_INFO_RO_ATTR(cp_foreground_calls, cp_count);
976-
STAT_INFO_RO_ATTR(cp_background_calls, bg_cp_count);
985+
STAT_INFO_RO_ATTR(cp_foreground_calls, cp_call_count[FOREGROUND]);
986+
STAT_INFO_RO_ATTR(cp_background_calls, cp_call_count[BACKGROUND]);
977987
STAT_INFO_RO_ATTR(gc_foreground_calls, gc_call_count[FOREGROUND]);
978988
STAT_INFO_RO_ATTR(gc_background_calls, gc_call_count[BACKGROUND]);
979989
#endif

0 commit comments

Comments
 (0)