aboutsummaryrefslogtreecommitdiffstats
path: root/fs/ext4/mballoc.c
diff options
context:
space:
mode:
Diffstat (limited to 'fs/ext4/mballoc.c')
-rw-r--r--fs/ext4/mballoc.c99
1 files changed, 43 insertions, 56 deletions
diff --git a/fs/ext4/mballoc.c b/fs/ext4/mballoc.c
index d34afad3e137..b423a364dca3 100644
--- a/fs/ext4/mballoc.c
+++ b/fs/ext4/mballoc.c
@@ -23,6 +23,7 @@
23 23
24#include "mballoc.h" 24#include "mballoc.h"
25#include <linux/debugfs.h> 25#include <linux/debugfs.h>
26#include <linux/slab.h>
26#include <trace/events/ext4.h> 27#include <trace/events/ext4.h>
27 28
28/* 29/*
@@ -69,7 +70,7 @@
69 * 70 *
70 * pa_lstart -> the logical start block for this prealloc space 71 * pa_lstart -> the logical start block for this prealloc space
71 * pa_pstart -> the physical start block for this prealloc space 72 * pa_pstart -> the physical start block for this prealloc space
72 * pa_len -> lenght for this prealloc space 73 * pa_len -> length for this prealloc space
73 * pa_free -> free space available in this prealloc space 74 * pa_free -> free space available in this prealloc space
74 * 75 *
75 * The inode preallocation space is used looking at the _logical_ start 76 * The inode preallocation space is used looking at the _logical_ start
@@ -441,10 +442,9 @@ static void mb_free_blocks_double(struct inode *inode, struct ext4_buddy *e4b,
441 for (i = 0; i < count; i++) { 442 for (i = 0; i < count; i++) {
442 if (!mb_test_bit(first + i, e4b->bd_info->bb_bitmap)) { 443 if (!mb_test_bit(first + i, e4b->bd_info->bb_bitmap)) {
443 ext4_fsblk_t blocknr; 444 ext4_fsblk_t blocknr;
444 blocknr = e4b->bd_group * EXT4_BLOCKS_PER_GROUP(sb); 445
446 blocknr = ext4_group_first_block_no(sb, e4b->bd_group);
445 blocknr += first + i; 447 blocknr += first + i;
446 blocknr +=
447 le32_to_cpu(EXT4_SB(sb)->s_es->s_first_data_block);
448 ext4_grp_locked_error(sb, e4b->bd_group, 448 ext4_grp_locked_error(sb, e4b->bd_group,
449 __func__, "double-free of inode" 449 __func__, "double-free of inode"
450 " %lu's block %llu(bit %u in group %u)", 450 " %lu's block %llu(bit %u in group %u)",
@@ -1255,10 +1255,9 @@ static void mb_free_blocks(struct inode *inode, struct ext4_buddy *e4b,
1255 1255
1256 if (!mb_test_bit(block, EXT4_MB_BITMAP(e4b))) { 1256 if (!mb_test_bit(block, EXT4_MB_BITMAP(e4b))) {
1257 ext4_fsblk_t blocknr; 1257 ext4_fsblk_t blocknr;
1258 blocknr = e4b->bd_group * EXT4_BLOCKS_PER_GROUP(sb); 1258
1259 blocknr = ext4_group_first_block_no(sb, e4b->bd_group);
1259 blocknr += block; 1260 blocknr += block;
1260 blocknr +=
1261 le32_to_cpu(EXT4_SB(sb)->s_es->s_first_data_block);
1262 ext4_grp_locked_error(sb, e4b->bd_group, 1261 ext4_grp_locked_error(sb, e4b->bd_group,
1263 __func__, "double-free of inode" 1262 __func__, "double-free of inode"
1264 " %lu's block %llu(bit %u in group %u)", 1263 " %lu's block %llu(bit %u in group %u)",
@@ -1631,7 +1630,6 @@ int ext4_mb_find_by_goal(struct ext4_allocation_context *ac,
1631 int max; 1630 int max;
1632 int err; 1631 int err;
1633 struct ext4_sb_info *sbi = EXT4_SB(ac->ac_sb); 1632 struct ext4_sb_info *sbi = EXT4_SB(ac->ac_sb);
1634 struct ext4_super_block *es = sbi->s_es;
1635 struct ext4_free_extent ex; 1633 struct ext4_free_extent ex;
1636 1634
1637 if (!(ac->ac_flags & EXT4_MB_HINT_TRY_GOAL)) 1635 if (!(ac->ac_flags & EXT4_MB_HINT_TRY_GOAL))
@@ -1648,8 +1646,8 @@ int ext4_mb_find_by_goal(struct ext4_allocation_context *ac,
1648 if (max >= ac->ac_g_ex.fe_len && ac->ac_g_ex.fe_len == sbi->s_stripe) { 1646 if (max >= ac->ac_g_ex.fe_len && ac->ac_g_ex.fe_len == sbi->s_stripe) {
1649 ext4_fsblk_t start; 1647 ext4_fsblk_t start;
1650 1648
1651 start = (e4b->bd_group * EXT4_BLOCKS_PER_GROUP(ac->ac_sb)) + 1649 start = ext4_group_first_block_no(ac->ac_sb, e4b->bd_group) +
1652 ex.fe_start + le32_to_cpu(es->s_first_data_block); 1650 ex.fe_start;
1653 /* use do_div to get remainder (would be 64-bit modulo) */ 1651 /* use do_div to get remainder (would be 64-bit modulo) */
1654 if (do_div(start, sbi->s_stripe) == 0) { 1652 if (do_div(start, sbi->s_stripe) == 0) {
1655 ac->ac_found++; 1653 ac->ac_found++;
@@ -1803,8 +1801,8 @@ void ext4_mb_scan_aligned(struct ext4_allocation_context *ac,
1803 BUG_ON(sbi->s_stripe == 0); 1801 BUG_ON(sbi->s_stripe == 0);
1804 1802
1805 /* find first stripe-aligned block in group */ 1803 /* find first stripe-aligned block in group */
1806 first_group_block = e4b->bd_group * EXT4_BLOCKS_PER_GROUP(sb) 1804 first_group_block = ext4_group_first_block_no(sb, e4b->bd_group);
1807 + le32_to_cpu(sbi->s_es->s_first_data_block); 1805
1808 a = first_group_block + sbi->s_stripe - 1; 1806 a = first_group_block + sbi->s_stripe - 1;
1809 do_div(a, sbi->s_stripe); 1807 do_div(a, sbi->s_stripe);
1810 i = (a * sbi->s_stripe) - first_group_block; 1808 i = (a * sbi->s_stripe) - first_group_block;
@@ -2256,7 +2254,7 @@ int ext4_mb_add_groupinfo(struct super_block *sb, ext4_group_t group,
2256 2254
2257 INIT_LIST_HEAD(&meta_group_info[i]->bb_prealloc_list); 2255 INIT_LIST_HEAD(&meta_group_info[i]->bb_prealloc_list);
2258 init_rwsem(&meta_group_info[i]->alloc_sem); 2256 init_rwsem(&meta_group_info[i]->alloc_sem);
2259 meta_group_info[i]->bb_free_root.rb_node = NULL; 2257 meta_group_info[i]->bb_free_root = RB_ROOT;
2260 2258
2261#ifdef DOUBLE_CHECK 2259#ifdef DOUBLE_CHECK
2262 { 2260 {
@@ -2537,6 +2535,17 @@ static void release_blocks_on_commit(journal_t *journal, transaction_t *txn)
2537 mb_debug(1, "gonna free %u blocks in group %u (0x%p):", 2535 mb_debug(1, "gonna free %u blocks in group %u (0x%p):",
2538 entry->count, entry->group, entry); 2536 entry->count, entry->group, entry);
2539 2537
2538 if (test_opt(sb, DISCARD)) {
2539 ext4_fsblk_t discard_block;
2540
2541 discard_block = entry->start_blk +
2542 ext4_group_first_block_no(sb, entry->group);
2543 trace_ext4_discard_blocks(sb,
2544 (unsigned long long)discard_block,
2545 entry->count);
2546 sb_issue_discard(sb, discard_block, entry->count);
2547 }
2548
2540 err = ext4_mb_load_buddy(sb, entry->group, &e4b); 2549 err = ext4_mb_load_buddy(sb, entry->group, &e4b);
2541 /* we expect to find existing buddy because it's pinned */ 2550 /* we expect to find existing buddy because it's pinned */
2542 BUG_ON(err != 0); 2551 BUG_ON(err != 0);
@@ -2558,19 +2567,6 @@ static void release_blocks_on_commit(journal_t *journal, transaction_t *txn)
2558 page_cache_release(e4b.bd_bitmap_page); 2567 page_cache_release(e4b.bd_bitmap_page);
2559 } 2568 }
2560 ext4_unlock_group(sb, entry->group); 2569 ext4_unlock_group(sb, entry->group);
2561 if (test_opt(sb, DISCARD)) {
2562 ext4_fsblk_t discard_block;
2563 struct ext4_super_block *es = EXT4_SB(sb)->s_es;
2564
2565 discard_block = (ext4_fsblk_t)entry->group *
2566 EXT4_BLOCKS_PER_GROUP(sb)
2567 + entry->start_blk
2568 + le32_to_cpu(es->s_first_data_block);
2569 trace_ext4_discard_blocks(sb,
2570 (unsigned long long)discard_block,
2571 entry->count);
2572 sb_issue_discard(sb, discard_block, entry->count);
2573 }
2574 kmem_cache_free(ext4_free_ext_cachep, entry); 2570 kmem_cache_free(ext4_free_ext_cachep, entry);
2575 ext4_mb_release_desc(&e4b); 2571 ext4_mb_release_desc(&e4b);
2576 } 2572 }
@@ -2703,14 +2699,11 @@ ext4_mb_mark_diskspace_used(struct ext4_allocation_context *ac,
2703 if (err) 2699 if (err)
2704 goto out_err; 2700 goto out_err;
2705 2701
2706 block = ac->ac_b_ex.fe_group * EXT4_BLOCKS_PER_GROUP(sb) 2702 block = ext4_grp_offs_to_block(sb, &ac->ac_b_ex);
2707 + ac->ac_b_ex.fe_start
2708 + le32_to_cpu(es->s_first_data_block);
2709 2703
2710 len = ac->ac_b_ex.fe_len; 2704 len = ac->ac_b_ex.fe_len;
2711 if (!ext4_data_block_valid(sbi, block, len)) { 2705 if (!ext4_data_block_valid(sbi, block, len)) {
2712 ext4_error(sb, __func__, 2706 ext4_error(sb, "Allocating blocks %llu-%llu which overlap "
2713 "Allocating blocks %llu-%llu which overlap "
2714 "fs metadata\n", block, block+len); 2707 "fs metadata\n", block, block+len);
2715 /* File system mounted not to panic on error 2708 /* File system mounted not to panic on error
2716 * Fix the bitmap and repeat the block allocation 2709 * Fix the bitmap and repeat the block allocation
@@ -3161,9 +3154,7 @@ ext4_mb_use_preallocated(struct ext4_allocation_context *ac)
3161 /* The max size of hash table is PREALLOC_TB_SIZE */ 3154 /* The max size of hash table is PREALLOC_TB_SIZE */
3162 order = PREALLOC_TB_SIZE - 1; 3155 order = PREALLOC_TB_SIZE - 1;
3163 3156
3164 goal_block = ac->ac_g_ex.fe_group * EXT4_BLOCKS_PER_GROUP(ac->ac_sb) + 3157 goal_block = ext4_grp_offs_to_block(ac->ac_sb, &ac->ac_g_ex);
3165 ac->ac_g_ex.fe_start +
3166 le32_to_cpu(EXT4_SB(ac->ac_sb)->s_es->s_first_data_block);
3167 /* 3158 /*
3168 * search for the prealloc space that is having 3159 * search for the prealloc space that is having
3169 * minimal distance from the goal block. 3160 * minimal distance from the goal block.
@@ -3526,8 +3517,7 @@ ext4_mb_release_inode_pa(struct ext4_buddy *e4b, struct buffer_head *bitmap_bh,
3526 if (bit >= end) 3517 if (bit >= end)
3527 break; 3518 break;
3528 next = mb_find_next_bit(bitmap_bh->b_data, end, bit); 3519 next = mb_find_next_bit(bitmap_bh->b_data, end, bit);
3529 start = group * EXT4_BLOCKS_PER_GROUP(sb) + bit + 3520 start = ext4_group_first_block_no(sb, group) + bit;
3530 le32_to_cpu(sbi->s_es->s_first_data_block);
3531 mb_debug(1, " free preallocated %u/%u in group %u\n", 3521 mb_debug(1, " free preallocated %u/%u in group %u\n",
3532 (unsigned) start, (unsigned) next - bit, 3522 (unsigned) start, (unsigned) next - bit,
3533 (unsigned) group); 3523 (unsigned) group);
@@ -3623,15 +3613,13 @@ ext4_mb_discard_group_preallocations(struct super_block *sb,
3623 3613
3624 bitmap_bh = ext4_read_block_bitmap(sb, group); 3614 bitmap_bh = ext4_read_block_bitmap(sb, group);
3625 if (bitmap_bh == NULL) { 3615 if (bitmap_bh == NULL) {
3626 ext4_error(sb, __func__, "Error in reading block " 3616 ext4_error(sb, "Error reading block bitmap for %u", group);
3627 "bitmap for %u", group);
3628 return 0; 3617 return 0;
3629 } 3618 }
3630 3619
3631 err = ext4_mb_load_buddy(sb, group, &e4b); 3620 err = ext4_mb_load_buddy(sb, group, &e4b);
3632 if (err) { 3621 if (err) {
3633 ext4_error(sb, __func__, "Error in loading buddy " 3622 ext4_error(sb, "Error loading buddy information for %u", group);
3634 "information for %u", group);
3635 put_bh(bitmap_bh); 3623 put_bh(bitmap_bh);
3636 return 0; 3624 return 0;
3637 } 3625 }
@@ -3804,15 +3792,15 @@ repeat:
3804 3792
3805 err = ext4_mb_load_buddy(sb, group, &e4b); 3793 err = ext4_mb_load_buddy(sb, group, &e4b);
3806 if (err) { 3794 if (err) {
3807 ext4_error(sb, __func__, "Error in loading buddy " 3795 ext4_error(sb, "Error loading buddy information for %u",
3808 "information for %u", group); 3796 group);
3809 continue; 3797 continue;
3810 } 3798 }
3811 3799
3812 bitmap_bh = ext4_read_block_bitmap(sb, group); 3800 bitmap_bh = ext4_read_block_bitmap(sb, group);
3813 if (bitmap_bh == NULL) { 3801 if (bitmap_bh == NULL) {
3814 ext4_error(sb, __func__, "Error in reading block " 3802 ext4_error(sb, "Error reading block bitmap for %u",
3815 "bitmap for %u", group); 3803 group);
3816 ext4_mb_release_desc(&e4b); 3804 ext4_mb_release_desc(&e4b);
3817 continue; 3805 continue;
3818 } 3806 }
@@ -3938,7 +3926,7 @@ static void ext4_mb_group_or_file(struct ext4_allocation_context *ac)
3938 3926
3939 /* don't use group allocation for large files */ 3927 /* don't use group allocation for large files */
3940 size = max(size, isize); 3928 size = max(size, isize);
3941 if (size >= sbi->s_mb_stream_request) { 3929 if (size > sbi->s_mb_stream_request) {
3942 ac->ac_flags |= EXT4_MB_STREAM_ALLOC; 3930 ac->ac_flags |= EXT4_MB_STREAM_ALLOC;
3943 return; 3931 return;
3944 } 3932 }
@@ -4077,8 +4065,8 @@ ext4_mb_discard_lg_preallocations(struct super_block *sb,
4077 4065
4078 ext4_get_group_no_and_offset(sb, pa->pa_pstart, &group, NULL); 4066 ext4_get_group_no_and_offset(sb, pa->pa_pstart, &group, NULL);
4079 if (ext4_mb_load_buddy(sb, group, &e4b)) { 4067 if (ext4_mb_load_buddy(sb, group, &e4b)) {
4080 ext4_error(sb, __func__, "Error in loading buddy " 4068 ext4_error(sb, "Error loading buddy information for %u",
4081 "information for %u", group); 4069 group);
4082 continue; 4070 continue;
4083 } 4071 }
4084 ext4_lock_group(sb, group); 4072 ext4_lock_group(sb, group);
@@ -4254,7 +4242,7 @@ ext4_fsblk_t ext4_mb_new_blocks(handle_t *handle,
4254 return 0; 4242 return 0;
4255 } 4243 }
4256 reserv_blks = ar->len; 4244 reserv_blks = ar->len;
4257 while (ar->len && vfs_dq_alloc_block(ar->inode, ar->len)) { 4245 while (ar->len && dquot_alloc_block(ar->inode, ar->len)) {
4258 ar->flags |= EXT4_MB_HINT_NOPREALLOC; 4246 ar->flags |= EXT4_MB_HINT_NOPREALLOC;
4259 ar->len--; 4247 ar->len--;
4260 } 4248 }
@@ -4331,7 +4319,7 @@ out2:
4331 kmem_cache_free(ext4_ac_cachep, ac); 4319 kmem_cache_free(ext4_ac_cachep, ac);
4332out1: 4320out1:
4333 if (inquota && ar->len < inquota) 4321 if (inquota && ar->len < inquota)
4334 vfs_dq_free_block(ar->inode, inquota - ar->len); 4322 dquot_free_block(ar->inode, inquota - ar->len);
4335out3: 4323out3:
4336 if (!ar->len) { 4324 if (!ar->len) {
4337 if (!EXT4_I(ar->inode)->i_delalloc_reserved_flag) 4325 if (!EXT4_I(ar->inode)->i_delalloc_reserved_flag)
@@ -4476,10 +4464,10 @@ void ext4_free_blocks(handle_t *handle, struct inode *inode,
4476 4464
4477 sbi = EXT4_SB(sb); 4465 sbi = EXT4_SB(sb);
4478 es = EXT4_SB(sb)->s_es; 4466 es = EXT4_SB(sb)->s_es;
4479 if (!ext4_data_block_valid(sbi, block, count)) { 4467 if (!(flags & EXT4_FREE_BLOCKS_VALIDATED) &&
4480 ext4_error(sb, __func__, 4468 !ext4_data_block_valid(sbi, block, count)) {
4481 "Freeing blocks not in datazone - " 4469 ext4_error(sb, "Freeing blocks not in datazone - "
4482 "block = %llu, count = %lu", block, count); 4470 "block = %llu, count = %lu", block, count);
4483 goto error_return; 4471 goto error_return;
4484 } 4472 }
4485 4473
@@ -4547,8 +4535,7 @@ do_more:
4547 in_range(block + count - 1, ext4_inode_table(sb, gdp), 4535 in_range(block + count - 1, ext4_inode_table(sb, gdp),
4548 EXT4_SB(sb)->s_itb_per_group)) { 4536 EXT4_SB(sb)->s_itb_per_group)) {
4549 4537
4550 ext4_error(sb, __func__, 4538 ext4_error(sb, "Freeing blocks in system zone - "
4551 "Freeing blocks in system zone - "
4552 "Block = %llu, count = %lu", block, count); 4539 "Block = %llu, count = %lu", block, count);
4553 /* err = 0. ext4_std_error should be a no op */ 4540 /* err = 0. ext4_std_error should be a no op */
4554 goto error_return; 4541 goto error_return;
@@ -4646,7 +4633,7 @@ do_more:
4646 sb->s_dirt = 1; 4633 sb->s_dirt = 1;
4647error_return: 4634error_return:
4648 if (freed) 4635 if (freed)
4649 vfs_dq_free_block(inode, freed); 4636 dquot_free_block(inode, freed);
4650 brelse(bitmap_bh); 4637 brelse(bitmap_bh);
4651 ext4_std_error(sb, err); 4638 ext4_std_error(sb, err);
4652 if (ac) 4639 if (ac)