Skip to content

Commit ec6a867

Browse files
committed
Merge git://git.kernel.org/pub/scm/linux/kernel/git/mason/btrfs-unstable
* git://git.kernel.org/pub/scm/linux/kernel/git/mason/btrfs-unstable: Btrfs: be more polite in the async caching threads Btrfs: preserve commit_root for async caching
2 parents db06816 + f36f304 commit ec6a867

5 files changed

Lines changed: 28 additions & 12 deletions

File tree

‎fs/btrfs/ctree.h‎

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -825,6 +825,7 @@ struct btrfs_fs_info {
825825
struct mutex drop_mutex;
826826
struct mutex volume_mutex;
827827
struct mutex tree_reloc_mutex;
828+
struct rw_semaphore extent_commit_sem;
828829

829830
/*
830831
* this protects the ordered operations list only while we are
@@ -959,9 +960,6 @@ struct btrfs_root {
959960
/* the node lock is held while changing the node pointer */
960961
spinlock_t node_lock;
961962

962-
/* taken when updating the commit root */
963-
struct rw_semaphore commit_root_sem;
964-
965963
struct extent_buffer *commit_root;
966964
struct btrfs_root *log_root;
967965
struct btrfs_root *reloc_root;

‎fs/btrfs/disk-io.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -909,7 +909,6 @@ static int __setup_root(u32 nodesize, u32 leafsize, u32 sectorsize,
909909
spin_lock_init(&root->inode_lock);
910910
mutex_init(&root->objectid_mutex);
911911
mutex_init(&root->log_mutex);
912-
init_rwsem(&root->commit_root_sem);
913912
init_waitqueue_head(&root->log_writer_wait);
914913
init_waitqueue_head(&root->log_commit_wait[0]);
915914
init_waitqueue_head(&root->log_commit_wait[1]);
@@ -1640,6 +1639,7 @@ struct btrfs_root *open_ctree(struct super_block *sb,
16401639
mutex_init(&fs_info->cleaner_mutex);
16411640
mutex_init(&fs_info->volume_mutex);
16421641
mutex_init(&fs_info->tree_reloc_mutex);
1642+
init_rwsem(&fs_info->extent_commit_sem);
16431643

16441644
btrfs_init_free_cluster(&fs_info->meta_alloc_cluster);
16451645
btrfs_init_free_cluster(&fs_info->data_alloc_cluster);

‎fs/btrfs/extent-tree.c‎

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -267,7 +267,7 @@ static int caching_kthread(void *data)
267267
last = max_t(u64, block_group->key.objectid, BTRFS_SUPER_INFO_OFFSET);
268268
again:
269269
/* need to make sure the commit_root doesn't disappear */
270-
down_read(&fs_info->extent_root->commit_root_sem);
270+
down_read(&fs_info->extent_commit_sem);
271271

272272
/*
273273
* We don't want to deadlock with somebody trying to allocate a new
@@ -302,10 +302,11 @@ static int caching_kthread(void *data)
302302
else if (ret)
303303
break;
304304

305-
if (need_resched()) {
305+
if (need_resched() ||
306+
btrfs_transaction_in_commit(fs_info)) {
306307
btrfs_release_path(fs_info->extent_root, path);
307-
up_read(&fs_info->extent_root->commit_root_sem);
308-
cond_resched();
308+
up_read(&fs_info->extent_commit_sem);
309+
schedule_timeout(1);
309310
goto again;
310311
}
311312

@@ -345,7 +346,7 @@ static int caching_kthread(void *data)
345346

346347
err:
347348
btrfs_free_path(path);
348-
up_read(&fs_info->extent_root->commit_root_sem);
349+
up_read(&fs_info->extent_commit_sem);
349350
atomic_dec(&block_group->space_info->caching_threads);
350351
wake_up(&block_group->caching_q);
351352

‎fs/btrfs/transaction.c‎

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,8 @@ static noinline void put_transaction(struct btrfs_transaction *transaction)
4242

4343
static noinline void switch_commit_root(struct btrfs_root *root)
4444
{
45-
down_write(&root->commit_root_sem);
4645
free_extent_buffer(root->commit_root);
4746
root->commit_root = btrfs_root_node(root);
48-
up_write(&root->commit_root_sem);
4947
}
5048

5149
/*
@@ -466,7 +464,10 @@ static int update_cowonly_root(struct btrfs_trans_handle *trans,
466464
ret = btrfs_write_dirty_block_groups(trans, root);
467465
BUG_ON(ret);
468466
}
469-
switch_commit_root(root);
467+
468+
if (root != root->fs_info->extent_root)
469+
switch_commit_root(root);
470+
470471
return 0;
471472
}
472473

@@ -499,6 +500,11 @@ static noinline int commit_cowonly_roots(struct btrfs_trans_handle *trans,
499500

500501
update_cowonly_root(trans, root);
501502
}
503+
504+
down_write(&fs_info->extent_commit_sem);
505+
switch_commit_root(fs_info->extent_root);
506+
up_write(&fs_info->extent_commit_sem);
507+
502508
return 0;
503509
}
504510

@@ -851,6 +857,16 @@ static void update_super_roots(struct btrfs_root *root)
851857
super->root_level = root_item->level;
852858
}
853859

860+
int btrfs_transaction_in_commit(struct btrfs_fs_info *info)
861+
{
862+
int ret = 0;
863+
spin_lock(&info->new_trans_lock);
864+
if (info->running_transaction)
865+
ret = info->running_transaction->in_commit;
866+
spin_unlock(&info->new_trans_lock);
867+
return ret;
868+
}
869+
854870
int btrfs_commit_transaction(struct btrfs_trans_handle *trans,
855871
struct btrfs_root *root)
856872
{

‎fs/btrfs/transaction.h‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,4 +107,5 @@ int btrfs_record_root_in_trans(struct btrfs_trans_handle *trans,
107107
struct btrfs_root *root);
108108
int btrfs_write_and_wait_marked_extents(struct btrfs_root *root,
109109
struct extent_io_tree *dirty_pages);
110+
int btrfs_transaction_in_commit(struct btrfs_fs_info *info);
110111
#endif

0 commit comments

Comments
 (0)