[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Message-Id: <20220809165615.9694-1-ubizjak@gmail.com>
Date: Tue, 9 Aug 2022 18:56:15 +0200
From: Uros Bizjak <ubizjak@...il.com>
To: linux-xfs@...r.kernel.org, linux-kernel@...r.kernel.org
Cc: Uros Bizjak <ubizjak@...il.com>,
"Darrick J. Wong" <djwong@...nel.org>
Subject: [PATCH] fs/xfs: Use atomic64_try_cmpxchg in xlog_grant_{add,sub}_space
Use `!atomic64_try_cmpxchg(ptr, &old, new)` instead of
`atomic64_cmpxchg(ptr, old, new) != old` in xlog_grant_{add,sub}_space.
This has two benefits:
- The x86 cmpxchg instruction returns success in the ZF flag, so this
change saves a compare after cmpxchg, as well as a related move
instruction in the front of cmpxchg.
- atomic64_try_cmpxchg implicitly assigns the *ptr value to &old when
cmpxchg fails, enabling further code simplifications.
This patch has no functional change.
Cc: "Darrick J. Wong" <djwong@...nel.org>
Signed-off-by: Uros Bizjak <ubizjak@...il.com>
---
fs/xfs/xfs_log.c | 14 ++++++--------
1 file changed, 6 insertions(+), 8 deletions(-)
diff --git a/fs/xfs/xfs_log.c b/fs/xfs/xfs_log.c
index 4b1c0a9c6368..92e39873d09e 100644
--- a/fs/xfs/xfs_log.c
+++ b/fs/xfs/xfs_log.c
@@ -148,7 +148,7 @@ xlog_grant_sub_space(
int bytes)
{
int64_t head_val = atomic64_read(head);
- int64_t new, old;
+ int64_t new;
do {
int cycle, space;
@@ -161,10 +161,9 @@ xlog_grant_sub_space(
cycle--;
}
- old = head_val;
new = xlog_assign_grant_head_val(cycle, space);
- head_val = atomic64_cmpxchg(head, old, new);
- } while (head_val != old);
+
+ } while (!atomic64_try_cmpxchg(head, &head_val, new));
}
static void
@@ -174,7 +173,7 @@ xlog_grant_add_space(
int bytes)
{
int64_t head_val = atomic64_read(head);
- int64_t new, old;
+ int64_t new;
do {
int tmp;
@@ -190,10 +189,9 @@ xlog_grant_add_space(
cycle++;
}
- old = head_val;
new = xlog_assign_grant_head_val(cycle, space);
- head_val = atomic64_cmpxchg(head, old, new);
- } while (head_val != old);
+
+ } while (!atomic64_try_cmpxchg(head, &head_val, new));
}
STATIC void
--
2.37.1
Powered by blists - more mailing lists