Skip to content

Commit fc7100e

Browse files
Hridya ValsarajuJaegeuk Kim
authored andcommitted
f2fs: Add f2fs stats to sysfs
Currently f2fs stats are only available from /d/f2fs/status. This patch adds some of the f2fs stats to sysfs so that they are accessible even when debugfs is not mounted. The following sysfs nodes are added: -/sys/fs/f2fs/<disk>/free_segments -/sys/fs/f2fs/<disk>/cp_foreground_calls -/sys/fs/f2fs/<disk>/cp_background_calls -/sys/fs/f2fs/<disk>/gc_foreground_calls -/sys/fs/f2fs/<disk>/gc_background_calls -/sys/fs/f2fs/<disk>/moved_blocks_foreground -/sys/fs/f2fs/<disk>/moved_blocks_background -/sys/fs/f2fs/<disk>/avg_vblocks Signed-off-by: Hridya Valsaraju <hridya@google.com> [Jaegeuk Kim: allow STAT_FS without DEBUG_FS] Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
1 parent f5fa7c8 commit fc7100e

6 files changed

Lines changed: 204 additions & 74 deletions

File tree

‎Documentation/ABI/testing/sysfs-fs-f2fs‎

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -271,3 +271,50 @@ Date July 2019
271271
Contact: "Daniel Rosenberg" <drosen@google.com>
272272
Description: Displays name and version of the encoding set for the filesystem.
273273
If no encoding is set, displays (none)
274+
275+
What: /sys/fs/f2fs/<disk>/free_segments
276+
Date: September 2019
277+
Contact: "Hridya Valsaraju" <hridya@google.com>
278+
Description: Number of free segments in disk.
279+
280+
What: /sys/fs/f2fs/<disk>/cp_foreground_calls
281+
Date: September 2019
282+
Contact: "Hridya Valsaraju" <hridya@google.com>
283+
Description: Number of checkpoint operations performed on demand. Available when
284+
CONFIG_F2FS_STAT_FS=y.
285+
286+
What: /sys/fs/f2fs/<disk>/cp_background_calls
287+
Date: September 2019
288+
Contact: "Hridya Valsaraju" <hridya@google.com>
289+
Description: Number of checkpoint operations performed in the background to
290+
free segments. Available when CONFIG_F2FS_STAT_FS=y.
291+
292+
What: /sys/fs/f2fs/<disk>/gc_foreground_calls
293+
Date: September 2019
294+
Contact: "Hridya Valsaraju" <hridya@google.com>
295+
Description: Number of garbage collection operations performed on demand.
296+
Available when CONFIG_F2FS_STAT_FS=y.
297+
298+
What: /sys/fs/f2fs/<disk>/gc_background_calls
299+
Date: September 2019
300+
Contact: "Hridya Valsaraju" <hridya@google.com>
301+
Description: Number of garbage collection operations triggered in background.
302+
Available when CONFIG_F2FS_STAT_FS=y.
303+
304+
What: /sys/fs/f2fs/<disk>/moved_blocks_foreground
305+
Date: September 2019
306+
Contact: "Hridya Valsaraju" <hridya@google.com>
307+
Description: Number of blocks moved by garbage collection in foreground.
308+
Available when CONFIG_F2FS_STAT_FS=y.
309+
310+
What: /sys/fs/f2fs/<disk>/moved_blocks_background
311+
Date: September 2019
312+
Contact: "Hridya Valsaraju" <hridya@google.com>
313+
Description: Number of blocks moved by garbage collection in background.
314+
Available when CONFIG_F2FS_STAT_FS=y.
315+
316+
What: /sys/fs/f2fs/<disk>/avg_vblocks
317+
Date: September 2019
318+
Contact: "Hridya Valsaraju" <hridya@google.com>
319+
Description: Average number of valid blocks.
320+
Available when CONFIG_F2FS_STAT_FS=y.

‎fs/f2fs/Kconfig‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ config F2FS_FS
2121

2222
config F2FS_STAT_FS
2323
bool "F2FS Status Information"
24-
depends on F2FS_FS && DEBUG_FS
24+
depends on F2FS_FS
2525
default y
2626
help
2727
/sys/kernel/debug/f2fs/ contains information about all the partitions

‎fs/f2fs/debug.c‎

Lines changed: 43 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,45 @@
2121
#include "gc.h"
2222

