aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFilipe Manana <fdmanana@suse.com>2026-07-16 15:27:34 +0100
committerDavid Sterba <dsterba@suse.com>2026-08-07 19:17:18 +0200
commit3ccdd23e9f8f3e94981e6472645442dfd6a789ea (patch)
treef7c1384a2d2159ff3fbb9d9b4c74de6dfbdf4989
parent31ffb32245be3049f040bf65aaba33fef3a39b21 (diff)
btrfs: check for exit condition after waking in wait_log_commit()
We check for the exit condition after we add ourselves to the wait queue and before we unlock the root's log_mutex, sleep and lock again log_mutex. This is not incorrect, but it's not optimal since in the first iteration this is pointless because we already know that root->log_commit[index] is not zero, so we should check the exit condition only after unlocking log_mutex, sleeping, waking up and locking again the log_mutex. So move the check for the exit condition to bottom of the loop, after we were woken and locked log_mutex again. Reviewed-by: Boris Burkov <boris@bur.io> Reviewed-by: Jeff Layton <jlayton@kernel.org> Signed-off-by: Filipe Manana <fdmanana@suse.com> Signed-off-by: David Sterba <dsterba@suse.com>
-rw-r--r--fs/btrfs/tree-log.c8
1 files changed, 4 insertions, 4 deletions
diff --git a/fs/btrfs/tree-log.c b/fs/btrfs/tree-log.c
index 495da98a211d..7d7a0dbc7b4a 100644
--- a/fs/btrfs/tree-log.c
+++ b/fs/btrfs/tree-log.c
@@ -3182,13 +3182,13 @@ static bool wait_log_commit(struct btrfs_root *root, int transid)
prepare_to_wait(&root->log_commit_wait[index],
&wait, TASK_UNINTERRUPTIBLE);
- if (!(root->log_transid_committed < transid &&
- atomic_read(&root->log_commit[index])))
- break;
-
mutex_unlock(&root->log_mutex);
schedule();
mutex_lock(&root->log_mutex);
+
+ if (!(root->log_transid_committed < transid &&
+ atomic_read(&root->log_commit[index]) != 0))
+ break;
}
finish_wait(&root->log_commit_wait[index], &wait);