summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKent Overstreet <kent.overstreet@gmail.com>2021-12-19 19:02:50 -0500
committerKent Overstreet <kent.overstreet@gmail.com>2021-12-25 17:37:12 -0500
commitc1b3d4eb5decf6d4d80a3beb2df4b2d0a0ff6fd3 (patch)
treedbd34c0138712633c9f38923ff3c0cb3cdf5c352
parent23686c1e39538aae4a418e6497d8b00696c471bd (diff)
bcachefs: Optimize memory accesses in bch2_btree_node_get()
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>
-rw-r--r--fs/bcachefs/btree_cache.c19
1 files changed, 10 insertions, 9 deletions
diff --git a/fs/bcachefs/btree_cache.c b/fs/bcachefs/btree_cache.c
index 5ae61e5d3923..3411d5a02203 100644
--- a/fs/bcachefs/btree_cache.c
+++ b/fs/bcachefs/btree_cache.c
@@ -768,16 +768,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)) {