@@ -2146,6 +2146,8 @@ static int ext4_mb_good_group_nolock(struct ext4_allocation_context *ac,
2146
2146
ext4_grpblk_t free ;
2147
2147
int ret = 0 ;
2148
2148
2149
+ if (sbi -> s_mb_stats )
2150
+ atomic64_inc (& sbi -> s_bal_cX_groups_considered [ac -> ac_criteria ]);
2149
2151
if (should_lock )
2150
2152
ext4_lock_group (sb , group );
2151
2153
free = grp -> bb_free ;
@@ -2420,6 +2422,9 @@ ext4_mb_regular_allocator(struct ext4_allocation_context *ac)
2420
2422
if (ac -> ac_status != AC_STATUS_CONTINUE )
2421
2423
break ;
2422
2424
}
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 ]);
2423
2428
}
2424
2429
2425
2430
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)
2449
2454
goto repeat ;
2450
2455
}
2451
2456
}
2457
+
2458
+ if (sbi -> s_mb_stats && ac -> ac_status == AC_STATUS_FOUND )
2459
+ atomic64_inc (& sbi -> s_bal_cX_hits [ac -> ac_criteria ]);
2452
2460
out :
2453
2461
if (!err && ac -> ac_status != AC_STATUS_FOUND && first_err )
2454
2462
err = first_err ;
@@ -2548,6 +2556,67 @@ const struct seq_operations ext4_mb_seq_groups_ops = {
2548
2556
.show = ext4_mb_seq_groups_show ,
2549
2557
};
2550
2558
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
+
2551
2620
static struct kmem_cache * get_groupinfo_cache (int blocksize_bits )
2552
2621
{
2553
2622
int cache_index = blocksize_bits - EXT4_MIN_BLOCK_LOG_SIZE ;
@@ -2975,9 +3044,10 @@ int ext4_mb_release(struct super_block *sb)
2975
3044
atomic_read (& sbi -> s_bal_reqs ),
2976
3045
atomic_read (& sbi -> s_bal_success ));
2977
3046
ext4_msg (sb , KERN_INFO ,
2978
- "mballoc: %u extents scanned, %u goal hits, "
3047
+ "mballoc: %u extents scanned, %u groups scanned, %u goal hits, "
2979
3048
"%u 2^N hits, %u breaks, %u lost" ,
2980
3049
atomic_read (& sbi -> s_bal_ex_scanned ),
3050
+ atomic_read (& sbi -> s_bal_groups_scanned ),
2981
3051
atomic_read (& sbi -> s_bal_goals ),
2982
3052
atomic_read (& sbi -> s_bal_2orders ),
2983
3053
atomic_read (& sbi -> s_bal_breaks ),
@@ -3580,12 +3650,13 @@ static void ext4_mb_collect_stats(struct ext4_allocation_context *ac)
3580
3650
{
3581
3651
struct ext4_sb_info * sbi = EXT4_SB (ac -> ac_sb );
3582
3652
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 ) {
3584
3654
atomic_inc (& sbi -> s_bal_reqs );
3585
3655
atomic_add (ac -> ac_b_ex .fe_len , & sbi -> s_bal_allocated );
3586
3656
if (ac -> ac_b_ex .fe_len >= ac -> ac_o_ex .fe_len )
3587
3657
atomic_inc (& sbi -> s_bal_success );
3588
3658
atomic_add (ac -> ac_found , & sbi -> s_bal_ex_scanned );
3659
+ atomic_add (ac -> ac_groups_scanned , & sbi -> s_bal_groups_scanned );
3589
3660
if (ac -> ac_g_ex .fe_start == ac -> ac_b_ex .fe_start &&
3590
3661
ac -> ac_g_ex .fe_group == ac -> ac_b_ex .fe_group )
3591
3662
atomic_inc (& sbi -> s_bal_goals );
0 commit comments