btrfs: Set relative data on clear btrfs_block_group_cache->pinned
v3 cover btrfs: Set relative data on clear btrfs_block_group_cache->pinned
From: Zhao Lei <[email protected]>
Changelog v1->v2:
[PATCH 2/2] btrfs: add WARN_ON() to check is space_info op current
Put WARN_ON()s under the ENOSPC_DEBUG mount option. Suggested by: David Sterba <[email protected]>
Changelog v1->v2:
drop patch of:
Remove BUG_ON() when failed searching block_group_cache in unpin_extent_range() because Filipe Manana <[email protected]> already fixed it with better way.
Zhao Lei (2):
btrfs: Set relative data on clear btrfs_block_group_cache->pinned
btrfs: add WARN_ON() to check is space_info op current
fs/btrfs/extent-tree.c | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+)
Signature · 1 line
1.8.5.1
PATCH v3 1/2 btrfs: Set relative data on clear btrfs_block_group_cache->pinned
From: Zhao Lei <[email protected]>
Bug1:
space_info->bytes_readonly was set to very large(negative) value in btrfs_remove_block_group().
Reason:
Current code set block_group_cache->pinned = 0 in btrfs_delete_unused_bgs(), but above space was not counted to space_info->bytes_readonly.
Then in btrfs_remove_block_group():
block_group->space_info->bytes_readonly -= block_group->key.offset;
We can see following value in trace:
btrfs_remove_block_group: pid=2677 comm=btrfs-cleaner WARNING: bytes_readonly=12582912, key.offset=134217728Bug2:
space_info->total_bytes_pinned grow to value larger than fs size. In a 1.2G fs, we can get following trace log:
at first:
ZL_DEBUG: add_pinned_bytes: pid=2710 comm=sync change total_bytes_pinned flags=1 869793792 + 95944704 = 965738496
after some op:
ZL_DEBUG: add_pinned_bytes: pid=2770 comm=sync change total_bytes_pinned flags=1 1780178944 + 95944704 = 1876123648
after some op:
ZL_DEBUG: add_pinned_bytes: pid=3193 comm=sync change total_bytes_pinned flags=1 2924568576 + 95551488 = 3020120064...
Reason:
Similar to bug1, we also need to adjust space_info->total_bytes_pinned in above code block.
--- fs/btrfs/extent-tree.c | 10 ++++++++++ 1 file changed, 10 insertions(+)
fs/btrfs/extent-tree.c +10 -0
@@ -9605,8 +9605,18 @@ void btrfs_delete_unused_bgs(struct btrfs_fs_info *fs_info)mutex_unlock (&fs_info->unused_bg_unpin_mutex);/* Reset pinned so btrfs_put_block_group doesn't complain */ +spin_lock (&space_info->lock); +spin_lock (&block_group->lock); + + space_info->bytes_pinned -= block_group->pinned; + space_info->bytes_readonly += block_group->pinned; +percpu_counter_add (&space_info->total_bytes_pinned, + -block_group->pinned); block_group->pinned =0 ; +spin_unlock (&block_group->lock); +spin_unlock (&space_info->lock); +/* * Btrfs_remove_chunk will abort the transaction if things go * horribly wrong.
Signature · 1 line
1.8.5.1
PATCH v3 2/2 btrfs: add WARN_ON() to check is space_info op current
In reply to ZhaoleiFrom: Zhao Lei <[email protected]>
space_info's value calculation is some complex and easy to cause bug, add WARN_ON() to help debug.
Changelog v1->v2:
Put WARN_ON()s under the ENOSPC_DEBUG mount option. Suggested by: David Sterba <[email protected]>
--- fs/btrfs/extent-tree.c | 10 ++++++++++ 1 file changed, 10 insertions(+)
fs/btrfs/extent-tree.c +10 -0
@@ -9415,9 +9415,19 @@ int btrfs_remove_block_group(struct btrfs_trans_handle *trans,spin_lock (&block_group->space_info->lock);list_del_init (&block_group->ro_list); + +if (btrfs_test_opt (root,ENOSPC_DEBUG )) { +WARN_ON (block_group->space_info->total_bytes + < block_group->key.offset); +WARN_ON (block_group->space_info->bytes_readonly + < block_group->key.offset); +WARN_ON (block_group->space_info->disk_total + < block_group->key.offset * factor); + } block_group->space_info->total_bytes -= block_group->key.offset; block_group->space_info->bytes_readonly -= block_group->key.offset; block_group->space_info->disk_total -= block_group->key.offset * factor; +spin_unlock (&block_group->space_info->lock);memcpy (&key, &block_group->key,sizeof (key));
Signature · 1 line
1.8.5.1