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 */ 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; 44*a60108f7SJaegeuk 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 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); 138*a60108f7SJaegeuk Kim si->total_count = (int)sbi->user_block_count / BLKS_PER_SEG(sbi); 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; 179902829aaSGreg Kroah-Hartman si->util_free = (int)(free_user_blocks(sbi) >> sbi->log_blocks_per_seg) 180902829aaSGreg Kroah-Hartman * 100 / (int)(sbi->user_block_count >> sbi->log_blocks_per_seg) 181902829aaSGreg Kroah-Hartman / 2; 182902829aaSGreg Kroah-Hartman si->util_valid = (int)(written_block_count(sbi) >> 183902829aaSGreg Kroah-Hartman sbi->log_blocks_per_seg) 184902829aaSGreg Kroah-Hartman * 100 / (int)(sbi->user_block_count >> sbi->log_blocks_per_seg) 185902829aaSGreg Kroah-Hartman / 2; 186902829aaSGreg Kroah-Hartman si->util_invalid = 50 - si->util_free - si->util_valid; 187d0b9e42aSChao Yu for (i = CURSEG_HOT_DATA; i < NO_CHECK_TYPE; i++) { 188902829aaSGreg Kroah-Hartman struct curseg_info *curseg = CURSEG_I(sbi, i); 1895f029c04SYi Zhuang 190902829aaSGreg Kroah-Hartman si->curseg[i] = curseg->segno; 1914ddb1a4dSJaegeuk Kim si->cursec[i] = GET_SEC_FROM_SEG(sbi, curseg->segno); 1924ddb1a4dSJaegeuk Kim si->curzone[i] = GET_ZONE_FROM_SEC(sbi, si->cursec[i]); 193902829aaSGreg Kroah-Hartman } 194902829aaSGreg Kroah-Hartman 195b63e7be5SChao Yu for (i = META_CP; i < META_MAX; i++) 196b63e7be5SChao Yu si->meta_count[i] = atomic_read(&sbi->meta_count[i]); 197b63e7be5SChao Yu 1980759e2c1SChao Yu for (i = 0; i < NO_CHECK_TYPE; i++) { 1990759e2c1SChao Yu si->dirty_seg[i] = 0; 2000759e2c1SChao Yu si->full_seg[i] = 0; 2010759e2c1SChao Yu si->valid_blks[i] = 0; 2020759e2c1SChao Yu } 2030759e2c1SChao Yu 2040759e2c1SChao Yu for (i = 0; i < MAIN_SEGS(sbi); i++) { 2050759e2c1SChao Yu int blks = get_seg_entry(sbi, i)->valid_blocks; 2060759e2c1SChao Yu int type = get_seg_entry(sbi, i)->type; 2070759e2c1SChao Yu 2080759e2c1SChao Yu if (!blks) 2090759e2c1SChao Yu continue; 2100759e2c1SChao Yu 211*a60108f7SJaegeuk Kim if (blks == BLKS_PER_SEG(sbi)) 2120759e2c1SChao Yu si->full_seg[type]++; 2130759e2c1SChao Yu else 2140759e2c1SChao Yu si->dirty_seg[type]++; 2150759e2c1SChao Yu si->valid_blks[type] += blks; 2160759e2c1SChao Yu } 2170759e2c1SChao Yu 218eb61c2ccSChao Yu for (i = 0; i < MAX_CALL_TYPE; i++) 219eb61c2ccSChao Yu si->cp_call_count[i] = atomic_read(&sbi->cp_call_count[i]); 220eb61c2ccSChao Yu 221902829aaSGreg Kroah-Hartman for (i = 0; i < 2; i++) { 222902829aaSGreg Kroah-Hartman si->segment_count[i] = sbi->segment_count[i]; 223902829aaSGreg Kroah-Hartman si->block_count[i] = sbi->block_count[i]; 224902829aaSGreg Kroah-Hartman } 225b9a2c252SChangman Lee 226b9a2c252SChangman Lee si->inplace_count = atomic_read(&sbi->inplace_count); 227902829aaSGreg Kroah-Hartman } 228902829aaSGreg Kroah-Hartman 2290a8165d7SJaegeuk Kim /* 230902829aaSGreg Kroah-Hartman * This function calculates memory footprint. 231902829aaSGreg Kroah-Hartman */ 232902829aaSGreg Kroah-Hartman static void update_mem_info(struct f2fs_sb_info *sbi) 233902829aaSGreg Kroah-Hartman { 234963d4f7dSGu Zheng struct f2fs_stat_info *si = F2FS_STAT(sbi); 2358c402946SJaegeuk Kim int i; 236902829aaSGreg Kroah-Hartman 237902829aaSGreg Kroah-Hartman if (si->base_mem) 238902829aaSGreg Kroah-Hartman goto get_cache; 239902829aaSGreg Kroah-Hartman 24070874fb3SKinglong Mee /* build stat */ 24170874fb3SKinglong Mee si->base_mem = sizeof(struct f2fs_stat_info); 24270874fb3SKinglong Mee 24370874fb3SKinglong Mee /* build superblock */ 24470874fb3SKinglong Mee si->base_mem += sizeof(struct f2fs_sb_info) + sbi->sb->s_blocksize; 245902829aaSGreg Kroah-Hartman si->base_mem += 2 * sizeof(struct f2fs_inode_info); 246902829aaSGreg Kroah-Hartman si->base_mem += sizeof(*sbi->ckpt); 247902829aaSGreg Kroah-Hartman 248902829aaSGreg Kroah-Hartman /* build sm */ 249902829aaSGreg Kroah-Hartman si->base_mem += sizeof(struct f2fs_sm_info); 250902829aaSGreg Kroah-Hartman 251902829aaSGreg Kroah-Hartman /* build sit */ 252902829aaSGreg Kroah-Hartman si->base_mem += sizeof(struct sit_info); 2537cd8558bSJaegeuk Kim si->base_mem += MAIN_SEGS(sbi) * sizeof(struct seg_entry); 2547cd8558bSJaegeuk Kim si->base_mem += f2fs_bitmap_size(MAIN_SEGS(sbi)); 2553e025740SJaegeuk Kim si->base_mem += 2 * SIT_VBLOCK_MAP_SIZE * MAIN_SEGS(sbi); 2563e025740SJaegeuk Kim si->base_mem += SIT_VBLOCK_MAP_SIZE * MAIN_SEGS(sbi); 25760a3b782SJaegeuk Kim si->base_mem += SIT_VBLOCK_MAP_SIZE; 2582c70c5e3SChao Yu if (__is_large_section(sbi)) 2597cd8558bSJaegeuk Kim si->base_mem += MAIN_SECS(sbi) * sizeof(struct sec_entry); 260902829aaSGreg Kroah-Hartman si->base_mem += __bitmap_size(sbi, SIT_BITMAP); 261902829aaSGreg Kroah-Hartman 262902829aaSGreg Kroah-Hartman /* build free segmap */ 263902829aaSGreg Kroah-Hartman si->base_mem += sizeof(struct free_segmap_info); 2647cd8558bSJaegeuk Kim si->base_mem += f2fs_bitmap_size(MAIN_SEGS(sbi)); 2657cd8558bSJaegeuk Kim si->base_mem += f2fs_bitmap_size(MAIN_SECS(sbi)); 266902829aaSGreg Kroah-Hartman 267902829aaSGreg Kroah-Hartman /* build curseg */ 268902829aaSGreg Kroah-Hartman si->base_mem += sizeof(struct curseg_info) * NR_CURSEG_TYPE; 26909cbfeafSKirill A. Shutemov si->base_mem += PAGE_SIZE * NR_CURSEG_TYPE; 270902829aaSGreg Kroah-Hartman 271902829aaSGreg Kroah-Hartman /* build dirty segmap */ 272902829aaSGreg Kroah-Hartman si->base_mem += sizeof(struct dirty_seglist_info); 2737cd8558bSJaegeuk Kim si->base_mem += NR_DIRTY_TYPE * f2fs_bitmap_size(MAIN_SEGS(sbi)); 2747cd8558bSJaegeuk Kim si->base_mem += f2fs_bitmap_size(MAIN_SECS(sbi)); 275902829aaSGreg Kroah-Hartman 276e1c42045Sarter97 /* build nm */ 277902829aaSGreg Kroah-Hartman si->base_mem += sizeof(struct f2fs_nm_info); 278902829aaSGreg Kroah-Hartman si->base_mem += __bitmap_size(sbi, NAT_BITMAP); 27922ad0b6aSJaegeuk Kim si->base_mem += (NM_I(sbi)->nat_bits_blocks << F2FS_BLKSIZE_BITS); 280e15d54d5SYunlei He si->base_mem += NM_I(sbi)->nat_blocks * 281e15d54d5SYunlei He f2fs_bitmap_size(NAT_ENTRY_PER_BLOCK); 2824ac91242SChao Yu si->base_mem += NM_I(sbi)->nat_blocks / 8; 283586d1492SChao Yu si->base_mem += NM_I(sbi)->nat_blocks * sizeof(unsigned short); 284902829aaSGreg Kroah-Hartman 285902829aaSGreg Kroah-Hartman get_cache: 2869066c6a7SChao Yu si->cache_mem = 0; 2879066c6a7SChao Yu 2889066c6a7SChao Yu /* build gc */ 2899066c6a7SChao Yu if (sbi->gc_thread) 2909066c6a7SChao Yu si->cache_mem += sizeof(struct f2fs_gc_kthread); 2919066c6a7SChao Yu 2929066c6a7SChao Yu /* build merge flush thread */ 293b01a9201SJaegeuk Kim if (SM_I(sbi)->fcc_info) 2949066c6a7SChao Yu si->cache_mem += sizeof(struct flush_cmd_control); 2955f32366aSChao Yu if (SM_I(sbi)->dcc_info) { 2960b54fb84SJaegeuk Kim si->cache_mem += sizeof(struct discard_cmd_control); 2975f32366aSChao Yu si->cache_mem += sizeof(struct discard_cmd) * 2985f32366aSChao Yu atomic_read(&SM_I(sbi)->dcc_info->discard_cmd_cnt); 2995f32366aSChao Yu } 3009066c6a7SChao Yu 301902829aaSGreg Kroah-Hartman /* free nids */ 3029a4ffdf5SChao Yu si->cache_mem += (NM_I(sbi)->nid_cnt[FREE_NID] + 3039a4ffdf5SChao Yu NM_I(sbi)->nid_cnt[PREALLOC_NID]) * 304b8559dc2SChao Yu sizeof(struct free_nid); 305a95ba66aSJaegeuk Kim si->cache_mem += NM_I(sbi)->nat_cnt[TOTAL_NAT] * 306a95ba66aSJaegeuk Kim sizeof(struct nat_entry); 307a95ba66aSJaegeuk Kim si->cache_mem += NM_I(sbi)->nat_cnt[DIRTY_NAT] * 3086f0aacbcSJaegeuk Kim sizeof(struct nat_entry_set); 309b77061bfSChao Yu for (i = 0; i < MAX_INO_ENTRY; i++) 31067298804SChao Yu si->cache_mem += sbi->im[i].ino_num * sizeof(struct ino_entry); 311e7547dacSJaegeuk Kim 312e7547dacSJaegeuk Kim for (i = 0; i < NR_EXTENT_CACHES; i++) { 313e7547dacSJaegeuk Kim struct extent_tree_info *eti = &sbi->extent_tree[i]; 314e7547dacSJaegeuk Kim 315e7547dacSJaegeuk Kim si->ext_mem[i] = atomic_read(&eti->total_ext_tree) * 3167441ccefSJaegeuk Kim sizeof(struct extent_tree); 317e7547dacSJaegeuk Kim si->ext_mem[i] += atomic_read(&eti->total_ext_node) * 3184bf6fd9fSChao Yu sizeof(struct extent_node); 319e7547dacSJaegeuk Kim si->cache_mem += si->ext_mem[i]; 320e7547dacSJaegeuk Kim } 3216f0aacbcSJaegeuk Kim 3226f0aacbcSJaegeuk Kim si->page_mem = 0; 3237c77bf7dSJaegeuk Kim if (sbi->node_inode) { 3247411143fSYangtao Li unsigned long npages = NODE_MAPPING(sbi)->nrpages; 3255f029c04SYi Zhuang 32609cbfeafSKirill A. Shutemov si->page_mem += (unsigned long long)npages << PAGE_SHIFT; 3277c77bf7dSJaegeuk Kim } 3287c77bf7dSJaegeuk Kim if (sbi->meta_inode) { 3297411143fSYangtao Li unsigned long npages = META_MAPPING(sbi)->nrpages; 3305f029c04SYi Zhuang 33109cbfeafSKirill A. Shutemov si->page_mem += (unsigned long long)npages << PAGE_SHIFT; 332902829aaSGreg Kroah-Hartman } 3336ce19affSChao Yu #ifdef CONFIG_F2FS_FS_COMPRESSION 3346ce19affSChao Yu if (sbi->compress_inode) { 3357411143fSYangtao Li unsigned long npages = COMPRESS_MAPPING(sbi)->nrpages; 3367411143fSYangtao Li 3376ce19affSChao Yu si->page_mem += (unsigned long long)npages << PAGE_SHIFT; 3386ce19affSChao Yu } 3396ce19affSChao Yu #endif 3407c77bf7dSJaegeuk Kim } 341902829aaSGreg Kroah-Hartman 3425bb9c111SYangtao Li static const char *s_flag[MAX_SBI_FLAG] = { 343b6d9246dSYangtao Li [SBI_IS_DIRTY] = "fs_dirty", 344b6d9246dSYangtao Li [SBI_IS_CLOSE] = "closing", 345b6d9246dSYangtao Li [SBI_NEED_FSCK] = "need_fsck", 346b6d9246dSYangtao Li [SBI_POR_DOING] = "recovering", 347b6d9246dSYangtao Li [SBI_NEED_SB_WRITE] = "sb_dirty", 348b6d9246dSYangtao Li [SBI_NEED_CP] = "need_cp", 349b6d9246dSYangtao Li [SBI_IS_SHUTDOWN] = "shutdown", 350b6d9246dSYangtao Li [SBI_IS_RECOVERED] = "recovered", 351b6d9246dSYangtao Li [SBI_CP_DISABLED] = "cp_disabled", 352b6d9246dSYangtao Li [SBI_CP_DISABLED_QUICK] = "cp_disabled_quick", 353b6d9246dSYangtao Li [SBI_QUOTA_NEED_FLUSH] = "quota_need_flush", 354b6d9246dSYangtao Li [SBI_QUOTA_SKIP_FLUSH] = "quota_skip_flush", 355b6d9246dSYangtao Li [SBI_QUOTA_NEED_REPAIR] = "quota_need_repair", 356b6d9246dSYangtao Li [SBI_IS_RESIZEFS] = "resizefs", 357ba900534SJaegeuk Kim [SBI_IS_FREEZING] = "freezefs", 358e1bb7d3dSChao Yu [SBI_IS_WRITABLE] = "writable", 359b6d9246dSYangtao Li }; 360b6d9246dSYangtao Li 361f2e35789SYangtao Li static const char *ipu_mode_names[F2FS_IPU_MAX] = { 362f2e35789SYangtao Li [F2FS_IPU_FORCE] = "FORCE", 363f2e35789SYangtao Li [F2FS_IPU_SSR] = "SSR", 364f2e35789SYangtao Li [F2FS_IPU_UTIL] = "UTIL", 365f2e35789SYangtao Li [F2FS_IPU_SSR_UTIL] = "SSR_UTIL", 366f2e35789SYangtao Li [F2FS_IPU_FSYNC] = "FSYNC", 367f2e35789SYangtao Li [F2FS_IPU_ASYNC] = "ASYNC", 368f2e35789SYangtao Li [F2FS_IPU_NOCACHE] = "NOCACHE", 369f2e35789SYangtao Li [F2FS_IPU_HONOR_OPU_WRITE] = "HONOR_OPU_WRITE", 370f2e35789SYangtao Li }; 371f2e35789SYangtao Li 372902829aaSGreg Kroah-Hartman static int stat_show(struct seq_file *s, void *v) 373902829aaSGreg Kroah-Hartman { 374145b04e5Smajianpeng struct f2fs_stat_info *si; 375b6d9246dSYangtao Li int i = 0, j = 0; 37698237fcdSJaegeuk Kim unsigned long flags; 377902829aaSGreg Kroah-Hartman 37898237fcdSJaegeuk Kim raw_spin_lock_irqsave(&f2fs_stat_lock, flags); 379145b04e5Smajianpeng list_for_each_entry(si, &f2fs_stat_list, stat_list) { 380dda7d77bSYangtao Li struct f2fs_sb_info *sbi = si->sbi; 381dda7d77bSYangtao Li 382dda7d77bSYangtao Li update_general_status(sbi); 383902829aaSGreg Kroah-Hartman 384b6d9246dSYangtao Li seq_printf(s, "\n=====[ partition info(%pg). #%d, %s, CP: %s]=====\n", 385dda7d77bSYangtao Li sbi->sb->s_bdev, i++, 386dda7d77bSYangtao Li f2fs_readonly(sbi->sb) ? "RO" : "RW", 387dda7d77bSYangtao Li is_set_ckpt_flags(sbi, CP_DISABLED_FLAG) ? 388dda7d77bSYangtao Li "Disabled" : (f2fs_cp_error(sbi) ? "Error" : "Good")); 389dda7d77bSYangtao Li if (sbi->s_flag) { 390b6d9246dSYangtao Li seq_puts(s, "[SBI:"); 3915bb9c111SYangtao Li for_each_set_bit(j, &sbi->s_flag, MAX_SBI_FLAG) 3925bb9c111SYangtao Li seq_printf(s, " %s", s_flag[j]); 393b6d9246dSYangtao Li seq_puts(s, "]\n"); 394b6d9246dSYangtao Li } 3957880ceedSHuajun Li seq_printf(s, "[SB: 1] [CP: 2] [SIT: %d] [NAT: %d] ", 3967880ceedSHuajun Li si->sit_area_segs, si->nat_area_segs); 397902829aaSGreg Kroah-Hartman seq_printf(s, "[SSA: %d] [MAIN: %d", 398902829aaSGreg Kroah-Hartman si->ssa_area_segs, si->main_area_segs); 399902829aaSGreg Kroah-Hartman seq_printf(s, "(OverProv:%d Resv:%d)]\n\n", 400902829aaSGreg Kroah-Hartman si->overp_segs, si->rsvd_segs); 401a7e679b5SJaegeuk Kim seq_printf(s, "Current Time Sec: %llu / Mounted Time Sec: %llu\n\n", 402a7e679b5SJaegeuk Kim ktime_get_boottime_seconds(), 403dda7d77bSYangtao Li SIT_I(sbi)->mounted_time); 404f2e35789SYangtao Li 405f2e35789SYangtao Li seq_puts(s, "Policy:\n"); 406f2e35789SYangtao Li seq_puts(s, " - IPU: ["); 407dda7d77bSYangtao Li if (IS_F2FS_IPU_DISABLE(sbi)) { 408f2e35789SYangtao Li seq_puts(s, " DISABLE"); 409f2e35789SYangtao Li } else { 410dda7d77bSYangtao Li unsigned long policy = SM_I(sbi)->ipu_policy; 411f2e35789SYangtao Li 412f2e35789SYangtao Li for_each_set_bit(j, &policy, F2FS_IPU_MAX) 413f2e35789SYangtao Li seq_printf(s, " %s", ipu_mode_names[j]); 414f2e35789SYangtao Li } 415f2e35789SYangtao Li seq_puts(s, " ]\n\n"); 416f2e35789SYangtao Li 417dda7d77bSYangtao Li if (test_opt(sbi, DISCARD)) 418f83a2584SYunlei He seq_printf(s, "Utilization: %u%% (%u valid blocks, %u discard blocks)\n", 419f83a2584SYunlei He si->utilization, si->valid_count, si->discard_blks); 420f83a2584SYunlei He else 421f83a2584SYunlei He seq_printf(s, "Utilization: %u%% (%u valid blocks)\n", 422902829aaSGreg Kroah-Hartman si->utilization, si->valid_count); 423f83a2584SYunlei He 424902829aaSGreg Kroah-Hartman seq_printf(s, " - Node: %u (Inode: %u, ", 425902829aaSGreg Kroah-Hartman si->valid_node_count, si->valid_inode_count); 426902829aaSGreg Kroah-Hartman seq_printf(s, "Other: %u)\n - Data: %u\n", 427902829aaSGreg Kroah-Hartman si->valid_node_count - si->valid_inode_count, 428902829aaSGreg Kroah-Hartman si->valid_count - si->valid_node_count); 429d5e8f6c9SChao Yu seq_printf(s, " - Inline_xattr Inode: %u\n", 430d5e8f6c9SChao Yu si->inline_xattr); 4310dbdc2aeSJaegeuk Kim seq_printf(s, " - Inline_data Inode: %u\n", 4320dbdc2aeSJaegeuk Kim si->inline_inode); 4333289c061SJaegeuk Kim seq_printf(s, " - Inline_dentry Inode: %u\n", 4343289c061SJaegeuk Kim si->inline_dir); 435ae999bb9SDaeho Jeong seq_printf(s, " - Compressed Inode: %u, Blocks: %llu\n", 4364c8ff709SChao Yu si->compr_inode, si->compr_blocks); 4378ec071c3SChao Yu seq_printf(s, " - Swapfile Inode: %u\n", 4388ec071c3SChao Yu si->swapfile_inode); 439a00861dbSJaegeuk Kim seq_printf(s, " - Orphan/Append/Update Inode: %u, %u, %u\n", 440a00861dbSJaegeuk Kim si->orphans, si->append, si->update); 441902829aaSGreg Kroah-Hartman seq_printf(s, "\nMain area: %d segs, %d secs %d zones\n", 442902829aaSGreg Kroah-Hartman si->main_area_segs, si->main_area_sections, 443902829aaSGreg Kroah-Hartman si->main_area_zones); 4440759e2c1SChao Yu seq_printf(s, " TYPE %8s %8s %8s %10s %10s %10s\n", 4450759e2c1SChao Yu "segno", "secno", "zoneno", "dirty_seg", "full_seg", "valid_blk"); 4460759e2c1SChao Yu seq_printf(s, " - COLD data: %8d %8d %8d %10u %10u %10u\n", 447902829aaSGreg Kroah-Hartman si->curseg[CURSEG_COLD_DATA], 448902829aaSGreg Kroah-Hartman si->cursec[CURSEG_COLD_DATA], 4490759e2c1SChao Yu si->curzone[CURSEG_COLD_DATA], 4500759e2c1SChao Yu si->dirty_seg[CURSEG_COLD_DATA], 4510759e2c1SChao Yu si->full_seg[CURSEG_COLD_DATA], 4520759e2c1SChao Yu si->valid_blks[CURSEG_COLD_DATA]); 4530759e2c1SChao Yu seq_printf(s, " - WARM data: %8d %8d %8d %10u %10u %10u\n", 454902829aaSGreg Kroah-Hartman si->curseg[CURSEG_WARM_DATA], 455902829aaSGreg Kroah-Hartman si->cursec[CURSEG_WARM_DATA], 4560759e2c1SChao Yu si->curzone[CURSEG_WARM_DATA], 4570759e2c1SChao Yu si->dirty_seg[CURSEG_WARM_DATA], 4580759e2c1SChao Yu si->full_seg[CURSEG_WARM_DATA], 4590759e2c1SChao Yu si->valid_blks[CURSEG_WARM_DATA]); 4600759e2c1SChao Yu seq_printf(s, " - HOT data: %8d %8d %8d %10u %10u %10u\n", 461902829aaSGreg Kroah-Hartman si->curseg[CURSEG_HOT_DATA], 462902829aaSGreg Kroah-Hartman si->cursec[CURSEG_HOT_DATA], 4630759e2c1SChao Yu si->curzone[CURSEG_HOT_DATA], 4640759e2c1SChao Yu si->dirty_seg[CURSEG_HOT_DATA], 4650759e2c1SChao Yu si->full_seg[CURSEG_HOT_DATA], 4660759e2c1SChao Yu si->valid_blks[CURSEG_HOT_DATA]); 4670759e2c1SChao Yu seq_printf(s, " - Dir dnode: %8d %8d %8d %10u %10u %10u\n", 468902829aaSGreg Kroah-Hartman si->curseg[CURSEG_HOT_NODE], 469902829aaSGreg Kroah-Hartman si->cursec[CURSEG_HOT_NODE], 4700759e2c1SChao Yu si->curzone[CURSEG_HOT_NODE], 4710759e2c1SChao Yu si->dirty_seg[CURSEG_HOT_NODE], 4720759e2c1SChao Yu si->full_seg[CURSEG_HOT_NODE], 4730759e2c1SChao Yu si->valid_blks[CURSEG_HOT_NODE]); 4740759e2c1SChao Yu seq_printf(s, " - File dnode: %8d %8d %8d %10u %10u %10u\n", 475902829aaSGreg Kroah-Hartman si->curseg[CURSEG_WARM_NODE], 476902829aaSGreg Kroah-Hartman si->cursec[CURSEG_WARM_NODE], 4770759e2c1SChao Yu si->curzone[CURSEG_WARM_NODE], 4780759e2c1SChao Yu si->dirty_seg[CURSEG_WARM_NODE], 4790759e2c1SChao Yu si->full_seg[CURSEG_WARM_NODE], 4800759e2c1SChao Yu si->valid_blks[CURSEG_WARM_NODE]); 4810759e2c1SChao Yu seq_printf(s, " - Indir nodes: %8d %8d %8d %10u %10u %10u\n", 482902829aaSGreg Kroah-Hartman si->curseg[CURSEG_COLD_NODE], 483902829aaSGreg Kroah-Hartman si->cursec[CURSEG_COLD_NODE], 4840759e2c1SChao Yu si->curzone[CURSEG_COLD_NODE], 4850759e2c1SChao Yu si->dirty_seg[CURSEG_COLD_NODE], 4860759e2c1SChao Yu si->full_seg[CURSEG_COLD_NODE], 4870759e2c1SChao Yu si->valid_blks[CURSEG_COLD_NODE]); 488d0b9e42aSChao Yu seq_printf(s, " - Pinned file: %8d %8d %8d\n", 489d0b9e42aSChao Yu si->curseg[CURSEG_COLD_DATA_PINNED], 490d0b9e42aSChao Yu si->cursec[CURSEG_COLD_DATA_PINNED], 491d0b9e42aSChao Yu si->curzone[CURSEG_COLD_DATA_PINNED]); 492093749e2SChao Yu seq_printf(s, " - ATGC data: %8d %8d %8d\n", 493093749e2SChao Yu si->curseg[CURSEG_ALL_DATA_ATGC], 494093749e2SChao Yu si->cursec[CURSEG_ALL_DATA_ATGC], 495093749e2SChao Yu si->curzone[CURSEG_ALL_DATA_ATGC]); 496902829aaSGreg Kroah-Hartman seq_printf(s, "\n - Valid: %d\n - Dirty: %d\n", 497902829aaSGreg Kroah-Hartman si->main_area_segs - si->dirty_count - 498902829aaSGreg Kroah-Hartman si->prefree_count - si->free_segs, 499902829aaSGreg Kroah-Hartman si->dirty_count); 500902829aaSGreg Kroah-Hartman seq_printf(s, " - Prefree: %d\n - Free: %d (%d)\n\n", 501902829aaSGreg Kroah-Hartman si->prefree_count, si->free_segs, si->free_secs); 50242190d2aSJaegeuk Kim seq_printf(s, "CP calls: %d (BG: %d)\n", 503eb61c2ccSChao Yu si->cp_call_count[TOTAL_CALL], 504eb61c2ccSChao Yu si->cp_call_count[BACKGROUND]); 505eb61c2ccSChao Yu seq_printf(s, "CP count: %d\n", si->cp_count); 506b63e7be5SChao Yu seq_printf(s, " - cp blocks : %u\n", si->meta_count[META_CP]); 507b63e7be5SChao Yu seq_printf(s, " - sit blocks : %u\n", 508b63e7be5SChao Yu si->meta_count[META_SIT]); 509b63e7be5SChao Yu seq_printf(s, " - nat blocks : %u\n", 510b63e7be5SChao Yu si->meta_count[META_NAT]); 511b63e7be5SChao Yu seq_printf(s, " - ssa blocks : %u\n", 512b63e7be5SChao Yu si->meta_count[META_SSA]); 5137411143fSYangtao Li seq_puts(s, "CP merge:\n"); 5147411143fSYangtao Li seq_printf(s, " - Queued : %4d\n", si->nr_queued_ckpt); 5157411143fSYangtao Li seq_printf(s, " - Issued : %4d\n", si->nr_issued_ckpt); 5167411143fSYangtao Li seq_printf(s, " - Total : %4d\n", si->nr_total_ckpt); 5177411143fSYangtao Li seq_printf(s, " - Cur time : %4d(ms)\n", si->cur_ckpt_time); 5187411143fSYangtao Li seq_printf(s, " - Peak time : %4d(ms)\n", si->peak_ckpt_time); 5199bf1dcbdSChao Yu seq_printf(s, "GC calls: %d (gc_thread: %d)\n", 5209bf1dcbdSChao Yu si->gc_call_count[BACKGROUND] + 5219bf1dcbdSChao Yu si->gc_call_count[FOREGROUND], 5229bf1dcbdSChao Yu si->gc_call_count[BACKGROUND]); 5239bf1dcbdSChao Yu if (__is_large_section(sbi)) { 5249bf1dcbdSChao Yu seq_printf(s, " - data sections : %d (BG: %d)\n", 5259bf1dcbdSChao Yu si->gc_secs[DATA][BG_GC] + si->gc_secs[DATA][FG_GC], 5269bf1dcbdSChao Yu si->gc_secs[DATA][BG_GC]); 5279bf1dcbdSChao Yu seq_printf(s, " - node sections : %d (BG: %d)\n", 5289bf1dcbdSChao Yu si->gc_secs[NODE][BG_GC] + si->gc_secs[NODE][FG_GC], 5299bf1dcbdSChao Yu si->gc_secs[NODE][BG_GC]); 5309bf1dcbdSChao Yu } 5319bf1dcbdSChao Yu seq_printf(s, " - data segments : %d (BG: %d)\n", 5329bf1dcbdSChao Yu si->gc_segs[DATA][BG_GC] + si->gc_segs[DATA][FG_GC], 5339bf1dcbdSChao Yu si->gc_segs[DATA][BG_GC]); 5349bf1dcbdSChao Yu seq_printf(s, " - node segments : %d (BG: %d)\n", 5359bf1dcbdSChao Yu si->gc_segs[NODE][BG_GC] + si->gc_segs[NODE][FG_GC], 5369bf1dcbdSChao Yu si->gc_segs[NODE][BG_GC]); 5377411143fSYangtao Li seq_puts(s, " - Reclaimed segs :\n"); 538dda7d77bSYangtao Li seq_printf(s, " - Normal : %d\n", sbi->gc_reclaimed_segs[GC_NORMAL]); 539dda7d77bSYangtao Li seq_printf(s, " - Idle CB : %d\n", sbi->gc_reclaimed_segs[GC_IDLE_CB]); 5407411143fSYangtao Li seq_printf(s, " - Idle Greedy : %d\n", 541dda7d77bSYangtao Li sbi->gc_reclaimed_segs[GC_IDLE_GREEDY]); 542dda7d77bSYangtao Li seq_printf(s, " - Idle AT : %d\n", sbi->gc_reclaimed_segs[GC_IDLE_AT]); 5437411143fSYangtao Li seq_printf(s, " - Urgent High : %d\n", 544dda7d77bSYangtao Li sbi->gc_reclaimed_segs[GC_URGENT_HIGH]); 545dda7d77bSYangtao Li seq_printf(s, " - Urgent Mid : %d\n", sbi->gc_reclaimed_segs[GC_URGENT_MID]); 546dda7d77bSYangtao Li seq_printf(s, " - Urgent Low : %d\n", sbi->gc_reclaimed_segs[GC_URGENT_LOW]); 547e1235983SChangman Lee seq_printf(s, "Try to move %d blocks (BG: %d)\n", si->tot_blks, 548e1235983SChangman Lee si->bg_data_blks + si->bg_node_blks); 549e1235983SChangman Lee seq_printf(s, " - data blocks : %d (%d)\n", si->data_blks, 550e1235983SChangman Lee si->bg_data_blks); 551e1235983SChangman Lee seq_printf(s, " - node blocks : %d (%d)\n", si->node_blks, 552e1235983SChangman Lee si->bg_node_blks); 553274bd9baSChao Yu seq_printf(s, "BG skip : IO: %u, Other: %u\n", 554274bd9baSChao Yu si->io_skip_bggc, si->other_skip_bggc); 555e7547dacSJaegeuk Kim seq_puts(s, "\nExtent Cache (Read):\n"); 5565b7ee374SChao Yu seq_printf(s, " - Hit Count: L1-1:%llu L1-2:%llu L2:%llu\n", 557e7547dacSJaegeuk Kim si->hit_largest, si->hit_cached[EX_READ], 558e7547dacSJaegeuk Kim si->hit_rbtree[EX_READ]); 5595b7ee374SChao Yu seq_printf(s, " - Hit Ratio: %llu%% (%llu / %llu)\n", 560e7547dacSJaegeuk Kim !si->total_ext[EX_READ] ? 0 : 561e7547dacSJaegeuk Kim div64_u64(si->hit_total[EX_READ] * 100, 562e7547dacSJaegeuk Kim si->total_ext[EX_READ]), 563e7547dacSJaegeuk Kim si->hit_total[EX_READ], si->total_ext[EX_READ]); 564c00ba554SJaegeuk Kim seq_printf(s, " - Inner Struct Count: tree: %d(%d), node: %d\n", 565e7547dacSJaegeuk Kim si->ext_tree[EX_READ], si->zombie_tree[EX_READ], 566e7547dacSJaegeuk Kim si->ext_node[EX_READ]); 56771644dffSJaegeuk Kim seq_puts(s, "\nExtent Cache (Block Age):\n"); 56871644dffSJaegeuk Kim seq_printf(s, " - Allocated Data Blocks: %llu\n", 56971644dffSJaegeuk Kim si->allocated_data_blocks); 57071644dffSJaegeuk Kim seq_printf(s, " - Hit Count: L1:%llu L2:%llu\n", 57171644dffSJaegeuk Kim si->hit_cached[EX_BLOCK_AGE], 57271644dffSJaegeuk Kim si->hit_rbtree[EX_BLOCK_AGE]); 57371644dffSJaegeuk Kim seq_printf(s, " - Hit Ratio: %llu%% (%llu / %llu)\n", 57471644dffSJaegeuk Kim !si->total_ext[EX_BLOCK_AGE] ? 0 : 57571644dffSJaegeuk Kim div64_u64(si->hit_total[EX_BLOCK_AGE] * 100, 57671644dffSJaegeuk Kim si->total_ext[EX_BLOCK_AGE]), 57771644dffSJaegeuk Kim si->hit_total[EX_BLOCK_AGE], 57871644dffSJaegeuk Kim si->total_ext[EX_BLOCK_AGE]); 57971644dffSJaegeuk Kim seq_printf(s, " - Inner Struct Count: tree: %d(%d), node: %d\n", 58071644dffSJaegeuk Kim si->ext_tree[EX_BLOCK_AGE], 58171644dffSJaegeuk Kim si->zombie_tree[EX_BLOCK_AGE], 58271644dffSJaegeuk Kim si->ext_node[EX_BLOCK_AGE]); 5836c311ec6SChris Fries seq_puts(s, "\nBalancing F2FS Async:\n"); 58402b16d0aSChao Yu seq_printf(s, " - DIO (R: %4d, W: %4d)\n", 58502b16d0aSChao Yu si->nr_dio_read, si->nr_dio_write); 5865f9abab4SJaegeuk Kim seq_printf(s, " - IO_R (Data: %4d, Node: %4d, Meta: %4d\n", 5875f9abab4SJaegeuk Kim si->nr_rd_data, si->nr_rd_node, si->nr_rd_meta); 5887411143fSYangtao Li seq_printf(s, " - IO_W (CP: %4d, Data: %4d, Flush: (%4d %4d %4d), ", 589dcc9165dSJaegeuk Kim si->nr_wb_cp_data, si->nr_wb_data, 5908b8dd65fSChao Yu si->nr_flushing, si->nr_flushed, 5917411143fSYangtao Li si->flush_list_empty); 5927411143fSYangtao Li seq_printf(s, "Discard: (%4d %4d)) cmd: %4d undiscard:%4u\n", 5935f32366aSChao Yu si->nr_discarding, si->nr_discarded, 594d84d1cbdSChao Yu si->nr_discard_cmd, si->undiscard_blks); 5957bc155feSJaegeuk Kim seq_printf(s, " - atomic IO: %4d (Max. %4d)\n", 5967bc155feSJaegeuk Kim si->aw_cnt, si->max_aw_cnt); 5976ce19affSChao Yu seq_printf(s, " - compress: %4d, hit:%8d\n", si->compress_pages, si->compress_page_hit); 59835782b23SJaegeuk Kim seq_printf(s, " - nodes: %4d in %4d\n", 599902829aaSGreg Kroah-Hartman si->ndirty_node, si->node_pages); 60035782b23SJaegeuk Kim seq_printf(s, " - dents: %4d in dirs:%4d (%4d)\n", 6010f18b462SJaegeuk Kim si->ndirty_dent, si->ndirty_dirs, si->ndirty_all); 60235782b23SJaegeuk Kim seq_printf(s, " - datas: %4d in files:%4d\n", 60333fbd510SChao Yu si->ndirty_data, si->ndirty_files); 6042c8a4a28SJaegeuk Kim seq_printf(s, " - quota datas: %4d in quota files:%4d\n", 6052c8a4a28SJaegeuk Kim si->ndirty_qdata, si->nquota_files); 60635782b23SJaegeuk Kim seq_printf(s, " - meta: %4d in %4d\n", 607902829aaSGreg Kroah-Hartman si->ndirty_meta, si->meta_pages); 60835782b23SJaegeuk Kim seq_printf(s, " - imeta: %4d\n", 6095bc994a0SChao Yu si->ndirty_imeta); 61047c8ebccSJaegeuk Kim seq_printf(s, " - fsync mark: %4lld\n", 61147c8ebccSJaegeuk Kim percpu_counter_sum_positive( 612dda7d77bSYangtao Li &sbi->rf_node_block_count)); 613dd4e4b59SJaegeuk Kim seq_printf(s, " - NATs: %9d/%9d\n - SITs: %9d/%9d\n", 614dd4e4b59SJaegeuk Kim si->dirty_nats, si->nats, si->dirty_sits, si->sits); 6155b0ef73cSJaegeuk Kim seq_printf(s, " - free_nids: %9d/%9d\n - alloc_nids: %9d\n", 6165b0ef73cSJaegeuk Kim si->free_nids, si->avail_nids, si->alloc_nids); 6172d219c51SGu Zheng seq_puts(s, "\nDistribution of User Blocks:"); 6182d219c51SGu Zheng seq_puts(s, " [ valid | invalid | free ]\n"); 6192d219c51SGu Zheng seq_puts(s, " ["); 620902829aaSGreg Kroah-Hartman 621902829aaSGreg Kroah-Hartman for (j = 0; j < si->util_valid; j++) 6222d219c51SGu Zheng seq_putc(s, '-'); 6232d219c51SGu Zheng seq_putc(s, '|'); 624902829aaSGreg Kroah-Hartman 625902829aaSGreg Kroah-Hartman for (j = 0; j < si->util_invalid; j++) 6262d219c51SGu Zheng seq_putc(s, '-'); 6272d219c51SGu Zheng seq_putc(s, '|'); 628902829aaSGreg Kroah-Hartman 629902829aaSGreg Kroah-Hartman for (j = 0; j < si->util_free; j++) 6302d219c51SGu Zheng seq_putc(s, '-'); 6312d219c51SGu Zheng seq_puts(s, "]\n\n"); 632b9a2c252SChangman Lee seq_printf(s, "IPU: %u blocks\n", si->inplace_count); 633902829aaSGreg Kroah-Hartman seq_printf(s, "SSR: %u blocks in %u segments\n", 634902829aaSGreg Kroah-Hartman si->block_count[SSR], si->segment_count[SSR]); 635902829aaSGreg Kroah-Hartman seq_printf(s, "LFS: %u blocks in %u segments\n", 636902829aaSGreg Kroah-Hartman si->block_count[LFS], si->segment_count[LFS]); 637902829aaSGreg Kroah-Hartman 638902829aaSGreg Kroah-Hartman /* segment usage info */ 639dda7d77bSYangtao Li f2fs_update_sit_info(sbi); 640902829aaSGreg Kroah-Hartman seq_printf(s, "\nBDF: %u, avg. vblocks: %u\n", 641902829aaSGreg Kroah-Hartman si->bimodal, si->avg_vblocks); 642902829aaSGreg Kroah-Hartman 643902829aaSGreg Kroah-Hartman /* memory footprint */ 644dda7d77bSYangtao Li update_mem_info(sbi); 6459edcdabfSChao Yu seq_printf(s, "\nMemory: %llu KB\n", 6466f0aacbcSJaegeuk Kim (si->base_mem + si->cache_mem + si->page_mem) >> 10); 6479edcdabfSChao Yu seq_printf(s, " - static: %llu KB\n", 6486f0aacbcSJaegeuk Kim si->base_mem >> 10); 649e7547dacSJaegeuk Kim seq_printf(s, " - cached all: %llu KB\n", 6506f0aacbcSJaegeuk Kim si->cache_mem >> 10); 651e7547dacSJaegeuk Kim seq_printf(s, " - read extent cache: %llu KB\n", 652e7547dacSJaegeuk Kim si->ext_mem[EX_READ] >> 10); 65371644dffSJaegeuk Kim seq_printf(s, " - block age extent cache: %llu KB\n", 65471644dffSJaegeuk Kim si->ext_mem[EX_BLOCK_AGE] >> 10); 6559edcdabfSChao Yu seq_printf(s, " - paged : %llu KB\n", 6566f0aacbcSJaegeuk Kim si->page_mem >> 10); 657902829aaSGreg Kroah-Hartman } 65898237fcdSJaegeuk Kim raw_spin_unlock_irqrestore(&f2fs_stat_lock, flags); 659902829aaSGreg Kroah-Hartman return 0; 660902829aaSGreg Kroah-Hartman } 661902829aaSGreg Kroah-Hartman 662155c62feSYangtao Li DEFINE_SHOW_ATTRIBUTE(stat); 663fc7100eaSHridya Valsaraju #endif 664902829aaSGreg Kroah-Hartman 6654589d25dSNamjae Jeon int f2fs_build_stats(struct f2fs_sb_info *sbi) 666902829aaSGreg Kroah-Hartman { 667902829aaSGreg Kroah-Hartman struct f2fs_super_block *raw_super = F2FS_RAW_SUPER(sbi); 668902829aaSGreg Kroah-Hartman struct f2fs_stat_info *si; 66998237fcdSJaegeuk Kim unsigned long flags; 670b63e7be5SChao Yu int i; 671902829aaSGreg Kroah-Hartman 672acbf054dSChao Yu si = f2fs_kzalloc(sbi, sizeof(struct f2fs_stat_info), GFP_KERNEL); 673963d4f7dSGu Zheng if (!si) 674902829aaSGreg Kroah-Hartman return -ENOMEM; 675902829aaSGreg Kroah-Hartman 676902829aaSGreg Kroah-Hartman si->all_area_segs = le32_to_cpu(raw_super->segment_count); 677902829aaSGreg Kroah-Hartman si->sit_area_segs = le32_to_cpu(raw_super->segment_count_sit); 678902829aaSGreg Kroah-Hartman si->nat_area_segs = le32_to_cpu(raw_super->segment_count_nat); 679902829aaSGreg Kroah-Hartman si->ssa_area_segs = le32_to_cpu(raw_super->segment_count_ssa); 680902829aaSGreg Kroah-Hartman si->main_area_segs = le32_to_cpu(raw_super->segment_count_main); 681902829aaSGreg Kroah-Hartman si->main_area_sections = le32_to_cpu(raw_super->section_count); 682902829aaSGreg Kroah-Hartman si->main_area_zones = si->main_area_sections / 683902829aaSGreg Kroah-Hartman le32_to_cpu(raw_super->secs_per_zone); 684902829aaSGreg Kroah-Hartman si->sbi = sbi; 685963d4f7dSGu Zheng sbi->stat_info = si; 68666af62ceSmajianpeng 687e7547dacSJaegeuk Kim /* general extent cache stats */ 688e7547dacSJaegeuk Kim for (i = 0; i < NR_EXTENT_CACHES; i++) { 689e7547dacSJaegeuk Kim atomic64_set(&sbi->total_hit_ext[i], 0); 690e7547dacSJaegeuk Kim atomic64_set(&sbi->read_hit_rbtree[i], 0); 691e7547dacSJaegeuk Kim atomic64_set(&sbi->read_hit_cached[i], 0); 692e7547dacSJaegeuk Kim } 693e7547dacSJaegeuk Kim 694e7547dacSJaegeuk Kim /* read extent_cache only */ 6955b7ee374SChao Yu atomic64_set(&sbi->read_hit_largest, 0); 696727edac5SChao Yu 697d5e8f6c9SChao Yu atomic_set(&sbi->inline_xattr, 0); 69803e14d52SChao Yu atomic_set(&sbi->inline_inode, 0); 69903e14d52SChao Yu atomic_set(&sbi->inline_dir, 0); 7004c8ff709SChao Yu atomic_set(&sbi->compr_inode, 0); 701ae999bb9SDaeho Jeong atomic64_set(&sbi->compr_blocks, 0); 7028ec071c3SChao Yu atomic_set(&sbi->swapfile_inode, 0); 703b4dac120SChao Yu atomic_set(&sbi->atomic_files, 0); 704b9a2c252SChangman Lee atomic_set(&sbi->inplace_count, 0); 705b63e7be5SChao Yu for (i = META_CP; i < META_MAX; i++) 706b63e7be5SChao Yu atomic_set(&sbi->meta_count[i], 0); 707eb61c2ccSChao Yu for (i = 0; i < MAX_CALL_TYPE; i++) 708eb61c2ccSChao Yu atomic_set(&sbi->cp_call_count[i], 0); 70903e14d52SChao Yu 71026a28a0cSJaegeuk Kim atomic_set(&sbi->max_aw_cnt, 0); 71126a28a0cSJaegeuk Kim 71298237fcdSJaegeuk Kim raw_spin_lock_irqsave(&f2fs_stat_lock, flags); 71366af62ceSmajianpeng list_add_tail(&si->stat_list, &f2fs_stat_list); 71498237fcdSJaegeuk Kim raw_spin_unlock_irqrestore(&f2fs_stat_lock, flags); 71566af62ceSmajianpeng 716902829aaSGreg Kroah-Hartman return 0; 717902829aaSGreg Kroah-Hartman } 718902829aaSGreg Kroah-Hartman 719902829aaSGreg Kroah-Hartman void f2fs_destroy_stats(struct f2fs_sb_info *sbi) 720902829aaSGreg Kroah-Hartman { 721963d4f7dSGu Zheng struct f2fs_stat_info *si = F2FS_STAT(sbi); 72298237fcdSJaegeuk Kim unsigned long flags; 723902829aaSGreg Kroah-Hartman 72498237fcdSJaegeuk Kim raw_spin_lock_irqsave(&f2fs_stat_lock, flags); 725902829aaSGreg Kroah-Hartman list_del(&si->stat_list); 72698237fcdSJaegeuk Kim raw_spin_unlock_irqrestore(&f2fs_stat_lock, flags); 72766af62ceSmajianpeng 728c8eb7024SChao Yu kfree(si); 729902829aaSGreg Kroah-Hartman } 730902829aaSGreg Kroah-Hartman 731c20e57b3SGreg Kroah-Hartman void __init f2fs_create_root_stats(void) 7324589d25dSNamjae Jeon { 733fc7100eaSHridya Valsaraju #ifdef CONFIG_DEBUG_FS 73440e1ebe9SYounger Liu f2fs_debugfs_root = debugfs_create_dir("f2fs", NULL); 735c524723eSYounger Liu 736491f7f71SYangtao Li debugfs_create_file("status", 0444, f2fs_debugfs_root, NULL, 737c20e57b3SGreg Kroah-Hartman &stat_fops); 738fc7100eaSHridya Valsaraju #endif 7394589d25dSNamjae Jeon } 7404589d25dSNamjae Jeon 7414589d25dSNamjae Jeon void f2fs_destroy_root_stats(void) 742902829aaSGreg Kroah-Hartman { 743fc7100eaSHridya Valsaraju #ifdef CONFIG_DEBUG_FS 74440e1ebe9SYounger Liu debugfs_remove_recursive(f2fs_debugfs_root); 74540e1ebe9SYounger Liu f2fs_debugfs_root = NULL; 746fc7100eaSHridya Valsaraju #endif 747902829aaSGreg Kroah-Hartman } 748