All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 1/9] Btrfs: use ACCESS_ONCE to prevent the optimize accesses to ->last_trans_log_full_commit
@ 2014-02-20 10:08 Miao Xie
  2014-02-20 10:08 ` [PATCH 2/9] Btrfs: fix the skipped transaction commit during the file sync Miao Xie
                   ` (7 more replies)
  0 siblings, 8 replies; 17+ messages in thread
From: Miao Xie @ 2014-02-20 10:08 UTC (permalink / raw)
  To: linux-btrfs

->last_trans_log_full_commit may be changed by the other tasks without lock,
so we need prevent the compiler from the optimize access just like
	tmp = fs_info->last_trans_log_full_commit
	if (tmp == ...)
		...

	<do something>

	if (tmp == ...)
		...

In fact, we need get the new value of ->last_trans_log_full_commit during
the second access. Fix it by ACCESS_ONCE().

Signed-off-by: Miao Xie <miaox@cn.fujitsu.com>
---
 fs/btrfs/tree-log.c | 17 ++++++++++-------
 1 file changed, 10 insertions(+), 7 deletions(-)

diff --git a/fs/btrfs/tree-log.c b/fs/btrfs/tree-log.c
index 7c449c6..5a4e10b 100644
--- a/fs/btrfs/tree-log.c
+++ b/fs/btrfs/tree-log.c
@@ -2375,14 +2375,14 @@ static int wait_log_commit(struct btrfs_trans_handle *trans,
 				&wait, TASK_UNINTERRUPTIBLE);
 		mutex_unlock(&root->log_mutex);
 
-		if (root->fs_info->last_trans_log_full_commit !=
+		if (ACCESS_ONCE(root->fs_info->last_trans_log_full_commit) !=
 		    trans->transid && root->log_transid < transid + 2 &&
 		    atomic_read(&root->log_commit[index]))
 			schedule();
 
 		finish_wait(&root->log_commit_wait[index], &wait);
 		mutex_lock(&root->log_mutex);
-	} while (root->fs_info->last_trans_log_full_commit !=
+	} while (ACCESS_ONCE(root->fs_info->last_trans_log_full_commit) !=
 		 trans->transid && root->log_transid < transid + 2 &&
 		 atomic_read(&root->log_commit[index]));
 	return 0;
@@ -2392,12 +2392,12 @@ static void wait_for_writer(struct btrfs_trans_handle *trans,
 			    struct btrfs_root *root)
 {
 	DEFINE_WAIT(wait);
-	while (root->fs_info->last_trans_log_full_commit !=
+	while (ACCESS_ONCE(root->fs_info->last_trans_log_full_commit) !=
 	       trans->transid && atomic_read(&root->log_writers)) {
 		prepare_to_wait(&root->log_writer_wait,
 				&wait, TASK_UNINTERRUPTIBLE);
 		mutex_unlock(&root->log_mutex);
-		if (root->fs_info->last_trans_log_full_commit !=
+		if (ACCESS_ONCE(root->fs_info->last_trans_log_full_commit) !=
 		    trans->transid && atomic_read(&root->log_writers))
 			schedule();
 		mutex_lock(&root->log_mutex);
@@ -2456,7 +2456,8 @@ int btrfs_sync_log(struct btrfs_trans_handle *trans,
 	}
 
 	/* bail out if we need to do a full commit */
-	if (root->fs_info->last_trans_log_full_commit == trans->transid) {
+	if (ACCESS_ONCE(root->fs_info->last_trans_log_full_commit) ==
+	    trans->transid) {
 		ret = -EAGAIN;
 		btrfs_free_logged_extents(log, log_transid);
 		mutex_unlock(&root->log_mutex);
@@ -2515,7 +2516,8 @@ int btrfs_sync_log(struct btrfs_trans_handle *trans,
 			mutex_unlock(&log_root_tree->log_mutex);
 			goto out;
 		}
-		root->fs_info->last_trans_log_full_commit = trans->transid;
+		ACCESS_ONCE(root->fs_info->last_trans_log_full_commit) =
+								trans->transid;
 		btrfs_wait_marked_extents(log, &log->dirty_log_pages, mark);
 		btrfs_free_logged_extents(log, log_transid);
 		mutex_unlock(&log_root_tree->log_mutex);
@@ -2547,7 +2549,8 @@ int btrfs_sync_log(struct btrfs_trans_handle *trans,
 	 * now that we've moved on to the tree of log tree roots,
 	 * check the full commit flag again
 	 */
-	if (root->fs_info->last_trans_log_full_commit == trans->transid) {
+	if (ACCESS_ONCE(root->fs_info->last_trans_log_full_commit) ==
+	    trans->transid) {
 		blk_finish_plug(&plug);
 		btrfs_wait_marked_extents(log, &log->dirty_log_pages, mark);
 		btrfs_free_logged_extents(log, log_transid);
-- 
1.8.1.4


^ permalink raw reply related	[flat|nested] 17+ messages in thread

end of thread, other threads:[~2014-03-10  1:14 UTC | newest]

Thread overview: 17+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-02-20 10:08 [PATCH 1/9] Btrfs: use ACCESS_ONCE to prevent the optimize accesses to ->last_trans_log_full_commit Miao Xie
2014-02-20 10:08 ` [PATCH 2/9] Btrfs: fix the skipped transaction commit during the file sync Miao Xie
2014-02-20 10:08 ` [PATCH 3/9] Btrfs: don't start the log transaction if the log tree init fails Miao Xie
2014-02-20 10:08 ` [PATCH 4/9] Btrfs: use bitfield instead of integer data type for the some variants in btrfs_root Miao Xie
2014-02-22  0:23   ` David Sterba
2014-02-26  9:10     ` Miao Xie
2014-02-27 17:02       ` David Sterba
2014-03-07 23:54   ` Josef Bacik
2014-03-08  0:00   ` Josef Bacik
2014-03-10  1:16     ` Miao Xie
2014-02-20 10:08 ` [PATCH 5/9] Btrfs: remove unnecessary memory barrier in btrfs_sync_log() Miao Xie
2014-02-20 10:08 ` [PATCH 6/9] Btrfs: use signed integer instead of unsigned long integer for log transid Miao Xie
2014-02-20 10:08 ` [PATCH 7/9] Btrfs: stop joining the log transaction if sync log fails Miao Xie
2014-02-22  0:27   ` David Sterba
2014-02-26  8:51     ` Miao Xie
2014-02-20 10:08 ` [PATCH 8/9] Btrfs: fix skipped error handle when log sync failed Miao Xie
2014-02-20 10:08 ` [PATCH 9/9] Btrfs: just wait or commit our own log sub-transaction Miao Xie

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.