Skip to content

Commit

Permalink
Btrfs: always account pinned bytes when dropping a tree block ref
Browse files Browse the repository at this point in the history
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 <[email protected]>
Tested-by: Holger Hoffstätte <[email protected]>
Reviewed-by: Liu Bo <[email protected]>
Signed-off-by: David Sterba <[email protected]>
  • Loading branch information
osandov authored and kdave committed Jun 29, 2017
1 parent 4da8b76 commit 0a16c7d
Showing 1 changed file with 8 additions and 9 deletions.
17 changes: 8 additions & 9 deletions fs/btrfs/extent-tree.c
Original file line number Diff line number Diff line change
Expand Up @@ -7193,10 +7193,7 @@ void btrfs_free_tree_block(struct btrfs_trans_handle *trans,
BUG_ON(ret); /* -ENOMEM */
}

if (!last_ref)
return;

if (btrfs_header_generation(buf) == trans->transid) {
if (last_ref && btrfs_header_generation(buf) == trans->transid) {
struct btrfs_block_group_cache *cache;

if (root->root_key.objectid != BTRFS_TREE_LOG_OBJECTID) {
Expand Down Expand Up @@ -7227,11 +7224,13 @@ void btrfs_free_tree_block(struct btrfs_trans_handle *trans,
add_pinned_bytes(fs_info, buf->len, btrfs_header_level(buf),
root->root_key.objectid);

/*
* Deleting the buffer, clear the corrupt flag since it doesn't matter
* anymore.
*/
clear_bit(EXTENT_BUFFER_CORRUPT, &buf->bflags);
if (last_ref) {
/*
* Deleting the buffer, clear the corrupt flag since it doesn't
* matter anymore.
*/
clear_bit(EXTENT_BUFFER_CORRUPT, &buf->bflags);
}
}

/* Can return -ENOMEM */
Expand Down

0 comments on commit 0a16c7d

Please sign in to comment.