Btrfs: always account pinned bytes when dropping a tree block ref
authorOmar Sandoval <osandov@fb.com>
Tue, 6 Jun 2017 23:45:29 +0000 (16:45 -0700)
committerDavid Sterba <dsterba@suse.com>
Thu, 29 Jun 2017 18:17:01 +0000 (20:17 +0200)
commit0a16c7d7aecfae8987197e50116ebfc338cbe0a2
tree45e7f32dd3253b5604db57d0fe198e6cef81d750
parent4da8b76d347bcae951f89522a040c36d9fc9f3b3
Btrfs: always account pinned bytes when dropping a tree block ref

Currently, we only increment total_bytes_pinned in
btrfs_free_tree_block() when dropping the last reference on the block.
However, when the delayed ref is run later, we will decrement
total_bytes_pinned regardless of whether it was the last reference or
not. This causes the counter to underflow when the reference we dropped
was not the last reference. Fix it by incrementing the counter
unconditionally, which is what btrfs_free_extent() does. This makes
total_bytes_pinned an overestimate when references to shared extents are
dropped, but in the worst case this will just make us try to commit the
transaction to try to free up space and find we didn't free enough.

Signed-off-by: Omar Sandoval <osandov@fb.com>
Tested-by: Holger Hoffstätte <holger@applied-asynchrony.com>
Reviewed-by: Liu Bo <bo.li.liu@oracle.com>
Signed-off-by: David Sterba <dsterba@suse.com>
fs/btrfs/extent-tree.c