summaryrefslogtreecommitdiffstats
path: root/fs/bcachefs/btree_locking.c
diff options
context:
space:
mode:
authorKent Overstreet <kent.overstreet@linux.dev>2022-10-02 01:41:08 -0400
committerKent Overstreet <kent.overstreet@linux.dev>2023-10-22 17:09:42 -0400
commit40a44873a5ca9843532344d12583e6a3a78ea848 (patch)
treedae065156a658dfa45826f099e7d7eec8dab203d /fs/bcachefs/btree_locking.c
parent943f9946a6cc58e2c15ae39970547cddbe845190 (diff)
downloadlinux-stable-40a44873a5ca9843532344d12583e6a3a78ea848.tar.gz
linux-stable-40a44873a5ca9843532344d12583e6a3a78ea848.tar.bz2
linux-stable-40a44873a5ca9843532344d12583e6a3a78ea848.zip
bcachefs: Improve btree_deadlock debugfs output
This changes bch2_check_for_deadlock() to print the longest chains it finds - when we have a deadlock because the cycle detector isn't finding something, this will let us see what it's missing. Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
Diffstat (limited to 'fs/bcachefs/btree_locking.c')
-rw-r--r--fs/bcachefs/btree_locking.c54
1 files changed, 38 insertions, 16 deletions
diff --git a/fs/bcachefs/btree_locking.c b/fs/bcachefs/btree_locking.c
index 19062cea8774..b79543ae5eeb 100644
--- a/fs/bcachefs/btree_locking.c
+++ b/fs/bcachefs/btree_locking.c
@@ -71,11 +71,6 @@ struct lock_graph {
unsigned nr;
};
-static void lock_graph_pop(struct lock_graph *g)
-{
- closure_put(&g->g[--g->nr].trans->ref);
-}
-
static noinline void print_cycle(struct printbuf *out, struct lock_graph *g)
{
struct trans_waiting_for_lock *i;
@@ -87,6 +82,18 @@ static noinline void print_cycle(struct printbuf *out, struct lock_graph *g)
bch2_btree_trans_to_text(out, i->trans);
}
+static noinline void print_chain(struct printbuf *out, struct lock_graph *g)
+{
+ struct trans_waiting_for_lock *i;
+
+ for (i = g->g; i != g->g + g->nr; i++) {
+ if (i != g->g)
+ prt_str(out, "<- ");
+ prt_printf(out, "%u ", i->trans->locking_wait.task->pid);
+ }
+ prt_newline(out);
+}
+
static int abort_lock(struct lock_graph *g, struct trans_waiting_for_lock *i)
{
int ret;
@@ -134,6 +141,21 @@ static noinline int break_cycle(struct lock_graph *g)
BUG();
}
+static void lock_graph_pop(struct lock_graph *g)
+{
+ closure_put(&g->g[--g->nr].trans->ref);
+}
+
+static void lock_graph_pop_above(struct lock_graph *g, struct trans_waiting_for_lock *above,
+ struct printbuf *cycle)
+{
+ if (g->nr > 1 && cycle)
+ print_chain(cycle, g);
+
+ while (g->g + g->nr > above)
+ lock_graph_pop(g);
+}
+
static int lock_graph_descend(struct lock_graph *g, struct btree_trans *trans,
struct printbuf *cycle)
{
@@ -142,11 +164,10 @@ static int lock_graph_descend(struct lock_graph *g, struct btree_trans *trans,
int ret = 0;
for (i = g->g; i < g->g + g->nr; i++) {
- if (i->trans->locking != i->node_want)
- while (g->g + g->nr >= i) {
- lock_graph_pop(g);
- return 0;
- }
+ if (i->trans->locking != i->node_want) {
+ lock_graph_pop_above(g, i - 1, cycle);
+ return 0;
+ }
if (i->trans == trans) {
if (cycle) {
@@ -185,20 +206,19 @@ static int lock_graph_descend(struct lock_graph *g, struct btree_trans *trans,
return 0;
deadlock:
- while (g->nr)
- lock_graph_pop(g);
+ lock_graph_pop_above(g, g->g, cycle);
return ret;
}
-static noinline void lock_graph_remove_non_waiters(struct lock_graph *g)
+static noinline void lock_graph_remove_non_waiters(struct lock_graph *g,
+ struct printbuf *cycle)
{
struct trans_waiting_for_lock *i;
for (i = g->g + 1; i < g->g + g->nr; i++)
if (i->trans->locking != i->node_want ||
i->trans->locking_wait.start_time != i[-1].lock_start_time) {
- while (g->g + g->nr >= i)
- lock_graph_pop(g);
+ lock_graph_pop_above(g, i - 1, cycle);
return;
}
BUG();
@@ -252,7 +272,7 @@ next:
b = &READ_ONCE(path->l[top->level].b)->c;
if (unlikely(IS_ERR_OR_NULL(b))) {
- lock_graph_remove_non_waiters(&g);
+ lock_graph_remove_non_waiters(&g, cycle);
goto next;
}
@@ -286,6 +306,8 @@ next:
}
}
+ if (g.nr > 1 && cycle)
+ print_chain(cycle, &g);
lock_graph_pop(&g);
goto next;
}