aboutsummaryrefslogtreecommitdiffstats
path: root/fs/btrfs/extent-tree.c
diff options
context:
space:
mode:
Diffstat (limited to 'fs/btrfs/extent-tree.c')
-rw-r--r--fs/btrfs/extent-tree.c51
1 files changed, 32 insertions, 19 deletions
diff --git a/fs/btrfs/extent-tree.c b/fs/btrfs/extent-tree.c
index 283af7a676a3..37e0a800d34e 100644
--- a/fs/btrfs/extent-tree.c
+++ b/fs/btrfs/extent-tree.c
@@ -3312,7 +3312,8 @@ commit_trans:
3312 } 3312 }
3313 data_sinfo->bytes_may_use += bytes; 3313 data_sinfo->bytes_may_use += bytes;
3314 trace_btrfs_space_reservation(root->fs_info, "space_info", 3314 trace_btrfs_space_reservation(root->fs_info, "space_info",
3315 (u64)data_sinfo, bytes, 1); 3315 (u64)(unsigned long)data_sinfo,
3316 bytes, 1);
3316 spin_unlock(&data_sinfo->lock); 3317 spin_unlock(&data_sinfo->lock);
3317 3318
3318 return 0; 3319 return 0;
@@ -3333,7 +3334,8 @@ void btrfs_free_reserved_data_space(struct inode *inode, u64 bytes)
3333 spin_lock(&data_sinfo->lock); 3334 spin_lock(&data_sinfo->lock);
3334 data_sinfo->bytes_may_use -= bytes; 3335 data_sinfo->bytes_may_use -= bytes;
3335 trace_btrfs_space_reservation(root->fs_info, "space_info", 3336 trace_btrfs_space_reservation(root->fs_info, "space_info",
3336 (u64)data_sinfo, bytes, 0); 3337 (u64)(unsigned long)data_sinfo,
3338 bytes, 0);
3337 spin_unlock(&data_sinfo->lock); 3339 spin_unlock(&data_sinfo->lock);
3338} 3340}
3339 3341
@@ -3611,12 +3613,15 @@ static int may_commit_transaction(struct btrfs_root *root,
3611 if (space_info != delayed_rsv->space_info) 3613 if (space_info != delayed_rsv->space_info)
3612 return -ENOSPC; 3614 return -ENOSPC;
3613 3615
3616 spin_lock(&space_info->lock);
3614 spin_lock(&delayed_rsv->lock); 3617 spin_lock(&delayed_rsv->lock);
3615 if (delayed_rsv->size < bytes) { 3618 if (space_info->bytes_pinned + delayed_rsv->size < bytes) {
3616 spin_unlock(&delayed_rsv->lock); 3619 spin_unlock(&delayed_rsv->lock);
3620 spin_unlock(&space_info->lock);
3617 return -ENOSPC; 3621 return -ENOSPC;
3618 } 3622 }
3619 spin_unlock(&delayed_rsv->lock); 3623 spin_unlock(&delayed_rsv->lock);
3624 spin_unlock(&space_info->lock);
3620 3625
3621commit: 3626commit:
3622 trans = btrfs_join_transaction(root); 3627 trans = btrfs_join_transaction(root);
@@ -3695,9 +3700,9 @@ again:
3695 if (used + orig_bytes <= space_info->total_bytes) { 3700 if (used + orig_bytes <= space_info->total_bytes) {
3696 space_info->bytes_may_use += orig_bytes; 3701 space_info->bytes_may_use += orig_bytes;
3697 trace_btrfs_space_reservation(root->fs_info, 3702 trace_btrfs_space_reservation(root->fs_info,
3698 "space_info", 3703 "space_info",
3699 (u64)space_info, 3704 (u64)(unsigned long)space_info,
3700 orig_bytes, 1); 3705 orig_bytes, 1);
3701 ret = 0; 3706 ret = 0;
3702 } else { 3707 } else {
3703 /* 3708 /*
@@ -3766,9 +3771,9 @@ again:
3766 if (used + num_bytes < space_info->total_bytes + avail) { 3771 if (used + num_bytes < space_info->total_bytes + avail) {
3767 space_info->bytes_may_use += orig_bytes; 3772 space_info->bytes_may_use += orig_bytes;
3768 trace_btrfs_space_reservation(root->fs_info, 3773 trace_btrfs_space_reservation(root->fs_info,
3769 "space_info", 3774 "space_info",
3770 (u64)space_info, 3775 (u64)(unsigned long)space_info,
3771 orig_bytes, 1); 3776 orig_bytes, 1);
3772 ret = 0; 3777 ret = 0;
3773 } else { 3778 } else {
3774 wait_ordered = true; 3779 wait_ordered = true;
@@ -3913,8 +3918,8 @@ static void block_rsv_release_bytes(struct btrfs_fs_info *fs_info,
3913 spin_lock(&space_info->lock); 3918 spin_lock(&space_info->lock);
3914 space_info->bytes_may_use -= num_bytes; 3919 space_info->bytes_may_use -= num_bytes;
3915 trace_btrfs_space_reservation(fs_info, "space_info", 3920 trace_btrfs_space_reservation(fs_info, "space_info",
3916 (u64)space_info, 3921 (u64)(unsigned long)space_info,
3917 num_bytes, 0); 3922 num_bytes, 0);
3918 space_info->reservation_progress++; 3923 space_info->reservation_progress++;
3919 spin_unlock(&space_info->lock); 3924 spin_unlock(&space_info->lock);
3920 } 3925 }
@@ -4105,7 +4110,7 @@ static u64 calc_global_metadata_size(struct btrfs_fs_info *fs_info)
4105 num_bytes += div64_u64(data_used + meta_used, 50); 4110 num_bytes += div64_u64(data_used + meta_used, 50);
4106 4111
4107 if (num_bytes * 3 > meta_used) 4112 if (num_bytes * 3 > meta_used)
4108 num_bytes = div64_u64(meta_used, 3); 4113 num_bytes = div64_u64(meta_used, 3) * 2;
4109 4114
4110 return ALIGN(num_bytes, fs_info->extent_root->leafsize << 10); 4115 return ALIGN(num_bytes, fs_info->extent_root->leafsize << 10);
4111} 4116}
@@ -4132,14 +4137,14 @@ static void update_global_block_rsv(struct btrfs_fs_info *fs_info)
4132 block_rsv->reserved += num_bytes; 4137 block_rsv->reserved += num_bytes;
4133 sinfo->bytes_may_use += num_bytes; 4138 sinfo->bytes_may_use += num_bytes;
4134 trace_btrfs_space_reservation(fs_info, "space_info", 4139 trace_btrfs_space_reservation(fs_info, "space_info",
4135 (u64)sinfo, num_bytes, 1); 4140 (u64)(unsigned long)sinfo, num_bytes, 1);
4136 } 4141 }
4137 4142
4138 if (block_rsv->reserved >= block_rsv->size) { 4143 if (block_rsv->reserved >= block_rsv->size) {
4139 num_bytes = block_rsv->reserved - block_rsv->size; 4144 num_bytes = block_rsv->reserved - block_rsv->size;
4140 sinfo->bytes_may_use -= num_bytes; 4145 sinfo->bytes_may_use -= num_bytes;
4141 trace_btrfs_space_reservation(fs_info, "space_info", 4146 trace_btrfs_space_reservation(fs_info, "space_info",
4142 (u64)sinfo, num_bytes, 0); 4147 (u64)(unsigned long)sinfo, num_bytes, 0);
4143 sinfo->reservation_progress++; 4148 sinfo->reservation_progress++;
4144 block_rsv->reserved = block_rsv->size; 4149 block_rsv->reserved = block_rsv->size;
4145 block_rsv->full = 1; 4150 block_rsv->full = 1;
@@ -4192,7 +4197,8 @@ void btrfs_trans_release_metadata(struct btrfs_trans_handle *trans,
4192 if (!trans->bytes_reserved) 4197 if (!trans->bytes_reserved)
4193 return; 4198 return;
4194 4199
4195 trace_btrfs_space_reservation(root->fs_info, "transaction", (u64)trans, 4200 trace_btrfs_space_reservation(root->fs_info, "transaction",
4201 (u64)(unsigned long)trans,
4196 trans->bytes_reserved, 0); 4202 trans->bytes_reserved, 0);
4197 btrfs_block_rsv_release(root, trans->block_rsv, trans->bytes_reserved); 4203 btrfs_block_rsv_release(root, trans->block_rsv, trans->bytes_reserved);
4198 trans->bytes_reserved = 0; 4204 trans->bytes_reserved = 0;
@@ -4710,9 +4716,9 @@ static int btrfs_update_reserved_bytes(struct btrfs_block_group_cache *cache,
4710 space_info->bytes_reserved += num_bytes; 4716 space_info->bytes_reserved += num_bytes;
4711 if (reserve == RESERVE_ALLOC) { 4717 if (reserve == RESERVE_ALLOC) {
4712 trace_btrfs_space_reservation(cache->fs_info, 4718 trace_btrfs_space_reservation(cache->fs_info,
4713 "space_info", 4719 "space_info",
4714 (u64)space_info, 4720 (u64)(unsigned long)space_info,
4715 num_bytes, 0); 4721 num_bytes, 0);
4716 space_info->bytes_may_use -= num_bytes; 4722 space_info->bytes_may_use -= num_bytes;
4717 } 4723 }
4718 } 4724 }
@@ -7886,9 +7892,16 @@ int btrfs_trim_fs(struct btrfs_root *root, struct fstrim_range *range)
7886 u64 start; 7892 u64 start;
7887 u64 end; 7893 u64 end;
7888 u64 trimmed = 0; 7894 u64 trimmed = 0;
7895 u64 total_bytes = btrfs_super_total_bytes(fs_info->super_copy);
7889 int ret = 0; 7896 int ret = 0;
7890 7897
7891 cache = btrfs_lookup_block_group(fs_info, range->start); 7898 /*
7899 * try to trim all FS space, our block group may start from non-zero.
7900 */
7901 if (range->len == total_bytes)
7902 cache = btrfs_lookup_first_block_group(fs_info, range->start);
7903 else
7904 cache = btrfs_lookup_block_group(fs_info, range->start);
7892 7905
7893 while (cache) { 7906 while (cache) {
7894 if (cache->key.objectid >= (range->start + range->len)) { 7907 if (cache->key.objectid >= (range->start + range->len)) {