From: Kent Overstreet Date: Mon, 13 Sep 2021 20:04:49 +0000 (-0400) Subject: bcachefs: Improve btree_node_mem_ptr optimization X-Git-Tag: microblaze-v6.8~204^2~1391 X-Git-Url: http://git.monstr.eu/?a=commitdiff_plain;h=aae4eea60cf0c824abe6be809f0260df8574f49a;p=linux-2.6-microblaze.git bcachefs: Improve btree_node_mem_ptr optimization This patch checks b->hash_val before attempting to lock the node in the btree, which makes it more equivalent to the "lookup in hash table" path - and potentially avoids an unnecessary transaction restart if btree_node_mem_ptr(k) no longer points to the node we want. Signed-off-by: Kent Overstreet --- diff --git a/fs/bcachefs/btree_cache.c b/fs/bcachefs/btree_cache.c index d45218d5fd35..7f5620a4d7c5 100644 --- a/fs/bcachefs/btree_cache.c +++ b/fs/bcachefs/btree_cache.c @@ -777,7 +777,12 @@ struct btree *bch2_btree_node_get(struct btree_trans *trans, struct btree_path * if (c->opts.btree_node_mem_ptr_optimization) { b = btree_node_mem_ptr(k); - if (b) + /* + * 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)) goto lock_node; } retry: