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 error conditions in the transaction commit path

Errors are unexpected during the transaction commit path, and when they
happen we abort the transaction (by calling cleanup_transaction() under
the label 'cleanup_transaction' in btrfs_commit_transaction()). So mark
every error check in the transaction commit path as unlikely, to hint the
compiler so that it can possibly generate better code, and make it clear
for a reader about being unexpected.

On a x86_84 box using gcc 14.2.0-19 from Debian, this resulted in a slight
reduction of the module's text size.

Before:

$ size fs/btrfs/btrfs.ko
text data bss dec hex filename
1939476 172568 15592 2127636 207714 fs/btrfs/btrfs.ko

After:

$ size fs/btrfs/btrfs.ko
text data bss dec hex filename
1939044 172568 15592 2127204 207564 fs/btrfs/btrfs.ko

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
858f3293 4cdb457a

+22 -22
+22 -22
fs/btrfs/transaction.c
··· 1515 1515 1516 1516 btrfs_free_log(trans, root); 1517 1517 ret2 = btrfs_update_reloc_root(trans, root); 1518 - if (ret2) 1518 + if (unlikely(ret2)) 1519 1519 return ret2; 1520 1520 1521 1521 /* see comments in should_cow_block() */ ··· 1532 1532 ret2 = btrfs_update_root(trans, fs_info->tree_root, 1533 1533 &root->root_key, 1534 1534 &root->root_item); 1535 - if (ret2) 1535 + if (unlikely(ret2)) 1536 1536 return ret2; 1537 1537 spin_lock(&fs_info->fs_roots_radix_lock); 1538 1538 } ··· 1687 1687 &pending->dentry->d_name, 0, 1688 1688 &fname); 1689 1689 memalloc_nofs_restore(nofs_flags); 1690 - if (pending->error) 1690 + if (unlikely(pending->error)) 1691 1691 goto free_pending; 1692 1692 1693 1693 pending->error = btrfs_get_free_objectid(tree_root, &objectid); 1694 - if (pending->error) 1694 + if (unlikely(pending->error)) 1695 1695 goto free_fname; 1696 1696 1697 1697 /* ··· 1707 1707 &pending->block_rsv, 1708 1708 to_reserve, 1709 1709 BTRFS_RESERVE_NO_FLUSH); 1710 - if (pending->error) 1710 + if (unlikely(pending->error)) 1711 1711 goto clear_skip_qgroup; 1712 1712 } 1713 1713 ··· 1719 1719 trans->bytes_reserved, 1); 1720 1720 parent_root = parent_inode->root; 1721 1721 ret = record_root_in_trans(trans, parent_root, 0); 1722 - if (ret) 1722 + if (unlikely(ret)) 1723 1723 goto fail; 1724 1724 cur_time = current_time(&parent_inode->vfs_inode); 1725 1725 ··· 1736 1736 dir_item = btrfs_lookup_dir_item(NULL, parent_root, path, 1737 1737 btrfs_ino(parent_inode), 1738 1738 &fname.disk_name, 0); 1739 - if (dir_item != NULL && !IS_ERR(dir_item)) { 1739 + if (unlikely(dir_item != NULL && !IS_ERR(dir_item))) { 1740 1740 pending->error = -EEXIST; 1741 1741 goto dir_item_existed; 1742 1742 } else if (IS_ERR(dir_item)) { ··· 1873 1873 else if (btrfs_qgroup_mode(fs_info) == BTRFS_QGROUP_MODE_SIMPLE) 1874 1874 ret = btrfs_qgroup_inherit(trans, btrfs_root_id(root), objectid, 1875 1875 btrfs_root_id(parent_root), pending->inherit); 1876 - if (ret < 0) 1876 + if (unlikely(ret < 0)) 1877 1877 goto fail; 1878 1878 1879 1879 ret = btrfs_insert_dir_item(trans, &fname.disk_name, ··· 1939 1939 list_for_each_entry_safe(pending, next, head, list) { 1940 1940 list_del(&pending->list); 1941 1941 ret = create_pending_snapshot(trans, pending); 1942 - if (ret) 1942 + if (unlikely(ret)) 1943 1943 break; 1944 1944 } 1945 1945 return ret; ··· 2258 2258 2259 2259 if (run_it) { 2260 2260 ret = btrfs_start_dirty_block_groups(trans); 2261 - if (ret) 2261 + if (unlikely(ret)) 2262 2262 goto lockdep_trans_commit_start_release; 2263 2263 } 2264 2264 } ··· 2308 2308 ret = READ_ONCE(prev_trans->aborted); 2309 2309 2310 2310 btrfs_put_transaction(prev_trans); 2311 - if (ret) 2311 + if (unlikely(ret)) 2312 2312 goto lockdep_release; 2313 2313 spin_lock(&fs_info->trans_lock); 2314 2314 } ··· 2338 2338 extwriter_counter_dec(cur_trans, trans->type); 2339 2339 2340 2340 ret = btrfs_start_delalloc_flush(fs_info); 2341 - if (ret) 2341 + if (unlikely(ret)) 2342 2342 goto lockdep_release; 2343 2343 2344 2344 ret = btrfs_run_delayed_items(trans); 2345 - if (ret) 2345 + if (unlikely(ret)) 2346 2346 goto lockdep_release; 2347 2347 2348 2348 /* ··· 2357 2357 2358 2358 /* some pending stuffs might be added after the previous flush. */ 2359 2359 ret = btrfs_run_delayed_items(trans); 2360 - if (ret) { 2360 + if (unlikely(ret)) { 2361 2361 btrfs_lockdep_release(fs_info, btrfs_trans_num_writers); 2362 2362 goto cleanup_transaction; 2363 2363 } ··· 2429 2429 * core function of the snapshot creation. 2430 2430 */ 2431 2431 ret = create_pending_snapshots(trans); 2432 - if (ret) 2432 + if (unlikely(ret)) 2433 2433 goto unlock_reloc; 2434 2434 2435 2435 /* ··· 2443 2443 * the nodes and leaves. 2444 2444 */ 2445 2445 ret = btrfs_run_delayed_items(trans); 2446 - if (ret) 2446 + if (unlikely(ret)) 2447 2447 goto unlock_reloc; 2448 2448 2449 2449 ret = btrfs_run_delayed_refs(trans, U64_MAX); 2450 - if (ret) 2450 + if (unlikely(ret)) 2451 2451 goto unlock_reloc; 2452 2452 2453 2453 /* ··· 2459 2459 WARN_ON(cur_trans != trans->transaction); 2460 2460 2461 2461 ret = commit_fs_roots(trans); 2462 - if (ret) 2462 + if (unlikely(ret)) 2463 2463 goto unlock_reloc; 2464 2464 2465 2465 /* commit_fs_roots gets rid of all the tree log roots, it is now ··· 2472 2472 * new_roots. So let's do quota accounting. 2473 2473 */ 2474 2474 ret = btrfs_qgroup_account_extents(trans); 2475 - if (ret < 0) 2475 + if (unlikely(ret < 0)) 2476 2476 goto unlock_reloc; 2477 2477 2478 2478 ret = commit_cowonly_roots(trans); 2479 - if (ret) 2479 + if (unlikely(ret)) 2480 2480 goto unlock_reloc; 2481 2481 2482 2482 /* ··· 2562 2562 * to go about their business 2563 2563 */ 2564 2564 mutex_unlock(&fs_info->tree_log_mutex); 2565 - if (ret) 2565 + if (unlikely(ret)) 2566 2566 goto scrub_continue; 2567 2567 2568 2568 update_commit_stats(fs_info); ··· 2575 2575 btrfs_trans_state_lockdep_release(fs_info, BTRFS_LOCKDEP_TRANS_SUPER_COMMITTED); 2576 2576 2577 2577 ret = btrfs_finish_extent_commit(trans); 2578 - if (ret) 2578 + if (unlikely(ret)) 2579 2579 goto scrub_continue; 2580 2580 2581 2581 if (test_bit(BTRFS_TRANS_HAVE_FREE_BGS, &cur_trans->flags))