six locks: Seq now only incremented on unlock
authorKent Overstreet <kent.overstreet@linux.dev>
Fri, 16 Jun 2023 19:56:42 +0000 (15:56 -0400)
committerKent Overstreet <kent.overstreet@linux.dev>
Sun, 22 Oct 2023 21:10:02 +0000 (17:10 -0400)
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
fs/bcachefs/btree_iter.c
fs/bcachefs/btree_iter.h
fs/bcachefs/btree_locking.h
fs/bcachefs/six.c

index 3e65e6876ec7a38b52631dc890ea516750df2468..f0d0b64a55a40c5450bf67c1b6a0a80fff1e2dee 100644 (file)
@@ -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;
index 7d3564d72a7d8ed2108dc5e11f2313c535dc1fda..0cfb8af3d0e1ff4569502b5b8c6e91bfa634679b 100644 (file)
@@ -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,
index f9bb8736c061a580ff83aa36e886151cf1d2f0e2..d3837c25f110a1ef7110306df986746b0c4898fc 100644 (file)
@@ -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);
 }
index 54e4aa35a350e08891fd1dadb023c8020555b229..8ce0998b977540663712dc504b644acd885de369 100644 (file)
@@ -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)