]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
xfs: Use xchg() in xlog_cil_insert_pcp_aggregate()
authorUros Bizjak <ubizjak@gmail.com>
Wed, 20 Nov 2024 15:06:22 +0000 (16:06 +0100)
committerCarlos Maiolino <cem@kernel.org>
Thu, 28 Nov 2024 11:42:10 +0000 (12:42 +0100)
try_cmpxchg() loop with constant "new" value can be substituted
with just xchg() to atomically get and clear the location.

The code on x86_64 improves from:

    1e7f: 48 89 4c 24 10        mov    %rcx,0x10(%rsp)
    1e84: 48 03 14 c5 00 00 00  add    0x0(,%rax,8),%rdx
    1e8b: 00
1e88: R_X86_64_32S __per_cpu_offset
    1e8c: 8b 02                 mov    (%rdx),%eax
    1e8e: 41 89 c5              mov    %eax,%r13d
    1e91: 31 c9                 xor    %ecx,%ecx
    1e93: f0 0f b1 0a           lock cmpxchg %ecx,(%rdx)
    1e97: 75 f5                 jne    1e8e <xlog_cil_commit+0x84e>
    1e99: 48 8b 4c 24 10        mov    0x10(%rsp),%rcx
    1e9e: 45 01 e9              add    %r13d,%r9d

to just:

    1e7f: 48 03 14 cd 00 00 00  add    0x0(,%rcx,8),%rdx
    1e86: 00
1e83: R_X86_64_32S __per_cpu_offset
    1e87: 31 c9                 xor    %ecx,%ecx
    1e89: 87 0a                 xchg   %ecx,(%rdx)
    1e8b: 41 01 cb              add    %ecx,%r11d

No functional change intended.

Signed-off-by: Uros Bizjak <ubizjak@gmail.com>
Cc: Chandan Babu R <chandan.babu@oracle.com>
Cc: Darrick J. Wong <djwong@kernel.org>
Cc: Christoph Hellwig <hch@infradead.org>
Cc: Dave Chinner <dchinner@redhat.com>
Reviewed-by: Alex Elder <elder@riscstar.com>
Reviewed-by: Dave Chinner <dchinner@redhat.com>
Signed-off-by: Carlos Maiolino <cem@kernel.org>
fs/xfs/xfs_log_cil.c

index 2e9157b650e647215e16a81a3ec335abe6d2746c..1ca406ec1b40b324e31ebaab49c9d38d87aa1adc 100644 (file)
@@ -171,11 +171,8 @@ xlog_cil_insert_pcp_aggregate(
         */
        for_each_cpu(cpu, &ctx->cil_pcpmask) {
                struct xlog_cil_pcp     *cilpcp = per_cpu_ptr(cil->xc_pcp, cpu);
-               int                     old = READ_ONCE(cilpcp->space_used);
 
-               while (!try_cmpxchg(&cilpcp->space_used, &old, 0))
-                       ;
-               count += old;
+               count += xchg(&cilpcp->space_used, 0);
        }
        atomic_add(count, &ctx->space_used);
 }