bcachefs: Improve trace_trans_restart_too_many_iters()
authorKent Overstreet <kent.overstreet@linux.dev>
Sun, 26 Nov 2023 22:02:06 +0000 (17:02 -0500)
committerKent Overstreet <kent.overstreet@linux.dev>
Mon, 1 Jan 2024 16:47:39 +0000 (11:47 -0500)
We now include the list of paths in use.

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

index ff5448fca7882f7ddae1ef3a982b7feeeace798d..f83fab9e62fc1bdf9f959761ffaea904b992476b 100644 (file)
@@ -1492,6 +1492,22 @@ static void bch2_trans_update_max_paths(struct btree_trans *trans)
        trans->nr_max_paths = hweight64(trans->paths_allocated);
 }
 
+noinline __cold
+int __bch2_btree_trans_too_many_iters(struct btree_trans *trans)
+{
+       if (trace_trans_restart_too_many_iters_enabled()) {
+               struct printbuf buf = PRINTBUF;
+
+               bch2_trans_paths_to_text(&buf, trans);
+               trace_trans_restart_too_many_iters(trans, _THIS_IP_, buf.buf);
+               printbuf_exit(&buf);
+       }
+
+       count_event(trans->c, trans_restart_too_many_iters);
+
+       return btree_trans_restart(trans, BCH_ERR_transaction_restart_too_many_iters);
+}
+
 static noinline void btree_path_overflow(struct btree_trans *trans)
 {
        bch2_dump_trans_paths_updates(trans);
index 9ef5021a6d37ce3c3457a652a1418e92cae1b7e5..3859c0b27d2b34044e1c5b322da7b641f13479d1 100644 (file)
@@ -627,12 +627,12 @@ static inline struct bkey_s_c bch2_btree_iter_peek_upto_type(struct btree_iter *
        return bch2_btree_iter_peek_slot(iter);
 }
 
+int __bch2_btree_trans_too_many_iters(struct btree_trans *);
+
 static inline int btree_trans_too_many_iters(struct btree_trans *trans)
 {
-       if (hweight64(trans->paths_allocated) > BTREE_ITER_MAX - 8) {
-               trace_and_count(trans->c, trans_restart_too_many_iters, trans, _THIS_IP_);
-               return btree_trans_restart(trans, BCH_ERR_transaction_restart_too_many_iters);
-       }
+       if (hweight64(trans->paths_allocated) > BTREE_ITER_MAX - 8)
+               return __bch2_btree_trans_too_many_iters(trans);
 
        return 0;
 }
index 6eced95ce3748676f3c399470d10bcfb61d633e1..e0c8db352bff673c570b42fda0c99e25a3b74d11 100644 (file)
@@ -32,7 +32,7 @@ DECLARE_EVENT_CLASS(bpos,
        TP_printk("%llu:%llu:%u", __entry->p_inode, __entry->p_offset, __entry->p_snapshot)
 );
 
-DECLARE_EVENT_CLASS(str,
+DECLARE_EVENT_CLASS(fs_str,
        TP_PROTO(struct bch_fs *c, const char *str),
        TP_ARGS(c, str),
 
@@ -49,6 +49,29 @@ DECLARE_EVENT_CLASS(str,
        TP_printk("%d,%d %s", MAJOR(__entry->dev), MINOR(__entry->dev), __get_str(str))
 );
 
+DECLARE_EVENT_CLASS(trans_str,
+       TP_PROTO(struct btree_trans *trans, unsigned long caller_ip, const char *str),
+       TP_ARGS(trans, caller_ip, str),
+
+       TP_STRUCT__entry(
+               __field(dev_t,          dev                     )
+               __array(char,           trans_fn, 32            )
+               __field(unsigned long,  caller_ip               )
+               __string(str,           str                     )
+       ),
+
+       TP_fast_assign(
+               __entry->dev            = trans->c->dev;
+               strscpy(__entry->trans_fn, trans->fn, sizeof(__entry->trans_fn));
+               __entry->caller_ip              = caller_ip;
+               __assign_str(str, str);
+       ),
+
+       TP_printk("%d,%d %s %pS %s",
+                 MAJOR(__entry->dev), MINOR(__entry->dev),
+                 __entry->trans_fn, (void *) __entry->caller_ip, __get_str(str))
+);
+
 DECLARE_EVENT_CLASS(btree_node,
        TP_PROTO(struct bch_fs *c, struct btree *b),
        TP_ARGS(c, b),
@@ -738,22 +761,22 @@ TRACE_EVENT(bucket_evacuate,
                  __entry->dev_idx, __entry->bucket)
 );
 
-DEFINE_EVENT(str, move_extent,
+DEFINE_EVENT(fs_str, move_extent,
        TP_PROTO(struct bch_fs *c, const char *k),
        TP_ARGS(c, k)
 );
 
-DEFINE_EVENT(str, move_extent_read,
+DEFINE_EVENT(fs_str, move_extent_read,
        TP_PROTO(struct bch_fs *c, const char *k),
        TP_ARGS(c, k)
 );
 
-DEFINE_EVENT(str, move_extent_write,
+DEFINE_EVENT(fs_str, move_extent_write,
        TP_PROTO(struct bch_fs *c, const char *k),
        TP_ARGS(c, k)
 );
 
-DEFINE_EVENT(str, move_extent_finish,
+DEFINE_EVENT(fs_str, move_extent_finish,
        TP_PROTO(struct bch_fs *c, const char *k),
        TP_ARGS(c, k)
 );
@@ -775,7 +798,7 @@ TRACE_EVENT(move_extent_fail,
        TP_printk("%d:%d %s", MAJOR(__entry->dev), MINOR(__entry->dev), __get_str(msg))
 );
 
-DEFINE_EVENT(str, move_extent_start_fail,
+DEFINE_EVENT(fs_str, move_extent_start_fail,
        TP_PROTO(struct bch_fs *c, const char *str),
        TP_ARGS(c, str)
 );
@@ -1008,10 +1031,11 @@ DEFINE_EVENT(transaction_event, trans_restart_key_cache_raced,
        TP_ARGS(trans, caller_ip)
 );
 
-DEFINE_EVENT(transaction_event,        trans_restart_too_many_iters,
+DEFINE_EVENT(trans_str, trans_restart_too_many_iters,
        TP_PROTO(struct btree_trans *trans,
-                unsigned long caller_ip),
-       TP_ARGS(trans, caller_ip)
+                unsigned long caller_ip,
+                const char *paths),
+       TP_ARGS(trans, caller_ip, paths)
 );
 
 DECLARE_EVENT_CLASS(transaction_restart_iter,
@@ -1368,12 +1392,12 @@ TRACE_EVENT(write_buffer_flush_slowpath,
        TP_printk("%zu/%zu", __entry->slowpath, __entry->total)
 );
 
-DEFINE_EVENT(str, rebalance_extent,
+DEFINE_EVENT(fs_str, rebalance_extent,
        TP_PROTO(struct bch_fs *c, const char *str),
        TP_ARGS(c, str)
 );
 
-DEFINE_EVENT(str, data_update,
+DEFINE_EVENT(fs_str, data_update,
        TP_PROTO(struct bch_fs *c, const char *str),
        TP_ARGS(c, str)
 );