2323
static LIST_HEAD(f2fs_stat_list);
24-
static struct dentry *f2fs_debugfs_root;
2524
static DEFINE_MUTEX(f2fs_stat_mutex);
25+
#ifdef CONFIG_DEBUG_FS
26+
static struct dentry *f2fs_debugfs_root;
27+
#endif
28+
29+
/*
30+
* This function calculates BDF of every segments
31+
*/
32+
void f2fs_update_sit_info(struct f2fs_sb_info *sbi)
33+
{
34+
struct f2fs_stat_info *si = F2FS_STAT(sbi);
35+
unsigned long long blks_per_sec, hblks_per_sec, total_vblocks;
36+
unsigned long long bimodal, dist;
37+
unsigned int segno, vblocks;
38+
int ndirty = 0;
39+
40+
bimodal = 0;
41+
total_vblocks = 0;
42+
blks_per_sec = BLKS_PER_SEC(sbi);
43+
hblks_per_sec = blks_per_sec / 2;
44+
for (segno = 0; segno < MAIN_SEGS(sbi); segno += sbi->segs_per_sec) {
45+
vblocks = get_valid_blocks(sbi, segno, true);
46+
dist = abs(vblocks - hblks_per_sec);
47+
bimodal += dist * dist;
48+
49+
if (vblocks > 0 && vblocks < blks_per_sec) {
50+
total_vblocks += vblocks;
51+
ndirty++;
52+
}
53+
}
54+
dist = div_u64(MAIN_SECS(sbi) * hblks_per_sec * hblks_per_sec, 100);
55+
si->bimodal = div64_u64(bimodal, dist);
56+
if (si->dirty_count)
57+
si->avg_vblocks = div_u64(total_vblocks, ndirty);
58+
else
59+
si->avg_vblocks = 0;
60+
}
2661

62+
#ifdef CONFIG_DEBUG_FS
2763
static void update_general_status(struct f2fs_sb_info *sbi)
2864
{
2965
struct f2fs_stat_info *si = F2FS_STAT(sbi);
@@ -116,7 +152,6 @@ static void update_general_status(struct f2fs_sb_info *sbi)
116152
si->free_nids = NM_I(sbi)->nid_cnt[FREE_NID];
117153
si->avail_nids = NM_I(sbi)->available_nids;
118154
si->alloc_nids = NM_I(sbi)->nid_cnt[PREALLOC_NID];
119-
si->bg_gc = sbi->bg_gc;
120155
si->io_skip_bggc = sbi->io_skip_bggc;
121156
si->other_skip_bggc = sbi->other_skip_bggc;
122157
si->skipped_atomic_files[BG_GC] = sbi->skipped_atomic_files[BG_GC];
@@ -147,39 +182,6 @@ static void update_general_status(struct f2fs_sb_info *sbi)
147182
si->inplace_count = atomic_read(&sbi->inplace_count);
148183
}
149184

150-
/*
151-
* This function calculates BDF of every segments
152-
*/
153-
static void update_sit_info(struct f2fs_sb_info *sbi)
154-
{
155-
struct f2fs_stat_info *si = F2FS_STAT(sbi);
156-
unsigned long long blks_per_sec, hblks_per_sec, total_vblocks;
157-
unsigned long long bimodal, dist;
158-
unsigned int segno, vblocks;
159-
int ndirty = 0;
160-
161-
bimodal = 0;
162-
total_vblocks = 0;
163-
blks_per_sec = BLKS_PER_SEC(sbi);
164-
hblks_per_sec = blks_per_sec / 2;
165-
for (segno = 0; segno < MAIN_SEGS(sbi); segno += sbi->segs_per_sec) {
166-
vblocks = get_valid_blocks(sbi, segno, true);
167-
dist = abs(vblocks - hblks_per_sec);
168-
bimodal += dist * dist;
169-
170-
if (vblocks > 0 && vblocks < blks_per_sec) {
171-
total_vblocks += vblocks;
172-
ndirty++;
173-
}
174-
}
175-
dist = div_u64(MAIN_SECS(sbi) * hblks_per_sec * hblks_per_sec, 100);
176-
si->bimodal = div64_u64(bimodal, dist);
177-
if (si->dirty_count)
178-
si->avg_vblocks = div_u64(total_vblocks, ndirty);
179-
else
180-
si->avg_vblocks = 0;
181-
}
182-
183185
/*
184186
* This function calculates memory footprint.
185187
*/
@@ -445,7 +447,7 @@ static int stat_show(struct seq_file *s, void *v)
445447
si->block_count[LFS], si->segment_count[LFS]);
446448

447449
/* segment usage info */
448-
update_sit_info(si->sbi);
450+
f2fs_update_sit_info(si->sbi);
449451
seq_printf(s, "\nBDF: %u, avg. vblocks: %u\n",
450452
si->bimodal, si->avg_vblocks);
451453

@@ -465,6 +467,7 @@ static int stat_show(struct seq_file *s, void *v)
465467
}
466468

467469
DEFINE_SHOW_ATTRIBUTE(stat);
470+
#endif
468471

