summaryrefslogtreecommitdiff
path: root/fs/bcachefs/btree_cache.c
diff options
context:
space:
mode:
authorKent Overstreet <kent.overstreet@gmail.com>2021-12-20 03:02:50 +0300
committerKent Overstreet <kent.overstreet@linux.dev>2023-10-23 00:09:19 +0300
commit1aeed4549de41cabf8e7f52c62646bac7b20a385 (patch)
treeea596a3fb19ef18dc29c36cbe9eae55c10aada9f /fs/bcachefs/btree_cache.c
parent6be1b6d9df9dfe7065220b64b32de339b1120f1b (diff)
downloadlinux-1aeed4549de41cabf8e7f52c62646bac7b20a385.tar.xz
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>
Diffstat (limited to 'fs/bcachefs/btree_cache.c')
-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 4e855ae51731..5bf493a315ca 100644
--- a/fs/bcachefs/btree_cache.c
+++ b/fs/bcachefs/btree_cache.c
@@ -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)) {