Skip to content

Commit 2517920

Browse files
Josef Bacikchrismason-xx
authored andcommitted
Btrfs: nuke fs wide allocation mutex V2
This patch removes the giant fs_info->alloc_mutex and replaces it with a bunch of little locks. There is now a pinned_mutex, which is used when messing with the pinned_extents extent io tree, and the extent_ins_mutex which is used with the pending_del and extent_ins extent io trees. The locking for the extent tree stuff was inspired by a patch that Yan Zheng wrote to fix a race condition, I cleaned it up some and changed the locking around a little bit, but the idea remains the same. Basically instead of holding the extent_ins_mutex throughout the processing of an extent on the extent_ins or pending_del trees, we just hold it while we're searching and when we clear the bits on those trees, and lock the extent for the duration of the operations on the extent. Also to keep from getting hung up waiting to lock an extent, I've added a try_lock_extent so if we cannot lock the extent, move on to the next one in the tree and we'll come back to that one. I have tested this heavily and it does not appear to break anything. This has to be applied on top of my find_free_extent redo patch. I tested this patch on top of Yan's space reblancing code and it worked fine. The only thing that has changed since the last version is I pulled out all my debugging stuff, apparently I forgot to run guilt refresh before I sent the last patch out. Thank you, Signed-off-by: Josef Bacik <[email protected]>
1 parent 80eb234 commit 2517920

File tree

11 files changed

+250
-216
lines changed

11 files changed

+250
-216
lines changed

fs/btrfs/ctree.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1387,8 +1387,7 @@ int btrfs_search_slot(struct btrfs_trans_handle *trans, struct btrfs_root
13871387
lowest_level = p->lowest_level;
13881388
WARN_ON(lowest_level && ins_len > 0);
13891389
WARN_ON(p->nodes[0] != NULL);
1390-
WARN_ON(cow && root == root->fs_info->extent_root &&
1391-
!mutex_is_locked(&root->fs_info->alloc_mutex));
1390+
13921391
if (ins_len < 0)
13931392
lowest_unlock = 2;
13941393

fs/btrfs/ctree.h

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -558,6 +558,7 @@ struct btrfs_block_group_cache {
558558
struct btrfs_key key;
559559
struct btrfs_block_group_item item;
560560
spinlock_t lock;
561+
struct mutex alloc_mutex;
561562
u64 pinned;
562563
u64 reserved;
563564
u64 flags;
@@ -635,7 +636,8 @@ struct btrfs_fs_info {
635636
struct mutex tree_log_mutex;
636637
struct mutex transaction_kthread_mutex;
637638
struct mutex cleaner_mutex;
638-
struct mutex alloc_mutex;
639+
struct mutex extent_ins_mutex;
640+
struct mutex pinned_mutex;
639641
struct mutex chunk_mutex;
640642
struct mutex drop_mutex;
641643
struct mutex volume_mutex;
@@ -1941,8 +1943,12 @@ int btrfs_acl_chmod(struct inode *inode);
19411943
/* free-space-cache.c */
19421944
int btrfs_add_free_space(struct btrfs_block_group_cache *block_group,
19431945
u64 bytenr, u64 size);
1946+
int btrfs_add_free_space_lock(struct btrfs_block_group_cache *block_group,
1947+
u64 offset, u64 bytes);
19441948
int btrfs_remove_free_space(struct btrfs_block_group_cache *block_group,
19451949
u64 bytenr, u64 size);
1950+
int btrfs_remove_free_space_lock(struct btrfs_block_group_cache *block_group,
1951+
u64 offset, u64 bytes);
19461952
void btrfs_remove_free_space_cache(struct btrfs_block_group_cache
19471953
*block_group);
19481954
struct btrfs_free_space *btrfs_find_free_space(struct btrfs_block_group_cache

fs/btrfs/disk-io.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1460,7 +1460,8 @@ struct btrfs_root *open_ctree(struct super_block *sb,
14601460
mutex_init(&fs_info->trans_mutex);
14611461
mutex_init(&fs_info->tree_log_mutex);
14621462
mutex_init(&fs_info->drop_mutex);
1463-
mutex_init(&fs_info->alloc_mutex);
1463+
mutex_init(&fs_info->extent_ins_mutex);
1464+
mutex_init(&fs_info->pinned_mutex);
14641465
mutex_init(&fs_info->chunk_mutex);
14651466
mutex_init(&fs_info->transaction_kthread_mutex);
14661467
mutex_init(&fs_info->cleaner_mutex);

0 commit comments

Comments
 (0)