summaryrefslogtreecommitdiff
path: root/fs/btrfs/ctree.c
diff options
context:
space:
mode:
authorLiu Bo <bo.liu@linux.alibaba.com>2018-05-18 11:00:23 +0800
committerDavid Sterba <dsterba@suse.com>2018-05-30 16:46:51 +0200
commit662c653bfda58698cf48d7143a39bd3a063fd9c6 (patch)
treec4996ca4d8c9fd5410c400dfdffaa1dadddb2cc6 /fs/btrfs/ctree.c
parent1fc28d8e2e9bf22044f1bacd17fe941cd0df5ba6 (diff)
Btrfs: grab write lock directly if write_lock_level is the max level
Typically, when acquiring root node's lock, btrfs tries its best to get read lock and trade for write lock if @write_lock_level implies to do so. In case of (cow && (p->keep_locks || p->lowest_level)), write_lock_level is set to BTRFS_MAX_LEVEL, which means we need to acquire root node's write lock directly. In this particular case, the dance of acquiring read lock and then trading for write lock can be saved. Signed-off-by: Liu Bo <bo.liu@linux.alibaba.com> Reviewed-by: David Sterba <dsterba@suse.com> Signed-off-by: David Sterba <dsterba@suse.com>
Diffstat (limited to 'fs/btrfs/ctree.c')
-rw-r--r--fs/btrfs/ctree.c27
1 files changed, 16 insertions, 11 deletions
diff --git a/fs/btrfs/ctree.c b/fs/btrfs/ctree.c
index 44dd1950f88a..239682330929 100644
--- a/fs/btrfs/ctree.c
+++ b/fs/btrfs/ctree.c
@@ -2632,19 +2632,24 @@ static struct extent_buffer *btrfs_search_slot_get_root(struct btrfs_root *root,
}
/*
- * We don't know the level of the root node until we actually have it
- * read locked
+ * If the level is set to maximum, we can skip trying to get the read
+ * lock.
*/
- b = btrfs_read_lock_root_node(root);
- level = btrfs_header_level(b);
- if (level > write_lock_level)
- goto out;
+ if (write_lock_level < BTRFS_MAX_LEVEL) {
+ /*
+ * We don't know the level of the root node until we actually
+ * have it read locked
+ */
+ b = btrfs_read_lock_root_node(root);
+ level = btrfs_header_level(b);
+ if (level > write_lock_level)
+ goto out;
+
+ /* Whoops, must trade for write lock */
+ btrfs_tree_read_unlock(b);
+ free_extent_buffer(b);
+ }
- /*
- * whoops, must trade for write lock
- */
- btrfs_tree_read_unlock(b);
- free_extent_buffer(b);
b = btrfs_lock_root_node(root);
root_lock = BTRFS_WRITE_LOCK;