Skip to content

Commit a6c75ea

Browse files
harshadjstytso
authored andcommitted
ext4: add mballoc stats proc file
Add new stats for measuring the performance of mballoc. This patch is forked from Artem Blagodarenko's work that can be found here: https://github.com/lustre/lustre-release/blob/master/ldiskfs/kernel_patches/patches/rhel8/ext4-simple-blockalloc.patch This patch reorganizes the stats by cr level. This is how the output looks like: mballoc: reqs: 0 success: 0 groups_scanned: 0 cr0_stats: hits: 0 groups_considered: 0 useless_loops: 0 bad_suggestions: 0 cr1_stats: hits: 0 groups_considered: 0 useless_loops: 0 bad_suggestions: 0 cr2_stats: hits: 0 groups_considered: 0 useless_loops: 0 cr3_stats: hits: 0 groups_considered: 0 useless_loops: 0 extents_scanned: 0 goal_hits: 0 2^n_hits: 0 breaks: 0 lost: 0 buddies_generated: 0/40 buddies_time_used: 0 preallocated: 0 discarded: 0 Signed-off-by: Harshad Shirwadkar <[email protected]> Reviewed-by: Andreas Dilger <[email protected]> Reviewed-by: Ritesh Harjani <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Theodore Ts'o <[email protected]>
1 parent b237e30 commit a6c75ea

File tree

3 files changed

+80
-2
lines changed

3 files changed

+80
-2
lines changed

fs/ext4/ext4.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1550,9 +1550,13 @@ struct ext4_sb_info {
15501550
atomic_t s_bal_success; /* we found long enough chunks */
15511551
atomic_t s_bal_allocated; /* in blocks */
15521552
atomic_t s_bal_ex_scanned; /* total extents scanned */
1553+
atomic_t s_bal_groups_scanned; /* number of groups scanned */
15531554
atomic_t s_bal_goals; /* goal hits */
15541555
atomic_t s_bal_breaks; /* too long searches */
15551556
atomic_t s_bal_2orders; /* 2^order hits */
1557+
atomic64_t s_bal_cX_groups_considered[4];
1558+
atomic64_t s_bal_cX_hits[4];
1559+
atomic64_t s_bal_cX_failed[4]; /* cX loop didn't find blocks */
15561560
atomic_t s_mb_buddies_generated; /* number of buddies generated */
15571561
atomic64_t s_mb_generation_time;
15581562
atomic_t s_mb_lost_chunks;
@@ -2856,6 +2860,7 @@ int __init ext4_fc_init_dentry_cache(void);
28562860
extern const struct seq_operations ext4_mb_seq_groups_ops;
28572861
extern long ext4_mb_stats;
28582862
extern long ext4_mb_max_to_scan;
2863+
extern int ext4_seq_mb_stats_show(struct seq_file *seq, void *offset);
28592864
extern int ext4_mb_init(struct super_block *);
28602865
extern int ext4_mb_release(struct super_block *);
28612866
extern ext4_fsblk_t ext4_mb_new_blocks(handle_t *,

fs/ext4/mballoc.c

Lines changed: 73 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2146,6 +2146,8 @@ static int ext4_mb_good_group_nolock(struct ext4_allocation_context *ac,
21462146
ext4_grpblk_t free;
21472147
int ret = 0;
21482148

2149+
if (sbi->s_mb_stats)
2150+
atomic64_inc(&sbi->s_bal_cX_groups_considered[ac->ac_criteria]);
21492151
if (should_lock)
21502152
ext4_lock_group(sb, group);
21512153
free = grp->bb_free;
@@ -2420,6 +2422,9 @@ ext4_mb_regular_allocator(struct ext4_allocation_context *ac)
24202422
if (ac->ac_status != AC_STATUS_CONTINUE)
24212423
break;
24222424
}
2425+
/* Processed all groups and haven't found blocks */
2426+
if (sbi->s_mb_stats && i == ngroups)
2427+
atomic64_inc(&sbi->s_bal_cX_failed[cr]);
24232428
}
24242429

24252430
if (ac->ac_b_ex.fe_len > 0 && ac->ac_status != AC_STATUS_FOUND &&
@@ -2449,6 +2454,9 @@ ext4_mb_regular_allocator(struct ext4_allocation_context *ac)
24492454
goto repeat;
24502455
}
24512456
}
2457+
2458+
if (sbi->s_mb_stats && ac->ac_status == AC_STATUS_FOUND)
2459+
atomic64_inc(&sbi->s_bal_cX_hits[ac->ac_criteria]);
24522460
out:
24532461
if (!err && ac->ac_status != AC_STATUS_FOUND && first_err)
24542462
err = first_err;
@@ -2548,6 +2556,67 @@ const struct seq_operations ext4_mb_seq_groups_ops = {
25482556
.show = ext4_mb_seq_groups_show,
25492557
};
25502558

