bcachefs: Optimize memory accesses in bch2_btree_node_get()
authorKent Overstreet <kent.overstreet@gmail.com>
Mon, 20 Dec 2021 00:02:50 +0000 (19:02 -0500)
committerKent Overstreet <kent.overstreet@linux.dev>
Sun, 22 Oct 2023 21:09:19 +0000 (17:09 -0400)
This puts a load behind some branches before where it's used, so that it
can execute in parallel with other loads.

Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
fs/bcachefs/btree_cache.c

index 4e855ae51731619838e4ec5c66d5837874017d3a..5bf493a315caf278ffc931f044abe57ab139b908 100644 (file)
@@ -775,16 +775,17 @@ struct btree *bch2_btree_node_get(struct btree_trans *trans, struct btree_path *
 
        EBUG_ON(level >= BTREE_MAX_DEPTH);
 
-       if (c->opts.btree_node_mem_ptr_optimization) {
-               b = btree_node_mem_ptr(k);
-               /*
-                * Check b->hash_val _before_ calling btree_node_lock() - this
-                * might not be the node we want anymore, and trying to lock the
-                * wrong node could cause an unneccessary transaction restart:
-                */
-               if (b && b->hash_val == btree_ptr_hash_val(k))
+       b = btree_node_mem_ptr(k);
+
+       /*
+        * Check b->hash_val _before_ calling btree_node_lock() - this might not
+        * be the node we want anymore, and trying to lock the wrong node could
+        * cause an unneccessary transaction restart:
+        */
+       if (likely(c->opts.btree_node_mem_ptr_optimization &&
+                  b &&
+                  b->hash_val == btree_ptr_hash_val(k)))
                        goto lock_node;
-       }
 retry:
        b = btree_cache_find(bc, k);
        if (unlikely(!b)) {