17c1a000dSChao Yu // SPDX-License-Identifier: GPL-2.0
20a8165d7SJaegeuk Kim /*
3902829aaSGreg Kroah-Hartman * f2fs debugging statistics
4902829aaSGreg Kroah-Hartman *
5902829aaSGreg Kroah-Hartman * Copyright (c) 2012 Samsung Electronics Co., Ltd.
6902829aaSGreg Kroah-Hartman * http://www.samsung.com/
7902829aaSGreg Kroah-Hartman * Copyright (c) 2012 Linux Foundation
8902829aaSGreg Kroah-Hartman * Copyright (c) 2012 Greg Kroah-Hartman <gregkh@linuxfoundation.org>
9902829aaSGreg Kroah-Hartman */
10902829aaSGreg Kroah-Hartman
11902829aaSGreg Kroah-Hartman #include <linux/fs.h>
12902829aaSGreg Kroah-Hartman #include <linux/backing-dev.h>
13902829aaSGreg Kroah-Hartman #include <linux/f2fs_fs.h>
14902829aaSGreg Kroah-Hartman #include <linux/blkdev.h>
15902829aaSGreg Kroah-Hartman #include <linux/debugfs.h>
16902829aaSGreg Kroah-Hartman #include <linux/seq_file.h>
17902829aaSGreg Kroah-Hartman
18902829aaSGreg Kroah-Hartman #include "f2fs.h"
19902829aaSGreg Kroah-Hartman #include "node.h"
20902829aaSGreg Kroah-Hartman #include "segment.h"
21902829aaSGreg Kroah-Hartman #include "gc.h"
22902829aaSGreg Kroah-Hartman
23902829aaSGreg Kroah-Hartman static LIST_HEAD(f2fs_stat_list);
2498237fcdSJaegeuk Kim static DEFINE_RAW_SPINLOCK(f2fs_stat_lock);
25fc7100eaSHridya Valsaraju #ifdef CONFIG_DEBUG_FS
26fc7100eaSHridya Valsaraju static struct dentry *f2fs_debugfs_root;
27fc7100eaSHridya Valsaraju #endif
28902829aaSGreg Kroah-Hartman
29fc7100eaSHridya Valsaraju /*
30fc7100eaSHridya Valsaraju * This function calculates BDF of every segments
31fc7100eaSHridya Valsaraju */
f2fs_update_sit_info(struct f2fs_sb_info * sbi)32fc7100eaSHridya Valsaraju void f2fs_update_sit_info(struct f2fs_sb_info *sbi)
33fc7100eaSHridya Valsaraju {
34fc7100eaSHridya Valsaraju struct f2fs_stat_info *si = F2FS_STAT(sbi);
35fc7100eaSHridya Valsaraju unsigned long long blks_per_sec, hblks_per_sec, total_vblocks;
36fc7100eaSHridya Valsaraju unsigned long long bimodal, dist;
37fc7100eaSHridya Valsaraju unsigned int segno, vblocks;
38fc7100eaSHridya Valsaraju int ndirty = 0;
39fc7100eaSHridya Valsaraju
40fc7100eaSHridya Valsaraju bimodal = 0;
41fc7100eaSHridya Valsaraju total_vblocks = 0;
42074b5ea2SJaegeuk Kim blks_per_sec = CAP_BLKS_PER_SEC(sbi);
43fc7100eaSHridya Valsaraju hblks_per_sec = blks_per_sec / 2;
44a60108f7SJaegeuk Kim for (segno = 0; segno < MAIN_SEGS(sbi); segno += SEGS_PER_SEC(sbi)) {
45fc7100eaSHridya Valsaraju vblocks = get_valid_blocks(sbi, segno, true);
46fc7100eaSHridya Valsaraju dist = abs(vblocks - hblks_per_sec);
47fc7100eaSHridya Valsaraju bimodal += dist * dist;
48fc7100eaSHridya Valsaraju
49fc7100eaSHridya Valsaraju if (vblocks > 0 && vblocks < blks_per_sec) {
50fc7100eaSHridya Valsaraju total_vblocks += vblocks;
51fc7100eaSHridya Valsaraju ndirty++;
52fc7100eaSHridya Valsaraju }
53fc7100eaSHridya Valsaraju }
54fc7100eaSHridya Valsaraju dist = div_u64(MAIN_SECS(sbi) * hblks_per_sec * hblks_per_sec, 100);
55fc7100eaSHridya Valsaraju si->bimodal = div64_u64(bimodal, dist);
56fc7100eaSHridya Valsaraju if (si->dirty_count)
57fc7100eaSHridya Valsaraju si->avg_vblocks = div_u64(total_vblocks, ndirty);
58fc7100eaSHridya Valsaraju else
59fc7100eaSHridya Valsaraju si->avg_vblocks = 0;
60fc7100eaSHridya Valsaraju }
61fc7100eaSHridya Valsaraju
62fc7100eaSHridya Valsaraju #ifdef CONFIG_DEBUG_FS
update_general_status(struct f2fs_sb_info * sbi)6325ca923bSJaegeuk Kim static void update_general_status(struct f2fs_sb_info *sbi)
64902829aaSGreg Kroah-Hartman {
65963d4f7dSGu Zheng struct f2fs_stat_info *si = F2FS_STAT(sbi);
6604f0b2eaSQiuyang Sun struct f2fs_super_block *raw_super = F2FS_RAW_SUPER(sbi);
67902829aaSGreg Kroah-Hartman int i;
68902829aaSGreg Kroah-Hartman
6904f0b2eaSQiuyang Sun /* these will be changed if online resize is done */
7004f0b2eaSQiuyang Sun si->main_area_segs = le32_to_cpu(raw_super->segment_count_main);
7104f0b2eaSQiuyang Sun si->main_area_sections = le32_to_cpu(raw_super->section_count);
7204f0b2eaSQiuyang Sun si->main_area_zones = si->main_area_sections /
7304f0b2eaSQiuyang Sun le32_to_cpu(raw_super->secs_per_zone);
7404f0b2eaSQiuyang Sun
75e7547dacSJaegeuk Kim /* general extent cache stats */
76e7547dacSJaegeuk Kim for (i = 0; i < NR_EXTENT_CACHES; i++) {
77e7547dacSJaegeuk Kim struct extent_tree_info *eti = &sbi->extent_tree[i];
78e7547dacSJaegeuk Kim
79e7547dacSJaegeuk Kim si->hit_cached[i] = atomic64_read(&sbi->read_hit_cached[i]);
80e7547dacSJaegeuk Kim si->hit_rbtree[i] = atomic64_read(&sbi->read_hit_rbtree[i]);
81e7547dacSJaegeuk Kim si->total_ext[i] = atomic64_read(&sbi->total_hit_ext[i]);
82e7547dacSJaegeuk Kim si->hit_total[i] = si->hit_cached[i] + si->hit_rbtree[i];
83e7547dacSJaegeuk Kim si->ext_tree[i] = atomic_read(&eti->total_ext_tree);
84e7547dacSJaegeuk Kim si->zombie_tree[i] = atomic_read(&eti->total_zombie_tree);
85e7547dacSJaegeuk Kim si->ext_node[i] = atomic_read(&eti->total_ext_node);
86e7547dacSJaegeuk Kim }
87e7547dacSJaegeuk Kim /* read extent_cache only */
885b7ee374SChao Yu si->hit_largest = atomic64_read(&sbi->read_hit_largest);
89e7547dacSJaegeuk Kim si->hit_total[EX_READ] += si->hit_largest;
90e7547dacSJaegeuk Kim
9171644dffSJaegeuk Kim /* block age extent_cache only */
9271644dffSJaegeuk Kim si->allocated_data_blocks = atomic64_read(&sbi->allocated_data_blocks);
9371644dffSJaegeuk Kim
94e7547dacSJaegeuk Kim /* validation check of the segment numbers */
95902829aaSGreg Kroah-Hartman si->ndirty_node = get_pages(sbi, F2FS_DIRTY_NODES);
96902829aaSGreg Kroah-Hartman si->ndirty_dent = get_pages(sbi, F2FS_DIRTY_DENTS);
97902829aaSGreg Kroah-Hartman si->ndirty_meta = get_pages(sbi, F2FS_DIRTY_META);
9833fbd510SChao Yu si->ndirty_data = get_pages(sbi, F2FS_DIRTY_DATA);
992c8a4a28SJaegeuk Kim si->ndirty_qdata = get_pages(sbi, F2FS_DIRTY_QDATA);
1005bc994a0SChao Yu si->ndirty_imeta = get_pages(sbi, F2FS_DIRTY_IMETA);
10133fbd510SChao Yu si->ndirty_dirs = sbi->ndirty_inode[DIR_INODE];
10233fbd510SChao Yu si->ndirty_files = sbi->ndirty_inode[FILE_INODE];
103292c196aSChao Yu si->nquota_files = sbi->nquota_files;
1040f18b462SJaegeuk Kim si->ndirty_all = sbi->ndirty_inode[DIRTY_META];
105b4dac120SChao Yu si->aw_cnt = atomic_read(&sbi->atomic_files);
10626a28a0cSJaegeuk Kim si->max_aw_cnt = atomic_read(&sbi->max_aw_cnt);
10702b16d0aSChao Yu si->nr_dio_read = get_pages(sbi, F2FS_DIO_READ);
10802b16d0aSChao Yu si->nr_dio_write = get_pages(sbi, F2FS_DIO_WRITE);
10936951b38SChao Yu si->nr_wb_cp_data = get_pages(sbi, F2FS_WB_CP_DATA);
11036951b38SChao Yu si->nr_wb_data = get_pages(sbi, F2FS_WB_DATA);
1115f9abab4SJaegeuk Kim si->nr_rd_data = get_pages(sbi, F2FS_RD_DATA);
1125f9abab4SJaegeuk Kim si->nr_rd_node = get_pages(sbi, F2FS_RD_NODE);
1135f9abab4SJaegeuk Kim si->nr_rd_meta = get_pages(sbi, F2FS_RD_META);
114280fd422SJia-Ju Bai if (SM_I(sbi)->fcc_info) {
1158b8dd65fSChao Yu si->nr_flushed =
1168b8dd65fSChao Yu atomic_read(&SM_I(sbi)->fcc_info->issued_flush);
1178b8dd65fSChao Yu si->nr_flushing =
11872691af6SJaegeuk Kim atomic_read(&SM_I(sbi)->fcc_info->queued_flush);
11914d8d5f7SChao Yu si->flush_list_empty =
12014d8d5f7SChao Yu llist_empty(&SM_I(sbi)->fcc_info->issue_list);
1218b8dd65fSChao Yu }
122280fd422SJia-Ju Bai if (SM_I(sbi)->dcc_info) {
1238b8dd65fSChao Yu si->nr_discarded =
1248b8dd65fSChao Yu atomic_read(&SM_I(sbi)->dcc_info->issued_discard);
1258b8dd65fSChao Yu si->nr_discarding =
12672691af6SJaegeuk Kim atomic_read(&SM_I(sbi)->dcc_info->queued_discard);
1275f32366aSChao Yu si->nr_discard_cmd =
1285f32366aSChao Yu atomic_read(&SM_I(sbi)->dcc_info->discard_cmd_cnt);
129d84d1cbdSChao Yu si->undiscard_blks = SM_I(sbi)->dcc_info->undiscard_blks;
1308b8dd65fSChao Yu }
131261eeb9cSDaeho Jeong si->nr_issued_ckpt = atomic_read(&sbi->cprc_info.issued_ckpt);
132261eeb9cSDaeho Jeong si->nr_total_ckpt = atomic_read(&sbi->cprc_info.total_ckpt);
133261eeb9cSDaeho Jeong si->nr_queued_ckpt = atomic_read(&sbi->cprc_info.queued_ckpt);
134261eeb9cSDaeho Jeong spin_lock(&sbi->cprc_info.stat_lock);
135261eeb9cSDaeho Jeong si->cur_ckpt_time = sbi->cprc_info.cur_time;
136261eeb9cSDaeho Jeong si->peak_ckpt_time = sbi->cprc_info.peak_time;
137261eeb9cSDaeho Jeong spin_unlock(&sbi->cprc_info.stat_lock);
13845809cd3SChao Yu si->total_count = BLKS_TO_SEGS(sbi, (int)sbi->user_block_count);
139902829aaSGreg Kroah-Hartman si->rsvd_segs = reserved_segments(sbi);
140902829aaSGreg Kroah-Hartman si->overp_segs = overprovision_segments(sbi);
141902829aaSGreg Kroah-Hartman si->valid_count = valid_user_blocks(sbi);
142f83a2584SYunlei He si->discard_blks = discard_blocks(sbi);
143902829aaSGreg Kroah-Hartman si->valid_node_count = valid_node_count(sbi);
144902829aaSGreg Kroah-Hartman si->valid_inode_count = valid_inode_count(sbi);
145d5e8f6c9SChao Yu si->inline_xattr = atomic_read(&sbi->inline_xattr);
14603e14d52SChao Yu si->inline_inode = atomic_read(&sbi->inline_inode);
14703e14d52SChao Yu si->inline_dir = atomic_read(&sbi->inline_dir);
1484c8ff709SChao Yu si->compr_inode = atomic_read(&sbi->compr_inode);
1498ec071c3SChao Yu si->swapfile_inode = atomic_read(&sbi->swapfile_inode);
150ae999bb9SDaeho Jeong si->compr_blocks = atomic64_read(&sbi->compr_blocks);
151a00861dbSJaegeuk Kim si->append = sbi->im[APPEND_INO].ino_num;
152a00861dbSJaegeuk Kim si->update = sbi->im[UPDATE_INO].ino_num;
153652be551SJaegeuk Kim si->orphans = sbi->im[ORPHAN_INO].ino_num;
154902829aaSGreg Kroah-Hartman si->utilization = utilization(sbi);
155902829aaSGreg Kroah-Hartman
156902829aaSGreg Kroah-Hartman si->free_segs = free_segments(sbi);
157902829aaSGreg Kroah-Hartman si->free_secs = free_sections(sbi);
158902829aaSGreg Kroah-Hartman si->prefree_count = prefree_segments(sbi);
159902829aaSGreg Kroah-Hartman si->dirty_count = dirty_segments(sbi);
1607c77bf7dSJaegeuk Kim if (sbi->node_inode)
1614ef51a8fSJaegeuk Kim si->node_pages = NODE_MAPPING(sbi)->nrpages;
1627c77bf7dSJaegeuk Kim if (sbi->meta_inode)
1639df27d98SGu Zheng si->meta_pages = META_MAPPING(sbi)->nrpages;
1646ce19affSChao Yu #ifdef CONFIG_F2FS_FS_COMPRESSION
1656ce19affSChao Yu if (sbi->compress_inode) {
1666ce19affSChao Yu si->compress_pages = COMPRESS_MAPPING(sbi)->nrpages;
1676ce19affSChao Yu si->compress_page_hit = atomic_read(&sbi->compress_page_hit);
1686ce19affSChao Yu }
1696ce19affSChao Yu #endif
170a95ba66aSJaegeuk Kim si->nats = NM_I(sbi)->nat_cnt[TOTAL_NAT];
171a95ba66aSJaegeuk Kim si->dirty_nats = NM_I(sbi)->nat_cnt[DIRTY_NAT];
172dd4e4b59SJaegeuk Kim si->sits = MAIN_SEGS(sbi);
173dd4e4b59SJaegeuk Kim si->dirty_sits = SIT_I(sbi)->dirty_sentries;
1749a4ffdf5SChao Yu si->free_nids = NM_I(sbi)->nid_cnt[FREE_NID];
1755b0ef73cSJaegeuk Kim si->avail_nids = NM_I(sbi)->available_nids;
1769a4ffdf5SChao Yu si->alloc_nids = NM_I(sbi)->nid_cnt[PREALLOC_NID];
177274bd9baSChao Yu si->io_skip_bggc = sbi->io_skip_bggc;
178274bd9baSChao Yu si->other_skip_bggc = sbi->other_skip_bggc;
17945809cd3SChao Yu si->util_free = (int)(BLKS_TO_SEGS(sbi, free_user_blocks(sbi)))
180902829aaSGreg Kroah-Hartman * 100 / (int)(sbi->user_block_count >> sbi->log_blocks_per_seg)
181902829aaSGreg Kroah-Hartman / 2;
18245809cd3SChao Yu si->util_valid = (int)(BLKS_TO_SEGS(sbi, written_block_count(sbi)))
183902829aaSGreg Kroah-Hartman * 100 / (int)(sbi->user_block_count >> sbi->log_blocks_per_seg)
184902829aaSGreg Kroah-Hartman / 2;
185902829aaSGreg Kroah-Hartman si->util_invalid = 50 - si->util_free - si->util_valid;
186d0b9e42aSChao Yu for (i = CURSEG_HOT_DATA; i < NO_CHECK_TYPE; i++) {
187902829aaSGreg Kroah-Hartman struct curseg_info *curseg = CURSEG_I(sbi, i);
1885f029c04SYi Zhuang
189902829aaSGreg Kroah-Hartman si->curseg[i] = curseg->segno;
1904ddb1a4dSJaegeuk Kim si->cursec[i] = GET_SEC_FROM_SEG(sbi, curseg->segno);
1914ddb1a4dSJaegeuk Kim si->curzone[i] = GET_ZONE_FROM_SEC(sbi, si->cursec[i]);
192902829aaSGreg Kroah-Hartman }
193902829aaSGreg Kroah-Hartman
194b63e7be5SChao Yu for (i = META_CP; i < META_MAX; i++)
195b63e7be5SChao Yu si->meta_count[i] = atomic_read(&sbi->meta_count[i]);
196b63e7be5SChao Yu
1970759e2c1SChao Yu for (i = 0; i < NO_CHECK_TYPE; i++) {
1980759e2c1SChao Yu si->dirty_seg[i] = 0;
1990759e2c1SChao Yu si->full_seg[i] = 0;
2000759e2c1SChao Yu si->valid_blks[i] = 0;
2010759e2c1SChao Yu }
2020759e2c1SChao Yu
2030759e2c1SChao Yu for (i = 0; i < MAIN_SEGS(sbi); i++) {
2040759e2c1SChao Yu int blks = get_seg_entry(sbi, i)->valid_blocks;
2050759e2c1SChao Yu int type = get_seg_entry(sbi, i)->type;
2060759e2c1SChao Yu
2070759e2c1SChao Yu if (!blks)
2080759e2c1SChao Yu continue;
2090759e2c1SChao Yu
210a60108f7SJaegeuk Kim if (blks == BLKS_PER_SEG(sbi))
2110759e2c1SChao Yu si->full_seg[type]++;
2120759e2c1SChao Yu else
2130759e2c1SChao Yu si->dirty_seg[type]++;
2140759e2c1SChao Yu si->valid_blks[type] += blks;
2150759e2c1SChao Yu }
2160759e2c1SChao Yu
217eb61c2ccSChao Yu for (i = 0; i < MAX_CALL_TYPE; i++)
218eb61c2ccSChao Yu si->cp_call_count[i] = atomic_read(&sbi->cp_call_count[i]);
219eb61c2ccSChao Yu
220902829aaSGreg Kroah-Hartman for (i = 0; i < 2; i++) {
221902829aaSGreg Kroah-Hartman si->segment_count[i] = sbi->segment_count[i];
222902829aaSGreg Kroah-Hartman si->block_count[i] = sbi->block_count[i];
223902829aaSGreg Kroah-Hartman }
224b9a2c252SChangman Lee
225b9a2c252SChangman Lee si->inplace_count = atomic_read(&sbi->inplace_count);
226902829aaSGreg Kroah-Hartman }
227902829aaSGreg Kroah-Hartman
2280a8165d7SJaegeuk Kim /*
229902829aaSGreg Kroah-Hartman * This function calculates memory footprint.
230902829aaSGreg Kroah-Hartman */
update_mem_info(struct f2fs_sb_info * sbi)231902829aaSGreg Kroah-Hartman static void update_mem_info(struct f2fs_sb_info *sbi)
232902829aaSGreg Kroah-Hartman {
233963d4f7dSGu Zheng struct f2fs_stat_info *si = F2FS_STAT(sbi);
2348c402946SJaegeuk Kim int i;
235902829aaSGreg Kroah-Hartman
236902829aaSGreg Kroah-Hartman if (si->base_mem)
237902829aaSGreg Kroah-Hartman goto get_cache;
238902829aaSGreg Kroah-Hartman
23970874fb3SKinglong Mee /* build stat */
24070874fb3SKinglong Mee si->base_mem = sizeof(struct f2fs_stat_info);
24170874fb3SKinglong Mee
24270874fb3SKinglong Mee /* build superblock */
24370874fb3SKinglong Mee si->base_mem += sizeof(struct f2fs_sb_info) + sbi->sb->s_blocksize;
244902829aaSGreg Kroah-Hartman si->base_mem += 2 * sizeof(struct f2fs_inode_info);
245902829aaSGreg Kroah-Hartman si->base_mem += sizeof(*sbi->ckpt);
246902829aaSGreg Kroah-Hartman
247902829aaSGreg Kroah-Hartman /* build sm */
248902829aaSGreg Kroah-Hartman si->base_mem += sizeof(struct f2fs_sm_info);
249902829aaSGreg Kroah-Hartman
250902829aaSGreg Kroah-Hartman /* build sit */
251902829aaSGreg Kroah-Hartman si->base_mem += sizeof(struct sit_info);
2527cd8558bSJaegeuk Kim si->base_mem += MAIN_SEGS(sbi) * sizeof(struct seg_entry);
2537cd8558bSJaegeuk Kim si->base_mem += f2fs_bitmap_size(MAIN_SEGS(sbi));
2543e025740SJaegeuk Kim si->base_mem += 2 * SIT_VBLOCK_MAP_SIZE * MAIN_SEGS(sbi);
2553e025740SJaegeuk Kim si->base_mem += SIT_VBLOCK_MAP_SIZE * MAIN_SEGS(sbi);
25660a3b782SJaegeuk Kim si->base_mem += SIT_VBLOCK_MAP_SIZE;
2572c70c5e3SChao Yu if (__is_large_section(sbi))
2587cd8558bSJaegeuk Kim si->base_mem += MAIN_SECS(sbi) * sizeof(struct sec_entry);
259902829aaSGreg Kroah-Hartman si->base_mem += __bitmap_size(sbi, SIT_BITMAP);
260902829aaSGreg Kroah-Hartman
261902829aaSGreg Kroah-Hartman /* build free segmap */
262902829aaSGreg Kroah-Hartman si->base_mem += sizeof(struct free_segmap_info);
2637cd8558bSJaegeuk Kim si->base_mem += f2fs_bitmap_size(MAIN_SEGS(sbi));
2647cd8558bSJaegeuk Kim si->base_mem += f2fs_bitmap_size(MAIN_SECS(sbi));
265902829aaSGreg Kroah-Hartman
266902829aaSGreg Kroah-Hartman /* build curseg */
267902829aaSGreg Kroah-Hartman si->base_mem += sizeof(struct curseg_info) * NR_CURSEG_TYPE;
26809cbfeafSKirill A. Shutemov si->base_mem += PAGE_SIZE * NR_CURSEG_TYPE;
269902829aaSGreg Kroah-Hartman
270902829aaSGreg Kroah-Hartman /* build dirty segmap */
271902829aaSGreg Kroah-Hartman si->base_mem += sizeof(struct dirty_seglist_info);
2727cd8558bSJaegeuk Kim si->base_mem += NR_DIRTY_TYPE * f2fs_bitmap_size(MAIN_SEGS(sbi));
2737cd8558bSJaegeuk Kim si->base_mem += f2fs_bitmap_size(MAIN_SECS(sbi));
274902829aaSGreg Kroah-Hartman
275e1c42045Sarter97 /* build nm */
276902829aaSGreg Kroah-Hartman si->base_mem += sizeof(struct f2fs_nm_info);
277902829aaSGreg Kroah-Hartman si->base_mem += __bitmap_size(sbi, NAT_BITMAP);
278*8fb9f319SZhiguo Niu si->base_mem += F2FS_BLK_TO_BYTES(NM_I(sbi)->nat_bits_blocks);
279e15d54d5SYunlei He si->base_mem += NM_I(sbi)->nat_blocks *
280e15d54d5SYunlei He f2fs_bitmap_size(NAT_ENTRY_PER_BLOCK);
2814ac91242SChao Yu si->base_mem += NM_I(sbi)->nat_blocks / 8;
282586d1492SChao Yu si->base_mem += NM_I(sbi)->nat_blocks * sizeof(unsigned short);
283902829aaSGreg Kroah-Hartman
284902829aaSGreg Kroah-Hartman get_cache:
2859066c6a7SChao Yu si->cache_mem = 0;
2869066c6a7SChao Yu
2879066c6a7SChao Yu /* build gc */
2889066c6a7SChao Yu if (sbi->gc_thread)
2899066c6a7SChao Yu si->cache_mem += sizeof(struct f2fs_gc_kthread);
2909066c6a7SChao Yu
2919066c6a7SChao Yu /* build merge flush thread */
292b01a9201SJaegeuk Kim if (SM_I(sbi)->fcc_info)
2939066c6a7SChao Yu si->cache_mem += sizeof(struct flush_cmd_control);
2945f32366aSChao Yu if (SM_I(sbi)->dcc_info) {
2950b54fb84SJaegeuk Kim si->cache_mem += sizeof(struct discard_cmd_control);
2965f32366aSChao Yu si->cache_mem += sizeof(struct discard_cmd) *
2975f32366aSChao Yu atomic_read(&SM_I(sbi)->dcc_info->discard_cmd_cnt);
2985f32366aSChao Yu }
2999066c6a7SChao Yu
300902829aaSGreg Kroah-Hartman /* free nids */
3019a4ffdf5SChao Yu si->cache_mem += (NM_I(sbi)->nid_cnt[FREE_NID] +
3029a4ffdf5SChao Yu NM_I(sbi)->nid_cnt[PREALLOC_NID]) *
303b8559dc2SChao Yu sizeof(struct free_nid);
304a95ba66aSJaegeuk Kim si->cache_mem += NM_I(sbi)->nat_cnt[TOTAL_NAT] *
305a95ba66aSJaegeuk Kim sizeof(struct nat_entry);
306a95ba66aSJaegeuk Kim si->cache_mem += NM_I(sbi)->nat_cnt[DIRTY_NAT] *
3076f0aacbcSJaegeuk Kim sizeof(struct nat_entry_set);
308b77061bfSChao Yu for (i = 0; i < MAX_INO_ENTRY; i++)
30967298804SChao Yu si->cache_mem += sbi->im[i].ino_num * sizeof(struct ino_entry);
310e7547dacSJaegeuk Kim
311e7547dacSJaegeuk Kim for (i = 0; i < NR_EXTENT_CACHES; i++) {
312e7547dacSJaegeuk Kim struct extent_tree_info *eti = &sbi->extent_tree[i];
313e7547dacSJaegeuk Kim
314e7547dacSJaegeuk Kim si->ext_mem[i] = atomic_read(&eti->total_ext_tree) *
3157441ccefSJaegeuk Kim sizeof(struct extent_tree);
316e7547dacSJaegeuk Kim si->ext_mem[i] += atomic_read(&eti->total_ext_node) *
3174bf6fd9fSChao Yu sizeof(struct extent_node);
318e7547dacSJaegeuk Kim si->cache_mem += si->ext_mem[i];
319e7547dacSJaegeuk Kim }
3206f0aacbcSJaegeuk Kim
3216f0aacbcSJaegeuk Kim si->page_mem = 0;
3227c77bf7dSJaegeuk Kim if (sbi->node_inode) {
3237411143fSYangtao Li unsigned long npages = NODE_MAPPING(sbi)->nrpages;
3245f029c04SYi Zhuang
32509cbfeafSKirill A. Shutemov si->page_mem += (unsigned long long)npages << PAGE_SHIFT;
3267c77bf7dSJaegeuk Kim }
3277c77bf7dSJaegeuk Kim if (sbi->meta_inode) {
3287411143fSYangtao Li unsigned long npages = META_MAPPING(sbi)->nrpages;
3295f029c04SYi Zhuang
33009cbfeafSKirill A. Shutemov si->page_mem += (unsigned long long)npages << PAGE_SHIFT;
331902829aaSGreg Kroah-Hartman }
3326ce19affSChao Yu #ifdef CONFIG_F2FS_FS_COMPRESSION
3336ce19affSChao Yu if (sbi->compress_inode) {
3347411143fSYangtao Li unsigned long npages = COMPRESS_MAPPING(sbi)->nrpages;
3357411143fSYangtao Li
3366ce19affSChao Yu si->page_mem += (unsigned long long)npages << PAGE_SHIFT;
3376ce19affSChao Yu }
3386ce19affSChao Yu #endif
3397c77bf7dSJaegeuk Kim }
340902829aaSGreg Kroah-Hartman
3415bb9c111SYangtao Li static const char *s_flag[MAX_SBI_FLAG] = {
342b6d9246dSYangtao Li [SBI_IS_DIRTY] = "fs_dirty",
343b6d9246dSYangtao Li [SBI_IS_CLOSE] = "closing",
344b6d9246dSYangtao Li [SBI_NEED_FSCK] = "need_fsck",
345b6d9246dSYangtao Li [SBI_POR_DOING] = "recovering",
346b6d9246dSYangtao Li [SBI_NEED_SB_WRITE] = "sb_dirty",
347b6d9246dSYangtao Li [SBI_NEED_CP] = "need_cp",
348b6d9246dSYangtao Li [SBI_IS_SHUTDOWN] = "shutdown",
349b6d9246dSYangtao Li [SBI_IS_RECOVERED] = "recovered",
350b6d9246dSYangtao Li [SBI_CP_DISABLED] = "cp_disabled",
351b6d9246dSYangtao Li [SBI_CP_DISABLED_QUICK] = "cp_disabled_quick",
352b6d9246dSYangtao Li [SBI_QUOTA_NEED_FLUSH] = "quota_need_flush",
353b6d9246dSYangtao Li [SBI_QUOTA_SKIP_FLUSH] = "quota_skip_flush",
354b6d9246dSYangtao Li [SBI_QUOTA_NEED_REPAIR] = "quota_need_repair",
355b6d9246dSYangtao Li [SBI_IS_RESIZEFS] = "resizefs",
356ba900534SJaegeuk Kim [SBI_IS_FREEZING] = "freezefs",
357e1bb7d3dSChao Yu [SBI_IS_WRITABLE] = "writable",
358b6d9246dSYangtao Li };
359b6d9246dSYangtao Li
360f2e35789SYangtao Li static const char *ipu_mode_names[F2FS_IPU_MAX] = {
361f2e35789SYangtao Li [F2FS_IPU_FORCE] = "FORCE",
362f2e35789SYangtao Li [F2FS_IPU_SSR] = "SSR",
363f2e35789SYangtao Li [F2FS_IPU_UTIL] = "UTIL",
364f2e35789SYangtao Li [F2FS_IPU_SSR_UTIL] = "SSR_UTIL",
365f2e35789SYangtao Li [F2FS_IPU_FSYNC] = "FSYNC",
366f2e35789SYangtao Li [F2FS_IPU_ASYNC] = "ASYNC",
367f2e35789SYangtao Li [F2FS_IPU_NOCACHE] = "NOCACHE",
368f2e35789SYangtao Li [F2FS_IPU_HONOR_OPU_WRITE] = "HONOR_OPU_WRITE",
369f2e35789SYangtao Li };
370f2e35789SYangtao Li
stat_show(struct seq_file * s,void * v)371902829aaSGreg Kroah-Hartman static int stat_show(struct seq_file *s, void *v)
372902829aaSGreg Kroah-Hartman {
373145b04e5Smajianpeng struct f2fs_stat_info *si;
374b6d9246dSYangtao Li int i = 0, j = 0;
37598237fcdSJaegeuk Kim unsigned long flags;
376902829aaSGreg Kroah-Hartman
37798237fcdSJaegeuk Kim raw_spin_lock_irqsave(&f2fs_stat_lock, flags);
378145b04e5Smajianpeng list_for_each_entry(si, &f2fs_stat_list, stat_list) {
379dda7d77bSYangtao Li struct f2fs_sb_info *sbi = si->sbi;
380dda7d77bSYangtao Li
381dda7d77bSYangtao Li update_general_status(sbi);
382902829aaSGreg Kroah-Hartman
383b6d9246dSYangtao Li seq_printf(s, "\n=====[ partition info(%pg). #%d, %s, CP: %s]=====\n",
384dda7d77bSYangtao Li sbi->sb->s_bdev, i++,
385dda7d77bSYangtao Li f2fs_readonly(sbi->sb) ? "RO" : "RW",
386dda7d77bSYangtao Li is_set_ckpt_flags(sbi, CP_DISABLED_FLAG) ?
387dda7d77bSYangtao Li "Disabled" : (f2fs_cp_error(sbi) ? "Error" : "Good"));
388dda7d77bSYangtao Li if (sbi->s_flag) {
389b6d9246dSYangtao Li seq_puts(s, "[SBI:");
3905bb9c111SYangtao Li for_each_set_bit(j, &sbi->s_flag, MAX_SBI_FLAG)
3915bb9c111SYangtao Li seq_printf(s, " %s", s_flag[j]);
392b6d9246dSYangtao Li seq_puts(s, "]\n");
393b6d9246dSYangtao Li }
3947880ceedSHuajun Li seq_printf(s, "[SB: 1] [CP: 2] [SIT: %d] [NAT: %d] ",
3957880ceedSHuajun Li si->sit_area_segs, si->nat_area_segs);
396902829aaSGreg Kroah-Hartman seq_printf(s, "[SSA: %d] [MAIN: %d",
397902829aaSGreg Kroah-Hartman si->ssa_area_segs, si->main_area_segs);
398902829aaSGreg Kroah-Hartman seq_printf(s, "(OverProv:%d Resv:%d)]\n\n",
399902829aaSGreg Kroah-Hartman si->overp_segs, si->rsvd_segs);
400a7e679b5SJaegeuk Kim seq_printf(s, "Current Time Sec: %llu / Mounted Time Sec: %llu\n\n",
401a7e679b5SJaegeuk Kim ktime_get_boottime_seconds(),
402dda7d77bSYangtao Li SIT_I(sbi)->mounted_time);
403f2e35789SYangtao Li
404f2e35789SYangtao Li seq_puts(s, "Policy:\n");
405f2e35789SYangtao Li seq_puts(s, " - IPU: [");
406dda7d77bSYangtao Li if (IS_F2FS_IPU_DISABLE(sbi)) {
407f2e35789SYangtao Li seq_puts(s, " DISABLE");
408f2e35789SYangtao Li } else {
409dda7d77bSYangtao Li unsigned long policy = SM_I(sbi)->ipu_policy;
410f2e35789SYangtao Li
411f2e35789SYangtao Li for_each_set_bit(j, &policy, F2FS_IPU_MAX)
412f2e35789SYangtao Li seq_printf(s, " %s", ipu_mode_names[j]);
413f2e35789SYangtao Li }
414f2e35789SYangtao Li seq_puts(s, " ]\n\n");
415f2e35789SYangtao Li
416dda7d77bSYangtao Li if (test_opt(sbi, DISCARD))
417f83a2584SYunlei He seq_printf(s, "Utilization: %u%% (%u valid blocks, %u discard blocks)\n",
418f83a2584SYunlei He si->utilization, si->valid_count, si->discard_blks);
419f83a2584SYunlei He else
420f83a2584SYunlei He seq_printf(s, "Utilization: %u%% (%u valid blocks)\n",
421902829aaSGreg Kroah-Hartman si->utilization, si->valid_count);
422f83a2584SYunlei He
423902829aaSGreg Kroah-Hartman seq_printf(s, " - Node: %u (Inode: %u, ",
424902829aaSGreg Kroah-Hartman si->valid_node_count, si->valid_inode_count);
425902829aaSGreg Kroah-Hartman seq_printf(s, "Other: %u)\n - Data: %u\n",
426902829aaSGreg Kroah-Hartman si->valid_node_count - si->valid_inode_count,
427902829aaSGreg Kroah-Hartman si->valid_count - si->valid_node_count);
428d5e8f6c9SChao Yu seq_printf(s, " - Inline_xattr Inode: %u\n",
429d5e8f6c9SChao Yu si->inline_xattr);
4300dbdc2aeSJaegeuk Kim seq_printf(s, " - Inline_data Inode: %u\n",
4310dbdc2aeSJaegeuk Kim si->inline_inode);
4323289c061SJaegeuk Kim seq_printf(s, " - Inline_dentry Inode: %u\n",
4333289c061SJaegeuk Kim si->inline_dir);
434ae999bb9SDaeho Jeong seq_printf(s, " - Compressed Inode: %u, Blocks: %llu\n",
4354c8ff709SChao Yu si->compr_inode, si->compr_blocks);
4368ec071c3SChao Yu seq_printf(s, " - Swapfile Inode: %u\n",
4378ec071c3SChao Yu si->swapfile_inode);
438a00861dbSJaegeuk Kim seq_printf(s, " - Orphan/Append/Update Inode: %u, %u, %u\n",
439a00861dbSJaegeuk Kim si->orphans, si->append, si->update);
440902829aaSGreg Kroah-Hartman seq_printf(s, "\nMain area: %d segs, %d secs %d zones\n",
441902829aaSGreg Kroah-Hartman si->main_area_segs, si->main_area_sections,
442902829aaSGreg Kroah-Hartman si->main_area_zones);
4430759e2c1SChao Yu seq_printf(s, " TYPE %8s %8s %8s %10s %10s %10s\n",
4440759e2c1SChao Yu "segno", "secno", "zoneno", "dirty_seg", "full_seg", "valid_blk");
4450759e2c1SChao Yu seq_printf(s, " - COLD data: %8d %8d %8d %10u %10u %10u\n",
446902829aaSGreg Kroah-Hartman si->curseg[CURSEG_COLD_DATA],
447902829aaSGreg Kroah-Hartman si->cursec[CURSEG_COLD_DATA],
4480759e2c1SChao Yu si->curzone[CURSEG_COLD_DATA],
4490759e2c1SChao Yu si->dirty_seg[CURSEG_COLD_DATA],
4500759e2c1SChao Yu si->full_seg[CURSEG_COLD_DATA],
4510759e2c1SChao Yu si->valid_blks[CURSEG_COLD_DATA]);
4520759e2c1SChao Yu seq_printf(s, " - WARM data: %8d %8d %8d %10u %10u %10u\n",
453902829aaSGreg Kroah-Hartman si->curseg[CURSEG_WARM_DATA],
454902829aaSGreg Kroah-Hartman si->cursec[CURSEG_WARM_DATA],
4550759e2c1SChao Yu si->curzone[CURSEG_WARM_DATA],
4560759e2c1SChao Yu si->dirty_seg[CURSEG_WARM_DATA],
4570759e2c1SChao Yu si->full_seg[CURSEG_WARM_DATA],
4580759e2c1SChao Yu si->valid_blks[CURSEG_WARM_DATA]);
4590759e2c1SChao Yu seq_printf(s, " - HOT data: %8d %8d %8d %10u %10u %10u\n",
460902829aaSGreg Kroah-Hartman si->curseg[CURSEG_HOT_DATA],
461902829aaSGreg Kroah-Hartman si->cursec[CURSEG_HOT_DATA],
4620759e2c1SChao Yu si->curzone[CURSEG_HOT_DATA],
4630759e2c1SChao Yu si->dirty_seg[CURSEG_HOT_DATA],
4640759e2c1SChao Yu si->full_seg[CURSEG_HOT_DATA],
4650759e2c1SChao Yu si->valid_blks[CURSEG_HOT_DATA]);
4660759e2c1SChao Yu seq_printf(s, " - Dir dnode: %8d %8d %8d %10u %10u %10u\n",
467902829aaSGreg Kroah-Hartman si->curseg[CURSEG_HOT_NODE],
468902829aaSGreg Kroah-Hartman si->cursec[CURSEG_HOT_NODE],
4690759e2c1SChao Yu si->curzone[CURSEG_HOT_NODE],
4700759e2c1SChao Yu si->dirty_seg[CURSEG_HOT_NODE],
4710759e2c1SChao Yu si->full_seg[CURSEG_HOT_NODE],
4720759e2c1SChao Yu si->valid_blks[CURSEG_HOT_NODE]);
4730759e2c1SChao Yu seq_printf(s, " - File dnode: %8d %8d %8d %10u %10u %10u\n",
474902829aaSGreg Kroah-Hartman si->curseg[CURSEG_WARM_NODE],
475902829aaSGreg Kroah-Hartman si->cursec[CURSEG_WARM_NODE],
4760759e2c1SChao Yu si->curzone[CURSEG_WARM_NODE],
4770759e2c1SChao Yu si->dirty_seg[CURSEG_WARM_NODE],
4780759e2c1SChao Yu si->full_seg[CURSEG_WARM_NODE],
4790759e2c1SChao Yu si->valid_blks[CURSEG_WARM_NODE]);
4800759e2c1SChao Yu seq_printf(s, " - Indir nodes: %8d %8d %8d %10u %10u %10u\n",
481902829aaSGreg Kroah-Hartman si->curseg[CURSEG_COLD_NODE],
482902829aaSGreg Kroah-Hartman si->cursec[CURSEG_COLD_NODE],
4830759e2c1SChao Yu si->curzone[CURSEG_COLD_NODE],
4840759e2c1SChao Yu si->dirty_seg[CURSEG_COLD_NODE],
4850759e2c1SChao Yu si->full_seg[CURSEG_COLD_NODE],
4860759e2c1SChao Yu si->valid_blks[CURSEG_COLD_NODE]);
487d0b9e42aSChao Yu seq_printf(s, " - Pinned file: %8d %8d %8d\n",
488d0b9e42aSChao Yu si->curseg[CURSEG_COLD_DATA_PINNED],
489d0b9e42aSChao Yu si->cursec[CURSEG_COLD_DATA_PINNED],
490d0b9e42aSChao Yu si->curzone[CURSEG_COLD_DATA_PINNED]);
491093749e2SChao Yu seq_printf(s, " - ATGC data: %8d %8d %8d\n",
492093749e2SChao Yu si->curseg[CURSEG_ALL_DATA_ATGC],
493093749e2SChao Yu si->cursec[CURSEG_ALL_DATA_ATGC],
494093749e2SChao Yu si->curzone[CURSEG_ALL_DATA_ATGC]);
495902829aaSGreg Kroah-Hartman seq_printf(s, "\n - Valid: %d\n - Dirty: %d\n",
496902829aaSGreg Kroah-Hartman si->main_area_segs - si->dirty_count -
497902829aaSGreg Kroah-Hartman si->prefree_count - si->free_segs,
498902829aaSGreg Kroah-Hartman si->dirty_count);
499902829aaSGreg Kroah-Hartman seq_printf(s, " - Prefree: %d\n - Free: %d (%d)\n\n",
500902829aaSGreg Kroah-Hartman si->prefree_count, si->free_segs, si->free_secs);
50142190d2aSJaegeuk Kim seq_printf(s, "CP calls: %d (BG: %d)\n",
502eb61c2ccSChao Yu si->cp_call_count[TOTAL_CALL],
503eb61c2ccSChao Yu si->cp_call_count[BACKGROUND]);
504eb61c2ccSChao Yu seq_printf(s, "CP count: %d\n", si->cp_count);
505b63e7be5SChao Yu seq_printf(s, " - cp blocks : %u\n", si->meta_count[META_CP]);
506b63e7be5SChao Yu seq_printf(s, " - sit blocks : %u\n",
507b63e7be5SChao Yu si->meta_count[META_SIT]);
508b63e7be5SChao Yu seq_printf(s, " - nat blocks : %u\n",
509b63e7be5SChao Yu si->meta_count[META_NAT]);
510b63e7be5SChao Yu seq_printf(s, " - ssa blocks : %u\n",
511b63e7be5SChao Yu si->meta_count[META_SSA]);
5127411143fSYangtao Li seq_puts(s, "CP merge:\n");
5137411143fSYangtao Li seq_printf(s, " - Queued : %4d\n", si->nr_queued_ckpt);
5147411143fSYangtao Li seq_printf(s, " - Issued : %4d\n", si->nr_issued_ckpt);
5157411143fSYangtao Li seq_printf(s, " - Total : %4d\n", si->nr_total_ckpt);
5167411143fSYangtao Li seq_printf(s, " - Cur time : %4d(ms)\n", si->cur_ckpt_time);
5177411143fSYangtao Li seq_printf(s, " - Peak time : %4d(ms)\n", si->peak_ckpt_time);
5189bf1dcbdSChao Yu seq_printf(s, "GC calls: %d (gc_thread: %d)\n",
5199bf1dcbdSChao Yu si->gc_call_count[BACKGROUND] +
5209bf1dcbdSChao Yu si->gc_call_count[FOREGROUND],
5219bf1dcbdSChao Yu si->gc_call_count[BACKGROUND]);
5229bf1dcbdSChao Yu if (__is_large_section(sbi)) {
5239bf1dcbdSChao Yu seq_printf(s, " - data sections : %d (BG: %d)\n",
5249bf1dcbdSChao Yu si->gc_secs[DATA][BG_GC] + si->gc_secs[DATA][FG_GC],
5259bf1dcbdSChao Yu si->gc_secs[DATA][BG_GC]);
5269bf1dcbdSChao Yu seq_printf(s, " - node sections : %d (BG: %d)\n",
5279bf1dcbdSChao Yu si->gc_secs[NODE][BG_GC] + si->gc_secs[NODE][FG_GC],
5289bf1dcbdSChao Yu si->gc_secs[NODE][BG_GC]);
5299bf1dcbdSChao Yu }
5309bf1dcbdSChao Yu seq_printf(s, " - data segments : %d (BG: %d)\n",
5319bf1dcbdSChao Yu si->gc_segs[DATA][BG_GC] + si->gc_segs[DATA][FG_GC],
5329bf1dcbdSChao Yu si->gc_segs[DATA][BG_GC]);
5339bf1dcbdSChao Yu seq_printf(s, " - node segments : %d (BG: %d)\n",
5349bf1dcbdSChao Yu si->gc_segs[NODE][BG_GC] + si->gc_segs[NODE][FG_GC],
5359bf1dcbdSChao Yu si->gc_segs[NODE][BG_GC]);
5367411143fSYangtao Li seq_puts(s, " - Reclaimed segs :\n");
537dda7d77bSYangtao Li seq_printf(s, " - Normal : %d\n", sbi->gc_reclaimed_segs[GC_NORMAL]);
538dda7d77bSYangtao Li seq_printf(s, " - Idle CB : %d\n", sbi->gc_reclaimed_segs[GC_IDLE_CB]);
5397411143fSYangtao Li seq_printf(s, " - Idle Greedy : %d\n",
540dda7d77bSYangtao Li sbi->gc_reclaimed_segs[GC_IDLE_GREEDY]);
541dda7d77bSYangtao Li seq_printf(s, " - Idle AT : %d\n", sbi->gc_reclaimed_segs[GC_IDLE_AT]);
5427411143fSYangtao Li seq_printf(s, " - Urgent High : %d\n",
543dda7d77bSYangtao Li sbi->gc_reclaimed_segs[GC_URGENT_HIGH]);
544dda7d77bSYangtao Li seq_printf(s, " - Urgent Mid : %d\n", sbi->gc_reclaimed_segs[GC_URGENT_MID]);
545dda7d77bSYangtao Li seq_printf(s, " - Urgent Low : %d\n", sbi->gc_reclaimed_segs[GC_URGENT_LOW]);
546e1235983SChangman Lee seq_printf(s, "Try to move %d blocks (BG: %d)\n", si->tot_blks,
547e1235983SChangman Lee si->bg_data_blks + si->bg_node_blks);
548e1235983SChangman Lee seq_printf(s, " - data blocks : %d (%d)\n", si->data_blks,
549e1235983SChangman Lee si->bg_data_blks);
550e1235983SChangman Lee seq_printf(s, " - node blocks : %d (%d)\n", si->node_blks,
551e1235983SChangman Lee si->bg_node_blks);
552274bd9baSChao Yu seq_printf(s, "BG skip : IO: %u, Other: %u\n",
553274bd9baSChao Yu si->io_skip_bggc, si->other_skip_bggc);
554e7547dacSJaegeuk Kim seq_puts(s, "\nExtent Cache (Read):\n");
5555b7ee374SChao Yu seq_printf(s, " - Hit Count: L1-1:%llu L1-2:%llu L2:%llu\n",
556e7547dacSJaegeuk Kim si->hit_largest, si->hit_cached[EX_READ],
557e7547dacSJaegeuk Kim si->hit_rbtree[EX_READ]);
5585b7ee374SChao Yu seq_printf(s, " - Hit Ratio: %llu%% (%llu / %llu)\n",
559e7547dacSJaegeuk Kim !si->total_ext[EX_READ] ? 0 :
560e7547dacSJaegeuk Kim div64_u64(si->hit_total[EX_READ] * 100,
561e7547dacSJaegeuk Kim si->total_ext[EX_READ]),
562e7547dacSJaegeuk Kim si->hit_total[EX_READ], si->total_ext[EX_READ]);
563c00ba554SJaegeuk Kim seq_printf(s, " - Inner Struct Count: tree: %d(%d), node: %d\n",
564e7547dacSJaegeuk Kim si->ext_tree[EX_READ], si->zombie_tree[EX_READ],
565e7547dacSJaegeuk Kim si->ext_node[EX_READ]);
56671644dffSJaegeuk Kim seq_puts(s, "\nExtent Cache (Block Age):\n");
56771644dffSJaegeuk Kim seq_printf(s, " - Allocated Data Blocks: %llu\n",
56871644dffSJaegeuk Kim si->allocated_data_blocks);
56971644dffSJaegeuk Kim seq_printf(s, " - Hit Count: L1:%llu L2:%llu\n",
57071644dffSJaegeuk Kim si->hit_cached[EX_BLOCK_AGE],
57171644dffSJaegeuk Kim si->hit_rbtree[EX_BLOCK_AGE]);
57271644dffSJaegeuk Kim seq_printf(s, " - Hit Ratio: %llu%% (%llu / %llu)\n",
57371644dffSJaegeuk Kim !si->total_ext[EX_BLOCK_AGE] ? 0 :
57471644dffSJaegeuk Kim div64_u64(si->hit_total[EX_BLOCK_AGE] * 100,
57571644dffSJaegeuk Kim si->total_ext[EX_BLOCK_AGE]),
57671644dffSJaegeuk Kim si->hit_total[EX_BLOCK_AGE],
57771644dffSJaegeuk Kim si->total_ext[EX_BLOCK_AGE]);
57871644dffSJaegeuk Kim seq_printf(s, " - Inner Struct Count: tree: %d(%d), node: %d\n",
57971644dffSJaegeuk Kim si->ext_tree[EX_BLOCK_AGE],
58071644dffSJaegeuk Kim si->zombie_tree[EX_BLOCK_AGE],
58171644dffSJaegeuk Kim si->ext_node[EX_BLOCK_AGE]);
5826c311ec6SChris Fries seq_puts(s, "\nBalancing F2FS Async:\n");
58302b16d0aSChao Yu seq_printf(s, " - DIO (R: %4d, W: %4d)\n",
58402b16d0aSChao Yu si->nr_dio_read, si->nr_dio_write);
5855f9abab4SJaegeuk Kim seq_printf(s, " - IO_R (Data: %4d, Node: %4d, Meta: %4d\n",
5865f9abab4SJaegeuk Kim si->nr_rd_data, si->nr_rd_node, si->nr_rd_meta);
5877411143fSYangtao Li seq_printf(s, " - IO_W (CP: %4d, Data: %4d, Flush: (%4d %4d %4d), ",
588dcc9165dSJaegeuk Kim si->nr_wb_cp_data, si->nr_wb_data,
5898b8dd65fSChao Yu si->nr_flushing, si->nr_flushed,
5907411143fSYangtao Li si->flush_list_empty);
5917411143fSYangtao Li seq_printf(s, "Discard: (%4d %4d)) cmd: %4d undiscard:%4u\n",
5925f32366aSChao Yu si->nr_discarding, si->nr_discarded,
593d84d1cbdSChao Yu si->nr_discard_cmd, si->undiscard_blks);
5947bc155feSJaegeuk Kim seq_printf(s, " - atomic IO: %4d (Max. %4d)\n",
5957bc155feSJaegeuk Kim si->aw_cnt, si->max_aw_cnt);
5966ce19affSChao Yu seq_printf(s, " - compress: %4d, hit:%8d\n", si->compress_pages, si->compress_page_hit);
59735782b23SJaegeuk Kim seq_printf(s, " - nodes: %4d in %4d\n",
598902829aaSGreg Kroah-Hartman si->ndirty_node, si->node_pages);
59935782b23SJaegeuk Kim seq_printf(s, " - dents: %4d in dirs:%4d (%4d)\n",
6000f18b462SJaegeuk Kim si->ndirty_dent, si->ndirty_dirs, si->ndirty_all);
60135782b23SJaegeuk Kim seq_printf(s, " - datas: %4d in files:%4d\n",
60233fbd510SChao Yu si->ndirty_data, si->ndirty_files);
6032c8a4a28SJaegeuk Kim seq_printf(s, " - quota datas: %4d in quota files:%4d\n",
6042c8a4a28SJaegeuk Kim si->ndirty_qdata, si->nquota_files);
60535782b23SJaegeuk Kim seq_printf(s, " - meta: %4d in %4d\n",
606902829aaSGreg Kroah-Hartman si->ndirty_meta, si->meta_pages);
60735782b23SJaegeuk Kim seq_printf(s, " - imeta: %4d\n",
6085bc994a0SChao Yu si->ndirty_imeta);
60947c8ebccSJaegeuk Kim seq_printf(s, " - fsync mark: %4lld\n",
61047c8ebccSJaegeuk Kim percpu_counter_sum_positive(
611dda7d77bSYangtao Li &sbi->rf_node_block_count));
612dd4e4b59SJaegeuk Kim seq_printf(s, " - NATs: %9d/%9d\n - SITs: %9d/%9d\n",
613dd4e4b59SJaegeuk Kim si->dirty_nats, si->nats, si->dirty_sits, si->sits);
6145b0ef73cSJaegeuk Kim seq_printf(s, " - free_nids: %9d/%9d\n - alloc_nids: %9d\n",
6155b0ef73cSJaegeuk Kim si->free_nids, si->avail_nids, si->alloc_nids);
6162d219c51SGu Zheng seq_puts(s, "\nDistribution of User Blocks:");
6172d219c51SGu Zheng seq_puts(s, " [ valid | invalid | free ]\n");
6182d219c51SGu Zheng seq_puts(s, " [");
619902829aaSGreg Kroah-Hartman
620902829aaSGreg Kroah-Hartman for (j = 0; j < si->util_valid; j++)
6212d219c51SGu Zheng seq_putc(s, '-');
6222d219c51SGu Zheng seq_putc(s, '|');
623902829aaSGreg Kroah-Hartman
624902829aaSGreg Kroah-Hartman for (j = 0; j < si->util_invalid; j++)
6252d219c51SGu Zheng seq_putc(s, '-');
6262d219c51SGu Zheng seq_putc(s, '|');
627902829aaSGreg Kroah-Hartman
628902829aaSGreg Kroah-Hartman for (j = 0; j < si->util_free; j++)
6292d219c51SGu Zheng seq_putc(s, '-');
6302d219c51SGu Zheng seq_puts(s, "]\n\n");
631b9a2c252SChangman Lee seq_printf(s, "IPU: %u blocks\n", si->inplace_count);
632902829aaSGreg Kroah-Hartman seq_printf(s, "SSR: %u blocks in %u segments\n",
633902829aaSGreg Kroah-Hartman si->block_count[SSR], si->segment_count[SSR]);
634902829aaSGreg Kroah-Hartman seq_printf(s, "LFS: %u blocks in %u segments\n",
635902829aaSGreg Kroah-Hartman si->block_count[LFS], si->segment_count[LFS]);
636902829aaSGreg Kroah-Hartman
637902829aaSGreg Kroah-Hartman /* segment usage info */
638dda7d77bSYangtao Li f2fs_update_sit_info(sbi);
639902829aaSGreg Kroah-Hartman seq_printf(s, "\nBDF: %u, avg. vblocks: %u\n",
640902829aaSGreg Kroah-Hartman si->bimodal, si->avg_vblocks);
641902829aaSGreg Kroah-Hartman
642902829aaSGreg Kroah-Hartman /* memory footprint */
643dda7d77bSYangtao Li update_mem_info(sbi);
6449edcdabfSChao Yu seq_printf(s, "\nMemory: %llu KB\n",
6456f0aacbcSJaegeuk Kim (si->base_mem + si->cache_mem + si->page_mem) >> 10);
6469edcdabfSChao Yu seq_printf(s, " - static: %llu KB\n",
6476f0aacbcSJaegeuk Kim si->base_mem >> 10);
648e7547dacSJaegeuk Kim seq_printf(s, " - cached all: %llu KB\n",
6496f0aacbcSJaegeuk Kim si->cache_mem >> 10);
650e7547dacSJaegeuk Kim seq_printf(s, " - read extent cache: %llu KB\n",
651e7547dacSJaegeuk Kim si->ext_mem[EX_READ] >> 10);
65271644dffSJaegeuk Kim seq_printf(s, " - block age extent cache: %llu KB\n",
65371644dffSJaegeuk Kim si->ext_mem[EX_BLOCK_AGE] >> 10);
6549edcdabfSChao Yu seq_printf(s, " - paged : %llu KB\n",
6556f0aacbcSJaegeuk Kim si->page_mem >> 10);
656902829aaSGreg Kroah-Hartman }
65798237fcdSJaegeuk Kim raw_spin_unlock_irqrestore(&f2fs_stat_lock, flags);
658902829aaSGreg Kroah-Hartman return 0;
659902829aaSGreg Kroah-Hartman }
660902829aaSGreg Kroah-Hartman
661155c62feSYangtao Li DEFINE_SHOW_ATTRIBUTE(stat);
662fc7100eaSHridya Valsaraju #endif
663902829aaSGreg Kroah-Hartman
f2fs_build_stats(struct f2fs_sb_info * sbi)6644589d25dSNamjae Jeon int f2fs_build_stats(struct f2fs_sb_info *sbi)
665902829aaSGreg Kroah-Hartman {
666902829aaSGreg Kroah-Hartman struct f2fs_super_block *raw_super = F2FS_RAW_SUPER(sbi);
667902829aaSGreg Kroah-Hartman struct f2fs_stat_info *si;
66898237fcdSJaegeuk Kim unsigned long flags;
669b63e7be5SChao Yu int i;
670902829aaSGreg Kroah-Hartman
671acbf054dSChao Yu si = f2fs_kzalloc(sbi, sizeof(struct f2fs_stat_info), GFP_KERNEL);
672963d4f7dSGu Zheng if (!si)
673902829aaSGreg Kroah-Hartman return -ENOMEM;
674902829aaSGreg Kroah-Hartman
675902829aaSGreg Kroah-Hartman si->all_area_segs = le32_to_cpu(raw_super->segment_count);
676902829aaSGreg Kroah-Hartman si->sit_area_segs = le32_to_cpu(raw_super->segment_count_sit);
677902829aaSGreg Kroah-Hartman si->nat_area_segs = le32_to_cpu(raw_super->segment_count_nat);
678902829aaSGreg Kroah-Hartman si->ssa_area_segs = le32_to_cpu(raw_super->segment_count_ssa);
679902829aaSGreg Kroah-Hartman si->main_area_segs = le32_to_cpu(raw_super->segment_count_main);
680902829aaSGreg Kroah-Hartman si->main_area_sections = le32_to_cpu(raw_super->section_count);
681902829aaSGreg Kroah-Hartman si->main_area_zones = si->main_area_sections /
682902829aaSGreg Kroah-Hartman le32_to_cpu(raw_super->secs_per_zone);
683902829aaSGreg Kroah-Hartman si->sbi = sbi;
684963d4f7dSGu Zheng sbi->stat_info = si;
68566af62ceSmajianpeng
686e7547dacSJaegeuk Kim /* general extent cache stats */
687e7547dacSJaegeuk Kim for (i = 0; i < NR_EXTENT_CACHES; i++) {
688e7547dacSJaegeuk Kim atomic64_set(&sbi->total_hit_ext[i], 0);
689e7547dacSJaegeuk Kim atomic64_set(&sbi->read_hit_rbtree[i], 0);
690e7547dacSJaegeuk Kim atomic64_set(&sbi->read_hit_cached[i], 0);
691e7547dacSJaegeuk Kim }
692e7547dacSJaegeuk Kim
693e7547dacSJaegeuk Kim /* read extent_cache only */
6945b7ee374SChao Yu atomic64_set(&sbi->read_hit_largest, 0);
695727edac5SChao Yu
696d5e8f6c9SChao Yu atomic_set(&sbi->inline_xattr, 0);
69703e14d52SChao Yu atomic_set(&sbi->inline_inode, 0);
69803e14d52SChao Yu atomic_set(&sbi->inline_dir, 0);
6994c8ff709SChao Yu atomic_set(&sbi->compr_inode, 0);
700ae999bb9SDaeho Jeong atomic64_set(&sbi->compr_blocks, 0);
7018ec071c3SChao Yu atomic_set(&sbi->swapfile_inode, 0);
702b4dac120SChao Yu atomic_set(&sbi->atomic_files, 0);
703b9a2c252SChangman Lee atomic_set(&sbi->inplace_count, 0);
704b63e7be5SChao Yu for (i = META_CP; i < META_MAX; i++)
705b63e7be5SChao Yu atomic_set(&sbi->meta_count[i], 0);
706eb61c2ccSChao Yu for (i = 0; i < MAX_CALL_TYPE; i++)
707eb61c2ccSChao Yu atomic_set(&sbi->cp_call_count[i], 0);
70803e14d52SChao Yu
70926a28a0cSJaegeuk Kim atomic_set(&sbi->max_aw_cnt, 0);
71026a28a0cSJaegeuk Kim
71198237fcdSJaegeuk Kim raw_spin_lock_irqsave(&f2fs_stat_lock, flags);
71266af62ceSmajianpeng list_add_tail(&si->stat_list, &f2fs_stat_list);
71398237fcdSJaegeuk Kim raw_spin_unlock_irqrestore(&f2fs_stat_lock, flags);
71466af62ceSmajianpeng
715902829aaSGreg Kroah-Hartman return 0;
716902829aaSGreg Kroah-Hartman }
717902829aaSGreg Kroah-Hartman
f2fs_destroy_stats(struct f2fs_sb_info * sbi)718902829aaSGreg Kroah-Hartman void f2fs_destroy_stats(struct f2fs_sb_info *sbi)
719902829aaSGreg Kroah-Hartman {
720963d4f7dSGu Zheng struct f2fs_stat_info *si = F2FS_STAT(sbi);
72198237fcdSJaegeuk Kim unsigned long flags;
722902829aaSGreg Kroah-Hartman
72398237fcdSJaegeuk Kim raw_spin_lock_irqsave(&f2fs_stat_lock, flags);
724902829aaSGreg Kroah-Hartman list_del(&si->stat_list);
72598237fcdSJaegeuk Kim raw_spin_unlock_irqrestore(&f2fs_stat_lock, flags);
72666af62ceSmajianpeng
727c8eb7024SChao Yu kfree(si);
728902829aaSGreg Kroah-Hartman }
729902829aaSGreg Kroah-Hartman
f2fs_create_root_stats(void)730c20e57b3SGreg Kroah-Hartman void __init f2fs_create_root_stats(void)
7314589d25dSNamjae Jeon {
732fc7100eaSHridya Valsaraju #ifdef CONFIG_DEBUG_FS
73340e1ebe9SYounger Liu f2fs_debugfs_root = debugfs_create_dir("f2fs", NULL);
734c524723eSYounger Liu
735491f7f71SYangtao Li debugfs_create_file("status", 0444, f2fs_debugfs_root, NULL,
736c20e57b3SGreg Kroah-Hartman &stat_fops);
737fc7100eaSHridya Valsaraju #endif
7384589d25dSNamjae Jeon }
7394589d25dSNamjae Jeon
f2fs_destroy_root_stats(void)7404589d25dSNamjae Jeon void f2fs_destroy_root_stats(void)
741902829aaSGreg Kroah-Hartman {
742fc7100eaSHridya Valsaraju #ifdef CONFIG_DEBUG_FS
74340e1ebe9SYounger Liu debugfs_remove_recursive(f2fs_debugfs_root);
74440e1ebe9SYounger Liu f2fs_debugfs_root = NULL;
745fc7100eaSHridya Valsaraju #endif
746902829aaSGreg Kroah-Hartman }
747