aboutsummaryrefslogtreecommitdiffstats
path: root/f2fs-move-statistics-code-into-one-file.patch
blob: 397e12456df31de470f4dddcb5641cef442c35ab (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
From foo@baz Tue Oct 23 10:11:17 PDT 2012
Date: Tue, 23 Oct 2012 10:11:17 -0700
To: Greg KH <gregkh@linuxfoundation.org>
From: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Subject: f2fs: move statistics code into one file

From: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

This moves all of the procfs statistics code into one file, debug.c and
removes the #ifdefs from the core f2fs code when calling statistic
functions.

This will make it more obvious how to move from procfs to debugfs, no
functionality was changed here at all.

Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

---
 fs/f2fs/Makefile |    1 
 fs/f2fs/debug.c  |  414 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
 fs/f2fs/f2fs.h   |   25 ++-
 fs/f2fs/gc.c     |  373 -------------------------------------------------
 fs/f2fs/super.c  |   21 --
 5 files changed, 442 insertions(+), 392 deletions(-)

--- a/fs/f2fs/Makefile
+++ b/fs/f2fs/Makefile
@@ -2,5 +2,6 @@ obj-$(CONFIG_F2FS_FS) += f2fs.o
 
 f2fs-y		:= dir.o file.o inode.o namei.o hash.o super.o
 f2fs-y		+= checkpoint.o gc.o data.o node.o segment.o recovery.o
+f2fs-$(CONFIG_F2FS_STAT_FS) += debug.o
 f2fs-$(CONFIG_F2FS_FS_XATTR) += xattr.o
 f2fs-$(CONFIG_F2FS_FS_POSIX_ACL) += acl.o
--- /dev/null
+++ b/fs/f2fs/debug.c
@@ -0,0 +1,414 @@
+/**
+ * f2fs debugging statistics
+ *
+ * Copyright (c) 2012 Samsung Electronics Co., Ltd.
+ *             http://www.samsung.com/
+ * Copyright (c) 2012 Linux Foundation
+ * Copyright (c) 2012 Greg Kroah-Hartman <gregkh@linuxfoundation.org>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ */
+
+#include <linux/fs.h>
+#include <linux/backing-dev.h>
+#include <linux/proc_fs.h>
+#include <linux/f2fs_fs.h>
+#include <linux/blkdev.h>
+
+#include "f2fs.h"
+#include "node.h"
+#include "segment.h"
+#include "gc.h"
+
+static LIST_HEAD(f2fs_stat_list);
+static struct proc_dir_entry *f2fs_proc_root;
+
+
+void f2fs_update_stat(struct f2fs_sb_info *sbi)
+{
+	struct f2fs_gc_info *gc_i = sbi->gc_info;
+	struct f2fs_stat_info *si = gc_i->stat_info;
+	int i;
+
+	/* valid check of the segment numbers */
+	si->hit_ext = sbi->read_hit_ext;
+	si->total_ext = sbi->total_hit_ext;
+	si->ndirty_node = get_pages(sbi, F2FS_DIRTY_NODES);
+	si->ndirty_dent = get_pages(sbi, F2FS_DIRTY_DENTS);
+	si->ndirty_dirs = sbi->n_dirty_dirs;
+	si->ndirty_meta = get_pages(sbi, F2FS_DIRTY_META);
+	si->total_count = (int)sbi->user_block_count / sbi->blocks_per_seg;
+	si->rsvd_segs = reserved_segments(sbi);
+	si->overp_segs = overprovision_segments(sbi);
+	si->valid_count = valid_user_blocks(sbi);
+	si->valid_node_count = valid_node_count(sbi);
+	si->valid_inode_count = valid_inode_count(sbi);
+	si->utilization = utilization(sbi);
+
+	si->free_segs = free_segments(sbi);
+	si->free_secs = free_sections(sbi);
+	si->prefree_count = prefree_segments(sbi);
+	si->dirty_count = dirty_segments(sbi);
+	si->node_pages = sbi->node_inode->i_mapping->nrpages;
+	si->meta_pages = sbi->meta_inode->i_mapping->nrpages;
+	si->nats = NM_I(sbi)->nat_cnt;
+	si->sits = SIT_I(sbi)->dirty_sentries;
+	si->fnids = NM_I(sbi)->fcnt;
+	si->bg_gc = sbi->bg_gc;
+	si->util_free = (int)(free_user_blocks(sbi) >> sbi->log_blocks_per_seg)
+		* 100 / (int)(sbi->user_block_count >> sbi->log_blocks_per_seg)
+		/ 2;
+	si->util_valid = (int)(written_block_count(sbi) >>
+						sbi->log_blocks_per_seg)
+		* 100 / (int)(sbi->user_block_count >> sbi->log_blocks_per_seg)
+		/ 2;
+	si->util_invalid = 50 - si->util_free - si->util_valid;
+	for (i = CURSEG_HOT_DATA; i <= CURSEG_COLD_NODE; i++) {
+		struct curseg_info *curseg = CURSEG_I(sbi, i);
+		si->curseg[i] = curseg->segno;
+		si->cursec[i] = curseg->segno / sbi->segs_per_sec;
+		si->curzone[i] = si->cursec[i] / sbi->secs_per_zone;
+	}
+
+	for (i = 0; i < 2; i++) {
+		si->segment_count[i] = sbi->segment_count[i];
+		si->block_count[i] = sbi->block_count[i];
+	}
+}
+
+/**
+ * This function calculates BDF of every segments
+ */
+static void f2fs_update_gc_metric(struct f2fs_sb_info *sbi)
+{
+	struct f2fs_gc_info *gc_i = sbi->gc_info;
+	struct f2fs_stat_info *si = gc_i->stat_info;
+	unsigned int blks_per_sec, hblks_per_sec, total_vblocks, bimodal, dist;
+	struct sit_info *sit_i = SIT_I(sbi);
+	unsigned int segno, vblocks;
+	int ndirty = 0;
+
+	bimodal = 0;
+	total_vblocks = 0;
+	blks_per_sec = sbi->segs_per_sec * (1 << sbi->log_blocks_per_seg);
+	hblks_per_sec = blks_per_sec / 2;
+	mutex_lock(&sit_i->sentry_lock);
+	for (segno = 0; segno < TOTAL_SEGS(sbi); segno += sbi->segs_per_sec) {
+		vblocks = get_valid_blocks(sbi, segno, sbi->segs_per_sec);
+		dist = abs(vblocks - hblks_per_sec);
+		bimodal += dist * dist;
+
+		if (vblocks > 0 && vblocks < blks_per_sec) {
+			total_vblocks += vblocks;
+			ndirty++;
+		}
+	}
+	mutex_unlock(&sit_i->sentry_lock);
+	dist = sbi->total_sections * hblks_per_sec * hblks_per_sec / 100;
+	si->bimodal = bimodal / dist;
+	if (si->dirty_count)
+		si->avg_vblocks = total_vblocks / ndirty;
+	else
+		si->avg_vblocks = 0;
+}
+
+static int f2fs_read_gc(char *page, char **start, off_t off,
+		int count, int *eof, void *data)
+{
+	struct f2fs_gc_info *gc_i, *next;
+	struct f2fs_stat_info *si;
+	char *buf = page;
+	int i = 0;
+
+	list_for_each_entry_safe(gc_i, next, &f2fs_stat_list, stat_list) {
+		int j;
+		si = gc_i->stat_info;
+
+		mutex_lock(&si->stat_list);
+		if (!si->sbi) {
+			mutex_unlock(&si->stat_list);
+			continue;
+		}
+		f2fs_update_stat(si->sbi);
+
+		buf += sprintf(buf, "=====[ partition info. #%d ]=====\n", i++);
+		buf += sprintf(buf, "[SB: 1] [CP: 2] [NAT: %d] [SIT: %d] ",
+				si->nat_area_segs, si->sit_area_segs);
+		buf += sprintf(buf, "[SSA: %d] [MAIN: %d",
+				si->ssa_area_segs, si->main_area_segs);
+		buf += sprintf(buf, "(OverProv:%d Resv:%d)]\n\n",
+				si->overp_segs, si->rsvd_segs);
+		buf += sprintf(buf, "Utilization: %d%% (%d valid blocks)\n",
+				si->utilization, si->valid_count);
+		buf += sprintf(buf, "  - Node: %u (Inode: %u, ",
+				si->valid_node_count, si->valid_inode_count);
+		buf += sprintf(buf, "Other: %u)\n  - Data: %u\n",
+				si->valid_node_count - si->valid_inode_count,
+				si->valid_count - si->valid_node_count);
+		buf += sprintf(buf, "\nMain area: %d segs, %d secs %d zones\n",
+				si->main_area_segs, si->main_area_sections,
+				si->main_area_zones);
+		buf += sprintf(buf, "  - COLD  data: %d, %d, %d\n",
+				si->curseg[CURSEG_COLD_DATA],
+				si->cursec[CURSEG_COLD_DATA],
+				si->curzone[CURSEG_COLD_DATA]);
+		buf += sprintf(buf, "  - WARM  data: %d, %d, %d\n",
+				si->curseg[CURSEG_WARM_DATA],
+				si->cursec[CURSEG_WARM_DATA],
+				si->curzone[CURSEG_WARM_DATA]);
+		buf += sprintf(buf, "  - HOT   data: %d, %d, %d\n",
+				si->curseg[CURSEG_HOT_DATA],
+				si->cursec[CURSEG_HOT_DATA],
+				si->curzone[CURSEG_HOT_DATA]);
+		buf += sprintf(buf, "  - Dir   dnode: %d, %d, %d\n",
+				si->curseg[CURSEG_HOT_NODE],
+				si->cursec[CURSEG_HOT_NODE],
+				si->curzone[CURSEG_HOT_NODE]);
+		buf += sprintf(buf, "  - File   dnode: %d, %d, %d\n",
+				si->curseg[CURSEG_WARM_NODE],
+				si->cursec[CURSEG_WARM_NODE],
+				si->curzone[CURSEG_WARM_NODE]);
+		buf += sprintf(buf, "  - Indir nodes: %d, %d, %d\n",
+				si->curseg[CURSEG_COLD_NODE],
+				si->cursec[CURSEG_COLD_NODE],
+				si->curzone[CURSEG_COLD_NODE]);
+		buf += sprintf(buf, "\n  - Valid: %d\n  - Dirty: %d\n",
+				si->main_area_segs - si->dirty_count -
+				si->prefree_count - si->free_segs,
+				si->dirty_count);
+		buf += sprintf(buf, "  - Prefree: %d\n  - Free: %d (%d)\n\n",
+				si->prefree_count,
+				si->free_segs,
+				si->free_secs);
+		buf += sprintf(buf, "GC calls: %d (BG: %d)\n",
+				si->call_count, si->bg_gc);
+		buf += sprintf(buf, "  - data segments : %d\n", si->data_segs);
+		buf += sprintf(buf, "  - node segments : %d\n", si->node_segs);
+		buf += sprintf(buf, "Try to move %d blocks\n", si->tot_blks);
+		buf += sprintf(buf, "  - data blocks : %d\n", si->data_blks);
+		buf += sprintf(buf, "  - node blocks : %d\n", si->node_blks);
+		buf += sprintf(buf, "\nExtent Hit Ratio: %d / %d\n",
+						si->hit_ext, si->total_ext);
+		buf += sprintf(buf, "\nBalancing F2FS Async:\n");
+		buf += sprintf(buf, "  - nodes %4d in %4d\n",
+					si->ndirty_node, si->node_pages);
+		buf += sprintf(buf, "  - dents %4d in dirs:%4d\n",
+					si->ndirty_dent, si->ndirty_dirs);
+		buf += sprintf(buf, "  - meta %4d in %4d\n",
+					si->ndirty_meta, si->meta_pages);
+		buf += sprintf(buf, "  - NATs %5d > %lu\n",
+						si->nats, NM_WOUT_THRESHOLD);
+		buf += sprintf(buf, "  - SITs: %5d\n  - free_nids: %5d\n",
+					si->sits, si->fnids);
+		buf += sprintf(buf, "\nDistribution of User Blocks:");
+		buf += sprintf(buf, " [ valid | invalid | free ]\n");
+		buf += sprintf(buf, "  [");
+		for (j = 0; j < si->util_valid; j++)
+			buf += sprintf(buf, "-");
+		buf += sprintf(buf, "|");
+		for (j = 0; j < si->util_invalid; j++)
+			buf += sprintf(buf, "-");
+		buf += sprintf(buf, "|");
+		for (j = 0; j < si->util_free; j++)
+			buf += sprintf(buf, "-");
+		buf += sprintf(buf, "]\n\n");
+		buf += sprintf(buf, "SSR: %u blocks in %u segments\n",
+				si->block_count[SSR], si->segment_count[SSR]);
+		buf += sprintf(buf, "LFS: %u blocks in %u segments\n",
+				si->block_count[LFS], si->segment_count[LFS]);
+		mutex_unlock(&si->stat_list);
+	}
+	return buf - page;
+}
+
+static int f2fs_read_sit(char *page, char **start, off_t off,
+		int count, int *eof, void *data)
+{
+	struct f2fs_gc_info *gc_i, *next;
+	struct f2fs_stat_info *si;
+	char *buf = page;
+
+	list_for_each_entry_safe(gc_i, next, &f2fs_stat_list, stat_list) {
+		si = gc_i->stat_info;
+
+		mutex_lock(&si->stat_list);
+		if (!si->sbi) {
+			mutex_unlock(&si->stat_list);
+			continue;
+		}
+		f2fs_update_gc_metric(si->sbi);
+
+		buf += sprintf(buf, "BDF: %u, avg. vblocks: %u\n",
+				si->bimodal, si->avg_vblocks);
+		mutex_unlock(&si->stat_list);
+	}
+	return buf - page;
+}
+
+static int f2fs_read_mem(char *page, char **start, off_t off,
+		int count, int *eof, void *data)
+{
+	struct f2fs_gc_info *gc_i, *next;
+	struct f2fs_stat_info *si;
+	char *buf = page;
+
+	list_for_each_entry_safe(gc_i, next, &f2fs_stat_list, stat_list) {
+		struct f2fs_sb_info *sbi = gc_i->stat_info->sbi;
+		unsigned npages;
+		unsigned base_mem = 0, cache_mem = 0;
+
+		si = gc_i->stat_info;
+		mutex_lock(&si->stat_list);
+		if (!si->sbi) {
+			mutex_unlock(&si->stat_list);
+			continue;
+		}
+		base_mem += sizeof(struct f2fs_sb_info) + sbi->sb->s_blocksize;
+		base_mem += 2 * sizeof(struct f2fs_inode_info);
+		base_mem += sizeof(*sbi->ckpt);
+
+		/* build sm */
+		base_mem += sizeof(struct f2fs_sm_info);
+
+		/* build sit */
+		base_mem += sizeof(struct sit_info);
+		base_mem += TOTAL_SEGS(sbi) * sizeof(struct seg_entry);
+		base_mem += f2fs_bitmap_size(TOTAL_SEGS(sbi));
+		base_mem += 2 * SIT_VBLOCK_MAP_SIZE * TOTAL_SEGS(sbi);
+		if (sbi->segs_per_sec > 1)
+			base_mem += sbi->total_sections *
+					sizeof(struct sec_entry);
+		base_mem += __bitmap_size(sbi, SIT_BITMAP);
+
+		/* build free segmap */
+		base_mem += sizeof(struct free_segmap_info);
+		base_mem += f2fs_bitmap_size(TOTAL_SEGS(sbi));
+		base_mem += f2fs_bitmap_size(sbi->total_sections);
+
+		/* build curseg */
+		base_mem += sizeof(struct curseg_info) * NR_CURSEG_TYPE;
+		base_mem += PAGE_CACHE_SIZE * NR_CURSEG_TYPE;
+
+		/* build dirty segmap */
+		base_mem += sizeof(struct dirty_seglist_info);
+		base_mem += NR_DIRTY_TYPE * f2fs_bitmap_size(TOTAL_SEGS(sbi));
+		base_mem += 2 * f2fs_bitmap_size(TOTAL_SEGS(sbi));
+
+		/* buld nm */
+		base_mem += sizeof(struct f2fs_nm_info);
+		base_mem += __bitmap_size(sbi, NAT_BITMAP);
+
+		/* build gc */
+		base_mem += sizeof(struct f2fs_gc_info);
+		base_mem += sizeof(struct f2fs_gc_kthread);
+
+		/* free nids */
+		cache_mem += NM_I(sbi)->fcnt;
+		cache_mem += NM_I(sbi)->nat_cnt;
+		npages = sbi->node_inode->i_mapping->nrpages;
+		cache_mem += npages << PAGE_CACHE_SHIFT;
+		npages = sbi->meta_inode->i_mapping->nrpages;
+		cache_mem += npages << PAGE_CACHE_SHIFT;
+		cache_mem += sbi->n_orphans * sizeof(struct orphan_inode_entry);
+		cache_mem += sbi->n_dirty_dirs * sizeof(struct dir_inode_entry);
+
+		buf += sprintf(buf, "%u KB = static: %u + cached: %u\n",
+				(base_mem + cache_mem) >> 10,
+				base_mem >> 10,
+				cache_mem >> 10);
+		mutex_unlock(&si->stat_list);
+	}
+	return buf - page;
+}
+
+static int init_stats(struct f2fs_sb_info *sbi)
+{
+	struct f2fs_stat_info *si;
+	struct f2fs_super_block *raw_super = F2FS_RAW_SUPER(sbi);
+	struct f2fs_gc_info *gc_i = sbi->gc_info;
+
+	gc_i->stat_info = kzalloc(sizeof(struct f2fs_stat_info),
+			GFP_KERNEL);
+	if (!gc_i->stat_info)
+		return -ENOMEM;
+	si = gc_i->stat_info;
+	mutex_init(&si->stat_list);
+	list_add_tail(&gc_i->stat_list, &f2fs_stat_list);
+
+	si->all_area_segs = le32_to_cpu(raw_super->segment_count);
+	si->sit_area_segs = le32_to_cpu(raw_super->segment_count_sit);
+	si->nat_area_segs = le32_to_cpu(raw_super->segment_count_nat);
+	si->ssa_area_segs = le32_to_cpu(raw_super->segment_count_ssa);
+	si->main_area_segs = le32_to_cpu(raw_super->segment_count_main);
+	si->main_area_sections = le32_to_cpu(raw_super->section_count);
+	si->main_area_zones = si->main_area_sections /
+				le32_to_cpu(raw_super->secs_per_zone);
+	si->sbi = sbi;
+	return 0;
+}
+
+void f2fs_destroy_gci_stats(struct f2fs_gc_info *gc_i)
+{
+	struct f2fs_stat_info *si = gc_i->stat_info;
+
+	list_del(&gc_i->stat_list);
+	mutex_lock(&si->stat_list);
+	si->sbi = NULL;
+	mutex_unlock(&si->stat_list);
+	kfree(gc_i->stat_info);
+}
+
+int f2fs_stat_init(struct super_block *sb, struct f2fs_sb_info *sbi)
+{
+	struct proc_dir_entry *entry;
+	int retval;
+
+	if (!f2fs_proc_root)
+		f2fs_proc_root = proc_mkdir("fs/f2fs", NULL);
+
+	sbi->s_proc = proc_mkdir(sb->s_id, f2fs_proc_root);
+
+	retval = init_stats(sbi);
+	if (retval)
+		return retval;
+
+	entry = create_proc_entry("f2fs_stat", 0, sbi->s_proc);
+	if (!entry)
+		return -ENOMEM;
+	entry->read_proc = f2fs_read_gc;
+	entry->write_proc = NULL;
+
+	entry = create_proc_entry("f2fs_sit_stat", 0, sbi->s_proc);
+	if (!entry) {
+		remove_proc_entry("f2fs_stat", sbi->s_proc);
+		return -ENOMEM;
+	}
+	entry->read_proc = f2fs_read_sit;
+	entry->write_proc = NULL;
+	entry = create_proc_entry("f2fs_mem_stat", 0, sbi->s_proc);
+	if (!entry) {
+		remove_proc_entry("f2fs_sit_stat", sbi->s_proc);
+		remove_proc_entry("f2fs_stat", sbi->s_proc);
+		return -ENOMEM;
+	}
+	entry->read_proc = f2fs_read_mem;
+	entry->write_proc = NULL;
+	return 0;
+}
+
+void f2fs_stat_exit(struct super_block *sb, struct f2fs_sb_info *sbi)
+{
+	if (sbi->s_proc) {
+		remove_proc_entry("f2fs_stat", sbi->s_proc);
+		remove_proc_entry("f2fs_sit_stat", sbi->s_proc);
+		remove_proc_entry("f2fs_mem_stat", sbi->s_proc);
+		remove_proc_entry(sb->s_id, f2fs_proc_root);
+	}
+}
+
+void f2fs_remove_stats(void)
+{
+	remove_proc_entry("fs/f2fs", NULL);
+}
--- a/fs/f2fs/f2fs.h
+++ b/fs/f2fs/f2fs.h
@@ -953,12 +953,6 @@ int start_gc_thread(struct f2fs_sb_info
 void stop_gc_thread(struct f2fs_sb_info *);
 block_t start_bidx_of_node(unsigned int);
 int f2fs_gc(struct f2fs_sb_info *, int);
-#ifdef CONFIG_F2FS_STAT_FS
-void f2fs_update_stat(struct f2fs_sb_info *);
-void f2fs_update_gc_metric(struct f2fs_sb_info *);
-int f2fs_stat_init(struct f2fs_sb_info *);
-void f2fs_stat_exit(struct f2fs_sb_info *);
-#endif
 int build_gc_manager(struct f2fs_sb_info *);
 void destroy_gc_manager(struct f2fs_sb_info *);
 int create_gc_caches(void);
@@ -970,6 +964,25 @@ void destroy_gc_caches(void);
 void recover_fsync_data(struct f2fs_sb_info *);
 bool space_for_roll_forward(struct f2fs_sb_info *);
 
+/**
+ * debug.c
+ */
+#ifdef CONFIG_F2FS_STAT_FS
+void f2fs_update_stat(struct f2fs_sb_info *);
+int f2fs_stat_init(struct super_block *sb, struct f2fs_sb_info *);
+void f2fs_stat_exit(struct super_block *sb, struct f2fs_sb_info *);
+void f2fs_destroy_gci_stats(struct f2fs_gc_info *gc_i);
+void f2fs_remove_stats(void);
+#else
+static inline void f2fs_update_stat(struct f2fs_sb_info *sbi) { }
+static inline int f2fs_stat_init(struct super_block *sb,
+				 struct f2fs_sb_info *sbi) { return 0; }
+static inline void f2fs_stat_exit(struct super_block *sb,
+				  struct f2fs_sb_info *sbi) { }
+static inline void f2fs_destroy_gci_stats(struct f2fs_gc_info *gc_i) { }
+static inline void f2fs_remove_stats(void) { }
+#endif
+
 extern const struct file_operations f2fs_dir_operations;
 extern const struct file_operations f2fs_file_operations;
 extern const struct inode_operations f2fs_file_inode_operations;
--- a/fs/f2fs/gc.c
+++ b/fs/f2fs/gc.c
@@ -24,7 +24,6 @@
 #include "segment.h"
 #include "gc.h"
 
-static LIST_HEAD(f2fs_stat_list);
 static struct kmem_cache *winode_slab;
 
 static int gc_thread_func(void *data)
@@ -727,350 +726,10 @@ stop:
 	return gc_status;
 }
 
-#ifdef CONFIG_F2FS_STAT_FS
-void f2fs_update_stat(struct f2fs_sb_info *sbi)
-{
-	struct f2fs_gc_info *gc_i = sbi->gc_info;
-	struct f2fs_stat_info *si = gc_i->stat_info;
-	int i;
-
-	/* valid check of the segment numbers */
-	si->hit_ext = sbi->read_hit_ext;
-	si->total_ext = sbi->total_hit_ext;
-	si->ndirty_node = get_pages(sbi, F2FS_DIRTY_NODES);
-	si->ndirty_dent = get_pages(sbi, F2FS_DIRTY_DENTS);
-	si->ndirty_dirs = sbi->n_dirty_dirs;
-	si->ndirty_meta = get_pages(sbi, F2FS_DIRTY_META);
-	si->total_count = (int)sbi->user_block_count / sbi->blocks_per_seg;
-	si->rsvd_segs = reserved_segments(sbi);
-	si->overp_segs = overprovision_segments(sbi);
-	si->valid_count = valid_user_blocks(sbi);
-	si->valid_node_count = valid_node_count(sbi);
-	si->valid_inode_count = valid_inode_count(sbi);
-	si->utilization = utilization(sbi);
-
-	si->free_segs = free_segments(sbi);
-	si->free_secs = free_sections(sbi);
-	si->prefree_count = prefree_segments(sbi);
-	si->dirty_count = dirty_segments(sbi);
-	si->node_pages = sbi->node_inode->i_mapping->nrpages;
-	si->meta_pages = sbi->meta_inode->i_mapping->nrpages;
-	si->nats = NM_I(sbi)->nat_cnt;
-	si->sits = SIT_I(sbi)->dirty_sentries;
-	si->fnids = NM_I(sbi)->fcnt;
-	si->bg_gc = sbi->bg_gc;
-	si->util_free = (int)(free_user_blocks(sbi) >> sbi->log_blocks_per_seg)
-		* 100 / (int)(sbi->user_block_count >> sbi->log_blocks_per_seg)
-		/ 2;
-	si->util_valid = (int)(written_block_count(sbi) >>
-						sbi->log_blocks_per_seg)
-		* 100 / (int)(sbi->user_block_count >> sbi->log_blocks_per_seg)
-		/ 2;
-	si->util_invalid = 50 - si->util_free - si->util_valid;
-	for (i = CURSEG_HOT_DATA; i <= CURSEG_COLD_NODE; i++) {
-		struct curseg_info *curseg = CURSEG_I(sbi, i);
-		si->curseg[i] = curseg->segno;
-		si->cursec[i] = curseg->segno / sbi->segs_per_sec;
-		si->curzone[i] = si->cursec[i] / sbi->secs_per_zone;
-	}
-
-	for (i = 0; i < 2; i++) {
-		si->segment_count[i] = sbi->segment_count[i];
-		si->block_count[i] = sbi->block_count[i];
-	}
-}
-
-/**
- * This function calculates BDF of every segments
- */
-void f2fs_update_gc_metric(struct f2fs_sb_info *sbi)
-{
-	struct f2fs_gc_info *gc_i = sbi->gc_info;
-	struct f2fs_stat_info *si = gc_i->stat_info;
-	unsigned int blks_per_sec, hblks_per_sec, total_vblocks, bimodal, dist;
-	struct sit_info *sit_i = SIT_I(sbi);
-	unsigned int segno, vblocks;
-	int ndirty = 0;
-
-	bimodal = 0;
-	total_vblocks = 0;
-	blks_per_sec = sbi->segs_per_sec * (1 << sbi->log_blocks_per_seg);
-	hblks_per_sec = blks_per_sec / 2;
-	mutex_lock(&sit_i->sentry_lock);
-	for (segno = 0; segno < TOTAL_SEGS(sbi); segno += sbi->segs_per_sec) {
-		vblocks = get_valid_blocks(sbi, segno, sbi->segs_per_sec);
-		dist = abs(vblocks - hblks_per_sec);
-		bimodal += dist * dist;
-
-		if (vblocks > 0 && vblocks < blks_per_sec) {
-			total_vblocks += vblocks;
-			ndirty++;
-		}
-	}
-	mutex_unlock(&sit_i->sentry_lock);
-	dist = sbi->total_sections * hblks_per_sec * hblks_per_sec / 100;
-	si->bimodal = bimodal / dist;
-	if (si->dirty_count)
-		si->avg_vblocks = total_vblocks / ndirty;
-	else
-		si->avg_vblocks = 0;
-}
-
-static int f2fs_read_gc(char *page, char **start, off_t off,
-		int count, int *eof, void *data)
-{
-	struct f2fs_gc_info *gc_i, *next;
-	struct f2fs_stat_info *si;
-	char *buf = page;
-	int i = 0;
-
-	list_for_each_entry_safe(gc_i, next, &f2fs_stat_list, stat_list) {
-		int j;
-		si = gc_i->stat_info;
-
-		mutex_lock(&si->stat_list);
-		if (!si->sbi) {
-			mutex_unlock(&si->stat_list);
-			continue;
-		}
-		f2fs_update_stat(si->sbi);
-
-		buf += sprintf(buf, "=====[ partition info. #%d ]=====\n", i++);
-		buf += sprintf(buf, "[SB: 1] [CP: 2] [NAT: %d] [SIT: %d] ",
-				si->nat_area_segs, si->sit_area_segs);
-		buf += sprintf(buf, "[SSA: %d] [MAIN: %d",
-				si->ssa_area_segs, si->main_area_segs);
-		buf += sprintf(buf, "(OverProv:%d Resv:%d)]\n\n",
-				si->overp_segs, si->rsvd_segs);
-		buf += sprintf(buf, "Utilization: %d%% (%d valid blocks)\n",
-				si->utilization, si->valid_count);
-		buf += sprintf(buf, "  - Node: %u (Inode: %u, ",
-				si->valid_node_count, si->valid_inode_count);
-		buf += sprintf(buf, "Other: %u)\n  - Data: %u\n",
-				si->valid_node_count - si->valid_inode_count,
-				si->valid_count - si->valid_node_count);
-		buf += sprintf(buf, "\nMain area: %d segs, %d secs %d zones\n",
-				si->main_area_segs, si->main_area_sections,
-				si->main_area_zones);
-		buf += sprintf(buf, "  - COLD  data: %d, %d, %d\n",
-				si->curseg[CURSEG_COLD_DATA],
-				si->cursec[CURSEG_COLD_DATA],
-				si->curzone[CURSEG_COLD_DATA]);
-		buf += sprintf(buf, "  - WARM  data: %d, %d, %d\n",
-				si->curseg[CURSEG_WARM_DATA],
-				si->cursec[CURSEG_WARM_DATA],
-				si->curzone[CURSEG_WARM_DATA]);
-		buf += sprintf(buf, "  - HOT   data: %d, %d, %d\n",
-				si->curseg[CURSEG_HOT_DATA],
-				si->cursec[CURSEG_HOT_DATA],
-				si->curzone[CURSEG_HOT_DATA]);
-		buf += sprintf(buf, "  - Dir   dnode: %d, %d, %d\n",
-				si->curseg[CURSEG_HOT_NODE],
-				si->cursec[CURSEG_HOT_NODE],
-				si->curzone[CURSEG_HOT_NODE]);
-		buf += sprintf(buf, "  - File   dnode: %d, %d, %d\n",
-				si->curseg[CURSEG_WARM_NODE],
-				si->cursec[CURSEG_WARM_NODE],
-				si->curzone[CURSEG_WARM_NODE]);
-		buf += sprintf(buf, "  - Indir nodes: %d, %d, %d\n",
-				si->curseg[CURSEG_COLD_NODE],
-				si->cursec[CURSEG_COLD_NODE],
-				si->curzone[CURSEG_COLD_NODE]);
-		buf += sprintf(buf, "\n  - Valid: %d\n  - Dirty: %d\n",
-				si->main_area_segs - si->dirty_count -
-				si->prefree_count - si->free_segs,
-				si->dirty_count);
-		buf += sprintf(buf, "  - Prefree: %d\n  - Free: %d (%d)\n\n",
-				si->prefree_count,
-				si->free_segs,
-				si->free_secs);
-		buf += sprintf(buf, "GC calls: %d (BG: %d)\n",
-				si->call_count, si->bg_gc);
-		buf += sprintf(buf, "  - data segments : %d\n", si->data_segs);
-		buf += sprintf(buf, "  - node segments : %d\n", si->node_segs);
-		buf += sprintf(buf, "Try to move %d blocks\n", si->tot_blks);
-		buf += sprintf(buf, "  - data blocks : %d\n", si->data_blks);
-		buf += sprintf(buf, "  - node blocks : %d\n", si->node_blks);
-		buf += sprintf(buf, "\nExtent Hit Ratio: %d / %d\n",
-						si->hit_ext, si->total_ext);
-		buf += sprintf(buf, "\nBalancing F2FS Async:\n");
-		buf += sprintf(buf, "  - nodes %4d in %4d\n",
-					si->ndirty_node, si->node_pages);
-		buf += sprintf(buf, "  - dents %4d in dirs:%4d\n",
-					si->ndirty_dent, si->ndirty_dirs);
-		buf += sprintf(buf, "  - meta %4d in %4d\n",
-					si->ndirty_meta, si->meta_pages);
-		buf += sprintf(buf, "  - NATs %5d > %lu\n",
-						si->nats, NM_WOUT_THRESHOLD);
-		buf += sprintf(buf, "  - SITs: %5d\n  - free_nids: %5d\n",
-					si->sits, si->fnids);
-		buf += sprintf(buf, "\nDistribution of User Blocks:");
-		buf += sprintf(buf, " [ valid | invalid | free ]\n");
-		buf += sprintf(buf, "  [");
-		for (j = 0; j < si->util_valid; j++)
-			buf += sprintf(buf, "-");
-		buf += sprintf(buf, "|");
-		for (j = 0; j < si->util_invalid; j++)
-			buf += sprintf(buf, "-");
-		buf += sprintf(buf, "|");
-		for (j = 0; j < si->util_free; j++)
-			buf += sprintf(buf, "-");
-		buf += sprintf(buf, "]\n\n");
-		buf += sprintf(buf, "SSR: %u blocks in %u segments\n",
-				si->block_count[SSR], si->segment_count[SSR]);
-		buf += sprintf(buf, "LFS: %u blocks in %u segments\n",
-				si->block_count[LFS], si->segment_count[LFS]);
-		mutex_unlock(&si->stat_list);
-	}
-	return buf - page;
-}
-
-static int f2fs_read_sit(char *page, char **start, off_t off,
-		int count, int *eof, void *data)
-{
-	struct f2fs_gc_info *gc_i, *next;
-	struct f2fs_stat_info *si;
-	char *buf = page;
-
-	list_for_each_entry_safe(gc_i, next, &f2fs_stat_list, stat_list) {
-		si = gc_i->stat_info;
-
-		mutex_lock(&si->stat_list);
-		if (!si->sbi) {
-			mutex_unlock(&si->stat_list);
-			continue;
-		}
-		f2fs_update_gc_metric(si->sbi);
-
-		buf += sprintf(buf, "BDF: %u, avg. vblocks: %u\n",
-				si->bimodal, si->avg_vblocks);
-		mutex_unlock(&si->stat_list);
-	}
-	return buf - page;
-}
-
-static int f2fs_read_mem(char *page, char **start, off_t off,
-		int count, int *eof, void *data)
-{
-	struct f2fs_gc_info *gc_i, *next;
-	struct f2fs_stat_info *si;
-	char *buf = page;
-
-	list_for_each_entry_safe(gc_i, next, &f2fs_stat_list, stat_list) {
-		struct f2fs_sb_info *sbi = gc_i->stat_info->sbi;
-		unsigned npages;
-		unsigned base_mem = 0, cache_mem = 0;
-
-		si = gc_i->stat_info;
-		mutex_lock(&si->stat_list);
-		if (!si->sbi) {
-			mutex_unlock(&si->stat_list);
-			continue;
-		}
-		base_mem += sizeof(struct f2fs_sb_info) + sbi->sb->s_blocksize;
-		base_mem += 2 * sizeof(struct f2fs_inode_info);
-		base_mem += sizeof(*sbi->ckpt);
-
-		/* build sm */
-		base_mem += sizeof(struct f2fs_sm_info);
-
-		/* build sit */
-		base_mem += sizeof(struct sit_info);
-		base_mem += TOTAL_SEGS(sbi) * sizeof(struct seg_entry);
-		base_mem += f2fs_bitmap_size(TOTAL_SEGS(sbi));
-		base_mem += 2 * SIT_VBLOCK_MAP_SIZE * TOTAL_SEGS(sbi);
-		if (sbi->segs_per_sec > 1)
-			base_mem += sbi->total_sections *
-					sizeof(struct sec_entry);
-		base_mem += __bitmap_size(sbi, SIT_BITMAP);
-
-		/* build free segmap */
-		base_mem += sizeof(struct free_segmap_info);
-		base_mem += f2fs_bitmap_size(TOTAL_SEGS(sbi));
-		base_mem += f2fs_bitmap_size(sbi->total_sections);
-
-		/* build curseg */
-		base_mem += sizeof(struct curseg_info) * NR_CURSEG_TYPE;
-		base_mem += PAGE_CACHE_SIZE * NR_CURSEG_TYPE;
-
-		/* build dirty segmap */
-		base_mem += sizeof(struct dirty_seglist_info);
-		base_mem += NR_DIRTY_TYPE * f2fs_bitmap_size(TOTAL_SEGS(sbi));
-		base_mem += 2 * f2fs_bitmap_size(TOTAL_SEGS(sbi));
-
-		/* buld nm */
-		base_mem += sizeof(struct f2fs_nm_info);
-		base_mem += __bitmap_size(sbi, NAT_BITMAP);
-
-		/* build gc */
-		base_mem += sizeof(struct f2fs_gc_info);
-		base_mem += sizeof(struct f2fs_gc_kthread);
-
-		/* free nids */
-		cache_mem += NM_I(sbi)->fcnt;
-		cache_mem += NM_I(sbi)->nat_cnt;
-		npages = sbi->node_inode->i_mapping->nrpages;
-		cache_mem += npages << PAGE_CACHE_SHIFT;
-		npages = sbi->meta_inode->i_mapping->nrpages;
-		cache_mem += npages << PAGE_CACHE_SHIFT;
-		cache_mem += sbi->n_orphans * sizeof(struct orphan_inode_entry);
-		cache_mem += sbi->n_dirty_dirs * sizeof(struct dir_inode_entry);
-
-		buf += sprintf(buf, "%u KB = static: %u + cached: %u\n",
-				(base_mem + cache_mem) >> 10,
-				base_mem >> 10,
-				cache_mem >> 10);
-		mutex_unlock(&si->stat_list);
-	}
-	return buf - page;
-}
-
-int f2fs_stat_init(struct f2fs_sb_info *sbi)
-{
-	struct proc_dir_entry *entry;
-
-	entry = create_proc_entry("f2fs_stat", 0, sbi->s_proc);
-	if (!entry)
-		return -ENOMEM;
-	entry->read_proc = f2fs_read_gc;
-	entry->write_proc = NULL;
-
-	entry = create_proc_entry("f2fs_sit_stat", 0, sbi->s_proc);
-	if (!entry) {
-		remove_proc_entry("f2fs_stat", sbi->s_proc);
-		return -ENOMEM;
-	}
-	entry->read_proc = f2fs_read_sit;
-	entry->write_proc = NULL;
-	entry = create_proc_entry("f2fs_mem_stat", 0, sbi->s_proc);
-	if (!entry) {
-		remove_proc_entry("f2fs_sit_stat", sbi->s_proc);
-		remove_proc_entry("f2fs_stat", sbi->s_proc);
-		return -ENOMEM;
-	}
-	entry->read_proc = f2fs_read_mem;
-	entry->write_proc = NULL;
-	return 0;
-}
-
-void f2fs_stat_exit(struct f2fs_sb_info *sbi)
-{
-	if (sbi->s_proc) {
-		remove_proc_entry("f2fs_stat", sbi->s_proc);
-		remove_proc_entry("f2fs_sit_stat", sbi->s_proc);
-		remove_proc_entry("f2fs_mem_stat", sbi->s_proc);
-	}
-}
-#endif
-
 int build_gc_manager(struct f2fs_sb_info *sbi)
 {
 	struct f2fs_gc_info *gc_i;
 	struct f2fs_checkpoint *ckp = F2FS_CKPT(sbi);
-#ifdef CONFIG_F2FS_STAT_FS
-	struct f2fs_super_block *raw_super = F2FS_RAW_SUPER(sbi);
-	struct f2fs_stat_info *si;
-#endif
 
 	gc_i = kzalloc(sizeof(struct f2fs_gc_info), GFP_KERNEL);
 	if (!gc_i)
@@ -1082,44 +741,18 @@ int build_gc_manager(struct f2fs_sb_info
 
 	DIRTY_I(sbi)->v_ops = &default_v_ops;
 
-#ifdef CONFIG_F2FS_STAT_FS
-	gc_i->stat_info = kzalloc(sizeof(struct f2fs_stat_info),
-			GFP_KERNEL);
-	if (!gc_i->stat_info)
-		return -ENOMEM;
-	si = gc_i->stat_info;
-	mutex_init(&si->stat_list);
-	list_add_tail(&gc_i->stat_list, &f2fs_stat_list);
-
-	si->all_area_segs = le32_to_cpu(raw_super->segment_count);
-	si->sit_area_segs = le32_to_cpu(raw_super->segment_count_sit);
-	si->nat_area_segs = le32_to_cpu(raw_super->segment_count_nat);
-	si->ssa_area_segs = le32_to_cpu(raw_super->segment_count_ssa);
-	si->main_area_segs = le32_to_cpu(raw_super->segment_count_main);
-	si->main_area_sections = le32_to_cpu(raw_super->section_count);
-	si->main_area_zones = si->main_area_sections /
-				le32_to_cpu(raw_super->secs_per_zone);
-	si->sbi = sbi;
-#endif
 	return 0;
 }
 
 void destroy_gc_manager(struct f2fs_sb_info *sbi)
 {
 	struct f2fs_gc_info *gc_i = sbi->gc_info;
-#ifdef CONFIG_F2FS_STAT_FS
-	struct f2fs_stat_info *si = gc_i->stat_info;
-#endif
+
 	if (!gc_i)
 		return;
 
-#ifdef CONFIG_F2FS_STAT_FS
-	list_del(&gc_i->stat_list);
-	mutex_lock(&si->stat_list);
-	si->sbi = NULL;
-	mutex_unlock(&si->stat_list);
-	kfree(gc_i->stat_info);
-#endif
+	f2fs_destroy_gci_stats(gc_i);
+
 	sbi->gc_info = NULL;
 	kfree(gc_i);
 }
--- a/fs/f2fs/super.c
+++ b/fs/f2fs/super.c
@@ -26,7 +26,6 @@
 #include "xattr.h"
 
 static struct kmem_cache *f2fs_inode_cachep;
-static struct proc_dir_entry *f2fs_proc_root;
 
 enum {
 	Opt_gc_background_off,
@@ -97,12 +96,7 @@ static void f2fs_put_super(struct super_
 {
 	struct f2fs_sb_info *sbi = F2FS_SB(sb);
 
-#ifdef CONFIG_F2FS_STAT_FS
-	if (sbi->s_proc) {
-		f2fs_stat_exit(sbi);
-		remove_proc_entry(sb->s_id, f2fs_proc_root);
-	}
-#endif
+	f2fs_stat_exit(sb, sbi);
 	stop_gc_thread(sbi);
 
 	write_checkpoint(sbi, false, true);
@@ -486,13 +480,9 @@ static int f2fs_fill_super(struct super_
 	if (start_gc_thread(sbi))
 		goto fail;
 
-#ifdef CONFIG_F2FS_STAT_FS
-	if (f2fs_proc_root) {
-		sbi->s_proc = proc_mkdir(sb->s_id, f2fs_proc_root);
-		if (f2fs_stat_init(sbi))
-			goto fail;
-	}
-#endif
+	if (f2fs_stat_init(sb, sbi))
+		goto fail;
+
 	return 0;
 fail:
 	stop_gc_thread(sbi);
@@ -566,7 +556,6 @@ static int __init init_f2fs_fs(void)
 	if (register_filesystem(&f2fs_fs_type))
 		return -EBUSY;
 
-	f2fs_proc_root = proc_mkdir("fs/f2fs", NULL);
 	return 0;
 fail:
 	return -ENOMEM;
@@ -574,7 +563,7 @@ fail:
 
 static void __exit exit_f2fs_fs(void)
 {
-	remove_proc_entry("fs/f2fs", NULL);
+	f2fs_remove_stats();
 	unregister_filesystem(&f2fs_fs_type);
 	destroy_checkpoint_caches();
 	destroy_gc_caches();