Commit 6dd70ce4 authored by Jan Kara's avatar Jan Kara Committed by Chris Mason

btrfs: Fix busyloops in transaction waiting code

wait_log_commit() and wait_for_writer() were using slightly different
conditions for deciding whether they should call schedule() and whether they
should continue in the wait loop. Thus it could happen that we busylooped when
the first condition was not true while the second one was. That is burning CPU
cycles needlessly and is deadly on UP machines...
Signed-off-by: default avatarJan Kara <jack@suse.cz>
Signed-off-by: default avatarChris Mason <chris.mason@oracle.com>
parent 357b9784
...@@ -1957,7 +1957,8 @@ static int wait_log_commit(struct btrfs_trans_handle *trans, ...@@ -1957,7 +1957,8 @@ static int wait_log_commit(struct btrfs_trans_handle *trans,
finish_wait(&root->log_commit_wait[index], &wait); finish_wait(&root->log_commit_wait[index], &wait);
mutex_lock(&root->log_mutex); mutex_lock(&root->log_mutex);
} while (root->log_transid < transid + 2 && } while (root->fs_info->last_trans_log_full_commit !=
trans->transid && root->log_transid < transid + 2 &&
atomic_read(&root->log_commit[index])); atomic_read(&root->log_commit[index]));
return 0; return 0;
} }
...@@ -1966,7 +1967,8 @@ static int wait_for_writer(struct btrfs_trans_handle *trans, ...@@ -1966,7 +1967,8 @@ static int wait_for_writer(struct btrfs_trans_handle *trans,
struct btrfs_root *root) struct btrfs_root *root)
{ {
DEFINE_WAIT(wait); DEFINE_WAIT(wait);
while (atomic_read(&root->log_writers)) { while (root->fs_info->last_trans_log_full_commit !=
trans->transid && atomic_read(&root->log_writers)) {
prepare_to_wait(&root->log_writer_wait, prepare_to_wait(&root->log_writer_wait,
&wait, TASK_UNINTERRUPTIBLE); &wait, TASK_UNINTERRUPTIBLE);
mutex_unlock(&root->log_mutex); mutex_unlock(&root->log_mutex);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment