bcachefs: Add some unlikely() annotations
authorKent Overstreet <kent.overstreet@linux.dev>
Thu, 24 Nov 2022 01:11:46 +0000 (20:11 -0500)
committerKent Overstreet <kent.overstreet@linux.dev>
Sun, 22 Oct 2023 21:09:48 +0000 (17:09 -0400)
Add a few easy unlikely() optimizations. These are mainly worthwhile
because the compiler will (usually) put the branch-not-taken path at the
end of the function, meaning better icache utilization.

Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
fs/bcachefs/bkey.c

index a10046ae01f26cf8bdbdf3ff1c45f6ef13f4deda..abb444192749fc4a933c5a025be3445dbc37ec70 100644 (file)
@@ -488,18 +488,18 @@ enum bkey_pack_pos_ret bch2_bkey_pack_pos_lossy(struct bkey_packed *out,
                     le64_to_cpu(f->field_offset[BKEY_FIELD_INODE])))
                return BKEY_PACK_POS_FAIL;
 
-       if (!set_inc_field_lossy(&state, BKEY_FIELD_INODE, in.inode)) {
+       if (unlikely(!set_inc_field_lossy(&state, BKEY_FIELD_INODE, in.inode))) {
                in.offset       = KEY_OFFSET_MAX;
                in.snapshot     = KEY_SNAPSHOT_MAX;
                exact = false;
        }
 
-       if (!set_inc_field_lossy(&state, BKEY_FIELD_OFFSET, in.offset)) {
+       if (unlikely(!set_inc_field_lossy(&state, BKEY_FIELD_OFFSET, in.offset))) {
                in.snapshot     = KEY_SNAPSHOT_MAX;
                exact = false;
        }
 
-       if (!set_inc_field_lossy(&state, BKEY_FIELD_SNAPSHOT, in.snapshot))
+       if (unlikely(!set_inc_field_lossy(&state, BKEY_FIELD_SNAPSHOT, in.snapshot)))
                exact = false;
 
        pack_state_finish(&state, out);