Btrfs: be more polite in the async caching threads
authorChris Mason <chris.mason@oracle.com>
Thu, 30 Jul 2009 14:04:48 +0000 (10:04 -0400)
committerChris Mason <chris.mason@oracle.com>
Thu, 30 Jul 2009 14:14:46 +0000 (10:14 -0400)
The semaphore used by the async caching threads can prevent a
transaction commit, which can make the FS appear to stall.  This
releases the semaphore more often when a transaction commit is
in progress.

Signed-off-by: Chris Mason <chris.mason@oracle.com>
fs/btrfs/extent-tree.c
fs/btrfs/transaction.c
fs/btrfs/transaction.h

index 2fe21fa74913448431847ef7c3090ced37df61d4..dc84daee6bc472dbc480efd7ad179933277c5eb4 100644 (file)
@@ -302,10 +302,11 @@ again:
                        else if (ret)
                                break;
 
-                       if (need_resched()) {
+                       if (need_resched() ||
+                           btrfs_transaction_in_commit(fs_info)) {
                                btrfs_release_path(fs_info->extent_root, path);
                                up_read(&fs_info->extent_commit_sem);
-                               cond_resched();
+                               schedule_timeout(1);
                                goto again;
                        }
 
index de48e4ec808cd6e600bc1d32a65840035dcdf37d..cdbb5022da52df1e2b33593650401021077ba280 100644 (file)
@@ -857,6 +857,16 @@ static void update_super_roots(struct btrfs_root *root)
        super->root_level = root_item->level;
 }
 
+int btrfs_transaction_in_commit(struct btrfs_fs_info *info)
+{
+       int ret = 0;
+       spin_lock(&info->new_trans_lock);
+       if (info->running_transaction)
+               ret = info->running_transaction->in_commit;
+       spin_unlock(&info->new_trans_lock);
+       return ret;
+}
+
 int btrfs_commit_transaction(struct btrfs_trans_handle *trans,
                             struct btrfs_root *root)
 {
index 961c3ee5a2e10697a120c2dbd7c0dd6d639f27ab..663c67404918dd30fb1c5cf0943b07b2455018bd 100644 (file)
@@ -107,4 +107,5 @@ int btrfs_record_root_in_trans(struct btrfs_trans_handle *trans,
                                struct btrfs_root *root);
 int btrfs_write_and_wait_marked_extents(struct btrfs_root *root,
                                        struct extent_io_tree *dirty_pages);
+int btrfs_transaction_in_commit(struct btrfs_fs_info *info);
 #endif