diff options
author | Chris Mason <chris.mason@oracle.com> | 2009-02-04 09:25:08 -0500 |
---|---|---|
committer | Chris Mason <chris.mason@oracle.com> | 2009-02-04 09:25:08 -0500 |
commit | b4ce94de9b4d64e8ab3cf155d13653c666e22b9b (patch) | |
tree | ebc44a9554a50b495b091cb0979d79fd29e50fe7 /fs/btrfs/tree-log.c | |
parent | c487685d7c18a8481900755aa5c56a7a74193101 (diff) |
Btrfs: Change btree locking to use explicit blocking points
Most of the btrfs metadata operations can be protected by a spinlock,
but some operations still need to schedule.
So far, btrfs has been using a mutex along with a trylock loop,
most of the time it is able to avoid going for the full mutex, so
the trylock loop is a big performance gain.
This commit is step one for getting rid of the blocking locks entirely.
btrfs_tree_lock takes a spinlock, and the code explicitly switches
to a blocking lock when it starts an operation that can schedule.
We'll be able get rid of the blocking locks in smaller pieces over time.
Tracing allows us to find the most common cause of blocking, so we
can start with the hot spots first.
The basic idea is:
btrfs_tree_lock() returns with the spin lock held
btrfs_set_lock_blocking() sets the EXTENT_BUFFER_BLOCKING bit in
the extent buffer flags, and then drops the spin lock. The buffer is
still considered locked by all of the btrfs code.
If btrfs_tree_lock gets the spinlock but finds the blocking bit set, it drops
the spin lock and waits on a wait queue for the blocking bit to go away.
Much of the code that needs to set the blocking bit finishes without actually
blocking a good percentage of the time. So, an adaptive spin is still
used against the blocking bit to avoid very high context switch rates.
btrfs_clear_lock_blocking() clears the blocking bit and returns
with the spinlock held again.
btrfs_tree_unlock() can be called on either blocking or spinning locks,
it does the right thing based on the blocking bit.
ctree.c has a helper function to set/clear all the locked buffers in a
path as blocking.
Signed-off-by: Chris Mason <chris.mason@oracle.com>
Diffstat (limited to 'fs/btrfs/tree-log.c')
-rw-r--r-- | fs/btrfs/tree-log.c | 4 |
1 files changed, 4 insertions, 0 deletions
diff --git a/fs/btrfs/tree-log.c b/fs/btrfs/tree-log.c index 4f26f3ed0c87..20794290256b 100644 --- a/fs/btrfs/tree-log.c +++ b/fs/btrfs/tree-log.c | |||
@@ -1615,6 +1615,7 @@ static noinline int walk_down_log_tree(struct btrfs_trans_handle *trans, | |||
1615 | 1615 | ||
1616 | btrfs_tree_lock(next); | 1616 | btrfs_tree_lock(next); |
1617 | clean_tree_block(trans, root, next); | 1617 | clean_tree_block(trans, root, next); |
1618 | btrfs_set_lock_blocking(next); | ||
1618 | btrfs_wait_tree_block_writeback(next); | 1619 | btrfs_wait_tree_block_writeback(next); |
1619 | btrfs_tree_unlock(next); | 1620 | btrfs_tree_unlock(next); |
1620 | 1621 | ||
@@ -1661,6 +1662,7 @@ static noinline int walk_down_log_tree(struct btrfs_trans_handle *trans, | |||
1661 | next = path->nodes[*level]; | 1662 | next = path->nodes[*level]; |
1662 | btrfs_tree_lock(next); | 1663 | btrfs_tree_lock(next); |
1663 | clean_tree_block(trans, root, next); | 1664 | clean_tree_block(trans, root, next); |
1665 | btrfs_set_lock_blocking(next); | ||
1664 | btrfs_wait_tree_block_writeback(next); | 1666 | btrfs_wait_tree_block_writeback(next); |
1665 | btrfs_tree_unlock(next); | 1667 | btrfs_tree_unlock(next); |
1666 | 1668 | ||
@@ -1718,6 +1720,7 @@ static noinline int walk_up_log_tree(struct btrfs_trans_handle *trans, | |||
1718 | 1720 | ||
1719 | btrfs_tree_lock(next); | 1721 | btrfs_tree_lock(next); |
1720 | clean_tree_block(trans, root, next); | 1722 | clean_tree_block(trans, root, next); |
1723 | btrfs_set_lock_blocking(next); | ||
1721 | btrfs_wait_tree_block_writeback(next); | 1724 | btrfs_wait_tree_block_writeback(next); |
1722 | btrfs_tree_unlock(next); | 1725 | btrfs_tree_unlock(next); |
1723 | 1726 | ||
@@ -1790,6 +1793,7 @@ static int walk_log_tree(struct btrfs_trans_handle *trans, | |||
1790 | 1793 | ||
1791 | btrfs_tree_lock(next); | 1794 | btrfs_tree_lock(next); |
1792 | clean_tree_block(trans, log, next); | 1795 | clean_tree_block(trans, log, next); |
1796 | btrfs_set_lock_blocking(next); | ||
1793 | btrfs_wait_tree_block_writeback(next); | 1797 | btrfs_wait_tree_block_writeback(next); |
1794 | btrfs_tree_unlock(next); | 1798 | btrfs_tree_unlock(next); |
1795 | 1799 | ||