Skip to content

Commit

Permalink
Btrfs: Only prep for btree deletion balances when nodes are mostly empty
Browse files Browse the repository at this point in the history
Whenever an item deletion is done, we need to balance all the nodes
in the tree to make sure we don't end up with an empty node if a pointer
is deleted.  This balance prep happens from the root of the tree down
so we can drop our locks as we go.

reada_for_balance was triggering read-ahead on neighboring nodes even
when no balancing was required.  This adds an extra check to avoid
calling balance_level() and avoid reada_for_balance() when a balance
won't be required.

Signed-off-by: Chris Mason <chris.mason@oracle.com>
  • Loading branch information
Chris Mason committed Feb 4, 2009
1 parent 12f4dac commit 7b78c17
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions fs/btrfs/ctree.c
Original file line number Diff line number Diff line change
Expand Up @@ -1518,18 +1518,19 @@ int btrfs_search_slot(struct btrfs_trans_handle *trans, struct btrfs_root
*/
if (prealloc_block.objectid &&
prealloc_block.offset != b->len) {
btrfs_set_path_blocking(p);
btrfs_release_path(root, p);
btrfs_free_reserved_extent(root,
prealloc_block.objectid,
prealloc_block.offset);
prealloc_block.objectid = 0;
goto again;
}

/*
* for higher level blocks, try not to allocate blocks
* with the block and the parent locks held.
*/
if (level > 1 && !prealloc_block.objectid &&
if (level > 0 && !prealloc_block.objectid &&
btrfs_path_lock_waiting(p, level)) {
u32 size = b->len;
u64 hint = b->start;
Expand Down Expand Up @@ -1614,7 +1615,9 @@ int btrfs_search_slot(struct btrfs_trans_handle *trans, struct btrfs_root
}
b = p->nodes[level];
slot = p->slots[level];
} else if (ins_len < 0) {
} else if (ins_len < 0 &&
btrfs_header_nritems(b) <
BTRFS_NODEPTRS_PER_BLOCK(root) / 4) {
int sret;

sret = reada_for_balance(root, p, level);
Expand Down

0 comments on commit 7b78c17

Please sign in to comment.