@@ -2523,9 +2523,6 @@ int ext4_mb_init(struct super_block *sb, int needs_recovery)
2523
2523
}
2524
2524
2525
2525
spin_lock_init (& sbi -> s_md_lock );
2526
- INIT_LIST_HEAD (& sbi -> s_active_transaction );
2527
- INIT_LIST_HEAD (& sbi -> s_closed_transaction );
2528
- INIT_LIST_HEAD (& sbi -> s_committed_transaction );
2529
2526
spin_lock_init (& sbi -> s_bal_lock );
2530
2527
2531
2528
sbi -> s_mb_max_to_scan = MB_DEFAULT_MAX_TO_SCAN ;
@@ -2554,6 +2551,8 @@ int ext4_mb_init(struct super_block *sb, int needs_recovery)
2554
2551
ext4_mb_init_per_dev_proc (sb );
2555
2552
ext4_mb_history_init (sb );
2556
2553
2554
+ sbi -> s_journal -> j_commit_callback = release_blocks_on_commit ;
2555
+
2557
2556
printk (KERN_INFO "EXT4-fs: mballoc enabled\n" );
2558
2557
return 0 ;
2559
2558
}
@@ -2583,15 +2582,6 @@ int ext4_mb_release(struct super_block *sb)
2583
2582
struct ext4_group_info * grinfo ;
2584
2583
struct ext4_sb_info * sbi = EXT4_SB (sb );
2585
2584
2586
- /* release freed, non-committed blocks */
2587
- spin_lock (& sbi -> s_md_lock );
2588
- list_splice_init (& sbi -> s_closed_transaction ,
2589
- & sbi -> s_committed_transaction );
2590
- list_splice_init (& sbi -> s_active_transaction ,
2591
- & sbi -> s_committed_transaction );
2592
- spin_unlock (& sbi -> s_md_lock );
2593
- ext4_mb_free_committed_blocks (sb );
2594
-
2595
2585
if (sbi -> s_group_info ) {
2596
2586
for (i = 0 ; i < sbi -> s_groups_count ; i ++ ) {
2597
2587
grinfo = ext4_get_group_info (sb , i );
@@ -2645,36 +2635,25 @@ int ext4_mb_release(struct super_block *sb)
2645
2635
return 0 ;
2646
2636
}
2647
2637
2648
- static noinline_for_stack void
2649
- ext4_mb_free_committed_blocks (struct super_block * sb )
2638
+ /*
2639
+ * This function is called by the jbd2 layer once the commit has finished,
2640
+ * so we know we can free the blocks that were released with that commit.
2641
+ */
2642
+ static void release_blocks_on_commit (journal_t * journal , transaction_t * txn )
2650
2643
{
2644
+ struct super_block * sb = journal -> j_private ;
2651
2645
struct ext4_buddy e4b ;
2652
2646
struct ext4_group_info * db ;
2653
- struct ext4_sb_info * sbi = EXT4_SB (sb );
2654
2647
int err , count = 0 , count2 = 0 ;
2655
2648
struct ext4_free_data * entry ;
2656
2649
ext4_fsblk_t discard_block ;
2650
+ struct list_head * l , * ltmp ;
2657
2651
2658
- if (list_empty (& sbi -> s_committed_transaction ))
2659
- return ;
2660
-
2661
- /* there is committed blocks to be freed yet */
2662
- do {
2663
- /* get next array of blocks */
2664
- entry = NULL ;
2665
- spin_lock (& sbi -> s_md_lock );
2666
- if (!list_empty (& sbi -> s_committed_transaction )) {
2667
- entry = list_entry (sbi -> s_committed_transaction .next ,
2668
- struct ext4_free_data , list );
2669
- list_del (& entry -> list );
2670
- }
2671
- spin_unlock (& sbi -> s_md_lock );
2672
-
2673
- if (entry == NULL )
2674
- break ;
2652
+ list_for_each_safe (l , ltmp , & txn -> t_private_list ) {
2653
+ entry = list_entry (l , struct ext4_free_data , list );
2675
2654
2676
2655
mb_debug ("gonna free %u blocks in group %lu (0x%p):" ,
2677
- entry -> count , entry -> group , entry );
2656
+ entry -> count , entry -> group , entry );
2678
2657
2679
2658
err = ext4_mb_load_buddy (sb , entry -> group , & e4b );
2680
2659
/* we expect to find existing buddy because it's pinned */
@@ -2706,7 +2685,7 @@ ext4_mb_free_committed_blocks(struct super_block *sb)
2706
2685
2707
2686
kmem_cache_free (ext4_free_ext_cachep , entry );
2708
2687
ext4_mb_release_desc (& e4b );
2709
- } while ( 1 );
2688
+ }
2710
2689
2711
2690
mb_debug ("freed %u blocks in %u structures\n" , count , count2 );
2712
2691
}
@@ -4348,8 +4327,6 @@ ext4_fsblk_t ext4_mb_new_blocks(handle_t *handle,
4348
4327
goto out1 ;
4349
4328
}
4350
4329
4351
- ext4_mb_poll_new_transaction (sb , handle );
4352
-
4353
4330
* errp = ext4_mb_initialize_context (ac , ar );
4354
4331
if (* errp ) {
4355
4332
ar -> len = 0 ;
@@ -4408,36 +4385,6 @@ ext4_fsblk_t ext4_mb_new_blocks(handle_t *handle,
4408
4385
4409
4386
return block ;
4410
4387
}
4411
- static void ext4_mb_poll_new_transaction (struct super_block * sb ,
4412
- handle_t * handle )
4413
- {
4414
- struct ext4_sb_info * sbi = EXT4_SB (sb );
4415
-
4416
- if (sbi -> s_last_transaction == handle -> h_transaction -> t_tid )
4417
- return ;
4418
-
4419
- /* new transaction! time to close last one and free blocks for
4420
- * committed transaction. we know that only transaction can be
4421
- * active, so previos transaction can be being logged and we
4422
- * know that transaction before previous is known to be already
4423
- * logged. this means that now we may free blocks freed in all
4424
- * transactions before previous one. hope I'm clear enough ... */
4425
-
4426
- spin_lock (& sbi -> s_md_lock );
4427
- if (sbi -> s_last_transaction != handle -> h_transaction -> t_tid ) {
4428
- mb_debug ("new transaction %lu, old %lu\n" ,
4429
- (unsigned long ) handle -> h_transaction -> t_tid ,
4430
- (unsigned long ) sbi -> s_last_transaction );
4431
- list_splice_init (& sbi -> s_closed_transaction ,
4432
- & sbi -> s_committed_transaction );
4433
- list_splice_init (& sbi -> s_active_transaction ,
4434
- & sbi -> s_closed_transaction );
4435
- sbi -> s_last_transaction = handle -> h_transaction -> t_tid ;
4436
- }
4437
- spin_unlock (& sbi -> s_md_lock );
4438
-
4439
- ext4_mb_free_committed_blocks (sb );
4440
- }
4441
4388
4442
4389
/*
4443
4390
* We can merge two free data extents only if the physical blocks
@@ -4531,9 +4478,9 @@ ext4_mb_free_metadata(handle_t *handle, struct ext4_buddy *e4b,
4531
4478
kmem_cache_free (ext4_free_ext_cachep , entry );
4532
4479
}
4533
4480
}
4534
- /* Add the extent to active_transaction list */
4481
+ /* Add the extent to transaction's private list */
4535
4482
spin_lock (& sbi -> s_md_lock );
4536
- list_add (& new_entry -> list , & sbi -> s_active_transaction );
4483
+ list_add (& new_entry -> list , & handle -> h_transaction -> t_private_list );
4537
4484
spin_unlock (& sbi -> s_md_lock );
4538
4485
ext4_unlock_group (sb , group );
4539
4486
return 0 ;
@@ -4562,8 +4509,6 @@ void ext4_mb_free_blocks(handle_t *handle, struct inode *inode,
4562
4509
4563
4510
* freed = 0 ;
4564
4511
4565
- ext4_mb_poll_new_transaction (sb , handle );
4566
-
4567
4512
sbi = EXT4_SB (sb );
4568
4513
es = EXT4_SB (sb )-> s_es ;
4569
4514
if (block < le32_to_cpu (es -> s_first_data_block ) ||
0 commit comments