Skip to content

Commit b97de45

Browse files
author
Kent Overstreet
committed
bcachefs: Improve trace_trans_restart_relock
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
1 parent 46bf2e9 commit b97de45

File tree

5 files changed

+44
-24
lines changed

5 files changed

+44
-24
lines changed

fs/bcachefs/btree_iter.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1337,7 +1337,7 @@ void bch2_path_put(struct btree_trans *trans, btree_path_idx_t path_idx, bool in
13371337

13381338
if (path->should_be_locked &&
13391339
!trans->restarted &&
1340-
(!dup || !bch2_btree_path_relock_norestart(trans, dup, _THIS_IP_)))
1340+
(!dup || !bch2_btree_path_relock_norestart(trans, dup)))
13411341
return;
13421342

13431343
if (dup) {

fs/bcachefs/btree_locking.c

Lines changed: 33 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -631,8 +631,7 @@ int bch2_btree_path_relock_intent(struct btree_trans *trans,
631631
}
632632

633633
__flatten
634-
bool bch2_btree_path_relock_norestart(struct btree_trans *trans,
635-
struct btree_path *path, unsigned long trace_ip)
634+
bool bch2_btree_path_relock_norestart(struct btree_trans *trans, struct btree_path *path)
636635
{
637636
struct get_locks_fail f;
638637

@@ -642,7 +641,7 @@ bool bch2_btree_path_relock_norestart(struct btree_trans *trans,
642641
int __bch2_btree_path_relock(struct btree_trans *trans,
643642
struct btree_path *path, unsigned long trace_ip)
644643
{
645-
if (!bch2_btree_path_relock_norestart(trans, path, trace_ip)) {
644+
if (!bch2_btree_path_relock_norestart(trans, path)) {
646645
trace_and_count(trans->c, trans_restart_relock_path, trans, trace_ip, path);
647646
return btree_trans_restart(trans, BCH_ERR_transaction_restart_relock_path);
648647
}
@@ -759,12 +758,39 @@ int bch2_trans_relock(struct btree_trans *trans)
759758
if (unlikely(trans->restarted))
760759
return -((int) trans->restarted);
761760

762-
trans_for_each_path(trans, path, i)
761+
trans_for_each_path(trans, path, i) {
762+
struct get_locks_fail f;
763+
763764
if (path->should_be_locked &&
764-
!bch2_btree_path_relock_norestart(trans, path, _RET_IP_)) {
765-
trace_and_count(trans->c, trans_restart_relock, trans, _RET_IP_, path);
765+
!btree_path_get_locks(trans, path, false, &f)) {
766+
if (trace_trans_restart_relock_enabled()) {
767+
struct printbuf buf = PRINTBUF;
768+
769+
bch2_bpos_to_text(&buf, path->pos);
770+
prt_printf(&buf, " l=%u seq=%u node seq=",
771+
f.l, path->l[f.l].lock_seq);
772+
if (IS_ERR_OR_NULL(f.b)) {
773+
prt_str(&buf, bch2_err_str(PTR_ERR(f.b)));
774+
} else {
775+
prt_printf(&buf, "%u", f.b->c.lock.seq);
776+
777+
struct six_lock_count c =
778+
bch2_btree_node_lock_counts(trans, NULL, &f.b->c, f.l);
779+
prt_printf(&buf, " self locked %u.%u.%u", c.n[0], c.n[1], c.n[2]);
780+
781+
c = six_lock_counts(&f.b->c.lock);
782+
prt_printf(&buf, " total locked %u.%u.%u", c.n[0], c.n[1], c.n[2]);
783+
}
784+
785+
trace_trans_restart_relock(trans, _RET_IP_, buf.buf);
786+
printbuf_exit(&buf);
787+
}
788+
789+
count_event(trans->c, trans_restart_relock);
766790
return btree_trans_restart(trans, BCH_ERR_transaction_restart_relock);
767791
}
792+
}
793+
768794
return 0;
769795
}
770796

@@ -778,7 +804,7 @@ int bch2_trans_relock_notrace(struct btree_trans *trans)
778804

779805
trans_for_each_path(trans, path, i)
780806
if (path->should_be_locked &&
781-
!bch2_btree_path_relock_norestart(trans, path, _RET_IP_)) {
807+
!bch2_btree_path_relock_norestart(trans, path)) {
782808
return btree_trans_restart(trans, BCH_ERR_transaction_restart_relock);
783809
}
784810
return 0;

fs/bcachefs/btree_locking.h

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -312,8 +312,7 @@ void bch2_btree_node_lock_write_nofail(struct btree_trans *,
312312

313313
/* relock: */
314314

315-
bool bch2_btree_path_relock_norestart(struct btree_trans *,
316-
struct btree_path *, unsigned long);
315+
bool bch2_btree_path_relock_norestart(struct btree_trans *, struct btree_path *);
317316
int __bch2_btree_path_relock(struct btree_trans *,
318317
struct btree_path *, unsigned long);
319318

@@ -353,12 +352,6 @@ static inline bool bch2_btree_node_relock_notrace(struct btree_trans *trans,
353352

354353
/* upgrade */
355354

356-
357-
struct get_locks_fail {
358-
unsigned l;
359-
struct btree *b;
360-
};
361-
362355
bool bch2_btree_path_upgrade_noupgrade_sibs(struct btree_trans *,
363356
struct btree_path *, unsigned,
364357
struct get_locks_fail *);

fs/bcachefs/btree_types.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -741,4 +741,9 @@ enum btree_node_sibling {
741741
btree_next_sib,
742742
};
743743

744+
struct get_locks_fail {
745+
unsigned l;
746+
struct btree *b;
747+
};
748+
744749
#endif /* _BCACHEFS_BTREE_TYPES_H */

fs/bcachefs/trace.h

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -528,7 +528,7 @@ TRACE_EVENT(btree_path_relock_fail,
528528
__entry->level = path->level;
529529
TRACE_BPOS_assign(pos, path->pos);
530530

531-
c = bch2_btree_node_lock_counts(trans, NULL, &path->l[level].b->c, level),
531+
c = bch2_btree_node_lock_counts(trans, NULL, &path->l[level].b->c, level);
532532
__entry->self_read_count = c.n[SIX_LOCK_read];
533533
__entry->self_intent_count = c.n[SIX_LOCK_intent];
534534

@@ -1120,8 +1120,6 @@ DEFINE_EVENT(transaction_restart_iter, trans_restart_btree_node_split,
11201120
TP_ARGS(trans, caller_ip, path)
11211121
);
11221122

1123-
struct get_locks_fail;
1124-
11251123
TRACE_EVENT(trans_restart_upgrade,
11261124
TP_PROTO(struct btree_trans *trans,
11271125
unsigned long caller_ip,
@@ -1169,11 +1167,9 @@ TRACE_EVENT(trans_restart_upgrade,
11691167
__entry->node_seq)
11701168
);
11711169

1172-
DEFINE_EVENT(transaction_restart_iter, trans_restart_relock,
1173-
TP_PROTO(struct btree_trans *trans,
1174-
unsigned long caller_ip,
1175-
struct btree_path *path),
1176-
TP_ARGS(trans, caller_ip, path)
1170+
DEFINE_EVENT(trans_str, trans_restart_relock,
1171+
TP_PROTO(struct btree_trans *trans, unsigned long caller_ip, const char *str),
1172+
TP_ARGS(trans, caller_ip, str)
11771173
);
11781174

11791175
DEFINE_EVENT(transaction_restart_iter, trans_restart_relock_next_node,

0 commit comments

Comments
 (0)