Btrfs: Only prep for btree deletion balances when nodes are mostly empty

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>

+6 -3
+6 -3
fs/btrfs/ctree.c
··· 1518 1518 */ 1519 1519 if (prealloc_block.objectid && 1520 1520 prealloc_block.offset != b->len) { 1521 - btrfs_set_path_blocking(p); 1521 + btrfs_release_path(root, p); 1522 1522 btrfs_free_reserved_extent(root, 1523 1523 prealloc_block.objectid, 1524 1524 prealloc_block.offset); 1525 1525 prealloc_block.objectid = 0; 1526 + goto again; 1526 1527 } 1527 1528 1528 1529 /* 1529 1530 * for higher level blocks, try not to allocate blocks 1530 1531 * with the block and the parent locks held. 1531 1532 */ 1532 - if (level > 1 && !prealloc_block.objectid && 1533 + if (level > 0 && !prealloc_block.objectid && 1533 1534 btrfs_path_lock_waiting(p, level)) { 1534 1535 u32 size = b->len; 1535 1536 u64 hint = b->start; ··· 1615 1614 } 1616 1615 b = p->nodes[level]; 1617 1616 slot = p->slots[level]; 1618 - } else if (ins_len < 0) { 1617 + } else if (ins_len < 0 && 1618 + btrfs_header_nritems(b) < 1619 + BTRFS_NODEPTRS_PER_BLOCK(root) / 4) { 1619 1620 int sret; 1620 1621 1621 1622 sret = reada_for_balance(root, p, level);