aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLiu Bo <bo.liu@linux.alibaba.com>2018-05-17 23:00:23 -0400
committerDavid Sterba <dsterba@suse.com>2018-05-30 10:46:51 -0400
commit662c653bfda58698cf48d7143a39bd3a063fd9c6 (patch)
treec4996ca4d8c9fd5410c400dfdffaa1dadddb2cc6
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>
-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,
2632 } 2632 }
2633 2633
2634 /* 2634 /*
2635 * We don't know the level of the root node until we actually have it 2635 * If the level is set to maximum, we can skip trying to get the read
2636 * read locked 2636 * lock.
2637 */ 2637 */
2638 b = btrfs_read_lock_root_node(root); 2638 if (write_lock_level < BTRFS_MAX_LEVEL) {
2639 level = btrfs_header_level(b); 2639 /*
2640 if (level > write_lock_level) 2640 * We don't know the level of the root node until we actually
2641 goto out; 2641 * have it read locked
2642 */
2643 b = btrfs_read_lock_root_node(root);
2644 level = btrfs_header_level(b);
2645 if (level > write_lock_level)
2646 goto out;
2647
2648 /* Whoops, must trade for write lock */
2649 btrfs_tree_read_unlock(b);
2650 free_extent_buffer(b);
2651 }
2642 2652
2643 /*
2644 * whoops, must trade for write lock
2645 */
2646 btrfs_tree_read_unlock(b);
2647 free_extent_buffer(b);
2648 b = btrfs_lock_root_node(root); 2653 b = btrfs_lock_root_node(root);
2649 root_lock = BTRFS_WRITE_LOCK; 2654 root_lock = BTRFS_WRITE_LOCK;
2650 2655