ext4: add mballoc stats proc file
[sfrench/cifs-2.6.git] / fs / ext4 / mballoc.c
index 34ddce5d6e5d469c389ed027f126013b92ade938..70b8ab19c25222bf5ce58667ddcad70afe587844 100644 (file)
@@ -2146,6 +2146,8 @@ static int ext4_mb_good_group_nolock(struct ext4_allocation_context *ac,
        ext4_grpblk_t free;
        int ret = 0;
 
+       if (sbi->s_mb_stats)
+               atomic64_inc(&sbi->s_bal_cX_groups_considered[ac->ac_criteria]);
        if (should_lock)
                ext4_lock_group(sb, group);
        free = grp->bb_free;
@@ -2420,6 +2422,9 @@ repeat:
                        if (ac->ac_status != AC_STATUS_CONTINUE)
                                break;
                }
+               /* Processed all groups and haven't found blocks */
+               if (sbi->s_mb_stats && i == ngroups)
+                       atomic64_inc(&sbi->s_bal_cX_failed[cr]);
        }
 
        if (ac->ac_b_ex.fe_len > 0 && ac->ac_status != AC_STATUS_FOUND &&
@@ -2449,6 +2454,9 @@ repeat:
                        goto repeat;
                }
        }
+
+       if (sbi->s_mb_stats && ac->ac_status == AC_STATUS_FOUND)
+               atomic64_inc(&sbi->s_bal_cX_hits[ac->ac_criteria]);
 out:
        if (!err && ac->ac_status != AC_STATUS_FOUND && first_err)
                err = first_err;
@@ -2548,6 +2556,67 @@ const struct seq_operations ext4_mb_seq_groups_ops = {
        .show   = ext4_mb_seq_groups_show,
 };
 
