btrfs: annotate as unlikely fs aborted checks in space flushing code

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>
This commit is contained in:
Filipe Manana 2025-10-22 19:15:00 +01:00 committed by David Sterba
parent f912f0af13
commit 38e03b820e

View 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 (!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 (abort_error)
if (unlikely(abort_error)) {
remove_ticket(space_info, ticket, abort_error);
else
} else {
if (steal_from_global_rsv(space_info, ticket))
return true;
if (btrfs_test_opt(fs_info, ENOSPC_DEBUG))
btrfs_info(fs_info, "failing ticket with %llu bytes",
ticket->bytes);
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);