btrfs: use cond_resched_lock where possible
authorDavid Sterba <dsterba@suse.cz>
Thu, 8 Jan 2015 14:20:54 +0000 (15:20 +0100)
committerDavid Sterba <dsterba@suse.cz>
Tue, 3 Mar 2015 16:23:56 +0000 (17:23 +0100)
Clean the opencoded variant, cond_resched_lock also checks the lock for
contention so it might help in some cases that were not covered by
simple need_resched().

Signed-off-by: David Sterba <dsterba@suse.cz>
fs/btrfs/file.c
fs/btrfs/free-space-cache.c
fs/btrfs/transaction.c

index e4090259569bccfdb3ec788481814e769ff84615..1e34bc00249f194641fd0e46d076535e17d48d0e 100644 (file)
@@ -273,11 +273,7 @@ void btrfs_cleanup_defrag_inodes(struct btrfs_fs_info *fs_info)
                defrag = rb_entry(node, struct inode_defrag, rb_node);
                kmem_cache_free(btrfs_inode_defrag_cachep, defrag);
 
-               if (need_resched()) {
-                       spin_unlock(&fs_info->defrag_inodes_lock);
-                       cond_resched();
-                       spin_lock(&fs_info->defrag_inodes_lock);
-               }
+               cond_resched_lock(&fs_info->defrag_inodes_lock);
 
                node = rb_first(&fs_info->defrag_inodes);
        }
index a71978578fa71a11d83f8c435541b807eedc2b51..96611fed552f5ba35b3fb403ff2f12f466385b76 100644 (file)
@@ -2402,11 +2402,8 @@ static void __btrfs_remove_free_space_cache_locked(
                } else {
                        free_bitmap(ctl, info);
                }
-               if (need_resched()) {
-                       spin_unlock(&ctl->tree_lock);
-                       cond_resched();
-                       spin_lock(&ctl->tree_lock);
-               }
+
+               cond_resched_lock(&ctl->tree_lock);
        }
 }
 
@@ -2431,11 +2428,8 @@ void btrfs_remove_free_space_cache(struct btrfs_block_group_cache *block_group)
 
                WARN_ON(cluster->block_group != block_group);
                __btrfs_return_cluster_to_free_space(block_group, cluster);
-               if (need_resched()) {
-                       spin_unlock(&ctl->tree_lock);
-                       cond_resched();
-                       spin_lock(&ctl->tree_lock);
-               }
+
+               cond_resched_lock(&ctl->tree_lock);
        }
        __btrfs_remove_free_space_cache_locked(ctl);
        spin_unlock(&ctl->tree_lock);
index 038fcf6051e001a9e2f876468b9b4f91956f6e45..efc5ebffa7ea223ac0fc4b15f780e2d22553e90c 100644 (file)
@@ -93,11 +93,8 @@ static void clear_btree_io_tree(struct extent_io_tree *tree)
                 */
                ASSERT(!waitqueue_active(&state->wq));
                free_extent_state(state);
-               if (need_resched()) {
-                       spin_unlock(&tree->lock);
-                       cond_resched();
-                       spin_lock(&tree->lock);
-               }
+
+               cond_resched_lock(&tree->lock);
        }
        spin_unlock(&tree->lock);
 }