+int ext4_seq_mb_stats_show(struct seq_file *seq, void *offset)
+{
+       struct super_block *sb = (struct super_block *)seq->private;
+       struct ext4_sb_info *sbi = EXT4_SB(sb);
+
+       seq_puts(seq, "mballoc:\n");
+       if (!sbi->s_mb_stats) {
+               seq_puts(seq, "\tmb stats collection turned off.\n");
+               seq_puts(seq, "\tTo enable, please write \"1\" to sysfs file mb_stats.\n");
+               return 0;
+       }
+       seq_printf(seq, "\treqs: %u\n", atomic_read(&sbi->s_bal_reqs));
+       seq_printf(seq, "\tsuccess: %u\n", atomic_read(&sbi->s_bal_success));
+
+       seq_printf(seq, "\tgroups_scanned: %u\n",  atomic_read(&sbi->s_bal_groups_scanned));
+
+       seq_puts(seq, "\tcr0_stats:\n");
+       seq_printf(seq, "\t\thits: %llu\n", atomic64_read(&sbi->s_bal_cX_hits[0]));
+       seq_printf(seq, "\t\tgroups_considered: %llu\n",
+                  atomic64_read(&sbi->s_bal_cX_groups_considered[0]));
+       seq_printf(seq, "\t\tuseless_loops: %llu\n",
+                  atomic64_read(&sbi->s_bal_cX_failed[0]));
+
+       seq_puts(seq, "\tcr1_stats:\n");
+       seq_printf(seq, "\t\thits: %llu\n", atomic64_read(&sbi->s_bal_cX_hits[1]));
+       seq_printf(seq, "\t\tgroups_considered: %llu\n",
+                  atomic64_read(&sbi->s_bal_cX_groups_considered[1]));
+       seq_printf(seq, "\t\tuseless_loops: %llu\n",
+                  atomic64_read(&sbi->s_bal_cX_failed[1]));
+
+       seq_puts(seq, "\tcr2_stats:\n");
+       seq_printf(seq, "\t\thits: %llu\n", atomic64_read(&sbi->s_bal_cX_hits[2]));
+       seq_printf(seq, "\t\tgroups_considered: %llu\n",
+                  atomic64_read(&sbi->s_bal_cX_groups_considered[2]));
+       seq_printf(seq, "\t\tuseless_loops: %llu\n",
+                  atomic64_read(&sbi->s_bal_cX_failed[2]));
+
+       seq_puts(seq, "\tcr3_stats:\n");
+       seq_printf(seq, "\t\thits: %llu\n", atomic64_read(&sbi->s_bal_cX_hits[3]));
+       seq_printf(seq, "\t\tgroups_considered: %llu\n",
+                  atomic64_read(&sbi->s_bal_cX_groups_considered[3]));
+       seq_printf(seq, "\t\tuseless_loops: %llu\n",
+                  atomic64_read(&sbi->s_bal_cX_failed[3]));
+       seq_printf(seq, "\textents_scanned: %u\n", atomic_read(&sbi->s_bal_ex_scanned));
+       seq_printf(seq, "\t\tgoal_hits: %u\n", atomic_read(&sbi->s_bal_goals));
+       seq_printf(seq, "\t\t2^n_hits: %u\n", atomic_read(&sbi->s_bal_2orders));
+       seq_printf(seq, "\t\tbreaks: %u\n", atomic_read(&sbi->s_bal_breaks));
+       seq_printf(seq, "\t\tlost: %u\n", atomic_read(&sbi->s_mb_lost_chunks));
+
+       seq_printf(seq, "\tbuddies_generated: %u/%u\n",
+                  atomic_read(&sbi->s_mb_buddies_generated),
+                  ext4_get_groups_count(sb));
+       seq_printf(seq, "\tbuddies_time_used: %llu\n",
+                  atomic64_read(&sbi->s_mb_generation_time));
+       seq_printf(seq, "\tpreallocated: %u\n",
+                  atomic_read(&sbi->s_mb_preallocated));
+       seq_printf(seq, "\tdiscarded: %u\n",
+                  atomic_read(&sbi->s_mb_discarded));
+       return 0;
+}
+
 static struct kmem_cache *get_groupinfo_cache(int blocksize_bits)
 {
        int cache_index = blocksize_bits - EXT4_MIN_BLOCK_LOG_SIZE;
@@ -2975,9 +3044,10 @@ int ext4_mb_release(struct super_block *sb)
                                atomic_read(&sbi->s_bal_reqs),
                                atomic_read(&sbi->s_bal_success));
                ext4_msg(sb, KERN_INFO,
-                     "mballoc: %u extents scanned, %u goal hits, "
+                     "mballoc: %u extents scanned, %u groups scanned, %u goal hits, "
                                "%u 2^N hits, %u breaks, %u lost",
                                atomic_read(&sbi->s_bal_ex_scanned),
+                               atomic_read(&sbi->s_bal_groups_scanned),
                                atomic_read(&sbi->s_bal_goals),
                                atomic_read(&sbi->s_bal_2orders),
                                atomic_read(&sbi->s_bal_breaks),
@@ -3580,12 +3650,13 @@ static void ext4_mb_collect_stats(struct ext4_allocation_context *ac)
 {
        struct ext4_sb_info *sbi = EXT4_SB(ac->ac_sb);
 
-       if (sbi->s_mb_stats && ac->ac_g_ex.fe_len > 1) {
+       if (sbi->s_mb_stats && ac->ac_g_ex.fe_len >= 1) {
                atomic_inc(&sbi->s_bal_reqs);
                atomic_add(ac->ac_b_ex.fe_len, &sbi->s_bal_allocated);
                if (ac->ac_b_ex.fe_len >= ac->ac_o_ex.fe_len)
                        atomic_inc(&sbi->s_bal_success);
                atomic_add(ac->ac_found, &sbi->s_bal_ex_scanned);
+               atomic_add(ac->ac_groups_scanned, &sbi->s_bal_groups_scanned);
                if (ac->ac_g_ex.fe_start == ac->ac_b_ex.fe_start &&
                                ac->ac_g_ex.fe_group == ac->ac_b_ex.fe_group)
                        atomic_inc(&sbi->s_bal_goals);