Commit b97de453 authored by Kent Overstreet's avatar Kent Overstreet
Browse files

bcachefs: Improve trace_trans_restart_relock

parent 46bf2e9c
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -1337,7 +1337,7 @@ void bch2_path_put(struct btree_trans *trans, btree_path_idx_t path_idx, bool in

	if (path->should_be_locked &&
	    !trans->restarted &&
	    (!dup || !bch2_btree_path_relock_norestart(trans, dup, _THIS_IP_)))
	    (!dup || !bch2_btree_path_relock_norestart(trans, dup)))
		return;

	if (dup) {
+33 −7
Original line number Diff line number Diff line
@@ -631,8 +631,7 @@ int bch2_btree_path_relock_intent(struct btree_trans *trans,
}

__flatten
bool bch2_btree_path_relock_norestart(struct btree_trans *trans,
			struct btree_path *path, unsigned long trace_ip)
bool bch2_btree_path_relock_norestart(struct btree_trans *trans, struct btree_path *path)
{
	struct get_locks_fail f;

@@ -642,7 +641,7 @@ bool bch2_btree_path_relock_norestart(struct btree_trans *trans,
int __bch2_btree_path_relock(struct btree_trans *trans,
			struct btree_path *path, unsigned long trace_ip)
{
	if (!bch2_btree_path_relock_norestart(trans, path, trace_ip)) {
	if (!bch2_btree_path_relock_norestart(trans, path)) {
		trace_and_count(trans->c, trans_restart_relock_path, trans, trace_ip, path);
		return btree_trans_restart(trans, BCH_ERR_transaction_restart_relock_path);
	}
@@ -759,12 +758,39 @@ int bch2_trans_relock(struct btree_trans *trans)
	if (unlikely(trans->restarted))
		return -((int) trans->restarted);

	trans_for_each_path(trans, path, i)
	trans_for_each_path(trans, path, i) {
		struct get_locks_fail f;

		if (path->should_be_locked &&
		    !bch2_btree_path_relock_norestart(trans, path, _RET_IP_)) {
			trace_and_count(trans->c, trans_restart_relock, trans, _RET_IP_, path);
		    !btree_path_get_locks(trans, path, false, &f)) {
			if (trace_trans_restart_relock_enabled()) {
				struct printbuf buf = PRINTBUF;

				bch2_bpos_to_text(&buf, path->pos);
				prt_printf(&buf, " l=%u seq=%u node seq=",
					   f.l, path->l[f.l].lock_seq);
				if (IS_ERR_OR_NULL(f.b)) {
					prt_str(&buf, bch2_err_str(PTR_ERR(f.b)));
				} else {
					prt_printf(&buf, "%u", f.b->c.lock.seq);

					struct six_lock_count c =
						bch2_btree_node_lock_counts(trans, NULL, &f.b->c, f.l);
					prt_printf(&buf, " self locked %u.%u.%u", c.n[0], c.n[1], c.n[2]);

					c = six_lock_counts(&f.b->c.lock);
					prt_printf(&buf, " total locked %u.%u.%u", c.n[0], c.n[1], c.n[2]);
				}

				trace_trans_restart_relock(trans, _RET_IP_, buf.buf);
				printbuf_exit(&buf);
			}

			count_event(trans->c, trans_restart_relock);
			return btree_trans_restart(trans, BCH_ERR_transaction_restart_relock);
		}
	}

	return 0;
}

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

	trans_for_each_path(trans, path, i)
		if (path->should_be_locked &&
		    !bch2_btree_path_relock_norestart(trans, path, _RET_IP_)) {
		    !bch2_btree_path_relock_norestart(trans, path)) {
			return btree_trans_restart(trans, BCH_ERR_transaction_restart_relock);
		}
	return 0;
+1 −8
Original line number Diff line number Diff line
@@ -312,8 +312,7 @@ void bch2_btree_node_lock_write_nofail(struct btree_trans *,

/* relock: */

bool bch2_btree_path_relock_norestart(struct btree_trans *,
				      struct btree_path *, unsigned long);
bool bch2_btree_path_relock_norestart(struct btree_trans *, struct btree_path *);
int __bch2_btree_path_relock(struct btree_trans *,
			     struct btree_path *, unsigned long);

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

/* upgrade */


struct get_locks_fail {
	unsigned	l;
	struct btree	*b;
};

bool bch2_btree_path_upgrade_noupgrade_sibs(struct btree_trans *,
			       struct btree_path *, unsigned,
			       struct get_locks_fail *);
+5 −0
Original line number Diff line number Diff line
@@ -741,4 +741,9 @@ enum btree_node_sibling {
	btree_next_sib,
};

struct get_locks_fail {
	unsigned	l;
	struct btree	*b;
};

#endif /* _BCACHEFS_BTREE_TYPES_H */
+4 −8
Original line number Diff line number Diff line
@@ -528,7 +528,7 @@ TRACE_EVENT(btree_path_relock_fail,
		__entry->level			= path->level;
		TRACE_BPOS_assign(pos, path->pos);

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

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

struct get_locks_fail;

TRACE_EVENT(trans_restart_upgrade,
	TP_PROTO(struct btree_trans *trans,
		 unsigned long caller_ip,
@@ -1169,11 +1167,9 @@ TRACE_EVENT(trans_restart_upgrade,
		  __entry->node_seq)
);

DEFINE_EVENT(transaction_restart_iter,	trans_restart_relock,
	TP_PROTO(struct btree_trans *trans,
		 unsigned long caller_ip,
		 struct btree_path *path),
	TP_ARGS(trans, caller_ip, path)
DEFINE_EVENT(trans_str,	trans_restart_relock,
	TP_PROTO(struct btree_trans *trans, unsigned long caller_ip, const char *str),
	TP_ARGS(trans, caller_ip, str)
);

DEFINE_EVENT(transaction_restart_iter,	trans_restart_relock_next_node,