2559+
int ext4_seq_mb_stats_show(struct seq_file *seq, void *offset)
2560+
{
2561+
struct super_block *sb = (struct super_block *)seq->private;
2562+
struct ext4_sb_info *sbi = EXT4_SB(sb);
2563+
2564+
seq_puts(seq, "mballoc:\n");
2565+
if (!sbi->s_mb_stats) {
2566+
seq_puts(seq, "\tmb stats collection turned off.\n");
2567+
seq_puts(seq, "\tTo enable, please write \"1\" to sysfs file mb_stats.\n");
2568+
return 0;
2569+
}
2570+
seq_printf(seq, "\treqs: %u\n", atomic_read(&sbi->s_bal_reqs));
2571+
seq_printf(seq, "\tsuccess: %u\n", atomic_read(&sbi->s_bal_success));
2572+
2573+
seq_printf(seq, "\tgroups_scanned: %u\n", atomic_read(&sbi->s_bal_groups_scanned));
2574+
2575+
seq_puts(seq, "\tcr0_stats:\n");
2576+
seq_printf(seq, "\t\thits: %llu\n", atomic64_read(&sbi->s_bal_cX_hits[0]));
2577+
seq_printf(seq, "\t\tgroups_considered: %llu\n",
2578+
atomic64_read(&sbi->s_bal_cX_groups_considered[0]));
2579+
seq_printf(seq, "\t\tuseless_loops: %llu\n",
2580+
atomic64_read(&sbi->s_bal_cX_failed[0]));
2581+
2582+
seq_puts(seq, "\tcr1_stats:\n");
2583+
seq_printf(seq, "\t\thits: %llu\n", atomic64_read(&sbi->s_bal_cX_hits[1]));
2584+
seq_printf(seq, "\t\tgroups_considered: %llu\n",
2585+
atomic64_read(&sbi->s_bal_cX_groups_considered[1]));
2586+
seq_printf(seq, "\t\tuseless_loops: %llu\n",
2587+
atomic64_read(&sbi->s_bal_cX_failed[1]));
2588+
2589+
seq_puts(seq, "\tcr2_stats:\n");
2590+
seq_printf(seq, "\t\thits: %llu\n", atomic64_read(&sbi->s_bal_cX_hits[2]));
2591+
seq_printf(seq, "\t\tgroups_considered: %llu\n",
2592+
atomic64_read(&sbi->s_bal_cX_groups_considered[2]));
2593+
seq_printf(seq, "\t\tuseless_loops: %llu\n",
2594+
atomic64_read(&sbi->s_bal_cX_failed[2]));
2595+
2596+
seq_puts(seq, "\tcr3_stats:\n");
2597+
seq_printf(seq, "\t\thits: %llu\n", atomic64_read(&sbi->s_bal_cX_hits[3]));
2598+
seq_printf(seq, "\t\tgroups_considered: %llu\n",
2599+
atomic64_read(&sbi->s_bal_cX_groups_considered[3]));
2600+
seq_printf(seq, "\t\tuseless_loops: %llu\n",
2601+
atomic64_read(&sbi->s_bal_cX_failed[3]));
2602+
seq_printf(seq, "\textents_scanned: %u\n", atomic_read(&sbi->s_bal_ex_scanned));
2603+
seq_printf(seq, "\t\tgoal_hits: %u\n", atomic_read(&sbi->s_bal_goals));
2604+
seq_printf(seq, "\t\t2^n_hits: %u\n", atomic_read(&sbi->s_bal_2orders));
2605+
seq_printf(seq, "\t\tbreaks: %u\n", atomic_read(&sbi->s_bal_breaks));
2606+
seq_printf(seq, "\t\tlost: %u\n", atomic_read(&sbi->s_mb_lost_chunks));
2607+
2608+
seq_printf(seq, "\tbuddies_generated: %u/%u\n",
2609+
atomic_read(&sbi->s_mb_buddies_generated),
2610+
ext4_get_groups_count(sb));
2611+
seq_printf(seq, "\tbuddies_time_used: %llu\n",
2612+
atomic64_read(&sbi->s_mb_generation_time));
2613+
seq_printf(seq, "\tpreallocated: %u\n",
2614+
atomic_read(&sbi->s_mb_preallocated));
2615+
seq_printf(seq, "\tdiscarded: %u\n",
2616+
atomic_read(&sbi->s_mb_discarded));
2617+
return 0;
2618+
}
2619+
25512620
static struct kmem_cache *get_groupinfo_cache(int blocksize_bits)
25522621
{
25532622
int cache_index = blocksize_bits - EXT4_MIN_BLOCK_LOG_SIZE;
@@ -2975,9 +3044,10 @@ int ext4_mb_release(struct super_block *sb)
29753044
atomic_read(&sbi->s_bal_reqs),
29763045
atomic_read(&sbi->s_bal_success));
29773046
ext4_msg(sb, KERN_INFO,
2978-
"mballoc: %u extents scanned, %u goal hits, "
3047+
"mballoc: %u extents scanned, %u groups scanned, %u goal hits, "
29793048
"%u 2^N hits, %u breaks, %u lost",
29803049
atomic_read(&sbi->s_bal_ex_scanned),
3050+
atomic_read(&sbi->s_bal_groups_scanned),
29813051
atomic_read(&sbi->s_bal_goals),
29823052
atomic_read(&sbi->s_bal_2orders),
29833053
atomic_read(&sbi->s_bal_breaks),
@@ -3580,12 +3650,13 @@ static void ext4_mb_collect_stats(struct ext4_allocation_context *ac)
35803650
{
35813651
struct ext4_sb_info *sbi = EXT4_SB(ac->ac_sb);
35823652

3583-
if (sbi->s_mb_stats && ac->ac_g_ex.fe_len > 1) {
3653+
if (sbi->s_mb_stats && ac->ac_g_ex.fe_len >= 1) {
35843654
atomic_inc(&sbi->s_bal_reqs);
35853655
atomic_add(ac->ac_b_ex.fe_len, &sbi->s_bal_allocated);
35863656
if (ac->ac_b_ex.fe_len >= ac->ac_o_ex.fe_len)
35873657
atomic_inc(&sbi->s_bal_success);
35883658
atomic_add(ac->ac_found, &sbi->s_bal_ex_scanned);
3659+
atomic_add(ac->ac_groups_scanned, &sbi->s_bal_groups_scanned);
35893660
if (ac->ac_g_ex.fe_start == ac->ac_b_ex.fe_start &&
35903661
ac->ac_g_ex.fe_group == ac->ac_b_ex.fe_group)
35913662
atomic_inc(&sbi->s_bal_goals);

fs/ext4/sysfs.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -530,6 +530,8 @@ int ext4_register_sysfs(struct super_block *sb)
530530
ext4_fc_info_show, sb);
531531
proc_create_seq_data("mb_groups", S_IRUGO, sbi->s_proc,
532532
&ext4_mb_seq_groups_ops, sb);
533+
proc_create_single_data("mb_stats", 0444, sbi->s_proc,
534+
ext4_seq_mb_stats_show, sb);
533535
}
534536
return 0;
535537
}

0 commit comments

Comments
 (0)