Skip to content

Commit c3df76a

Browse files
fdmananakdave
authored andcommitted
btrfs: tag 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 differentes. 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> Signed-off-by: David Sterba <dsterba@suse.com>
1 parent aa695ae commit c3df76a

File tree

1 file changed

+18
-19
lines changed

1 file changed

+18
-19
lines changed

fs/btrfs/space-info.c

Lines changed: 18 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1114,27 +1114,26 @@ static bool maybe_fail_all_tickets(struct btrfs_space_info *space_info)
11141114
tickets_id == space_info->tickets_id) {
11151115
ticket = list_first_entry(&space_info->tickets,
11161116
struct reserve_ticket, list);
1117+
if (unlikely(abort_error)) {
1118+
remove_ticket(space_info, ticket, abort_error);
1119+
} else {
1120+
if (steal_from_global_rsv(space_info, ticket))
1121+
return true;
11171122

1118-
if (!abort_error && steal_from_global_rsv(space_info, ticket))
1119-
return true;
1120-
1121-
if (!abort_error && btrfs_test_opt(fs_info, ENOSPC_DEBUG))
1122-
btrfs_info(fs_info, "failing ticket with %llu bytes",
1123-
ticket->bytes);
1123+
if (btrfs_test_opt(fs_info, ENOSPC_DEBUG))
1124+
btrfs_info(fs_info, "failing ticket with %llu bytes",
1125+
ticket->bytes);
11241126

1125-
if (abort_error)
1126-
remove_ticket(space_info, ticket, abort_error);
1127-
else
11281127
remove_ticket(space_info, ticket, -ENOSPC);
11291128

1130-
/*
1131-
* We're just throwing tickets away, so more flushing may not
1132-
* trip over btrfs_try_granting_tickets, so we need to call it
1133-
* here to see if we can make progress with the next ticket in
1134-
* the list.
1135-
*/
1136-
if (!abort_error)
1129+
/*
1130+
* We're just throwing tickets away, so more flushing may
1131+
* not trip over btrfs_try_granting_tickets, so we need
1132+
* to call it here to see if we can make progress with
1133+
* the next ticket in the list.
1134+
*/
11371135
btrfs_try_granting_tickets(space_info);
1136+
}
11381137
}
11391138
return (tickets_id != space_info->tickets_id);
11401139
}
@@ -1410,7 +1409,7 @@ static void do_async_reclaim_data_space(struct btrfs_space_info *space_info)
14101409
}
14111410

14121411
/* Something happened, fail everything and bail. */
1413-
if (BTRFS_FS_ERROR(fs_info))
1412+
if (unlikely(BTRFS_FS_ERROR(fs_info)))
14141413
goto aborted_fs;
14151414
last_tickets_id = space_info->tickets_id;
14161415
spin_unlock(&space_info->lock);
@@ -1444,7 +1443,7 @@ static void do_async_reclaim_data_space(struct btrfs_space_info *space_info)
14441443
}
14451444

14461445
/* Something happened, fail everything and bail. */
1447-
if (BTRFS_FS_ERROR(fs_info))
1446+
if (unlikely(BTRFS_FS_ERROR(fs_info)))
14481447
goto aborted_fs;
14491448

14501449
}
@@ -1548,7 +1547,7 @@ static void priority_reclaim_metadata_space(struct btrfs_space_info *space_info,
15481547
* just to have caller fail immediately instead of later when trying to
15491548
* modify the fs, making it easier to debug -ENOSPC problems.
15501549
*/
1551-
if (BTRFS_FS_ERROR(fs_info))
1550+
if (unlikely(BTRFS_FS_ERROR(fs_info)))
15521551
remove_ticket(space_info, ticket, BTRFS_FS_ERROR(fs_info));
15531552
else if (!steal_from_global_rsv(space_info, ticket))
15541553
remove_ticket(space_info, ticket, -ENOSPC);

0 commit comments

Comments
 (0)