Btrfs: be more polite in the async caching threads
[linux-2.6-block.git] / fs / btrfs / extent-tree.c
index 08188f1615d9ba4fac89c8f3f77ec5b859d20f12..dc84daee6bc472dbc480efd7ad179933277c5eb4 100644 (file)
@@ -267,7 +267,7 @@ static int caching_kthread(void *data)
        last = max_t(u64, block_group->key.objectid, BTRFS_SUPER_INFO_OFFSET);
 again:
        /* need to make sure the commit_root doesn't disappear */
-       down_read(&fs_info->extent_root->commit_root_sem);
+       down_read(&fs_info->extent_commit_sem);
 
        /*
         * We don't want to deadlock with somebody trying to allocate a new
@@ -288,8 +288,10 @@ again:
 
        while (1) {
                smp_mb();
-               if (block_group->fs_info->closing)
+               if (block_group->fs_info->closing > 1) {
+                       last = (u64)-1;
                        break;
+               }
 
                leaf = path->nodes[0];
                slot = path->slots[0];
@@ -300,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_root->commit_root_sem);
-                               cond_resched();
+                               up_read(&fs_info->extent_commit_sem);
+                               schedule_timeout(1);
                                goto again;
                        }
 
@@ -343,7 +346,7 @@ next:
 
 err:
        btrfs_free_path(path);
-       up_read(&fs_info->extent_root->commit_root_sem);
+       up_read(&fs_info->extent_commit_sem);
        atomic_dec(&block_group->space_info->caching_threads);
        wake_up(&block_group->caching_q);