aboutsummaryrefslogtreecommitdiffstats
path: root/fs/ext4/mballoc.c
diff options
context:
space:
mode:
authorTheodore Ts'o <tytso@mit.edu>2011-09-09 18:48:51 -0400
committerTheodore Ts'o <tytso@mit.edu>2011-09-09 18:48:51 -0400
commit53accfa9f819c80056db6f03f9c5cfa4bcba1ed8 (patch)
treea68dcd8ea8d286e07d31d4541311819a0082f78c /fs/ext4/mballoc.c
parent3212a80a58062056bb922811071062be58d8fee1 (diff)
ext4: teach mballoc preallocation code about bigalloc clusters
In most of mballoc.c, we do everything in units of clusters, since the block allocation bitmaps and buddy bitmaps are all denominated in clusters. The one place where we do deal with absolute block numbers is in the code that handles the preallocation regions, since in the case of inode-based preallocation regions, the start of the preallocation region can't be relative to the beginning of the group. So this adds a bit of complexity, where pa_pstart and pa_lstart are block numbers, while pa_free, pa_len, and fe_len are denominated in units of clusters. Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
Diffstat (limited to 'fs/ext4/mballoc.c')
-rw-r--r--fs/ext4/mballoc.c95
1 files changed, 54 insertions, 41 deletions
diff --git a/fs/ext4/mballoc.c b/fs/ext4/mballoc.c
index 81e28657a3c2..8765f2512f13 100644
--- a/fs/ext4/mballoc.c
+++ b/fs/ext4/mballoc.c
@@ -70,8 +70,8 @@
70 * 70 *
71 * pa_lstart -> the logical start block for this prealloc space 71 * pa_lstart -> the logical start block for this prealloc space
72 * pa_pstart -> the physical start block for this prealloc space 72 * pa_pstart -> the physical start block for this prealloc space
73 * pa_len -> length for this prealloc space 73 * pa_len -> length for this prealloc space (in clusters)
74 * pa_free -> free space available in this prealloc space 74 * pa_free -> free space available in this prealloc space (in clusters)
75 * 75 *
76 * The inode preallocation space is used looking at the _logical_ start 76 * The inode preallocation space is used looking at the _logical_ start
77 * block. If only the logical file block falls within the range of prealloc 77 * block. If only the logical file block falls within the range of prealloc
@@ -459,7 +459,7 @@ static void mb_free_blocks_double(struct inode *inode, struct ext4_buddy *e4b,
459 ext4_fsblk_t blocknr; 459 ext4_fsblk_t blocknr;
460 460
461 blocknr = ext4_group_first_block_no(sb, e4b->bd_group); 461 blocknr = ext4_group_first_block_no(sb, e4b->bd_group);
462 blocknr += first + i; 462 blocknr += EXT4_C2B(EXT4_SB(sb), first + i);
463 ext4_grp_locked_error(sb, e4b->bd_group, 463 ext4_grp_locked_error(sb, e4b->bd_group,
464 inode ? inode->i_ino : 0, 464 inode ? inode->i_ino : 0,
465 blocknr, 465 blocknr,
@@ -734,7 +734,7 @@ void ext4_mb_generate_buddy(struct super_block *sb,
734 734
735 if (free != grp->bb_free) { 735 if (free != grp->bb_free) {
736 ext4_grp_locked_error(sb, group, 0, 0, 736 ext4_grp_locked_error(sb, group, 0, 0,
737 "%u blocks in bitmap, %u in gd", 737 "%u clusters in bitmap, %u in gd",
738 free, grp->bb_free); 738 free, grp->bb_free);
739 /* 739 /*
740 * If we intent to continue, we consider group descritor 740 * If we intent to continue, we consider group descritor
@@ -1339,7 +1339,7 @@ static void mb_free_blocks(struct inode *inode, struct ext4_buddy *e4b,
1339 ext4_fsblk_t blocknr; 1339 ext4_fsblk_t blocknr;
1340 1340
1341 blocknr = ext4_group_first_block_no(sb, e4b->bd_group); 1341 blocknr = ext4_group_first_block_no(sb, e4b->bd_group);
1342 blocknr += block; 1342 blocknr += EXT4_C2B(EXT4_SB(sb), block);
1343 ext4_grp_locked_error(sb, e4b->bd_group, 1343 ext4_grp_locked_error(sb, e4b->bd_group,
1344 inode ? inode->i_ino : 0, 1344 inode ? inode->i_ino : 0,
1345 blocknr, 1345 blocknr,
@@ -1831,7 +1831,7 @@ void ext4_mb_complex_scan_group(struct ext4_allocation_context *ac,
1831 * we have free blocks 1831 * we have free blocks
1832 */ 1832 */
1833 ext4_grp_locked_error(sb, e4b->bd_group, 0, 0, 1833 ext4_grp_locked_error(sb, e4b->bd_group, 0, 0,
1834 "%d free blocks as per " 1834 "%d free clusters as per "
1835 "group info. But bitmap says 0", 1835 "group info. But bitmap says 0",
1836 free); 1836 free);
1837 break; 1837 break;
@@ -1841,7 +1841,7 @@ void ext4_mb_complex_scan_group(struct ext4_allocation_context *ac,
1841 BUG_ON(ex.fe_len <= 0); 1841 BUG_ON(ex.fe_len <= 0);
1842 if (free < ex.fe_len) { 1842 if (free < ex.fe_len) {
1843 ext4_grp_locked_error(sb, e4b->bd_group, 0, 0, 1843 ext4_grp_locked_error(sb, e4b->bd_group, 0, 0,
1844 "%d free blocks as per " 1844 "%d free clusters as per "
1845 "group info. But got %d blocks", 1845 "group info. But got %d blocks",
1846 free, ex.fe_len); 1846 free, ex.fe_len);
1847 /* 1847 /*
@@ -2752,7 +2752,7 @@ void ext4_exit_mballoc(void)
2752 */ 2752 */
2753static noinline_for_stack int 2753static noinline_for_stack int
2754ext4_mb_mark_diskspace_used(struct ext4_allocation_context *ac, 2754ext4_mb_mark_diskspace_used(struct ext4_allocation_context *ac,
2755 handle_t *handle, unsigned int reserv_blks) 2755 handle_t *handle, unsigned int reserv_clstrs)
2756{ 2756{
2757 struct buffer_head *bitmap_bh = NULL; 2757 struct buffer_head *bitmap_bh = NULL;
2758 struct ext4_group_desc *gdp; 2758 struct ext4_group_desc *gdp;
@@ -2791,7 +2791,7 @@ ext4_mb_mark_diskspace_used(struct ext4_allocation_context *ac,
2791 2791
2792 block = ext4_grp_offs_to_block(sb, &ac->ac_b_ex); 2792 block = ext4_grp_offs_to_block(sb, &ac->ac_b_ex);
2793 2793
2794 len = ac->ac_b_ex.fe_len; 2794 len = EXT4_C2B(sbi, ac->ac_b_ex.fe_len);
2795 if (!ext4_data_block_valid(sbi, block, len)) { 2795 if (!ext4_data_block_valid(sbi, block, len)) {
2796 ext4_error(sb, "Allocating blocks %llu-%llu which overlap " 2796 ext4_error(sb, "Allocating blocks %llu-%llu which overlap "
2797 "fs metadata\n", block, block+len); 2797 "fs metadata\n", block, block+len);
@@ -2838,7 +2838,7 @@ ext4_mb_mark_diskspace_used(struct ext4_allocation_context *ac,
2838 */ 2838 */
2839 if (!(ac->ac_flags & EXT4_MB_DELALLOC_RESERVED)) 2839 if (!(ac->ac_flags & EXT4_MB_DELALLOC_RESERVED))
2840 /* release all the reserved blocks if non delalloc */ 2840 /* release all the reserved blocks if non delalloc */
2841 percpu_counter_sub(&sbi->s_dirtyblocks_counter, reserv_blks); 2841 percpu_counter_sub(&sbi->s_dirtyblocks_counter, reserv_clstrs);
2842 2842
2843 if (sbi->s_log_groups_per_flex) { 2843 if (sbi->s_log_groups_per_flex) {
2844 ext4_group_t flex_group = ext4_flex_group(sbi, 2844 ext4_group_t flex_group = ext4_flex_group(sbi,
@@ -2886,6 +2886,7 @@ static noinline_for_stack void
2886ext4_mb_normalize_request(struct ext4_allocation_context *ac, 2886ext4_mb_normalize_request(struct ext4_allocation_context *ac,
2887 struct ext4_allocation_request *ar) 2887 struct ext4_allocation_request *ar)
2888{ 2888{
2889 struct ext4_sb_info *sbi = EXT4_SB(ac->ac_sb);
2889 int bsbits, max; 2890 int bsbits, max;
2890 ext4_lblk_t end; 2891 ext4_lblk_t end;
2891 loff_t size, orig_size, start_off; 2892 loff_t size, orig_size, start_off;
@@ -2916,7 +2917,7 @@ ext4_mb_normalize_request(struct ext4_allocation_context *ac,
2916 2917
2917 /* first, let's learn actual file size 2918 /* first, let's learn actual file size
2918 * given current request is allocated */ 2919 * given current request is allocated */
2919 size = ac->ac_o_ex.fe_logical + ac->ac_o_ex.fe_len; 2920 size = ac->ac_o_ex.fe_logical + EXT4_C2B(sbi, ac->ac_o_ex.fe_len);
2920 size = size << bsbits; 2921 size = size << bsbits;
2921 if (size < i_size_read(ac->ac_inode)) 2922 if (size < i_size_read(ac->ac_inode))
2922 size = i_size_read(ac->ac_inode); 2923 size = i_size_read(ac->ac_inode);
@@ -2988,7 +2989,8 @@ ext4_mb_normalize_request(struct ext4_allocation_context *ac,
2988 continue; 2989 continue;
2989 } 2990 }
2990 2991
2991 pa_end = pa->pa_lstart + pa->pa_len; 2992 pa_end = pa->pa_lstart + EXT4_C2B(EXT4_SB(ac->ac_sb),
2993 pa->pa_len);
2992 2994
2993 /* PA must not overlap original request */ 2995 /* PA must not overlap original request */
2994 BUG_ON(!(ac->ac_o_ex.fe_logical >= pa_end || 2996 BUG_ON(!(ac->ac_o_ex.fe_logical >= pa_end ||
@@ -3018,9 +3020,11 @@ ext4_mb_normalize_request(struct ext4_allocation_context *ac,
3018 rcu_read_lock(); 3020 rcu_read_lock();
3019 list_for_each_entry_rcu(pa, &ei->i_prealloc_list, pa_inode_list) { 3021 list_for_each_entry_rcu(pa, &ei->i_prealloc_list, pa_inode_list) {
3020 ext4_lblk_t pa_end; 3022 ext4_lblk_t pa_end;
3023
3021 spin_lock(&pa->pa_lock); 3024 spin_lock(&pa->pa_lock);
3022 if (pa->pa_deleted == 0) { 3025 if (pa->pa_deleted == 0) {
3023 pa_end = pa->pa_lstart + pa->pa_len; 3026 pa_end = pa->pa_lstart + EXT4_C2B(EXT4_SB(ac->ac_sb),
3027 pa->pa_len);
3024 BUG_ON(!(start >= pa_end || end <= pa->pa_lstart)); 3028 BUG_ON(!(start >= pa_end || end <= pa->pa_lstart));
3025 } 3029 }
3026 spin_unlock(&pa->pa_lock); 3030 spin_unlock(&pa->pa_lock);
@@ -3043,7 +3047,7 @@ ext4_mb_normalize_request(struct ext4_allocation_context *ac,
3043 /* XXX: is it better to align blocks WRT to logical 3047 /* XXX: is it better to align blocks WRT to logical
3044 * placement or satisfy big request as is */ 3048 * placement or satisfy big request as is */
3045 ac->ac_g_ex.fe_logical = start; 3049 ac->ac_g_ex.fe_logical = start;
3046 ac->ac_g_ex.fe_len = size; 3050 ac->ac_g_ex.fe_len = EXT4_NUM_B2C(sbi, size);
3047 3051
3048 /* define goal start in order to merge */ 3052 /* define goal start in order to merge */
3049 if (ar->pright && (ar->lright == (start + size))) { 3053 if (ar->pright && (ar->lright == (start + size))) {
@@ -3112,14 +3116,16 @@ static void ext4_discard_allocated_blocks(struct ext4_allocation_context *ac)
3112static void ext4_mb_use_inode_pa(struct ext4_allocation_context *ac, 3116static void ext4_mb_use_inode_pa(struct ext4_allocation_context *ac,
3113 struct ext4_prealloc_space *pa) 3117 struct ext4_prealloc_space *pa)
3114{ 3118{
3119 struct ext4_sb_info *sbi = EXT4_SB(ac->ac_sb);
3115 ext4_fsblk_t start; 3120 ext4_fsblk_t start;
3116 ext4_fsblk_t end; 3121 ext4_fsblk_t end;
3117 int len; 3122 int len;
3118 3123
3119 /* found preallocated blocks, use them */ 3124 /* found preallocated blocks, use them */
3120 start = pa->pa_pstart + (ac->ac_o_ex.fe_logical - pa->pa_lstart); 3125 start = pa->pa_pstart + (ac->ac_o_ex.fe_logical - pa->pa_lstart);
3121 end = min(pa->pa_pstart + pa->pa_len, start + ac->ac_o_ex.fe_len); 3126 end = min(pa->pa_pstart + EXT4_C2B(sbi, pa->pa_len),
3122 len = end - start; 3127 start + EXT4_C2B(sbi, ac->ac_o_ex.fe_len));
3128 len = EXT4_NUM_B2C(sbi, end - start);
3123 ext4_get_group_no_and_offset(ac->ac_sb, start, &ac->ac_b_ex.fe_group, 3129 ext4_get_group_no_and_offset(ac->ac_sb, start, &ac->ac_b_ex.fe_group,
3124 &ac->ac_b_ex.fe_start); 3130 &ac->ac_b_ex.fe_start);
3125 ac->ac_b_ex.fe_len = len; 3131 ac->ac_b_ex.fe_len = len;
@@ -3127,7 +3133,7 @@ static void ext4_mb_use_inode_pa(struct ext4_allocation_context *ac,
3127 ac->ac_pa = pa; 3133 ac->ac_pa = pa;
3128 3134
3129 BUG_ON(start < pa->pa_pstart); 3135 BUG_ON(start < pa->pa_pstart);
3130 BUG_ON(start + len > pa->pa_pstart + pa->pa_len); 3136 BUG_ON(end > pa->pa_pstart + EXT4_C2B(sbi, pa->pa_len));
3131 BUG_ON(pa->pa_free < len); 3137 BUG_ON(pa->pa_free < len);
3132 pa->pa_free -= len; 3138 pa->pa_free -= len;
3133 3139
@@ -3193,6 +3199,7 @@ ext4_mb_check_group_pa(ext4_fsblk_t goal_block,
3193static noinline_for_stack int 3199static noinline_for_stack int
3194ext4_mb_use_preallocated(struct ext4_allocation_context *ac) 3200ext4_mb_use_preallocated(struct ext4_allocation_context *ac)
3195{ 3201{
3202 struct ext4_sb_info *sbi = EXT4_SB(ac->ac_sb);
3196 int order, i; 3203 int order, i;
3197 struct ext4_inode_info *ei = EXT4_I(ac->ac_inode); 3204 struct ext4_inode_info *ei = EXT4_I(ac->ac_inode);
3198 struct ext4_locality_group *lg; 3205 struct ext4_locality_group *lg;
@@ -3210,12 +3217,14 @@ ext4_mb_use_preallocated(struct ext4_allocation_context *ac)
3210 /* all fields in this condition don't change, 3217 /* all fields in this condition don't change,
3211 * so we can skip locking for them */ 3218 * so we can skip locking for them */
3212 if (ac->ac_o_ex.fe_logical < pa->pa_lstart || 3219 if (ac->ac_o_ex.fe_logical < pa->pa_lstart ||
3213 ac->ac_o_ex.fe_logical >= pa->pa_lstart + pa->pa_len) 3220 ac->ac_o_ex.fe_logical >= (pa->pa_lstart +
3221 EXT4_C2B(sbi, pa->pa_len)))
3214 continue; 3222 continue;
3215 3223
3216 /* non-extent files can't have physical blocks past 2^32 */ 3224 /* non-extent files can't have physical blocks past 2^32 */
3217 if (!(ext4_test_inode_flag(ac->ac_inode, EXT4_INODE_EXTENTS)) && 3225 if (!(ext4_test_inode_flag(ac->ac_inode, EXT4_INODE_EXTENTS)) &&
3218 pa->pa_pstart + pa->pa_len > EXT4_MAX_BLOCK_FILE_PHYS) 3226 (pa->pa_pstart + EXT4_C2B(sbi, pa->pa_len) >
3227 EXT4_MAX_BLOCK_FILE_PHYS))
3219 continue; 3228 continue;
3220 3229
3221 /* found preallocated blocks, use them */ 3230 /* found preallocated blocks, use them */
@@ -3412,6 +3421,7 @@ static noinline_for_stack int
3412ext4_mb_new_inode_pa(struct ext4_allocation_context *ac) 3421ext4_mb_new_inode_pa(struct ext4_allocation_context *ac)
3413{ 3422{
3414 struct super_block *sb = ac->ac_sb; 3423 struct super_block *sb = ac->ac_sb;
3424 struct ext4_sb_info *sbi = EXT4_SB(sb);
3415 struct ext4_prealloc_space *pa; 3425 struct ext4_prealloc_space *pa;
3416 struct ext4_group_info *grp; 3426 struct ext4_group_info *grp;
3417 struct ext4_inode_info *ei; 3427 struct ext4_inode_info *ei;
@@ -3443,16 +3453,18 @@ ext4_mb_new_inode_pa(struct ext4_allocation_context *ac)
3443 winl = ac->ac_o_ex.fe_logical - ac->ac_g_ex.fe_logical; 3453 winl = ac->ac_o_ex.fe_logical - ac->ac_g_ex.fe_logical;
3444 3454
3445 /* also, we should cover whole original request */ 3455 /* also, we should cover whole original request */
3446 wins = ac->ac_b_ex.fe_len - ac->ac_o_ex.fe_len; 3456 wins = EXT4_C2B(sbi, ac->ac_b_ex.fe_len - ac->ac_o_ex.fe_len);
3447 3457
3448 /* the smallest one defines real window */ 3458 /* the smallest one defines real window */
3449 win = min(winl, wins); 3459 win = min(winl, wins);
3450 3460
3451 offs = ac->ac_o_ex.fe_logical % ac->ac_b_ex.fe_len; 3461 offs = ac->ac_o_ex.fe_logical %
3462 EXT4_C2B(sbi, ac->ac_b_ex.fe_len);
3452 if (offs && offs < win) 3463 if (offs && offs < win)
3453 win = offs; 3464 win = offs;
3454 3465
3455 ac->ac_b_ex.fe_logical = ac->ac_o_ex.fe_logical - win; 3466 ac->ac_b_ex.fe_logical = ac->ac_o_ex.fe_logical -
3467 EXT4_B2C(sbi, win);
3456 BUG_ON(ac->ac_o_ex.fe_logical < ac->ac_b_ex.fe_logical); 3468 BUG_ON(ac->ac_o_ex.fe_logical < ac->ac_b_ex.fe_logical);
3457 BUG_ON(ac->ac_o_ex.fe_len > ac->ac_b_ex.fe_len); 3469 BUG_ON(ac->ac_o_ex.fe_len > ac->ac_b_ex.fe_len);
3458 } 3470 }
@@ -3477,7 +3489,7 @@ ext4_mb_new_inode_pa(struct ext4_allocation_context *ac)
3477 trace_ext4_mb_new_inode_pa(ac, pa); 3489 trace_ext4_mb_new_inode_pa(ac, pa);
3478 3490
3479 ext4_mb_use_inode_pa(ac, pa); 3491 ext4_mb_use_inode_pa(ac, pa);
3480 atomic_add(pa->pa_free, &EXT4_SB(sb)->s_mb_preallocated); 3492 atomic_add(pa->pa_free, &sbi->s_mb_preallocated);
3481 3493
3482 ei = EXT4_I(ac->ac_inode); 3494 ei = EXT4_I(ac->ac_inode);
3483 grp = ext4_get_group_info(sb, ac->ac_b_ex.fe_group); 3495 grp = ext4_get_group_info(sb, ac->ac_b_ex.fe_group);
@@ -3592,7 +3604,7 @@ ext4_mb_release_inode_pa(struct ext4_buddy *e4b, struct buffer_head *bitmap_bh,
3592 3604
3593 BUG_ON(pa->pa_deleted == 0); 3605 BUG_ON(pa->pa_deleted == 0);
3594 ext4_get_group_no_and_offset(sb, pa->pa_pstart, &group, &bit); 3606 ext4_get_group_no_and_offset(sb, pa->pa_pstart, &group, &bit);
3595 grp_blk_start = pa->pa_pstart - bit; 3607 grp_blk_start = pa->pa_pstart - EXT4_C2B(sbi, bit);
3596 BUG_ON(group != e4b->bd_group && pa->pa_len != 0); 3608 BUG_ON(group != e4b->bd_group && pa->pa_len != 0);
3597 end = bit + pa->pa_len; 3609 end = bit + pa->pa_len;
3598 3610
@@ -3607,7 +3619,8 @@ ext4_mb_release_inode_pa(struct ext4_buddy *e4b, struct buffer_head *bitmap_bh,
3607 free += next - bit; 3619 free += next - bit;
3608 3620
3609 trace_ext4_mballoc_discard(sb, NULL, group, bit, next - bit); 3621 trace_ext4_mballoc_discard(sb, NULL, group, bit, next - bit);
3610 trace_ext4_mb_release_inode_pa(pa, grp_blk_start + bit, 3622 trace_ext4_mb_release_inode_pa(pa, (grp_blk_start +
3623 EXT4_C2B(sbi, bit)),
3611 next - bit); 3624 next - bit);
3612 mb_free_blocks(pa->pa_inode, e4b, bit, next - bit); 3625 mb_free_blocks(pa->pa_inode, e4b, bit, next - bit);
3613 bit = next + 1; 3626 bit = next + 1;
@@ -3958,7 +3971,7 @@ static void ext4_mb_group_or_file(struct ext4_allocation_context *ac)
3958 if (unlikely(ac->ac_flags & EXT4_MB_HINT_GOAL_ONLY)) 3971 if (unlikely(ac->ac_flags & EXT4_MB_HINT_GOAL_ONLY))
3959 return; 3972 return;
3960 3973
3961 size = ac->ac_o_ex.fe_logical + ac->ac_o_ex.fe_len; 3974 size = ac->ac_o_ex.fe_logical + EXT4_C2B(sbi, ac->ac_o_ex.fe_len);
3962 isize = (i_size_read(ac->ac_inode) + ac->ac_sb->s_blocksize - 1) 3975 isize = (i_size_read(ac->ac_inode) + ac->ac_sb->s_blocksize - 1)
3963 >> bsbits; 3976 >> bsbits;
3964 3977
@@ -4019,18 +4032,15 @@ ext4_mb_initialize_context(struct ext4_allocation_context *ac,
4019 4032
4020 /* set up allocation goals */ 4033 /* set up allocation goals */
4021 memset(ac, 0, sizeof(struct ext4_allocation_context)); 4034 memset(ac, 0, sizeof(struct ext4_allocation_context));
4022 ac->ac_b_ex.fe_logical = ar->logical; 4035 ac->ac_b_ex.fe_logical = ar->logical & ~(sbi->s_cluster_ratio - 1);
4023 ac->ac_status = AC_STATUS_CONTINUE; 4036 ac->ac_status = AC_STATUS_CONTINUE;
4024 ac->ac_sb = sb; 4037 ac->ac_sb = sb;
4025 ac->ac_inode = ar->inode; 4038 ac->ac_inode = ar->inode;
4026 ac->ac_o_ex.fe_logical = ar->logical; 4039 ac->ac_o_ex.fe_logical = ac->ac_b_ex.fe_logical;
4027 ac->ac_o_ex.fe_group = group; 4040 ac->ac_o_ex.fe_group = group;
4028 ac->ac_o_ex.fe_start = block; 4041 ac->ac_o_ex.fe_start = block;
4029 ac->ac_o_ex.fe_len = len; 4042 ac->ac_o_ex.fe_len = len;
4030 ac->ac_g_ex.fe_logical = ar->logical; 4043 ac->ac_g_ex = ac->ac_o_ex;
4031 ac->ac_g_ex.fe_group = group;
4032 ac->ac_g_ex.fe_start = block;
4033 ac->ac_g_ex.fe_len = len;
4034 ac->ac_flags = ar->flags; 4044 ac->ac_flags = ar->flags;
4035 4045
4036 /* we have to define context: we'll we work with a file or 4046 /* we have to define context: we'll we work with a file or
@@ -4182,13 +4192,14 @@ static void ext4_mb_add_n_trim(struct ext4_allocation_context *ac)
4182 */ 4192 */
4183static int ext4_mb_release_context(struct ext4_allocation_context *ac) 4193static int ext4_mb_release_context(struct ext4_allocation_context *ac)
4184{ 4194{
4195 struct ext4_sb_info *sbi = EXT4_SB(ac->ac_sb);
4185 struct ext4_prealloc_space *pa = ac->ac_pa; 4196 struct ext4_prealloc_space *pa = ac->ac_pa;
4186 if (pa) { 4197 if (pa) {
4187 if (pa->pa_type == MB_GROUP_PA) { 4198 if (pa->pa_type == MB_GROUP_PA) {
4188 /* see comment in ext4_mb_use_group_pa() */ 4199 /* see comment in ext4_mb_use_group_pa() */
4189 spin_lock(&pa->pa_lock); 4200 spin_lock(&pa->pa_lock);
4190 pa->pa_pstart += ac->ac_b_ex.fe_len; 4201 pa->pa_pstart += EXT4_C2B(sbi, ac->ac_b_ex.fe_len);
4191 pa->pa_lstart += ac->ac_b_ex.fe_len; 4202 pa->pa_lstart += EXT4_C2B(sbi, ac->ac_b_ex.fe_len);
4192 pa->pa_free -= ac->ac_b_ex.fe_len; 4203 pa->pa_free -= ac->ac_b_ex.fe_len;
4193 pa->pa_len -= ac->ac_b_ex.fe_len; 4204 pa->pa_len -= ac->ac_b_ex.fe_len;
4194 spin_unlock(&pa->pa_lock); 4205 spin_unlock(&pa->pa_lock);
@@ -4249,7 +4260,7 @@ ext4_fsblk_t ext4_mb_new_blocks(handle_t *handle,
4249 struct super_block *sb; 4260 struct super_block *sb;
4250 ext4_fsblk_t block = 0; 4261 ext4_fsblk_t block = 0;
4251 unsigned int inquota = 0; 4262 unsigned int inquota = 0;
4252 unsigned int reserv_blks = 0; 4263 unsigned int reserv_clstrs = 0;
4253 4264
4254 sb = ar->inode->i_sb; 4265 sb = ar->inode->i_sb;
4255 sbi = EXT4_SB(sb); 4266 sbi = EXT4_SB(sb);
@@ -4279,12 +4290,14 @@ ext4_fsblk_t ext4_mb_new_blocks(handle_t *handle,
4279 *errp = -ENOSPC; 4290 *errp = -ENOSPC;
4280 return 0; 4291 return 0;
4281 } 4292 }
4282 reserv_blks = ar->len; 4293 reserv_clstrs = ar->len;
4283 if (ar->flags & EXT4_MB_USE_ROOT_BLOCKS) { 4294 if (ar->flags & EXT4_MB_USE_ROOT_BLOCKS) {
4284 dquot_alloc_block_nofail(ar->inode, ar->len); 4295 dquot_alloc_block_nofail(ar->inode,
4296 EXT4_C2B(sbi, ar->len));
4285 } else { 4297 } else {
4286 while (ar->len && 4298 while (ar->len &&
4287 dquot_alloc_block(ar->inode, ar->len)) { 4299 dquot_alloc_block(ar->inode,
4300 EXT4_C2B(sbi, ar->len))) {
4288 4301
4289 ar->flags |= EXT4_MB_HINT_NOPREALLOC; 4302 ar->flags |= EXT4_MB_HINT_NOPREALLOC;
4290 ar->len--; 4303 ar->len--;
@@ -4328,7 +4341,7 @@ repeat:
4328 ext4_mb_new_preallocation(ac); 4341 ext4_mb_new_preallocation(ac);
4329 } 4342 }
4330 if (likely(ac->ac_status == AC_STATUS_FOUND)) { 4343 if (likely(ac->ac_status == AC_STATUS_FOUND)) {
4331 *errp = ext4_mb_mark_diskspace_used(ac, handle, reserv_blks); 4344 *errp = ext4_mb_mark_diskspace_used(ac, handle, reserv_clstrs);
4332 if (*errp == -EAGAIN) { 4345 if (*errp == -EAGAIN) {
4333 /* 4346 /*
4334 * drop the reference that we took 4347 * drop the reference that we took
@@ -4364,13 +4377,13 @@ out:
4364 if (ac) 4377 if (ac)
4365 kmem_cache_free(ext4_ac_cachep, ac); 4378 kmem_cache_free(ext4_ac_cachep, ac);
4366 if (inquota && ar->len < inquota) 4379 if (inquota && ar->len < inquota)
4367 dquot_free_block(ar->inode, inquota - ar->len); 4380 dquot_free_block(ar->inode, EXT4_C2B(sbi, inquota - ar->len));
4368 if (!ar->len) { 4381 if (!ar->len) {
4369 if (!ext4_test_inode_state(ar->inode, 4382 if (!ext4_test_inode_state(ar->inode,
4370 EXT4_STATE_DELALLOC_RESERVED)) 4383 EXT4_STATE_DELALLOC_RESERVED))
4371 /* release all the reserved blocks if non delalloc */ 4384 /* release all the reserved blocks if non delalloc */
4372 percpu_counter_sub(&sbi->s_dirtyblocks_counter, 4385 percpu_counter_sub(&sbi->s_dirtyblocks_counter,
4373 reserv_blks); 4386 reserv_clstrs);
4374 } 4387 }
4375 4388
4376 trace_ext4_allocate_blocks(ar, (unsigned long long)block); 4389 trace_ext4_allocate_blocks(ar, (unsigned long long)block);