koverstreet / bcachefs

Other
675 stars 69 forks source link

bcachefs: Use try_cmpxchg() family of functions instead of cmpxchg() #683

Closed ubizjak closed 4 months ago

ubizjak commented 4 months ago

Use try_cmpxchg() family of functions instead of cmpxchg (*ptr, old, new) == old. x86 CMPXCHG instruction returns success in ZF flag, so this change saves a compare after cmpxchg (and related move instruction in front of 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.

No functional change intended.

Cc: Kent Overstreet kent.overstreet@linux.dev Cc: Brian Foster bfoster@redhat.com