btrfs: tree-checker: more unlikely annotations
authorDavid Sterba <dsterba@suse.com>
Fri, 4 Apr 2025 18:19:38 +0000 (20:19 +0200)
committerDavid Sterba <dsterba@suse.com>
Thu, 15 May 2025 12:30:43 +0000 (14:30 +0200)
Add more unlikely annotations to branches that lead to EUCLEAN, overall
in the tree checker this helps to reorder instructions for the no-error
case.

Reviewed-by: Qu Wenruo <wqu@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
fs/btrfs/tree-checker.c

index 2b66a6130269a3e3a1496060a973732cf746b440..6ca3c09514e7b54e0aca6345e0fd96116b962041 100644 (file)
@@ -1571,7 +1571,7 @@ static int check_extent_item(struct extent_buffer *leaf,
                                   inline_type);
                        return -EUCLEAN;
                }
-               if (inline_type < last_type) {
+               if (unlikely(inline_type < last_type)) {
                        extent_err(leaf, slot,
                                   "inline ref out-of-order: has type %u, prev type %u",
                                   inline_type, last_type);
@@ -1580,7 +1580,7 @@ static int check_extent_item(struct extent_buffer *leaf,
                /* Type changed, allow the sequence starts from U64_MAX again. */
                if (inline_type > last_type)
                        last_seq = U64_MAX;
-               if (seq > last_seq) {
+               if (unlikely(seq > last_seq)) {
                        extent_err(leaf, slot,
 "inline ref out-of-order: has type %u offset %llu seq 0x%llx, prev type %u seq 0x%llx",
                                   inline_type, inline_offset, seq,
@@ -1929,7 +1929,7 @@ static enum btrfs_tree_block_status check_leaf_item(struct extent_buffer *leaf,
                break;
        }
 
-       if (ret)
+       if (unlikely(ret))
                return BTRFS_TREE_BLOCK_INVALID_ITEM;
        return BTRFS_TREE_BLOCK_CLEAN;
 }
@@ -2229,7 +2229,7 @@ int btrfs_verify_level_key(struct extent_buffer *eb,
        int ret;
 
        found_level = btrfs_header_level(eb);
-       if (found_level != check->level) {
+       if (unlikely(found_level != check->level)) {
                WARN(IS_ENABLED(CONFIG_BTRFS_DEBUG),
                     KERN_ERR "BTRFS: tree level check failed\n");
                btrfs_err(fs_info,
@@ -2251,7 +2251,7 @@ int btrfs_verify_level_key(struct extent_buffer *eb,
                return 0;
 
        /* We have @first_key, so this @eb must have at least one item */
-       if (btrfs_header_nritems(eb) == 0) {
+       if (unlikely(btrfs_header_nritems(eb) == 0)) {
                btrfs_err(fs_info,
                "invalid tree nritems, bytenr=%llu nritems=0 expect >0",
                          eb->start);
@@ -2263,9 +2263,9 @@ int btrfs_verify_level_key(struct extent_buffer *eb,
                btrfs_node_key_to_cpu(eb, &found_key, 0);
        else
                btrfs_item_key_to_cpu(eb, &found_key, 0);
-       ret = btrfs_comp_cpu_keys(&check->first_key, &found_key);
 
-       if (ret) {
+       ret = btrfs_comp_cpu_keys(&check->first_key, &found_key);
+       if (unlikely(ret)) {
                WARN(IS_ENABLED(CONFIG_BTRFS_DEBUG),
                     KERN_ERR "BTRFS: tree first key check failed\n");
                btrfs_err(fs_info,