btrfs: reorganize logic at free_extent_buffer() for better readability
authorFilipe Manana <fdmanana@suse.com>
Mon, 2 Jun 2025 12:27:49 +0000 (13:27 +0100)
committerDavid Sterba <dsterba@suse.com>
Mon, 21 Jul 2025 21:53:30 +0000 (23:53 +0200)
It's hard to read the logic to break out of the while loop since it's a
very long expression consisting of a logical or of two composite
expressions, each one composed by a logical and. Further each one is also
testing for the EXTENT_BUFFER_UNMAPPED bit, making it more verbose than
necessary.

So change from this:

    if ((!test_bit(EXTENT_BUFFER_UNMAPPED, &eb->bflags) && refs <= 3)
        || (test_bit(EXTENT_BUFFER_UNMAPPED, &eb->bflags) &&
            refs == 1))
       break;

To this:

    if (test_bit(EXTENT_BUFFER_UNMAPPED, &eb->bflags)) {
        if (refs == 1)
            break;
    } else if (refs <= 3) {
            break;
    }

At least on x86_64 using gcc 9.3.0, this doesn't change the object size.

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 d11e1d19278485d0c6fb057e4379df37f1d75234..21d2cb7f538e2ad244a6ea79ce311e777f9ac1f4 100644 (file)
@@ -3486,10 +3486,13 @@ void free_extent_buffer(struct extent_buffer *eb)
 
        refs = atomic_read(&eb->refs);
        while (1) {
-               if ((!test_bit(EXTENT_BUFFER_UNMAPPED, &eb->bflags) && refs <= 3)
-                   || (test_bit(EXTENT_BUFFER_UNMAPPED, &eb->bflags) &&
-                       refs == 1))
+               if (test_bit(EXTENT_BUFFER_UNMAPPED, &eb->bflags)) {
+                       if (refs == 1)
+                               break;
+               } else if (refs <= 3) {
                        break;
+               }
+
                if (atomic_try_cmpxchg(&eb->refs, &refs, refs - 1))
                        return;
        }