Skip to content

Commit 7801f3e

Browse files
fdmananakdave
authored andcommitted
btrfs: tag as unlikely if statements that check for fs in error state
Having the filesystem in an error state, meaning we had a transaction abort, is unexpected. Mark every check for the error state with the unlikely annotation to convey that and to allow the compiler to generate better code. On x86_64, using gcc 14.2.0-19 from Debian, resulted in a slightly reduced object size and better code. Before: $ size fs/btrfs/btrfs.ko text data bss dec hex filename 2008598 175912 15592 2200102 219226 fs/btrfs/btrfs.ko After: $ size fs/btrfs/btrfs.ko text data bss dec hex filename 2008450 175912 15592 2199954 219192 fs/btrfs/btrfs.ko Reviewed-by: Anand Jain <asj@kernel.org> Signed-off-by: Filipe Manana <fdmanana@suse.com> Reviewed-by: David Sterba <dsterba@suse.com> Signed-off-by: David Sterba <dsterba@suse.com>
1 parent 3f487be commit 7801f3e

10 files changed

Lines changed: 16 additions & 16 deletions

File tree

fs/btrfs/disk-io.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1556,7 +1556,7 @@ static int transaction_kthread(void *arg)
15561556
wake_up_process(fs_info->cleaner_kthread);
15571557
mutex_unlock(&fs_info->transaction_kthread_mutex);
15581558