469472
int f2fs_build_stats(struct f2fs_sb_info *sbi)
470473
{
@@ -525,14 +528,18 @@ void f2fs_destroy_stats(struct f2fs_sb_info *sbi)
525528

526529
void __init f2fs_create_root_stats(void)
527530
{
531+
#ifdef CONFIG_DEBUG_FS
528532
f2fs_debugfs_root = debugfs_create_dir("f2fs", NULL);
529533

530534
debugfs_create_file("status", S_IRUGO, f2fs_debugfs_root, NULL,
531535
&stat_fops);
536+
#endif
532537
}
533538

534539
void f2fs_destroy_root_stats(void)
535540
{
541+
#ifdef CONFIG_DEBUG_FS
536542
debugfs_remove_recursive(f2fs_debugfs_root);
537543
f2fs_debugfs_root = NULL;
544+
#endif
538545
}

‎fs/f2fs/f2fs.h‎

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1435,7 +1435,6 @@ struct f2fs_sb_info {
14351435
atomic_t vw_cnt; /* # of volatile writes */
14361436
atomic_t max_aw_cnt; /* max # of atomic writes */
14371437
atomic_t max_vw_cnt; /* max # of volatile writes */
1438-
int bg_gc; /* background gc calls */
14391438
unsigned int io_skip_bggc; /* skip background gc for in-flight IO */
14401439
unsigned int other_skip_bggc; /* skip background gc for other reasons */
14411440
unsigned int ndirty_inode[NR_INODE_TYPE]; /* # of dirty inodes */
@@ -3460,7 +3459,7 @@ static inline struct f2fs_stat_info *F2FS_STAT(struct f2fs_sb_info *sbi)
34603459
#define stat_inc_cp_count(si) ((si)->cp_count++)
34613460
#define stat_inc_bg_cp_count(si) ((si)->bg_cp_count++)
34623461
#define stat_inc_call_count(si) ((si)->call_count++)
3463-
#define stat_inc_bggc_count(sbi) ((sbi)->bg_gc++)
3462+
#define stat_inc_bggc_count(si) ((si)->bg_gc++)
34643463
#define stat_io_skip_bggc_count(sbi) ((sbi)->io_skip_bggc++)
34653464
#define stat_other_skip_bggc_count(sbi) ((sbi)->other_skip_bggc++)
34663465
#define stat_inc_dirty_inode(sbi, type) ((sbi)->ndirty_inode[type]++)
@@ -3584,6 +3583,7 @@ int f2fs_build_stats(struct f2fs_sb_info *sbi);
35843583
void f2fs_destroy_stats(struct f2fs_sb_info *sbi);
35853584
void __init f2fs_create_root_stats(void);
35863585
void f2fs_destroy_root_stats(void);
3586+
void f2fs_update_sit_info(struct f2fs_sb_info *sbi);
35873587
#else
35883588
#define stat_inc_cp_count(si) do { } while (0)
35893589
#define stat_inc_bg_cp_count(si) do { } while (0)
@@ -3593,8 +3593,8 @@ void f2fs_destroy_root_stats(void);
35933593
#define stat_other_skip_bggc_count(sbi) do { } while (0)
35943594
#define stat_inc_dirty_inode(sbi, type) do { } while (0)
35953595
#define stat_dec_dirty_inode(sbi, type) do { } while (0)
3596-
#define stat_inc_total_hit(sb) do { } while (0)
3597-
#define stat_inc_rbtree_node_hit(sb) do { } while (0)
3596+
#define stat_inc_total_hit(sbi) do { } while (0)
3597+
#define stat_inc_rbtree_node_hit(sbi) do { } while (0)
35983598
#define stat_inc_largest_node_hit(sbi) do { } while (0)
35993599
#define stat_inc_cached_node_hit(sbi) do { } while (0)
36003600
#define stat_inc_inline_xattr(inode) do { } while (0)
@@ -3626,6 +3626,7 @@ static inline int f2fs_build_stats(struct f2fs_sb_info *sbi) { return 0; }
36263626
static inline void f2fs_destroy_stats(struct f2fs_sb_info *sbi) { }
36273627
static inline void __init f2fs_create_root_stats(void) { }
36283628
static inline void f2fs_destroy_root_stats(void) { }
3629+
static inline void update_sit_info(struct f2fs_sb_info *sbi) {}
36293630
#endif
36303631

36313632
extern const struct file_operations f2fs_dir_operations;

‎fs/f2fs/gc.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ static int gc_thread_func(void *data)
9999
else
100100
increase_sleep_time(gc_th, &wait_ms);
101101
do_gc:
102-
stat_inc_bggc_count(sbi);
102+
stat_inc_bggc_count(sbi->stat_info);
103103

104104
/* if return value is not zero, no victim was selected */
105105
if (f2fs_gc(sbi, test_opt(sbi, FORCE_FG_GC), true, NULL_SEGNO))

0 commit comments

Comments
 (0)