Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

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>

authored by

Filipe Manana and committed by
David Sterba
7801f3ea 3f487be8

+16 -16
+2 -2
fs/btrfs/disk-io.c
··· 1556 1556 wake_up_process(fs_info->cleaner_kthread); 1557 1557 mutex_unlock(&fs_info->transaction_kthread_mutex); 1558 1558 1559 - if (BTRFS_FS_ERROR(fs_info)) 1559 + if (unlikely(BTRFS_FS_ERROR(fs_info))) 1560 1560 btrfs_cleanup_transaction(fs_info); 1561 1561 if (!kthread_should_stop() && 1562 1562 (!btrfs_transaction_blocked(fs_info) || ··· 4148 4148 drop_ref = true; 4149 4149 spin_unlock(&fs_info->fs_roots_radix_lock); 4150 4150 4151 - if (BTRFS_FS_ERROR(fs_info)) { 4151 + if (unlikely(BTRFS_FS_ERROR(fs_info))) { 4152 4152 ASSERT(root->log_root == NULL); 4153 4153 if (root->reloc_root) { 4154 4154 btrfs_put_root(root->reloc_root);
+1 -1
fs/btrfs/extent_io.c
··· 2400 2400 * and it only returns 0 or errors. 2401 2401 */ 2402 2402 ASSERT(ret <= 0); 2403 - if (!ret && BTRFS_FS_ERROR(fs_info)) 2403 + if (unlikely(!ret && BTRFS_FS_ERROR(fs_info))) 2404 2404 ret = -EROFS; 2405 2405 2406 2406 if (ctx.zoned_bg)
+1 -1
fs/btrfs/file.c
··· 1445 1445 * have opened a file as writable, we have to stop this write operation 1446 1446 * to ensure consistency. 1447 1447 */ 1448 - if (BTRFS_FS_ERROR(inode->root->fs_info)) 1448 + if (unlikely(BTRFS_FS_ERROR(inode->root->fs_info))) 1449 1449 return -EROFS; 1450 1450 1451 1451 if (encoded && (iocb->ki_flags & IOCB_NOWAIT))
+2 -2
fs/btrfs/inode.c
··· 8972 8972 { 8973 8973 struct btrfs_fs_info *fs_info = root->fs_info; 8974 8974 8975 - if (BTRFS_FS_ERROR(fs_info)) 8975 + if (unlikely(BTRFS_FS_ERROR(fs_info))) 8976 8976 return -EROFS; 8977 8977 return start_delalloc_inodes(root, NULL, true, in_reclaim_context); 8978 8978 } ··· 8985 8985 LIST_HEAD(splice); 8986 8986 int ret; 8987 8987 8988 - if (BTRFS_FS_ERROR(fs_info)) 8988 + if (unlikely(BTRFS_FS_ERROR(fs_info))) 8989 8989 return -EROFS; 8990 8990 8991 8991 mutex_lock(&fs_info->delalloc_root_mutex);
+1 -1
fs/btrfs/messages.c
··· 37 37 memcpy(curr, STATE_STRING_PREFACE, sizeof(STATE_STRING_PREFACE)); 38 38 curr += sizeof(STATE_STRING_PREFACE) - 1; 39 39 40 - if (BTRFS_FS_ERROR(info)) { 40 + if (unlikely(BTRFS_FS_ERROR(info))) { 41 41 *curr++ = 'E'; 42 42 states_printed = true; 43 43 }
+1 -1
fs/btrfs/scrub.c
··· 2974 2974 struct page *page; 2975 2975 struct btrfs_fs_info *fs_info = sctx->fs_info; 2976 2976 2977 - if (BTRFS_FS_ERROR(fs_info)) 2977 + if (unlikely(BTRFS_FS_ERROR(fs_info))) 2978 2978 return -EROFS; 2979 2979 2980 2980 page = alloc_page(GFP_KERNEL);
+1 -1
fs/btrfs/super.c
··· 1299 1299 { 1300 1300 int ret; 1301 1301 1302 - if (BTRFS_FS_ERROR(fs_info)) { 1302 + if (unlikely(BTRFS_FS_ERROR(fs_info))) { 1303 1303 btrfs_err(fs_info, 1304 1304 "remounting read-write after error is not allowed"); 1305 1305 return -EINVAL;
+5 -5
fs/btrfs/transaction.c
··· 275 275 spin_lock(&fs_info->trans_lock); 276 276 loop: 277 277 /* 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))) { 279 279 spin_unlock(&fs_info->trans_lock); 280 280 return -EROFS; 281 281 } ··· 333 333 btrfs_lockdep_release(fs_info, btrfs_trans_num_writers); 334 334 kfree(cur_trans); 335 335 goto loop; 336 - } else if (BTRFS_FS_ERROR(fs_info)) { 336 + } else if (unlikely(BTRFS_FS_ERROR(fs_info))) { 337 337 spin_unlock(&fs_info->trans_lock); 338 338 btrfs_lockdep_release(fs_info, btrfs_trans_num_extwriters); 339 339 btrfs_lockdep_release(fs_info, btrfs_trans_num_writers); ··· 612 612 bool do_chunk_alloc = false; 613 613 int ret; 614 614 615 - if (BTRFS_FS_ERROR(fs_info)) 615 + if (unlikely(BTRFS_FS_ERROR(fs_info))) 616 616 return ERR_PTR(-EROFS); 617 617 618 618 if (current->journal_info) { ··· 1120 1120 if (throttle) 1121 1121 btrfs_run_delayed_iputs(info); 1122 1122 1123 - if (TRANS_ABORTED(trans) || BTRFS_FS_ERROR(info)) { 1123 + if (unlikely(TRANS_ABORTED(trans) || BTRFS_FS_ERROR(info))) { 1124 1124 wake_up_process(info->transaction_kthread); 1125 1125 if (TRANS_ABORTED(trans)) 1126 1126 ret = trans->aborted; ··· 2351 2351 * abort to prevent writing a new superblock that reflects a 2352 2352 * corrupt state (pointing to trees with unwritten nodes/leafs). 2353 2353 */ 2354 - if (BTRFS_FS_ERROR(fs_info)) { 2354 + if (unlikely(BTRFS_FS_ERROR(fs_info))) { 2355 2355 spin_unlock(&fs_info->trans_lock); 2356 2356 ret = -EROFS; 2357 2357 goto lockdep_release;
+1 -1
fs/btrfs/tree-log.c
··· 3566 3566 * writing the super here would result in transid mismatches. If there 3567 3567 * is an error here just bail. 3568 3568 */ 3569 - if (BTRFS_FS_ERROR(fs_info)) { 3569 + if (unlikely(BTRFS_FS_ERROR(fs_info))) { 3570 3570 ret = -EIO; 3571 3571 btrfs_set_log_full_commit(trans); 3572 3572 btrfs_abort_transaction(trans, ret);
+1 -1
fs/btrfs/volumes.c
··· 3602 3602 * If we had a transaction abort, stop all running scrubs. 3603 3603 * See transaction.c:cleanup_transaction() why we do it here. 3604 3604 */ 3605 - if (BTRFS_FS_ERROR(fs_info)) 3605 + if (unlikely(BTRFS_FS_ERROR(fs_info))) 3606 3606 btrfs_scrub_cancel(fs_info); 3607 3607 return ret; 3608 3608 }