Skip to content

Commit

Permalink
Btrfs: fix heavy delalloc related deadlock
Browse files Browse the repository at this point in the history
I added a patch where we started taking the ordered operations mutex when we
waited on ordered extents.  We need this because we splice the list and process
it, so if a flusher came in during this scenario it would think the list was
empty and we'd usually get an early ENOSPC.  The problem with this is that this
lock is used in transaction committing.  So we end up with something like this

Transaction commit
	-> wait on writers

Delalloc flusher
	-> run_ordered_operations (holds mutex)
		->wait for filemap-flush to do its thing

flush task
	-> cow_file_range
		->wait on btrfs_join_transaction because we're commiting

some other task
	-> commit_transaction because we notice trans->transaction->flush is set
		-> run_ordered_operations (hang on mutex)

We need to disentangle the ordered operations flushing from the delalloc
flushing, since they are separate things.  This solves the deadlock issue I was
seeing.  Thanks,

Signed-off-by: Josef Bacik <[email protected]>
Signed-off-by: Chris Mason <[email protected]>
  • Loading branch information
Josef Bacik authored and Chris Mason committed Sep 1, 2013
1 parent 4ef31a4 commit 9ffba8c
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 2 deletions.
7 changes: 7 additions & 0 deletions fs/btrfs/ctree.h
Original file line number Diff line number Diff line change
Expand Up @@ -1413,6 +1413,13 @@ struct btrfs_fs_info {
* before jumping into the main commit.
*/
struct mutex ordered_operations_mutex;

/*
* Same as ordered_operations_mutex except this is for ordered extents
* and not the operations.
*/
struct mutex ordered_extent_flush_mutex;

struct rw_semaphore extent_commit_sem;

struct rw_semaphore cleanup_work_sem;
Expand Down
1 change: 1 addition & 0 deletions fs/btrfs/disk-io.c
Original file line number Diff line number Diff line change
Expand Up @@ -2277,6 +2277,7 @@ int open_ctree(struct super_block *sb,


mutex_init(&fs_info->ordered_operations_mutex);
mutex_init(&fs_info->ordered_extent_flush_mutex);
mutex_init(&fs_info->tree_log_mutex);
mutex_init(&fs_info->chunk_mutex);
mutex_init(&fs_info->transaction_kthread_mutex);
Expand Down
4 changes: 2 additions & 2 deletions fs/btrfs/ordered-data.c
Original file line number Diff line number Diff line change
Expand Up @@ -671,7 +671,7 @@ int btrfs_run_ordered_operations(struct btrfs_trans_handle *trans,
INIT_LIST_HEAD(&splice);
INIT_LIST_HEAD(&works);

mutex_lock(&root->fs_info->ordered_operations_mutex);
mutex_lock(&root->fs_info->ordered_extent_flush_mutex);
spin_lock(&root->fs_info->ordered_root_lock);
list_splice_init(&cur_trans->ordered_operations, &splice);
while (!list_empty(&splice)) {
Expand Down Expand Up @@ -718,7 +718,7 @@ int btrfs_run_ordered_operations(struct btrfs_trans_handle *trans,
list_del_init(&work->list);
btrfs_wait_and_free_delalloc_work(work);
}
mutex_unlock(&root->fs_info->ordered_operations_mutex);
mutex_unlock(&root->fs_info->ordered_extent_flush_mutex);
return ret;
}

Expand Down

0 comments on commit 9ffba8c

Please sign in to comment.