btrfs: add comment for optimization in free_extent_buffer()
authorFilipe Manana <fdmanana@suse.com>
Mon, 2 Jun 2025 12:46:23 +0000 (13:46 +0100)
committerDavid Sterba <dsterba@suse.com>
Mon, 21 Jul 2025 21:53:30 +0000 (23:53 +0200)
There's this special atomic compare and exchange logic which serves to
avoid locking the extent buffers refs_lock spinlock and therefore reduce
lock contention, so add a comment to make it more obvious.

Reviewed-by: Boris Burkov <boris@bur.io>
Signed-off-by: Filipe Manana <fdmanana@suse.com>
Reviewed-by: David Sterba <dsterba@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
fs/btrfs/extent_io.c

index 21d2cb7f538e2ad244a6ea79ce311e777f9ac1f4..5e8dd9a99e58c1ea33d9107a72761446445c3eec 100644 (file)
@@ -3493,6 +3493,7 @@ void free_extent_buffer(struct extent_buffer *eb)
                        break;
                }
 
+               /* Optimization to avoid locking eb->refs_lock. */
                if (atomic_try_cmpxchg(&eb->refs, &refs, refs - 1))
                        return;
        }