Commit 94c69faf authored by Kent Overstreet's avatar Kent Overstreet

bcachefs: Use six_lock_ip()

This uses the new _ip() interface to six locks and hooks it up to
btree_path->ip_allocated, when available.
Signed-off-by: default avatarKent Overstreet <kent.overstreet@linux.dev>
parent f746c62c
...@@ -1044,7 +1044,7 @@ struct btree *bch2_btree_node_get_noiter(struct btree_trans *trans, ...@@ -1044,7 +1044,7 @@ struct btree *bch2_btree_node_get_noiter(struct btree_trans *trans,
goto out; goto out;
} else { } else {
lock_node: 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)) if (bch2_err_matches(ret, BCH_ERR_transaction_restart))
return ERR_PTR(ret); return ERR_PTR(ret);
......
...@@ -26,7 +26,7 @@ static inline void btree_path_list_add(struct btree_trans *, struct btree_path * ...@@ -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) static inline unsigned long btree_iter_ip_allocated(struct btree_iter *iter)
{ {
#ifdef CONFIG_BCACHEFS_DEBUG #ifdef TRACK_PATH_ALLOCATED
return iter->ip_allocated; return iter->ip_allocated;
#else #else
return 0; return 0;
...@@ -1420,7 +1420,7 @@ void bch2_btree_path_to_text(struct printbuf *out, struct btree_path *path) ...@@ -1420,7 +1420,7 @@ void bch2_btree_path_to_text(struct printbuf *out, struct btree_path *path)
bch2_bpos_to_text(out, path->pos); bch2_bpos_to_text(out, path->pos);
prt_printf(out, " locks %u", path->nodes_locked); prt_printf(out, " locks %u", path->nodes_locked);
#ifdef CONFIG_BCACHEFS_DEBUG #ifdef TRACK_PATH_ALLOCATED
prt_printf(out, " %pS", (void *) path->ip_allocated); prt_printf(out, " %pS", (void *) path->ip_allocated);
#endif #endif
prt_newline(out); prt_newline(out);
...@@ -1570,7 +1570,7 @@ struct btree_path *bch2_path_get(struct btree_trans *trans, ...@@ -1570,7 +1570,7 @@ struct btree_path *bch2_path_get(struct btree_trans *trans,
path->nodes_locked = 0; path->nodes_locked = 0;
for (i = 0; i < ARRAY_SIZE(path->l); i++) for (i = 0; i < ARRAY_SIZE(path->l); i++)
path->l[i].b = ERR_PTR(-BCH_ERR_no_btree_node_init); path->l[i].b = ERR_PTR(-BCH_ERR_no_btree_node_init);
#ifdef CONFIG_BCACHEFS_DEBUG #ifdef TRACK_PATH_ALLOCATED
path->ip_allocated = ip; path->ip_allocated = ip;
#endif #endif
trans->paths_sorted = false; trans->paths_sorted = false;
......
...@@ -244,7 +244,7 @@ bkey_cached_alloc(struct btree_trans *trans, struct btree_path *path, ...@@ -244,7 +244,7 @@ bkey_cached_alloc(struct btree_trans *trans, struct btree_path *path,
if (ck) { if (ck) {
int ret; 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)) { if (unlikely(ret)) {
bkey_cached_move_to_freelist(bc, ck); bkey_cached_move_to_freelist(bc, ck);
return ERR_PTR(ret); return ERR_PTR(ret);
......
...@@ -366,7 +366,8 @@ int __bch2_btree_node_lock_write(struct btree_trans *trans, struct btree_path *p ...@@ -366,7 +366,8 @@ int __bch2_btree_node_lock_write(struct btree_trans *trans, struct btree_path *p
* locked: * locked:
*/ */
six_lock_readers_add(&b->lock, -readers); 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); six_lock_readers_add(&b->lock, readers);
if (ret) if (ret)
......
...@@ -190,7 +190,8 @@ int bch2_six_check_for_deadlock(struct six_lock *lock, void *p); ...@@ -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, static inline int __btree_node_lock_nopath(struct btree_trans *trans,
struct btree_bkey_cached_common *b, struct btree_bkey_cached_common *b,
enum six_lock_type type, enum six_lock_type type,
bool lock_may_not_fail) bool lock_may_not_fail,
unsigned long ip)
{ {
int ret; int ret;
...@@ -198,8 +199,8 @@ static inline int __btree_node_lock_nopath(struct btree_trans *trans, ...@@ -198,8 +199,8 @@ static inline int __btree_node_lock_nopath(struct btree_trans *trans,
trans->lock_must_abort = false; trans->lock_must_abort = false;
trans->locking = b; trans->locking = b;
ret = six_lock_type_waiter(&b->lock, type, &trans->locking_wait, ret = six_lock_type_ip_waiter(&b->lock, type, &trans->locking_wait,
bch2_six_check_for_deadlock, trans); bch2_six_check_for_deadlock, trans, ip);
WRITE_ONCE(trans->locking, NULL); WRITE_ONCE(trans->locking, NULL);
WRITE_ONCE(trans->locking_wait.start_time, 0); WRITE_ONCE(trans->locking_wait.start_time, 0);
return ret; return ret;
...@@ -208,16 +209,17 @@ static inline int __btree_node_lock_nopath(struct btree_trans *trans, ...@@ -208,16 +209,17 @@ static inline int __btree_node_lock_nopath(struct btree_trans *trans,
static inline int __must_check static inline int __must_check
btree_node_lock_nopath(struct btree_trans *trans, btree_node_lock_nopath(struct btree_trans *trans,
struct btree_bkey_cached_common *b, 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, static inline void btree_node_lock_nopath_nofail(struct btree_trans *trans,
struct btree_bkey_cached_common *b, struct btree_bkey_cached_common *b,
enum six_lock_type type) 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); BUG_ON(ret);
} }
...@@ -257,7 +259,7 @@ static inline int btree_node_lock(struct btree_trans *trans, ...@@ -257,7 +259,7 @@ static inline int btree_node_lock(struct btree_trans *trans,
if (likely(six_trylock_type(&b->lock, type)) || if (likely(six_trylock_type(&b->lock, type)) ||
btree_node_lock_increment(trans, b, level, 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 #ifdef CONFIG_BCACHEFS_LOCK_TIME_STATS
path->l[b->level].lock_taken_time = local_clock(); path->l[b->level].lock_taken_time = local_clock();
#endif #endif
......
...@@ -217,6 +217,10 @@ enum btree_path_uptodate { ...@@ -217,6 +217,10 @@ enum btree_path_uptodate {
BTREE_ITER_NEED_TRAVERSE = 2, BTREE_ITER_NEED_TRAVERSE = 2,
}; };
#if defined(CONFIG_BCACHEFS_LOCK_TIME_STATS) || defined(CONFIG_BCACHEFS_DEBUG)
#define TRACK_PATH_ALLOCATED
#endif
struct btree_path { struct btree_path {
u8 idx; u8 idx;
u8 sorted_idx; u8 sorted_idx;
...@@ -247,7 +251,7 @@ struct btree_path { ...@@ -247,7 +251,7 @@ struct btree_path {
u64 lock_taken_time; u64 lock_taken_time;
#endif #endif
} l[BTREE_MAX_DEPTH]; } l[BTREE_MAX_DEPTH];
#ifdef CONFIG_BCACHEFS_DEBUG #ifdef TRACK_PATH_ALLOCATED
unsigned long ip_allocated; unsigned long ip_allocated;
#endif #endif
}; };
...@@ -257,6 +261,15 @@ static inline struct btree_path_level *path_l(struct btree_path *path) ...@@ -257,6 +261,15 @@ static inline struct btree_path_level *path_l(struct btree_path *path)
return path->l + path->level; 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 * @pos - iterator's current position
* @level - current btree depth * @level - current btree depth
...@@ -290,7 +303,7 @@ struct btree_iter { ...@@ -290,7 +303,7 @@ struct btree_iter {
/* BTREE_ITER_WITH_JOURNAL: */ /* BTREE_ITER_WITH_JOURNAL: */
size_t journal_idx; size_t journal_idx;
struct bpos journal_pos; struct bpos journal_pos;
#ifdef CONFIG_BCACHEFS_DEBUG #ifdef TRACK_PATH_ALLOCATED
unsigned long ip_allocated; unsigned long ip_allocated;
#endif #endif
}; };
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment