btrfs: use atomic_try_cmpxchg in free_extent_buffer
authorUros Bizjak <ubizjak@gmail.com>
Tue, 9 Aug 2022 16:36:33 +0000 (18:36 +0200)
committerDavid Sterba <dsterba@suse.com>
Mon, 26 Sep 2022 10:27:55 +0000 (12:27 +0200)
commite5677f056010298d3a8d43f710f8b445dd73462d
tree50fbd1389650c103540c84998d1c3e556d49b44d
parentfc65bb53180cc13ea646c150316b219d4579ebe3
btrfs: use atomic_try_cmpxchg in free_extent_buffer

Use `atomic_try_cmpxchg(ptr, &old, new)` instead of
`atomic_cmpxchg(ptr, old, new) == old` in free_extent_buffer. 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.

- atomic_try_cmpxchg implicitly assigns the *ptr value to &old when
  cmpxchg fails, enabling further code simplifications.

This patch has no functional change.

Reviewed-by: Boris Burkov <boris@bur.io>
Signed-off-by: Uros Bizjak <ubizjak@gmail.com>
Reviewed-by: David Sterba <dsterba@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
fs/btrfs/extent_io.c