blob: e671373cc8ab89610a9d000e5e689fb698b95f0e [file] [log] [blame]
Jaegeuk Kim0a8165d2012-11-29 13:28:09 +09001/*
Greg Kroah-Hartman902829a2012-11-03 06:50:41 +09002 * f2fs debugging statistics
3 *
4 * Copyright (c) 2012 Samsung Electronics Co., Ltd.
5 * http://www.samsung.com/
6 * Copyright (c) 2012 Linux Foundation
7 * Copyright (c) 2012 Greg Kroah-Hartman <gregkh@linuxfoundation.org>
8 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License version 2 as
11 * published by the Free Software Foundation.
12 */
13
14#include <linux/fs.h>
15#include <linux/backing-dev.h>
Greg Kroah-Hartman902829a2012-11-03 06:50:41 +090016#include <linux/f2fs_fs.h>
17#include <linux/blkdev.h>
18#include <linux/debugfs.h>
19#include <linux/seq_file.h>
20
21#include "f2fs.h"
22#include "node.h"
23#include "segment.h"
24#include "gc.h"
25
26static LIST_HEAD(f2fs_stat_list);
Younger Liu40e1ebe2013-12-03 21:09:29 +080027static struct dentry *f2fs_debugfs_root;
majianpeng66af62c2013-01-14 20:08:16 +080028static DEFINE_MUTEX(f2fs_stat_mutex);
Greg Kroah-Hartman902829a2012-11-03 06:50:41 +090029
Jaegeuk Kim25ca9232012-11-28 16:12:41 +090030static void update_general_status(struct f2fs_sb_info *sbi)
Greg Kroah-Hartman902829a2012-11-03 06:50:41 +090031{
Gu Zheng963d4f72013-07-12 14:47:11 +080032 struct f2fs_stat_info *si = F2FS_STAT(sbi);
Greg Kroah-Hartman902829a2012-11-03 06:50:41 +090033 int i;
34
arter97e1c42042014-08-06 23:22:50 +090035 /* validation check of the segment numbers */
Greg Kroah-Hartman902829a2012-11-03 06:50:41 +090036 si->hit_ext = sbi->read_hit_ext;
37 si->total_ext = sbi->total_hit_ext;
38 si->ndirty_node = get_pages(sbi, F2FS_DIRTY_NODES);
39 si->ndirty_dent = get_pages(sbi, F2FS_DIRTY_DENTS);
40 si->ndirty_dirs = sbi->n_dirty_dirs;
41 si->ndirty_meta = get_pages(sbi, F2FS_DIRTY_META);
Jaegeuk Kim8dcf2ff72014-12-05 17:18:15 -080042 si->inmem_pages = get_pages(sbi, F2FS_INMEM_PAGES);
Jaegeuk Kimd24bdcb2015-01-30 16:43:11 -080043 si->wb_pages = get_pages(sbi, F2FS_WRITEBACK);
Greg Kroah-Hartman902829a2012-11-03 06:50:41 +090044 si->total_count = (int)sbi->user_block_count / sbi->blocks_per_seg;
45 si->rsvd_segs = reserved_segments(sbi);
46 si->overp_segs = overprovision_segments(sbi);
47 si->valid_count = valid_user_blocks(sbi);
48 si->valid_node_count = valid_node_count(sbi);
49 si->valid_inode_count = valid_inode_count(sbi);
Chao Yu03e14d52014-12-08 19:08:20 +080050 si->inline_inode = atomic_read(&sbi->inline_inode);
51 si->inline_dir = atomic_read(&sbi->inline_dir);
Greg Kroah-Hartman902829a2012-11-03 06:50:41 +090052 si->utilization = utilization(sbi);
53
54 si->free_segs = free_segments(sbi);
55 si->free_secs = free_sections(sbi);
56 si->prefree_count = prefree_segments(sbi);
57 si->dirty_count = dirty_segments(sbi);
Jaegeuk Kim4ef51a82014-01-21 18:51:16 +090058 si->node_pages = NODE_MAPPING(sbi)->nrpages;
Gu Zheng9df27d92014-01-20 18:37:04 +080059 si->meta_pages = META_MAPPING(sbi)->nrpages;
Greg Kroah-Hartman902829a2012-11-03 06:50:41 +090060 si->nats = NM_I(sbi)->nat_cnt;
Jaegeuk Kimdd4e4b52015-01-07 11:09:37 -080061 si->dirty_nats = NM_I(sbi)->dirty_nat_cnt;
62 si->sits = MAIN_SEGS(sbi);
63 si->dirty_sits = SIT_I(sbi)->dirty_sentries;
Greg Kroah-Hartman902829a2012-11-03 06:50:41 +090064 si->fnids = NM_I(sbi)->fcnt;
65 si->bg_gc = sbi->bg_gc;
66 si->util_free = (int)(free_user_blocks(sbi) >> sbi->log_blocks_per_seg)
67 * 100 / (int)(sbi->user_block_count >> sbi->log_blocks_per_seg)
68 / 2;
69 si->util_valid = (int)(written_block_count(sbi) >>
70 sbi->log_blocks_per_seg)
71 * 100 / (int)(sbi->user_block_count >> sbi->log_blocks_per_seg)
72 / 2;
73 si->util_invalid = 50 - si->util_free - si->util_valid;
74 for (i = CURSEG_HOT_DATA; i <= CURSEG_COLD_NODE; i++) {
75 struct curseg_info *curseg = CURSEG_I(sbi, i);
76 si->curseg[i] = curseg->segno;
77 si->cursec[i] = curseg->segno / sbi->segs_per_sec;
78 si->curzone[i] = si->cursec[i] / sbi->secs_per_zone;
79 }
80
81 for (i = 0; i < 2; i++) {
82 si->segment_count[i] = sbi->segment_count[i];
83 si->block_count[i] = sbi->block_count[i];
84 }
Changman Leeb9a2c252014-12-24 02:16:54 +090085
86 si->inplace_count = atomic_read(&sbi->inplace_count);
Greg Kroah-Hartman902829a2012-11-03 06:50:41 +090087}
88
Jaegeuk Kim0a8165d2012-11-29 13:28:09 +090089/*
Greg Kroah-Hartman902829a2012-11-03 06:50:41 +090090 * This function calculates BDF of every segments
91 */
92static void update_sit_info(struct f2fs_sb_info *sbi)
93{
Gu Zheng963d4f72013-07-12 14:47:11 +080094 struct f2fs_stat_info *si = F2FS_STAT(sbi);
Greg Kroah-Hartman902829a2012-11-03 06:50:41 +090095 unsigned int blks_per_sec, hblks_per_sec, total_vblocks, bimodal, dist;
Greg Kroah-Hartman902829a2012-11-03 06:50:41 +090096 unsigned int segno, vblocks;
97 int ndirty = 0;
98
99 bimodal = 0;
100 total_vblocks = 0;
101 blks_per_sec = sbi->segs_per_sec * (1 << sbi->log_blocks_per_seg);
102 hblks_per_sec = blks_per_sec / 2;
Jaegeuk Kim7cd85582014-09-23 11:23:01 -0700103 for (segno = 0; segno < MAIN_SEGS(sbi); segno += sbi->segs_per_sec) {
Greg Kroah-Hartman902829a2012-11-03 06:50:41 +0900104 vblocks = get_valid_blocks(sbi, segno, sbi->segs_per_sec);
105 dist = abs(vblocks - hblks_per_sec);
106 bimodal += dist * dist;
107
108 if (vblocks > 0 && vblocks < blks_per_sec) {
109 total_vblocks += vblocks;
110 ndirty++;
111 }
112 }
Jaegeuk Kim7cd85582014-09-23 11:23:01 -0700113 dist = MAIN_SECS(sbi) * hblks_per_sec * hblks_per_sec / 100;
Greg Kroah-Hartman902829a2012-11-03 06:50:41 +0900114 si->bimodal = bimodal / dist;
115 if (si->dirty_count)
116 si->avg_vblocks = total_vblocks / ndirty;
117 else
118 si->avg_vblocks = 0;
119}
120
Jaegeuk Kim0a8165d2012-11-29 13:28:09 +0900121/*
Greg Kroah-Hartman902829a2012-11-03 06:50:41 +0900122 * This function calculates memory footprint.
123 */
124static void update_mem_info(struct f2fs_sb_info *sbi)
125{
Gu Zheng963d4f72013-07-12 14:47:11 +0800126 struct f2fs_stat_info *si = F2FS_STAT(sbi);
Greg Kroah-Hartman902829a2012-11-03 06:50:41 +0900127 unsigned npages;
Jaegeuk Kim8c402942014-11-06 15:16:04 -0800128 int i;
Greg Kroah-Hartman902829a2012-11-03 06:50:41 +0900129
130 if (si->base_mem)
131 goto get_cache;
132
133 si->base_mem = sizeof(struct f2fs_sb_info) + sbi->sb->s_blocksize;
134 si->base_mem += 2 * sizeof(struct f2fs_inode_info);
135 si->base_mem += sizeof(*sbi->ckpt);
136
137 /* build sm */
138 si->base_mem += sizeof(struct f2fs_sm_info);
139
140 /* build sit */
141 si->base_mem += sizeof(struct sit_info);
Jaegeuk Kim7cd85582014-09-23 11:23:01 -0700142 si->base_mem += MAIN_SEGS(sbi) * sizeof(struct seg_entry);
143 si->base_mem += f2fs_bitmap_size(MAIN_SEGS(sbi));
144 si->base_mem += 2 * SIT_VBLOCK_MAP_SIZE * MAIN_SEGS(sbi);
Jaegeuk Kim60a3b782015-02-10 16:44:29 -0800145 si->base_mem += SIT_VBLOCK_MAP_SIZE;
Greg Kroah-Hartman902829a2012-11-03 06:50:41 +0900146 if (sbi->segs_per_sec > 1)
Jaegeuk Kim7cd85582014-09-23 11:23:01 -0700147 si->base_mem += MAIN_SECS(sbi) * sizeof(struct sec_entry);
Greg Kroah-Hartman902829a2012-11-03 06:50:41 +0900148 si->base_mem += __bitmap_size(sbi, SIT_BITMAP);
149
150 /* build free segmap */
151 si->base_mem += sizeof(struct free_segmap_info);
Jaegeuk Kim7cd85582014-09-23 11:23:01 -0700152 si->base_mem += f2fs_bitmap_size(MAIN_SEGS(sbi));
153 si->base_mem += f2fs_bitmap_size(MAIN_SECS(sbi));
Greg Kroah-Hartman902829a2012-11-03 06:50:41 +0900154
155 /* build curseg */
156 si->base_mem += sizeof(struct curseg_info) * NR_CURSEG_TYPE;
157 si->base_mem += PAGE_CACHE_SIZE * NR_CURSEG_TYPE;
158
159 /* build dirty segmap */
160 si->base_mem += sizeof(struct dirty_seglist_info);
Jaegeuk Kim7cd85582014-09-23 11:23:01 -0700161 si->base_mem += NR_DIRTY_TYPE * f2fs_bitmap_size(MAIN_SEGS(sbi));
162 si->base_mem += f2fs_bitmap_size(MAIN_SECS(sbi));
Greg Kroah-Hartman902829a2012-11-03 06:50:41 +0900163
arter97e1c42042014-08-06 23:22:50 +0900164 /* build nm */
Greg Kroah-Hartman902829a2012-11-03 06:50:41 +0900165 si->base_mem += sizeof(struct f2fs_nm_info);
166 si->base_mem += __bitmap_size(sbi, NAT_BITMAP);
167
Greg Kroah-Hartman902829a2012-11-03 06:50:41 +0900168get_cache:
Chao Yu9066c6a2015-01-10 20:09:52 +0800169 si->cache_mem = 0;
170
171 /* build gc */
172 if (sbi->gc_thread)
173 si->cache_mem += sizeof(struct f2fs_gc_kthread);
174
175 /* build merge flush thread */
176 if (SM_I(sbi)->cmd_control_info)
177 si->cache_mem += sizeof(struct flush_cmd_control);
178
Greg Kroah-Hartman902829a2012-11-03 06:50:41 +0900179 /* free nids */
Chao Yu9066c6a2015-01-10 20:09:52 +0800180 si->cache_mem += NM_I(sbi)->fcnt * sizeof(struct free_nid);
181 si->cache_mem += NM_I(sbi)->nat_cnt * sizeof(struct nat_entry);
Jaegeuk Kim6f0aacb2015-01-10 21:37:36 -0800182 si->cache_mem += NM_I(sbi)->dirty_nat_cnt *
183 sizeof(struct nat_entry_set);
184 si->cache_mem += si->inmem_pages * sizeof(struct inmem_pages);
Chao Yu06292072014-12-29 15:56:18 +0800185 si->cache_mem += sbi->n_dirty_dirs * sizeof(struct inode_entry);
Jaegeuk Kim8c402942014-11-06 15:16:04 -0800186 for (i = 0; i <= UPDATE_INO; i++)
Chao Yu67298802014-11-18 11:18:36 +0800187 si->cache_mem += sbi->im[i].ino_num * sizeof(struct ino_entry);
Jaegeuk Kim6f0aacb2015-01-10 21:37:36 -0800188
189 si->page_mem = 0;
190 npages = NODE_MAPPING(sbi)->nrpages;
191 si->page_mem += npages << PAGE_CACHE_SHIFT;
192 npages = META_MAPPING(sbi)->nrpages;
193 si->page_mem += npages << PAGE_CACHE_SHIFT;
Greg Kroah-Hartman902829a2012-11-03 06:50:41 +0900194}
195
196static int stat_show(struct seq_file *s, void *v)
197{
majianpeng145b04e2013-05-14 20:06:46 +0800198 struct f2fs_stat_info *si;
Greg Kroah-Hartman902829a2012-11-03 06:50:41 +0900199 int i = 0;
200 int j;
201
majianpeng66af62c2013-01-14 20:08:16 +0800202 mutex_lock(&f2fs_stat_mutex);
majianpeng145b04e2013-05-14 20:06:46 +0800203 list_for_each_entry(si, &f2fs_stat_list, stat_list) {
majianpengf83759e2013-02-01 15:00:30 +0800204 char devname[BDEVNAME_SIZE];
Greg Kroah-Hartman902829a2012-11-03 06:50:41 +0900205
Greg Kroah-Hartman902829a2012-11-03 06:50:41 +0900206 update_general_status(si->sbi);
207
majianpengf83759e2013-02-01 15:00:30 +0800208 seq_printf(s, "\n=====[ partition info(%s). #%d ]=====\n",
209 bdevname(si->sbi->sb->s_bdev, devname), i++);
Huajun Li7880cee2012-12-31 13:59:09 +0800210 seq_printf(s, "[SB: 1] [CP: 2] [SIT: %d] [NAT: %d] ",
211 si->sit_area_segs, si->nat_area_segs);
Greg Kroah-Hartman902829a2012-11-03 06:50:41 +0900212 seq_printf(s, "[SSA: %d] [MAIN: %d",
213 si->ssa_area_segs, si->main_area_segs);
214 seq_printf(s, "(OverProv:%d Resv:%d)]\n\n",
215 si->overp_segs, si->rsvd_segs);
216 seq_printf(s, "Utilization: %d%% (%d valid blocks)\n",
217 si->utilization, si->valid_count);
218 seq_printf(s, " - Node: %u (Inode: %u, ",
219 si->valid_node_count, si->valid_inode_count);
220 seq_printf(s, "Other: %u)\n - Data: %u\n",
221 si->valid_node_count - si->valid_inode_count,
222 si->valid_count - si->valid_node_count);
Jaegeuk Kim0dbdc2a2013-11-26 11:08:57 +0900223 seq_printf(s, " - Inline_data Inode: %u\n",
224 si->inline_inode);
Jaegeuk Kim3289c062014-10-13 20:00:16 -0700225 seq_printf(s, " - Inline_dentry Inode: %u\n",
226 si->inline_dir);
Greg Kroah-Hartman902829a2012-11-03 06:50:41 +0900227 seq_printf(s, "\nMain area: %d segs, %d secs %d zones\n",
228 si->main_area_segs, si->main_area_sections,
229 si->main_area_zones);
230 seq_printf(s, " - COLD data: %d, %d, %d\n",
231 si->curseg[CURSEG_COLD_DATA],
232 si->cursec[CURSEG_COLD_DATA],
233 si->curzone[CURSEG_COLD_DATA]);
234 seq_printf(s, " - WARM data: %d, %d, %d\n",
235 si->curseg[CURSEG_WARM_DATA],
236 si->cursec[CURSEG_WARM_DATA],
237 si->curzone[CURSEG_WARM_DATA]);
238 seq_printf(s, " - HOT data: %d, %d, %d\n",
239 si->curseg[CURSEG_HOT_DATA],
240 si->cursec[CURSEG_HOT_DATA],
241 si->curzone[CURSEG_HOT_DATA]);
242 seq_printf(s, " - Dir dnode: %d, %d, %d\n",
243 si->curseg[CURSEG_HOT_NODE],
244 si->cursec[CURSEG_HOT_NODE],
245 si->curzone[CURSEG_HOT_NODE]);
246 seq_printf(s, " - File dnode: %d, %d, %d\n",
247 si->curseg[CURSEG_WARM_NODE],
248 si->cursec[CURSEG_WARM_NODE],
249 si->curzone[CURSEG_WARM_NODE]);
250 seq_printf(s, " - Indir nodes: %d, %d, %d\n",
251 si->curseg[CURSEG_COLD_NODE],
252 si->cursec[CURSEG_COLD_NODE],
253 si->curzone[CURSEG_COLD_NODE]);
254 seq_printf(s, "\n - Valid: %d\n - Dirty: %d\n",
255 si->main_area_segs - si->dirty_count -
256 si->prefree_count - si->free_segs,
257 si->dirty_count);
258 seq_printf(s, " - Prefree: %d\n - Free: %d (%d)\n\n",
259 si->prefree_count, si->free_segs, si->free_secs);
Changman Lee942e0be2014-02-13 15:12:29 +0900260 seq_printf(s, "CP calls: %d\n", si->cp_count);
Greg Kroah-Hartman902829a2012-11-03 06:50:41 +0900261 seq_printf(s, "GC calls: %d (BG: %d)\n",
262 si->call_count, si->bg_gc);
263 seq_printf(s, " - data segments : %d\n", si->data_segs);
264 seq_printf(s, " - node segments : %d\n", si->node_segs);
265 seq_printf(s, "Try to move %d blocks\n", si->tot_blks);
266 seq_printf(s, " - data blocks : %d\n", si->data_blks);
267 seq_printf(s, " - node blocks : %d\n", si->node_blks);
268 seq_printf(s, "\nExtent Hit Ratio: %d / %d\n",
269 si->hit_ext, si->total_ext);
Chris Fries6c311ec2014-01-17 14:44:39 -0600270 seq_puts(s, "\nBalancing F2FS Async:\n");
Jaegeuk Kimd24bdcb2015-01-30 16:43:11 -0800271 seq_printf(s, " - inmem: %4d, wb: %4d\n",
272 si->inmem_pages, si->wb_pages);
Changman Lee499046a2014-01-13 10:34:18 +0900273 seq_printf(s, " - nodes: %4d in %4d\n",
Greg Kroah-Hartman902829a2012-11-03 06:50:41 +0900274 si->ndirty_node, si->node_pages);
Changman Lee499046a2014-01-13 10:34:18 +0900275 seq_printf(s, " - dents: %4d in dirs:%4d\n",
Greg Kroah-Hartman902829a2012-11-03 06:50:41 +0900276 si->ndirty_dent, si->ndirty_dirs);
Changman Lee499046a2014-01-13 10:34:18 +0900277 seq_printf(s, " - meta: %4d in %4d\n",
Greg Kroah-Hartman902829a2012-11-03 06:50:41 +0900278 si->ndirty_meta, si->meta_pages);
Jaegeuk Kimdd4e4b52015-01-07 11:09:37 -0800279 seq_printf(s, " - NATs: %9d/%9d\n - SITs: %9d/%9d\n",
280 si->dirty_nats, si->nats, si->dirty_sits, si->sits);
Jaegeuk Kima5f420102014-03-19 13:45:52 +0900281 seq_printf(s, " - free_nids: %9d\n",
282 si->fnids);
Gu Zheng2d219c52013-07-22 16:33:32 +0800283 seq_puts(s, "\nDistribution of User Blocks:");
284 seq_puts(s, " [ valid | invalid | free ]\n");
285 seq_puts(s, " [");
Greg Kroah-Hartman902829a2012-11-03 06:50:41 +0900286
287 for (j = 0; j < si->util_valid; j++)
Gu Zheng2d219c52013-07-22 16:33:32 +0800288 seq_putc(s, '-');
289 seq_putc(s, '|');
Greg Kroah-Hartman902829a2012-11-03 06:50:41 +0900290
291 for (j = 0; j < si->util_invalid; j++)
Gu Zheng2d219c52013-07-22 16:33:32 +0800292 seq_putc(s, '-');
293 seq_putc(s, '|');
Greg Kroah-Hartman902829a2012-11-03 06:50:41 +0900294
295 for (j = 0; j < si->util_free; j++)
Gu Zheng2d219c52013-07-22 16:33:32 +0800296 seq_putc(s, '-');
297 seq_puts(s, "]\n\n");
Changman Leeb9a2c252014-12-24 02:16:54 +0900298 seq_printf(s, "IPU: %u blocks\n", si->inplace_count);
Greg Kroah-Hartman902829a2012-11-03 06:50:41 +0900299 seq_printf(s, "SSR: %u blocks in %u segments\n",
300 si->block_count[SSR], si->segment_count[SSR]);
301 seq_printf(s, "LFS: %u blocks in %u segments\n",
302 si->block_count[LFS], si->segment_count[LFS]);
303
304 /* segment usage info */
305 update_sit_info(si->sbi);
306 seq_printf(s, "\nBDF: %u, avg. vblocks: %u\n",
307 si->bimodal, si->avg_vblocks);
308
309 /* memory footprint */
310 update_mem_info(si->sbi);
Jaegeuk Kim6f0aacb2015-01-10 21:37:36 -0800311 seq_printf(s, "\nMemory: %u KB\n",
312 (si->base_mem + si->cache_mem + si->page_mem) >> 10);
313 seq_printf(s, " - static: %u KB\n",
314 si->base_mem >> 10);
315 seq_printf(s, " - cached: %u KB\n",
316 si->cache_mem >> 10);
317 seq_printf(s, " - paged : %u KB\n",
318 si->page_mem >> 10);
Greg Kroah-Hartman902829a2012-11-03 06:50:41 +0900319 }
majianpeng66af62c2013-01-14 20:08:16 +0800320 mutex_unlock(&f2fs_stat_mutex);
Greg Kroah-Hartman902829a2012-11-03 06:50:41 +0900321 return 0;
322}
323
324static int stat_open(struct inode *inode, struct file *file)
325{
326 return single_open(file, stat_show, inode->i_private);
327}
328
329static const struct file_operations stat_fops = {
330 .open = stat_open,
331 .read = seq_read,
332 .llseek = seq_lseek,
333 .release = single_release,
334};
335
Namjae Jeon4589d252013-01-15 19:58:47 +0900336int f2fs_build_stats(struct f2fs_sb_info *sbi)
Greg Kroah-Hartman902829a2012-11-03 06:50:41 +0900337{
338 struct f2fs_super_block *raw_super = F2FS_RAW_SUPER(sbi);
339 struct f2fs_stat_info *si;
340
Gu Zheng963d4f72013-07-12 14:47:11 +0800341 si = kzalloc(sizeof(struct f2fs_stat_info), GFP_KERNEL);
342 if (!si)
Greg Kroah-Hartman902829a2012-11-03 06:50:41 +0900343 return -ENOMEM;
344
Greg Kroah-Hartman902829a2012-11-03 06:50:41 +0900345 si->all_area_segs = le32_to_cpu(raw_super->segment_count);
346 si->sit_area_segs = le32_to_cpu(raw_super->segment_count_sit);
347 si->nat_area_segs = le32_to_cpu(raw_super->segment_count_nat);
348 si->ssa_area_segs = le32_to_cpu(raw_super->segment_count_ssa);
349 si->main_area_segs = le32_to_cpu(raw_super->segment_count_main);
350 si->main_area_sections = le32_to_cpu(raw_super->section_count);
351 si->main_area_zones = si->main_area_sections /
352 le32_to_cpu(raw_super->secs_per_zone);
353 si->sbi = sbi;
Gu Zheng963d4f72013-07-12 14:47:11 +0800354 sbi->stat_info = si;
majianpeng66af62c2013-01-14 20:08:16 +0800355
Chao Yu03e14d52014-12-08 19:08:20 +0800356 atomic_set(&sbi->inline_inode, 0);
357 atomic_set(&sbi->inline_dir, 0);
Changman Leeb9a2c252014-12-24 02:16:54 +0900358 atomic_set(&sbi->inplace_count, 0);
Chao Yu03e14d52014-12-08 19:08:20 +0800359
majianpeng66af62c2013-01-14 20:08:16 +0800360 mutex_lock(&f2fs_stat_mutex);
361 list_add_tail(&si->stat_list, &f2fs_stat_list);
362 mutex_unlock(&f2fs_stat_mutex);
363
Greg Kroah-Hartman902829a2012-11-03 06:50:41 +0900364 return 0;
365}
366
Greg Kroah-Hartman902829a2012-11-03 06:50:41 +0900367void f2fs_destroy_stats(struct f2fs_sb_info *sbi)
368{
Gu Zheng963d4f72013-07-12 14:47:11 +0800369 struct f2fs_stat_info *si = F2FS_STAT(sbi);
Greg Kroah-Hartman902829a2012-11-03 06:50:41 +0900370
majianpeng66af62c2013-01-14 20:08:16 +0800371 mutex_lock(&f2fs_stat_mutex);
Greg Kroah-Hartman902829a2012-11-03 06:50:41 +0900372 list_del(&si->stat_list);
majianpeng66af62c2013-01-14 20:08:16 +0800373 mutex_unlock(&f2fs_stat_mutex);
374
Gu Zheng963d4f72013-07-12 14:47:11 +0800375 kfree(si);
Greg Kroah-Hartman902829a2012-11-03 06:50:41 +0900376}
377
Namjae Jeon4589d252013-01-15 19:58:47 +0900378void __init f2fs_create_root_stats(void)
379{
Younger Liuc5247232013-12-03 20:11:46 +0800380 struct dentry *file;
381
Younger Liu40e1ebe2013-12-03 21:09:29 +0800382 f2fs_debugfs_root = debugfs_create_dir("f2fs", NULL);
383 if (!f2fs_debugfs_root)
Gu Zheng7a6c76b2014-07-11 18:35:43 +0800384 return;
Younger Liuc5247232013-12-03 20:11:46 +0800385
Younger Liu40e1ebe2013-12-03 21:09:29 +0800386 file = debugfs_create_file("status", S_IRUGO, f2fs_debugfs_root,
Younger Liuc5247232013-12-03 20:11:46 +0800387 NULL, &stat_fops);
Gu Zheng7a6c76b2014-07-11 18:35:43 +0800388 if (!file) {
389 debugfs_remove(f2fs_debugfs_root);
390 f2fs_debugfs_root = NULL;
391 }
Namjae Jeon4589d252013-01-15 19:58:47 +0900392}
393
394void f2fs_destroy_root_stats(void)
Greg Kroah-Hartman902829a2012-11-03 06:50:41 +0900395{
Younger Liu40e1ebe2013-12-03 21:09:29 +0800396 if (!f2fs_debugfs_root)
Younger Liuc5247232013-12-03 20:11:46 +0800397 return;
398
Younger Liu40e1ebe2013-12-03 21:09:29 +0800399 debugfs_remove_recursive(f2fs_debugfs_root);
400 f2fs_debugfs_root = NULL;
Greg Kroah-Hartman902829a2012-11-03 06:50:41 +0900401}