Commit e2907c1a authored by Lu Fengqi's avatar Lu Fengqi Committed by David Sterba

btrfs: extent-tree: Detect bytes_pinned underflow earlier

Introduce a new wrapper update_bytes_pinned to replace open coded
bytes_pinned modifiers. Now the underflows of space_info::bytes_pinned
get detected and reported.
Reviewed-by: default avatarJosef Bacik <josef@toxicpanda.com>
Signed-off-by: default avatarLu Fengqi <lufq.fnst@cn.fujitsu.com>
Signed-off-by: default avatarDavid Sterba <dsterba@suse.com>
parent 9f9b8e8d
...@@ -67,6 +67,7 @@ static inline void update_##name(struct btrfs_space_info *sinfo, \ ...@@ -67,6 +67,7 @@ static inline void update_##name(struct btrfs_space_info *sinfo, \
} }
DECLARE_SPACE_INFO_UPDATE(bytes_may_use); DECLARE_SPACE_INFO_UPDATE(bytes_may_use);
DECLARE_SPACE_INFO_UPDATE(bytes_pinned);
static int __btrfs_free_extent(struct btrfs_trans_handle *trans, static int __btrfs_free_extent(struct btrfs_trans_handle *trans,
struct btrfs_delayed_ref_node *node, u64 parent, struct btrfs_delayed_ref_node *node, u64 parent,
...@@ -6165,7 +6166,7 @@ static int update_block_group(struct btrfs_trans_handle *trans, ...@@ -6165,7 +6166,7 @@ static int update_block_group(struct btrfs_trans_handle *trans,
old_val -= num_bytes; old_val -= num_bytes;
btrfs_set_block_group_used(&cache->item, old_val); btrfs_set_block_group_used(&cache->item, old_val);
cache->pinned += num_bytes; cache->pinned += num_bytes;
cache->space_info->bytes_pinned += num_bytes; update_bytes_pinned(cache->space_info, num_bytes);
cache->space_info->bytes_used -= num_bytes; cache->space_info->bytes_used -= num_bytes;
cache->space_info->disk_used -= num_bytes * factor; cache->space_info->disk_used -= num_bytes * factor;
spin_unlock(&cache->lock); spin_unlock(&cache->lock);
...@@ -6236,7 +6237,7 @@ static int pin_down_extent(struct btrfs_fs_info *fs_info, ...@@ -6236,7 +6237,7 @@ static int pin_down_extent(struct btrfs_fs_info *fs_info,
spin_lock(&cache->space_info->lock); spin_lock(&cache->space_info->lock);
spin_lock(&cache->lock); spin_lock(&cache->lock);
cache->pinned += num_bytes; cache->pinned += num_bytes;
cache->space_info->bytes_pinned += num_bytes; update_bytes_pinned(cache->space_info, num_bytes);
if (reserved) { if (reserved) {
cache->reserved -= num_bytes; cache->reserved -= num_bytes;
cache->space_info->bytes_reserved -= num_bytes; cache->space_info->bytes_reserved -= num_bytes;
...@@ -6601,7 +6602,7 @@ static int unpin_extent_range(struct btrfs_fs_info *fs_info, ...@@ -6601,7 +6602,7 @@ static int unpin_extent_range(struct btrfs_fs_info *fs_info,
spin_lock(&space_info->lock); spin_lock(&space_info->lock);
spin_lock(&cache->lock); spin_lock(&cache->lock);
cache->pinned -= len; cache->pinned -= len;
space_info->bytes_pinned -= len; update_bytes_pinned(space_info, -len);
trace_btrfs_space_reservation(fs_info, "pinned", trace_btrfs_space_reservation(fs_info, "pinned",
space_info->flags, len, 0); space_info->flags, len, 0);
...@@ -10712,7 +10713,7 @@ void btrfs_delete_unused_bgs(struct btrfs_fs_info *fs_info) ...@@ -10712,7 +10713,7 @@ void btrfs_delete_unused_bgs(struct btrfs_fs_info *fs_info)
spin_lock(&space_info->lock); spin_lock(&space_info->lock);
spin_lock(&block_group->lock); spin_lock(&block_group->lock);
space_info->bytes_pinned -= block_group->pinned; update_bytes_pinned(space_info, -block_group->pinned);
space_info->bytes_readonly += block_group->pinned; space_info->bytes_readonly += block_group->pinned;
percpu_counter_add_batch(&space_info->total_bytes_pinned, percpu_counter_add_batch(&space_info->total_bytes_pinned,
-block_group->pinned, -block_group->pinned,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment