From 38e03b820e00196018a7ad2523a3c45653b4927d Mon Sep 17 00:00:00 2001 From: Filipe Manana Date: Wed, 22 Oct 2025 19:15:00 +0100 Subject: [PATCH] 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 Signed-off-by: Filipe Manana Reviewed-by: David Sterba Signed-off-by: David Sterba --- fs/btrfs/space-info.c | 37 ++++++++++++++++++------------------- 1 file changed, 18 insertions(+), 19 deletions(-) diff --git a/fs/btrfs/space-info.c b/fs/btrfs/space-info.c index 50704e38d1336..c3e1831a48a36 100644 --- a/fs/btrfs/space-info.c +++ b/fs/btrfs/space-info.c @@ -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); -- 2.47.3