]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
btrfs: annotate as unlikely fs aborted checks in space flushing code
authorFilipe Manana <fdmanana@suse.com>
Wed, 22 Oct 2025 18:15:00 +0000 (19:15 +0100)
committerDavid Sterba <dsterba@suse.com>
Mon, 24 Nov 2025 21:20:29 +0000 (22:20 +0100)
It's not expected to have the fs in an aborted state, so surround the
abortion checks with unlikely to make it clear it's unexpected and to
hint the compiler to generate better code.

Also at maybe_fail_all_tickets() untangle all repeated checks for the
abortion into a single if-then-else. This makes things more readable
and makes the compiler generate less code. On x86_64 with gcc 14.2.0-19
from Debian I got the following object size differences.

Before this change:

  $ size fs/btrfs/btrfs.ko
     text    data     bss     dec     hex filename
  2021606  179704   25088 2226398  21f8de fs/btrfs/btrfs.ko

After this change:

  $ size fs/btrfs/btrfs.ko
     text    data     bss     dec     hex filename
  2021458  179704   25088 2226250  21f84a fs/btrfs/btrfs.ko

Reviewed-by: Johannes Thumshirn <johannes.thumshirn@wdc.com>
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/space-info.c

index 50704e38d1336aa0ded2924d93eb212092a18be3..c3e1831a48a3631142e34440d7a91d5b85c1a98b 100644 (file)
@@ -1119,27 +1119,26 @@ static bool maybe_fail_all_tickets(struct btrfs_space_info *space_info)
               tickets_id == space_info->tickets_id) {
                ticket = list_first_entry(&space_info->tickets,
                                          struct reserve_ticket, list);
+               if (unlikely(abort_error)) {
+                       remove_ticket(space_info, ticket, abort_error);
+               } else {
+                       if (steal_from_global_rsv(space_info, ticket))
+                               return true;
 
-               if (!abort_error && steal_from_global_rsv(space_info, ticket))
-                       return true;
-
-               if (!abort_error && btrfs_test_opt(fs_info, ENOSPC_DEBUG))
-                       btrfs_info(fs_info, "failing ticket with %llu bytes",
-                                  ticket->bytes);
+                       if (btrfs_test_opt(fs_info, ENOSPC_DEBUG))
+                               btrfs_info(fs_info, "failing ticket with %llu bytes",
+                                          ticket->bytes);
 
-               if (abort_error)
-                       remove_ticket(space_info, ticket, abort_error);
-               else
                        remove_ticket(space_info, ticket, -ENOSPC);
 
-               /*
-                * We're just throwing tickets away, so more flushing may not
-                * trip over btrfs_try_granting_tickets, so we need to call it
-                * here to see if we can make progress with the next ticket in
-                * the list.
-                */
-               if (!abort_error)
+                       /*
+                        * We're just throwing tickets away, so more flushing may
+                        * not trip over btrfs_try_granting_tickets, so we need
+                        * to call it here to see if we can make progress with
+                        * the next ticket in the list.
+                        */
                        btrfs_try_granting_tickets(space_info);
+               }
        }
        return (tickets_id != space_info->tickets_id);
 }
@@ -1415,7 +1414,7 @@ static void do_async_reclaim_data_space(struct btrfs_space_info *space_info)
                }
 
                /* Something happened, fail everything and bail. */
-               if (BTRFS_FS_ERROR(fs_info))
+               if (unlikely(BTRFS_FS_ERROR(fs_info)))
                        goto aborted_fs;
                last_tickets_id = space_info->tickets_id;
                spin_unlock(&space_info->lock);
@@ -1449,7 +1448,7 @@ static void do_async_reclaim_data_space(struct btrfs_space_info *space_info)
                        }
 
                        /* Something happened, fail everything and bail. */
-                       if (BTRFS_FS_ERROR(fs_info))
+                       if (unlikely(BTRFS_FS_ERROR(fs_info)))
                                goto aborted_fs;
 
                }
@@ -1553,7 +1552,7 @@ static void priority_reclaim_metadata_space(struct btrfs_space_info *space_info,
         * just to have caller fail immediately instead of later when trying to
         * modify the fs, making it easier to debug -ENOSPC problems.
         */
-       if (BTRFS_FS_ERROR(fs_info))
+       if (unlikely(BTRFS_FS_ERROR(fs_info)))
                remove_ticket(space_info, ticket, BTRFS_FS_ERROR(fs_info));
        else if (!steal_from_global_rsv(space_info, ticket))
                remove_ticket(space_info, ticket, -ENOSPC);