aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJosef Bacik <jbacik@fusionio.com>2013-08-14 11:33:56 -0400
committerChris Mason <chris.mason@fusionio.com>2013-09-01 08:05:04 -0400
commit9ffba8cda917c0158857426f0e74b64d0206aaa9 (patch)
tree04579a95f2f494d0563d84c331be849aa4980977
parent4ef31a45a009a81b2f3c5aaf6f07d7147f80bc8c (diff)
Btrfs: fix heavy delalloc related deadlock
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 <jbacik@fusionio.com> Signed-off-by: Chris Mason <chris.mason@fusionio.com>
-rw-r--r--fs/btrfs/ctree.h7
-rw-r--r--fs/btrfs/disk-io.c1
-rw-r--r--fs/btrfs/ordered-data.c4
3 files changed, 10 insertions, 2 deletions
diff --git a/fs/btrfs/ctree.h b/fs/btrfs/ctree.h
index 0632832d4446..063e48587126 100644
--- a/fs/btrfs/ctree.h
+++ b/fs/btrfs/ctree.h
@@ -1413,6 +1413,13 @@ struct btrfs_fs_info {
1413 * before jumping into the main commit. 1413 * before jumping into the main commit.
1414 */ 1414 */
1415 struct mutex ordered_operations_mutex; 1415 struct mutex ordered_operations_mutex;
1416
1417 /*
1418 * Same as ordered_operations_mutex except this is for ordered extents
1419 * and not the operations.
1420 */
1421 struct mutex ordered_extent_flush_mutex;
1422
1416 struct rw_semaphore extent_commit_sem; 1423 struct rw_semaphore extent_commit_sem;
1417 1424
1418 struct rw_semaphore cleanup_work_sem; 1425 struct rw_semaphore cleanup_work_sem;
diff --git a/fs/btrfs/disk-io.c b/fs/btrfs/disk-io.c
index 572e21eb644c..68391ecf2c59 100644
--- a/fs/btrfs/disk-io.c
+++ b/fs/btrfs/disk-io.c
@@ -2277,6 +2277,7 @@ int open_ctree(struct super_block *sb,
2277 2277
2278 2278
2279 mutex_init(&fs_info->ordered_operations_mutex); 2279 mutex_init(&fs_info->ordered_operations_mutex);
2280 mutex_init(&fs_info->ordered_extent_flush_mutex);
2280 mutex_init(&fs_info->tree_log_mutex); 2281 mutex_init(&fs_info->tree_log_mutex);
2281 mutex_init(&fs_info->chunk_mutex); 2282 mutex_init(&fs_info->chunk_mutex);
2282 mutex_init(&fs_info->transaction_kthread_mutex); 2283 mutex_init(&fs_info->transaction_kthread_mutex);
diff --git a/fs/btrfs/ordered-data.c b/fs/btrfs/ordered-data.c
index 81369827e514..b52b2c4010c2 100644
--- a/fs/btrfs/ordered-data.c
+++ b/fs/btrfs/ordered-data.c
@@ -671,7 +671,7 @@ int btrfs_run_ordered_operations(struct btrfs_trans_handle *trans,
671 INIT_LIST_HEAD(&splice); 671 INIT_LIST_HEAD(&splice);
672 INIT_LIST_HEAD(&works); 672 INIT_LIST_HEAD(&works);
673 673
674 mutex_lock(&root->fs_info->ordered_operations_mutex); 674 mutex_lock(&root->fs_info->ordered_extent_flush_mutex);
675 spin_lock(&root->fs_info->ordered_root_lock); 675 spin_lock(&root->fs_info->ordered_root_lock);
676 list_splice_init(&cur_trans->ordered_operations, &splice); 676 list_splice_init(&cur_trans->ordered_operations, &splice);
677 while (!list_empty(&splice)) { 677 while (!list_empty(&splice)) {
@@ -718,7 +718,7 @@ out:
718 list_del_init(&work->list); 718 list_del_init(&work->list);
719 btrfs_wait_and_free_delalloc_work(work); 719 btrfs_wait_and_free_delalloc_work(work);
720 } 720 }
721 mutex_unlock(&root->fs_info->ordered_operations_mutex); 721 mutex_unlock(&root->fs_info->ordered_extent_flush_mutex);
722 return ret; 722 return ret;
723} 723}
724 724