Btrfs: fix deadlocks and stalls on dead root removal
authorChris Mason <chris.mason@oracle.com>
Fri, 24 Apr 2009 18:39:25 +0000 (14:39 -0400)
committerChris Mason <chris.mason@oracle.com>
Fri, 24 Apr 2009 19:46:05 +0000 (15:46 -0400)
After a transaction commit, the old root of the subvol btrees are sent through
snapshot removal.  This is what actually frees up any blocks replaced by
COW, and anything the old blocks pointed to.

Snapshot deletion will pause when a transaction commit has started, which
helps to avoid a huge amount of delayed reference count updates piling up
as the transaction is trying to close.

But, this pause happens after the snapshot deletion process has asked other
procs on the system to throttle back a bit so that it can make progress.

We don't want to throttle everyone while we're waiting for the transaction
commit, it leads to deadlocks in the user transaction ioctls used by Ceph
and makes things slower in general.

This patch changes things to avoid the throttling while we sleep.

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

index 2869b33..01b1436 100644 (file)
@@ -687,7 +687,13 @@ static noinline int wait_transaction_pre_flush(struct btrfs_fs_info *info)
                prepare_to_wait(&info->transaction_wait, &wait,
                                TASK_UNINTERRUPTIBLE);
                mutex_unlock(&info->trans_mutex);
+
+               atomic_dec(&info->throttles);
+               wake_up(&info->transaction_throttle);
+
                schedule();
+
+               atomic_inc(&info->throttles);
                mutex_lock(&info->trans_mutex);
                finish_wait(&info->transaction_wait, &wait);
        }