Skip to content

Commit 20195d0

Browse files
ubizjakcmaiolino
authored andcommitted
xfs: Use try_cmpxchg() in xlog_cil_insert_pcp_aggregate()
Use !try_cmpxchg instead of cmpxchg (*ptr, old, new) != old in xlog_cil_insert_pcp_aggregate(). x86 CMPXCHG instruction returns success in ZF flag, so this change saves a compare after cmpxchg. Also, try_cmpxchg implicitly assigns old *ptr value to "old" when cmpxchg fails. There is no need to re-read the value in the loop. Note that the value from *ptr should be read using READ_ONCE to prevent the compiler from merging, refetching or reordering the read. No functional change intended. Signed-off-by: Uros Bizjak <[email protected]> Reviewed-by: Christoph Hellwig <[email protected]> Cc: Chandan Babu R <[email protected]> Cc: Darrick J. Wong <[email protected]> Reviewed-by: Dave Chinner <[email protected]> Signed-off-by: Carlos Maiolino <[email protected]>
1 parent 6148b77 commit 20195d0

File tree

1 file changed

+4
-7
lines changed

1 file changed

+4
-7
lines changed

fs/xfs/xfs_log_cil.c

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,6 @@ xlog_cil_insert_pcp_aggregate(
156156
struct xfs_cil *cil,
157157
struct xfs_cil_ctx *ctx)
158158
{
159-
struct xlog_cil_pcp *cilpcp;
160159
int cpu;
161160
int count = 0;
162161

@@ -171,13 +170,11 @@ xlog_cil_insert_pcp_aggregate(
171170
* structures that could have a nonzero space_used.
172171
*/
173172
for_each_cpu(cpu, &ctx->cil_pcpmask) {
174-
int old, prev;
173+
struct xlog_cil_pcp *cilpcp = per_cpu_ptr(cil->xc_pcp, cpu);
174+
int old = READ_ONCE(cilpcp->space_used);
175175

176-
cilpcp = per_cpu_ptr(cil->xc_pcp, cpu);
177-
do {
178-
old = cilpcp->space_used;
179-
prev = cmpxchg(&cilpcp->space_used, old, 0);
180-
} while (old != prev);
176+
while (!try_cmpxchg(&cilpcp->space_used, &old, 0))
177+
;
181178
count += old;
182179
}
183180
atomic_add(count, &ctx->space_used);

0 commit comments

Comments
 (0)