bcachefs: Use six_lock_ip()
authorKent Overstreet <kent.overstreet@linux.dev>
Sun, 5 Feb 2023 00:39:59 +0000 (19:39 -0500)
committerKent Overstreet <kent.overstreet@linux.dev>
Sun, 22 Oct 2023 21:09:50 +0000 (17:09 -0400)
This uses the new _ip() interface to six locks and hooks it up to
btree_path->ip_allocated, when available.

Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
fs/bcachefs/btree_cache.c
fs/bcachefs/btree_iter.c
fs/bcachefs/btree_key_cache.c
fs/bcachefs/btree_locking.c
fs/bcachefs/btree_locking.h
fs/bcachefs/btree_types.h

index 7868536d7581bc230f795b55dd6e3cfcaf6d073b..769f17b67fcf404c8f21239335b3d5d285249d5a 100644 (file)
@@ -1044,7 +1044,7 @@ retry:
                        goto out;
        } else {
 lock_node:
-               ret = btree_node_lock_nopath(trans, &b->c, SIX_LOCK_read);
+               ret = btree_node_lock_nopath(trans, &b->c, SIX_LOCK_read, _THIS_IP_);
                if (bch2_err_matches(ret, BCH_ERR_transaction_restart))
                        return ERR_PTR(ret);
 
index 25345ed11076e056b8f3345958c2d57bb22ce62d..f41c4416fe1c933084bbf013bbe1593f1b942946 100644 (file)
@@ -26,7 +26,7 @@ static inline void btree_path_list_add(struct btree_trans *, struct btree_path *
 
 static inline unsigned long btree_iter_ip_allocated(struct btree_iter *iter)
 {
-#ifdef CONFIG_BCACHEFS_DEBUG
+#ifdef TRACK_PATH_ALLOCATED
        return iter->ip_allocated;
 #else
        return 0;
@@ -1420,7 +1420,7 @@ void bch2_btree_path_to_text(struct printbuf *out, struct btree_path *path)
        bch2_bpos_to_text(out, path->pos);
 
        prt_printf(out, " locks %u", path->nodes_locked);
-#ifdef CONFIG_BCACHEFS_DEBUG
+#ifdef TRACK_PATH_ALLOCATED
        prt_printf(out, " %pS", (void *) path->ip_allocated);
 #endif
        prt_newline(out);
@@ -1570,7 +1570,7 @@ struct btree_path *bch2_path_get(struct btree_trans *trans,
                path->nodes_locked              = 0;
                for (i = 0; i < ARRAY_SIZE(path->l); i++)
                        path->l[i].b            = ERR_PTR(-BCH_ERR_no_btree_node_init);
-#ifdef CONFIG_BCACHEFS_DEBUG
+#ifdef TRACK_PATH_ALLOCATED
                path->ip_allocated              = ip;
 #endif
                trans->paths_sorted             = false;
index d4cfb48d2013142d1ec257d6a29c10a77d77ae62..743ebeba12b145401d28a80511336a6bfd468b13 100644 (file)
@@ -244,7 +244,7 @@ bkey_cached_alloc(struct btree_trans *trans, struct btree_path *path,
        if (ck) {
                int ret;
 
-               ret = btree_node_lock_nopath(trans, &ck->c, SIX_LOCK_intent);
+               ret = btree_node_lock_nopath(trans, &ck->c, SIX_LOCK_intent, _THIS_IP_);
                if (unlikely(ret)) {
                        bkey_cached_move_to_freelist(bc, ck);
                        return ERR_PTR(ret);
index e7659b4cf9e45aae39c4ee5dfc6984dc02081a85..56489e7b0ac25ce2d17e8010e1ec698286a9e3e2 100644 (file)
@@ -366,7 +366,8 @@ int __bch2_btree_node_lock_write(struct btree_trans *trans, struct btree_path *p
         * locked:
         */
        six_lock_readers_add(&b->lock, -readers);
-       ret = __btree_node_lock_nopath(trans, b, SIX_LOCK_write, lock_may_not_fail);
+       ret = __btree_node_lock_nopath(trans, b, SIX_LOCK_write,
+                                      lock_may_not_fail, _RET_IP_);
        six_lock_readers_add(&b->lock, readers);
 
        if (ret)
index 3356f089e268d452a80b583929a022c598f935ed..30c89daa50099636f5c903ec8f46c22528b3c823 100644 (file)
@@ -190,7 +190,8 @@ int bch2_six_check_for_deadlock(struct six_lock *lock, void *p);
 static inline int __btree_node_lock_nopath(struct btree_trans *trans,
                                         struct btree_bkey_cached_common *b,
                                         enum six_lock_type type,
-                                        bool lock_may_not_fail)
+                                        bool lock_may_not_fail,
+                                        unsigned long ip)
 {
        int ret;
 
@@ -198,8 +199,8 @@ static inline int __btree_node_lock_nopath(struct btree_trans *trans,
        trans->lock_must_abort  = false;
        trans->locking          = b;
 
-       ret = six_lock_type_waiter(&b->lock, type, &trans->locking_wait,
-                                  bch2_six_check_for_deadlock, trans);
+       ret = six_lock_type_ip_waiter(&b->lock, type, &trans->locking_wait,
+                                  bch2_six_check_for_deadlock, trans, ip);
        WRITE_ONCE(trans->locking, NULL);
        WRITE_ONCE(trans->locking_wait.start_time, 0);
        return ret;
@@ -208,16 +209,17 @@ static inline int __btree_node_lock_nopath(struct btree_trans *trans,
 static inline int __must_check
 btree_node_lock_nopath(struct btree_trans *trans,
                       struct btree_bkey_cached_common *b,
-                      enum six_lock_type type)
+                      enum six_lock_type type,
+                      unsigned long ip)
 {
-       return __btree_node_lock_nopath(trans, b, type, false);
+       return __btree_node_lock_nopath(trans, b, type, false, ip);
 }
 
 static inline void btree_node_lock_nopath_nofail(struct btree_trans *trans,
                                         struct btree_bkey_cached_common *b,
                                         enum six_lock_type type)
 {
-       int ret = __btree_node_lock_nopath(trans, b, type, true);
+       int ret = __btree_node_lock_nopath(trans, b, type, true, _THIS_IP_);
 
        BUG_ON(ret);
 }
@@ -257,7 +259,7 @@ static inline int btree_node_lock(struct btree_trans *trans,
 
        if (likely(six_trylock_type(&b->lock, type)) ||
            btree_node_lock_increment(trans, b, level, type) ||
-           !(ret = btree_node_lock_nopath(trans, b, type))) {
+           !(ret = btree_node_lock_nopath(trans, b, type, btree_path_ip_allocated(path)))) {
 #ifdef CONFIG_BCACHEFS_LOCK_TIME_STATS
                path->l[b->level].lock_taken_time = local_clock();
 #endif
index 5cf03ec52051e80a92215d1f35512a227dedab09..5660d076c678c6c80ae948af518561a4c3e582b9 100644 (file)
@@ -217,6 +217,10 @@ enum btree_path_uptodate {
        BTREE_ITER_NEED_TRAVERSE        = 2,
 };
 
+#if defined(CONFIG_BCACHEFS_LOCK_TIME_STATS) || defined(CONFIG_BCACHEFS_DEBUG)
+#define TRACK_PATH_ALLOCATED
+#endif
+
 struct btree_path {
        u8                      idx;
        u8                      sorted_idx;
@@ -247,7 +251,7 @@ struct btree_path {
                u64             lock_taken_time;
 #endif
        }                       l[BTREE_MAX_DEPTH];
-#ifdef CONFIG_BCACHEFS_DEBUG
+#ifdef TRACK_PATH_ALLOCATED
        unsigned long           ip_allocated;
 #endif
 };
@@ -257,6 +261,15 @@ static inline struct btree_path_level *path_l(struct btree_path *path)
        return path->l + path->level;
 }
 
+static inline unsigned long btree_path_ip_allocated(struct btree_path *path)
+{
+#ifdef TRACK_PATH_ALLOCATED
+       return path->ip_allocated;
+#else
+       return _THIS_IP_;
+#endif
+}
+
 /*
  * @pos                        - iterator's current position
  * @level              - current btree depth
@@ -290,7 +303,7 @@ struct btree_iter {
        /* BTREE_ITER_WITH_JOURNAL: */
        size_t                  journal_idx;
        struct bpos             journal_pos;
-#ifdef CONFIG_BCACHEFS_DEBUG
+#ifdef TRACK_PATH_ALLOCATED
        unsigned long           ip_allocated;
 #endif
 };