Btrfs: be more polite in the async caching threads

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>

+14 -2
+3 -2
fs/btrfs/extent-tree.c
··· 302 302 else if (ret) 303 303 break; 304 304 305 - if (need_resched()) { 305 + if (need_resched() || 306 + btrfs_transaction_in_commit(fs_info)) { 306 307 btrfs_release_path(fs_info->extent_root, path); 307 308 up_read(&fs_info->extent_commit_sem); 308 - cond_resched(); 309 + schedule_timeout(1); 309 310 goto again; 310 311 } 311 312
+10
fs/btrfs/transaction.c
··· 857 857 super->root_level = root_item->level; 858 858 } 859 859 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 + 860 870 int btrfs_commit_transaction(struct btrfs_trans_handle *trans, 861 871 struct btrfs_root *root) 862 872 {
+1
fs/btrfs/transaction.h
··· 107 107 struct btrfs_root *root); 108 108 int btrfs_write_and_wait_marked_extents(struct btrfs_root *root, 109 109 struct extent_io_tree *dirty_pages); 110 + int btrfs_transaction_in_commit(struct btrfs_fs_info *info); 110 111 #endif