1559-
if (BTRFS_FS_ERROR(fs_info))
1559+
if (unlikely(BTRFS_FS_ERROR(fs_info)))
15601560
btrfs_cleanup_transaction(fs_info);
15611561
if (!kthread_should_stop() &&
15621562
(!btrfs_transaction_blocked(fs_info) ||
@@ -4148,7 +4148,7 @@ void btrfs_drop_and_free_fs_root(struct btrfs_fs_info *fs_info,
41484148
drop_ref = true;
41494149
spin_unlock(&fs_info->fs_roots_radix_lock);
41504150

4151-
if (BTRFS_FS_ERROR(fs_info)) {
4151+
if (unlikely(BTRFS_FS_ERROR(fs_info))) {
41524152
ASSERT(root->log_root == NULL);
41534153
if (root->reloc_root) {
41544154
btrfs_put_root(root->reloc_root);

fs/btrfs/extent_io.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2400,7 +2400,7 @@ int btree_writepages(struct address_space *mapping, struct writeback_control *wb
24002400
* and it only returns 0 or errors.
24012401
*/
24022402
ASSERT(ret <= 0);
2403-
if (!ret && BTRFS_FS_ERROR(fs_info))
2403+
if (unlikely(!ret && BTRFS_FS_ERROR(fs_info)))
24042404
ret = -EROFS;
24052405

24062406
if (ctx.zoned_bg)

fs/btrfs/file.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1445,7 +1445,7 @@ ssize_t btrfs_do_write_iter(struct kiocb *iocb, struct iov_iter *from,
14451445
* have opened a file as writable, we have to stop this write operation
14461446
* to ensure consistency.
14471447
*/
1448-
if (BTRFS_FS_ERROR(inode->root->fs_info))
1448+
if (unlikely(BTRFS_FS_ERROR(inode->root->fs_info)))
14491449
return -EROFS;
14501450

14511451
if (encoded && (iocb->ki_flags & IOCB_NOWAIT))

fs/btrfs/inode.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8972,7 +8972,7 @@ int btrfs_start_delalloc_snapshot(struct btrfs_root *root, bool in_reclaim_conte
89728972
{
89738973
struct btrfs_fs_info *fs_info = root->fs_info;
89748974

8975-
if (BTRFS_FS_ERROR(fs_info))
8975+
if (unlikely(BTRFS_FS_ERROR(fs_info)))
89768976
return -EROFS;
89778977
return start_delalloc_inodes(root, NULL, true, in_reclaim_context);
89788978
}
@@ -8985,7 +8985,7 @@ int btrfs_start_delalloc_roots(struct btrfs_fs_info *fs_info, long nr,
89858985
LIST_HEAD(splice);
89868986
int ret;
89878987

8988-
if (BTRFS_FS_ERROR(fs_info))
8988+
if (unlikely(BTRFS_FS_ERROR(fs_info)))
89898989
return -EROFS;
89908990

89918991
mutex_lock(&fs_info->delalloc_root_mutex);

fs/btrfs/messages.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ static void btrfs_state_to_string(const struct btrfs_fs_info *info, char *buf)
3737
memcpy(curr, STATE_STRING_PREFACE, sizeof(STATE_STRING_PREFACE));
3838
curr += sizeof(STATE_STRING_PREFACE) - 1;
3939

40-
if (BTRFS_FS_ERROR(info)) {
40+
if (unlikely(BTRFS_FS_ERROR(info))) {
4141
*curr++ = 'E';
4242
states_printed = true;
4343
}

fs/btrfs/scrub.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2974,7 +2974,7 @@ static noinline_for_stack int scrub_supers(struct scrub_ctx *sctx,
29742974
struct page *page;
29752975
struct btrfs_fs_info *fs_info = sctx->fs_info;
29762976

2977-
if (BTRFS_FS_ERROR(fs_info))
2977+
if (unlikely(BTRFS_FS_ERROR(fs_info)))
29782978
return -EROFS;
29792979

29802980
page = alloc_page(GFP_KERNEL);

fs/btrfs/super.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1299,7 +1299,7 @@ static int btrfs_remount_rw(struct btrfs_fs_info *fs_info)
12991299
{
13001300
int ret;
13011301

1302-
if (BTRFS_FS_ERROR(fs_info)) {
1302+
if (unlikely(BTRFS_FS_ERROR(fs_info))) {
13031303
btrfs_err(fs_info,
13041304
"remounting read-write after error is not allowed");
13051305
return -EINVAL;

fs/btrfs/transaction.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -275,7 +275,7 @@ static noinline int join_transaction(struct btrfs_fs_info *fs_info,
275275
spin_lock(&fs_info->trans_lock);
276276
loop:
277277
/* The file system has been taken offline. No new transactions. */
278-
if (BTRFS_FS_ERROR(fs_info)) {
278+
if (unlikely(BTRFS_FS_ERROR(fs_info))) {
279279
spin_unlock(&fs_info->trans_lock);
280280
return -EROFS;
281281
}
@@ -333,7 +333,7 @@ static noinline int join_transaction(struct btrfs_fs_info *fs_info,
333333
btrfs_lockdep_release(fs_info, btrfs_trans_num_writers);
334334
kfree(cur_trans);
335335
goto loop;
336-
} else if (BTRFS_FS_ERROR(fs_info)) {
336+
} else if (unlikely(BTRFS_FS_ERROR(fs_info))) {
337337
spin_unlock(&fs_info->trans_lock);
338338
btrfs_lockdep_release(fs_info, btrfs_trans_num_extwriters);
339339
btrfs_lockdep_release(fs_info, btrfs_trans_num_writers);
@@ -612,7 +612,7 @@ start_transaction(struct btrfs_root *root, unsigned int num_items,
612612
bool do_chunk_alloc = false;
613613
int ret;
614614

615-
if (BTRFS_FS_ERROR(fs_info))
615+
if (unlikely(BTRFS_FS_ERROR(fs_info)))
616616
return ERR_PTR(-EROFS);
617617

618618
if (current->journal_info) {
@@ -1120,7 +1120,7 @@ static int __btrfs_end_transaction(struct btrfs_trans_handle *trans,
11201120
if (throttle)
11211121
btrfs_run_delayed_iputs(info);
11221122

1123-
if (TRANS_ABORTED(trans) || BTRFS_FS_ERROR(info)) {
1123+
if (unlikely(TRANS_ABORTED(trans) || BTRFS_FS_ERROR(info))) {
11241124
wake_up_process(info->transaction_kthread);
11251125
if (TRANS_ABORTED(trans))
11261126
ret = trans->aborted;
@@ -2351,7 +2351,7 @@ int btrfs_commit_transaction(struct btrfs_trans_handle *trans)
23512351
* abort to prevent writing a new superblock that reflects a
23522352
* corrupt state (pointing to trees with unwritten nodes/leafs).
23532353
*/
2354-
if (BTRFS_FS_ERROR(fs_info)) {
2354+
if (unlikely(BTRFS_FS_ERROR(fs_info))) {
23552355
spin_unlock(&fs_info->trans_lock);
23562356
ret = -EROFS;
23572357
goto lockdep_release;

fs/btrfs/tree-log.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3566,7 +3566,7 @@ int btrfs_sync_log(struct btrfs_trans_handle *trans,
35663566
* writing the super here would result in transid mismatches. If there
35673567
* is an error here just bail.
35683568
*/
3569-
if (BTRFS_FS_ERROR(fs_info)) {
3569+
if (unlikely(BTRFS_FS_ERROR(fs_info))) {
35703570
ret = -EIO;
35713571
btrfs_set_log_full_commit(trans);
35723572
btrfs_abort_transaction(trans, ret);

fs/btrfs/volumes.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3602,7 +3602,7 @@ int btrfs_relocate_chunk(struct btrfs_fs_info *fs_info, u64 chunk_offset, bool v
36023602
* If we had a transaction abort, stop all running scrubs.
36033603
* See transaction.c:cleanup_transaction() why we do it here.
36043604
*/
3605-
if (BTRFS_FS_ERROR(fs_info))
3605+
if (unlikely(BTRFS_FS_ERROR(fs_info)))
36063606
btrfs_scrub_cancel(fs_info);
36073607
return ret;
36083608
}

0 commit comments

Comments
 (0)