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/extent-tree.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/extent-tree.c')
-rw-r--r-- | fs/btrfs/extent-tree.c | 5 |
1 files changed, 5 insertions, 0 deletions
diff --git a/fs/btrfs/extent-tree.c b/fs/btrfs/extent-tree.c index 7a22f2e6ec47..ed1e25d72483 100644 --- a/fs/btrfs/extent-tree.c +++ b/fs/btrfs/extent-tree.c | |||
@@ -3407,7 +3407,10 @@ struct extent_buffer *btrfs_init_new_buffer(struct btrfs_trans_handle *trans, | |||
3407 | btrfs_set_header_generation(buf, trans->transid); | 3407 | btrfs_set_header_generation(buf, trans->transid); |
3408 | btrfs_tree_lock(buf); | 3408 | btrfs_tree_lock(buf); |
3409 | clean_tree_block(trans, root, buf); | 3409 | clean_tree_block(trans, root, buf); |
3410 | |||
3411 | btrfs_set_lock_blocking(buf); | ||
3410 | btrfs_set_buffer_uptodate(buf); | 3412 | btrfs_set_buffer_uptodate(buf); |
3413 | |||
3411 | if (root->root_key.objectid == BTRFS_TREE_LOG_OBJECTID) { | 3414 | if (root->root_key.objectid == BTRFS_TREE_LOG_OBJECTID) { |
3412 | set_extent_dirty(&root->dirty_log_pages, buf->start, | 3415 | set_extent_dirty(&root->dirty_log_pages, buf->start, |
3413 | buf->start + buf->len - 1, GFP_NOFS); | 3416 | buf->start + buf->len - 1, GFP_NOFS); |
@@ -3416,6 +3419,7 @@ struct extent_buffer *btrfs_init_new_buffer(struct btrfs_trans_handle *trans, | |||
3416 | buf->start + buf->len - 1, GFP_NOFS); | 3419 | buf->start + buf->len - 1, GFP_NOFS); |
3417 | } | 3420 | } |
3418 | trans->blocks_used++; | 3421 | trans->blocks_used++; |
3422 | /* this returns a buffer locked for blocking */ | ||
3419 | return buf; | 3423 | return buf; |
3420 | } | 3424 | } |
3421 | 3425 | ||
@@ -3752,6 +3756,7 @@ static noinline int walk_down_subtree(struct btrfs_trans_handle *trans, | |||
3752 | 3756 | ||
3753 | next = read_tree_block(root, bytenr, blocksize, ptr_gen); | 3757 | next = read_tree_block(root, bytenr, blocksize, ptr_gen); |
3754 | btrfs_tree_lock(next); | 3758 | btrfs_tree_lock(next); |
3759 | btrfs_set_lock_blocking(next); | ||
3755 | 3760 | ||
3756 | ret = btrfs_lookup_extent_ref(trans, root, bytenr, blocksize, | 3761 | ret = btrfs_lookup_extent_ref(trans, root, bytenr, blocksize, |
3757 | &refs); | 3762 | &refs); |