diff options
author | Chris Mason <chris.mason@oracle.com> | 2007-10-19 09:23:27 -0400 |
---|---|---|
committer | Chris Mason <chris.mason@oracle.com> | 2008-09-25 11:03:57 -0400 |
commit | 3685f791659c9f21b763ee1702ac8ca58bc20f81 (patch) | |
tree | 9cd9514f7689ee0dfaef1c6303308366f05e0d5e /fs/btrfs/ctree.c | |
parent | 59d169e2b3d69ba0beca0fa0936789080c8d61a9 (diff) |
Btrfs: CPU usage optimizations in push and the extent_map code
Signed-off-by: Chris Mason <chris.mason@oracle.com>
Diffstat (limited to 'fs/btrfs/ctree.c')
-rw-r--r-- | fs/btrfs/ctree.c | 44 |
1 files changed, 24 insertions, 20 deletions
diff --git a/fs/btrfs/ctree.c b/fs/btrfs/ctree.c index 17a322663f3b..e8466940fa30 100644 --- a/fs/btrfs/ctree.c +++ b/fs/btrfs/ctree.c | |||
@@ -1588,6 +1588,11 @@ static int push_leaf_left(struct btrfs_trans_handle *trans, struct btrfs_root | |||
1588 | if (!path->nodes[1]) | 1588 | if (!path->nodes[1]) |
1589 | return 1; | 1589 | return 1; |
1590 | 1590 | ||
1591 | right_nritems = btrfs_header_nritems(right); | ||
1592 | if (right_nritems == 0) { | ||
1593 | return 1; | ||
1594 | } | ||
1595 | |||
1591 | left = read_tree_block(root, btrfs_node_blockptr(path->nodes[1], | 1596 | left = read_tree_block(root, btrfs_node_blockptr(path->nodes[1], |
1592 | slot - 1), root->leafsize); | 1597 | slot - 1), root->leafsize); |
1593 | free_space = btrfs_leaf_free_space(root, left); | 1598 | free_space = btrfs_leaf_free_space(root, left); |
@@ -1604,18 +1609,13 @@ static int push_leaf_left(struct btrfs_trans_handle *trans, struct btrfs_root | |||
1604 | free_extent_buffer(left); | 1609 | free_extent_buffer(left); |
1605 | return 1; | 1610 | return 1; |
1606 | } | 1611 | } |
1612 | |||
1607 | free_space = btrfs_leaf_free_space(root, left); | 1613 | free_space = btrfs_leaf_free_space(root, left); |
1608 | if (free_space < data_size + sizeof(struct btrfs_item)) { | 1614 | if (free_space < data_size + sizeof(struct btrfs_item)) { |
1609 | free_extent_buffer(left); | 1615 | free_extent_buffer(left); |
1610 | return 1; | 1616 | return 1; |
1611 | } | 1617 | } |
1612 | 1618 | ||
1613 | right_nritems = btrfs_header_nritems(right); | ||
1614 | if (right_nritems == 0) { | ||
1615 | free_extent_buffer(left); | ||
1616 | return 1; | ||
1617 | } | ||
1618 | |||
1619 | for (i = 0; i < right_nritems - 1; i++) { | 1619 | for (i = 0; i < right_nritems - 1; i++) { |
1620 | item = btrfs_item_nr(right, i); | 1620 | item = btrfs_item_nr(right, i); |
1621 | if (!right->map_token) { | 1621 | if (!right->map_token) { |
@@ -1772,21 +1772,25 @@ static int split_leaf(struct btrfs_trans_handle *trans, struct btrfs_root | |||
1772 | struct btrfs_disk_key disk_key; | 1772 | struct btrfs_disk_key disk_key; |
1773 | 1773 | ||
1774 | /* first try to make some room by pushing left and right */ | 1774 | /* first try to make some room by pushing left and right */ |
1775 | wret = push_leaf_left(trans, root, path, data_size); | 1775 | if (ins_key->type != BTRFS_DIR_ITEM_KEY) { |
1776 | if (wret < 0) { | ||
1777 | return wret; | ||
1778 | } | ||
1779 | if (wret) { | ||
1780 | wret = push_leaf_right(trans, root, path, data_size); | 1776 | wret = push_leaf_right(trans, root, path, data_size); |
1781 | if (wret < 0) | 1777 | if (wret < 0) { |
1782 | return wret; | 1778 | return wret; |
1783 | } | 1779 | } |
1784 | l = path->nodes[0]; | 1780 | if (wret) { |
1781 | wret = push_leaf_left(trans, root, path, data_size); | ||
1782 | if (wret < 0) | ||
1783 | return wret; | ||
1784 | } | ||
1785 | l = path->nodes[0]; | ||
1785 | 1786 | ||
1786 | /* did the pushes work? */ | 1787 | /* did the pushes work? */ |
1787 | if (btrfs_leaf_free_space(root, l) >= | 1788 | if (btrfs_leaf_free_space(root, l) >= |
1788 | sizeof(struct btrfs_item) + data_size) { | 1789 | sizeof(struct btrfs_item) + data_size) { |
1789 | return 0; | 1790 | return 0; |
1791 | } | ||
1792 | } else { | ||
1793 | l = path->nodes[0]; | ||
1790 | } | 1794 | } |
1791 | 1795 | ||
1792 | if (!path->nodes[1]) { | 1796 | if (!path->nodes[1]) { |
@@ -2388,13 +2392,13 @@ int btrfs_del_item(struct btrfs_trans_handle *trans, struct btrfs_root *root, | |||
2388 | slot = path->slots[1]; | 2392 | slot = path->slots[1]; |
2389 | extent_buffer_get(leaf); | 2393 | extent_buffer_get(leaf); |
2390 | 2394 | ||
2391 | wret = push_leaf_left(trans, root, path, 1); | 2395 | wret = push_leaf_right(trans, root, path, 1); |
2392 | if (wret < 0 && wret != -ENOSPC) | 2396 | if (wret < 0 && wret != -ENOSPC) |
2393 | ret = wret; | 2397 | ret = wret; |
2394 | 2398 | ||
2395 | if (path->nodes[0] == leaf && | 2399 | if (path->nodes[0] == leaf && |
2396 | btrfs_header_nritems(leaf)) { | 2400 | btrfs_header_nritems(leaf)) { |
2397 | wret = push_leaf_right(trans, root, path, 1); | 2401 | wret = push_leaf_left(trans, root, path, 1); |
2398 | if (wret < 0 && wret != -ENOSPC) | 2402 | if (wret < 0 && wret != -ENOSPC) |
2399 | ret = wret; | 2403 | ret = wret; |
2400 | } | 2404 | } |