Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 25179201 authored by Josef Bacik's avatar Josef Bacik Committed by Chris Mason
Browse files

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: default avatarJosef Bacik <jbacik@redhat.com>
parent 80eb234a
Loading
Loading
Loading
Loading
+1 −2
Original line number Diff line number Diff line
@@ -1387,8 +1387,7 @@ int btrfs_search_slot(struct btrfs_trans_handle *trans, struct btrfs_root
	lowest_level = p->lowest_level;
	WARN_ON(lowest_level && ins_len > 0);
	WARN_ON(p->nodes[0] != NULL);
	WARN_ON(cow && root == root->fs_info->extent_root &&
		!mutex_is_locked(&root->fs_info->alloc_mutex));

	if (ins_len < 0)
		lowest_unlock = 2;

+7 −1
Original line number Diff line number Diff line
@@ -558,6 +558,7 @@ struct btrfs_block_group_cache {
	struct btrfs_key key;
	struct btrfs_block_group_item item;
	spinlock_t lock;
	struct mutex alloc_mutex;
	u64 pinned;
	u64 reserved;
	u64 flags;
@@ -635,7 +636,8 @@ struct btrfs_fs_info {
	struct mutex tree_log_mutex;
	struct mutex transaction_kthread_mutex;
	struct mutex cleaner_mutex;
	struct mutex alloc_mutex;
	struct mutex extent_ins_mutex;
	struct mutex pinned_mutex;
	struct mutex chunk_mutex;
	struct mutex drop_mutex;
	struct mutex volume_mutex;
@@ -1941,8 +1943,12 @@ int btrfs_acl_chmod(struct inode *inode);
/* free-space-cache.c */
int btrfs_add_free_space(struct btrfs_block_group_cache *block_group,
			 u64 bytenr, u64 size);
int btrfs_add_free_space_lock(struct btrfs_block_group_cache *block_group,
			      u64 offset, u64 bytes);
int btrfs_remove_free_space(struct btrfs_block_group_cache *block_group,
			    u64 bytenr, u64 size);
int btrfs_remove_free_space_lock(struct btrfs_block_group_cache *block_group,
				 u64 offset, u64 bytes);
void btrfs_remove_free_space_cache(struct btrfs_block_group_cache
				   *block_group);
struct btrfs_free_space *btrfs_find_free_space(struct btrfs_block_group_cache
+2 −1
Original line number Diff line number Diff line
@@ -1460,7 +1460,8 @@ struct btrfs_root *open_ctree(struct super_block *sb,
	mutex_init(&fs_info->trans_mutex);
	mutex_init(&fs_info->tree_log_mutex);
	mutex_init(&fs_info->drop_mutex);
	mutex_init(&fs_info->alloc_mutex);
	mutex_init(&fs_info->extent_ins_mutex);
	mutex_init(&fs_info->pinned_mutex);
	mutex_init(&fs_info->chunk_mutex);
	mutex_init(&fs_info->transaction_kthread_mutex);
	mutex_init(&fs_info->cleaner_mutex);
+156 −177

File changed.

Preview size limit exceeded, changes collapsed.

+14 −0
Original line number Diff line number Diff line
@@ -938,6 +938,20 @@ int lock_extent(struct extent_io_tree *tree, u64 start, u64 end, gfp_t mask)
}
EXPORT_SYMBOL(lock_extent);

int try_lock_extent(struct extent_io_tree *tree, u64 start, u64 end,
		    gfp_t mask)
{
	int err;
	u64 failed_start;

	err = set_extent_bit(tree, start, end, EXTENT_LOCKED, 1,
			     &failed_start, mask);
	if (err == -EEXIST)
		return 0;
	return 1;
}
EXPORT_SYMBOL(try_lock_extent);

int unlock_extent(struct extent_io_tree *tree, u64 start, u64 end,
		  gfp_t mask)
{
Loading