mirror of
https://github.com/linux-msm/laptops-kernel.git
synced 2026-08-13 14:19:53 -07:00
btrfs: use simple booleans for log_commit field in struct btrfs_root
We are using atomic types for the log_commit array of struct btrfs_root but all we need is simple booleans. The log_commit array elements are always protected by the root's log_mutex, both for writes and reads, so we can use a simple boolean. The use of atomics if from the very early days of the log tree code where the access to the fields was not protected by any lock. So switch to simple booleans, which results in cheaper code and slightly reduces the object size too. 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>
This commit is contained in:
committed by
David Sterba
parent
dee6c35c9c
commit
5bd7b60d41
+1
-1
@@ -195,7 +195,7 @@ struct btrfs_root {
|
||||
struct list_head log_ctxs[2];
|
||||
/* Used only for log trees of subvolumes, not for the log root tree */
|
||||
atomic_t log_writers;
|
||||
atomic_t log_commit[2];
|
||||
bool log_commit[2];
|
||||
/*
|
||||
* Protected by the 'log_mutex' lock but can be read without holding
|
||||
* that lock to avoid unnecessary lock contention, in which case it
|
||||
|
||||
@@ -666,8 +666,6 @@ static struct btrfs_root *btrfs_alloc_root(struct btrfs_fs_info *fs_info,
|
||||
init_waitqueue_head(&root->log_commit_wait[1]);
|
||||
INIT_LIST_HEAD(&root->log_ctxs[0]);
|
||||
INIT_LIST_HEAD(&root->log_ctxs[1]);
|
||||
atomic_set(&root->log_commit[0], 0);
|
||||
atomic_set(&root->log_commit[1], 0);
|
||||
atomic_set(&root->log_writers, 0);
|
||||
refcount_set(&root->refs, 1);
|
||||
atomic_set(&root->snapshot_force_cow, 0);
|
||||
|
||||
@@ -1517,12 +1517,8 @@ static noinline int commit_fs_roots(struct btrfs_trans_handle *trans)
|
||||
ASSERT(atomic_read(&root->log_writers) == 0,
|
||||
"atomic_read(&root->log_writers)=%d",
|
||||
atomic_read(&root->log_writers));
|
||||
ASSERT(atomic_read(&root->log_commit[0]) == 0,
|
||||
"atomic_read(&root->log_commit[0])=%d",
|
||||
atomic_read(&root->log_commit[0]));
|
||||
ASSERT(atomic_read(&root->log_commit[1]) == 0,
|
||||
"atomic_read(&root->log_commit[1])=%d",
|
||||
atomic_read(&root->log_commit[1]));
|
||||
ASSERT(!root->log_commit[0]);
|
||||
ASSERT(!root->log_commit[1]);
|
||||
|
||||
radix_tree_tag_clear(&fs_info->fs_roots_radix,
|
||||
(unsigned long)btrfs_root_id(root),
|
||||
|
||||
+8
-8
@@ -3170,7 +3170,7 @@ static bool wait_log_commit(struct btrfs_root *root, int transid)
|
||||
DEFINE_WAIT(wait);
|
||||
const int index = (transid >= 0 ? transid % 2 : -transid % 2);
|
||||
|
||||
if (atomic_read(&root->log_commit[index]) == 0)
|
||||
if (!root->log_commit[index])
|
||||
return false;
|
||||
|
||||
/*
|
||||
@@ -3187,7 +3187,7 @@ static bool wait_log_commit(struct btrfs_root *root, int transid)
|
||||
mutex_lock(&root->log_mutex);
|
||||
|
||||
if (!(root->log_transid_committed < transid &&
|
||||
atomic_read(&root->log_commit[index]) != 0))
|
||||
root->log_commit[index]))
|
||||
break;
|
||||
}
|
||||
finish_wait(&root->log_commit_wait[index], &wait);
|
||||
@@ -3325,7 +3325,7 @@ int btrfs_sync_log(struct btrfs_trans_handle *trans,
|
||||
}
|
||||
ASSERT(log_transid == root->log_transid,
|
||||
"log_transid=%d root->log_transid=%d", log_transid, root->log_transid);
|
||||
atomic_set(&root->log_commit[index1], 1);
|
||||
root->log_commit[index1] = true;
|
||||
|
||||
/* wait for previous tree log sync to complete */
|
||||
wait_log_commit(root, log_transid - 1);
|
||||
@@ -3445,7 +3445,7 @@ int btrfs_sync_log(struct btrfs_trans_handle *trans,
|
||||
goto out;
|
||||
}
|
||||
|
||||
if (atomic_read(&log_root_tree->log_commit[index2])) {
|
||||
if (log_root_tree->log_commit[index2]) {
|
||||
blk_finish_plug(&plug);
|
||||
ret = btrfs_wait_tree_log_extents(log, mark);
|
||||
wait_log_commit(log_root_tree,
|
||||
@@ -3459,7 +3459,7 @@ int btrfs_sync_log(struct btrfs_trans_handle *trans,
|
||||
ASSERT(root_log_ctx.log_transid == log_root_tree->log_transid,
|
||||
"root_log_ctx.log_transid=%d log_root_tree->log_transid=%d",
|
||||
root_log_ctx.log_transid, log_root_tree->log_transid);
|
||||
atomic_set(&log_root_tree->log_commit[index2], 1);
|
||||
log_root_tree->log_commit[index2] = true;
|
||||
|
||||
wait_log_commit(log_root_tree, root_log_ctx.log_transid - 1);
|
||||
|
||||
@@ -3559,7 +3559,7 @@ int btrfs_sync_log(struct btrfs_trans_handle *trans,
|
||||
|
||||
/*
|
||||
* We know there can only be one task here, since we have not yet set
|
||||
* root->log_commit[index1] to 0 and any task attempting to sync the
|
||||
* root->log_commit[index1] to false and any task attempting to sync the
|
||||
* log must wait for the previous log transaction to commit if it's
|
||||
* still in progress or wait for the current log transaction commit if
|
||||
* someone else already started it. We use <= and not < because the
|
||||
@@ -3575,7 +3575,7 @@ out_wake_log_root:
|
||||
btrfs_remove_all_log_ctxs(log_root_tree, index2, ret);
|
||||
|
||||
log_root_tree->log_transid_committed++;
|
||||
atomic_set(&log_root_tree->log_commit[index2], 0);
|
||||
log_root_tree->log_commit[index2] = false;
|
||||
mutex_unlock(&log_root_tree->log_mutex);
|
||||
|
||||
/*
|
||||
@@ -3588,7 +3588,7 @@ out:
|
||||
mutex_lock(&root->log_mutex);
|
||||
btrfs_remove_all_log_ctxs(root, index1, ret);
|
||||
root->log_transid_committed++;
|
||||
atomic_set(&root->log_commit[index1], 0);
|
||||
root->log_commit[index1] = false;
|
||||
mutex_unlock(&root->log_mutex);
|
||||
|
||||
/*
|
||||
|
||||
@@ -1578,9 +1578,9 @@ TRACE_EVENT(btrfs_sync_log_enter,
|
||||
__entry->log_transid_committed =
|
||||
data_race(root->log_transid_committed);
|
||||
__entry->log_committing =
|
||||
atomic_read(&root->log_commit[ctx->log_transid % 2]);
|
||||
data_race(root->log_commit[ctx->log_transid % 2]);
|
||||
__entry->log_committing_prev =
|
||||
atomic_read(&root->log_commit[(ctx->log_transid + 1) % 2]);
|
||||
data_race(root->log_commit[(ctx->log_transid + 1) % 2]);
|
||||
__entry->log_writers = atomic_read(&root->log_writers);
|
||||
),
|
||||
|
||||
|
||||
Reference in New Issue
Block a user