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@xxxxxxxxxx> Signed-off-by: Uros Bizjak <ubizjak@xxxxxxxxx> --- 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