From 32913f49f54f0cf9ccf581e3abd2d1fc6ba4debf Mon Sep 17 00:00:00 2001 From: Kent Overstreet Date: Fri, 16 Jun 2023 15:56:42 -0400 Subject: [PATCH] six locks: Seq now only incremented on unlock Signed-off-by: Kent Overstreet --- fs/bcachefs/btree_iter.c | 1 - fs/bcachefs/btree_iter.h | 9 +-------- fs/bcachefs/btree_locking.h | 4 ++-- fs/bcachefs/six.c | 5 ----- 4 files changed, 3 insertions(+), 16 deletions(-) diff --git a/fs/bcachefs/btree_iter.c b/fs/bcachefs/btree_iter.c index 3e65e6876ec7..f0d0b64a55a4 100644 --- a/fs/bcachefs/btree_iter.c +++ b/fs/bcachefs/btree_iter.c @@ -652,7 +652,6 @@ void bch2_btree_path_level_init(struct btree_trans *trans, BUG_ON(path->cached); EBUG_ON(!btree_path_pos_in_node(path, b)); - EBUG_ON(six_lock_seq(&b->c.lock) & 1); path->l[b->c.level].lock_seq = six_lock_seq(&b->c.lock); path->l[b->c.level].b = b; diff --git a/fs/bcachefs/btree_iter.h b/fs/bcachefs/btree_iter.h index 7d3564d72a7d..0cfb8af3d0e1 100644 --- a/fs/bcachefs/btree_iter.h +++ b/fs/bcachefs/btree_iter.h @@ -42,14 +42,7 @@ static inline struct btree *btree_path_node(struct btree_path *path, static inline bool btree_node_lock_seq_matches(const struct btree_path *path, const struct btree *b, unsigned level) { - /* - * We don't compare the low bits of the lock sequence numbers because - * @path might have taken a write lock on @b, and we don't want to skip - * the linked path if the sequence numbers were equal before taking that - * write lock. The lock sequence number is incremented by taking and - * releasing write locks and is even when unlocked: - */ - return path->l[level].lock_seq >> 1 == six_lock_seq(&b->c.lock) >> 1; + return path->l[level].lock_seq == six_lock_seq(&b->c.lock); } static inline struct btree *btree_node_parent(struct btree_path *path, diff --git a/fs/bcachefs/btree_locking.h b/fs/bcachefs/btree_locking.h index f9bb8736c061..d3837c25f110 100644 --- a/fs/bcachefs/btree_locking.h +++ b/fs/bcachefs/btree_locking.h @@ -175,13 +175,13 @@ bch2_btree_node_unlock_write_inlined(struct btree_trans *trans, struct btree_pat struct btree_path *linked; EBUG_ON(path->l[b->c.level].b != b); - EBUG_ON(path->l[b->c.level].lock_seq + 1 != six_lock_seq(&b->c.lock)); + EBUG_ON(path->l[b->c.level].lock_seq != six_lock_seq(&b->c.lock)); EBUG_ON(btree_node_locked_type(path, b->c.level) != SIX_LOCK_write); mark_btree_node_locked_noreset(path, b->c.level, SIX_LOCK_intent); trans_for_each_path_with_node(trans, b, linked) - linked->l[b->c.level].lock_seq += 2; + linked->l[b->c.level].lock_seq++; six_unlock_write(&b->c.lock); } diff --git a/fs/bcachefs/six.c b/fs/bcachefs/six.c index 54e4aa35a350..8ce0998b9775 100644 --- a/fs/bcachefs/six.c +++ b/fs/bcachefs/six.c @@ -302,9 +302,6 @@ bool six_trylock_ip(struct six_lock *lock, enum six_lock_type type, unsigned lon if (type != SIX_LOCK_write) six_acquire(&lock->dep_map, 1, type == SIX_LOCK_read, ip); - else - lock->seq++; - return true; } EXPORT_SYMBOL_GPL(six_trylock_ip); @@ -596,8 +593,6 @@ int six_lock_ip_waiter(struct six_lock *lock, enum six_lock_type type, ret = do_six_trylock(lock, type, true) ? 0 : six_lock_slowpath(lock, type, wait, should_sleep_fn, p, ip); - lock->seq += !ret && type == SIX_LOCK_write; - if (ret && type != SIX_LOCK_write) six_release(&lock->dep_map, ip); if (!ret)