]> git.proxmox.com Git - mirror_ubuntu-kernels.git/commitdiff
bcachefs: Improve trans_restart_mem_realloced tracepoint
authorKent Overstreet <kent.overstreet@gmail.com>
Thu, 15 Apr 2021 16:50:09 +0000 (12:50 -0400)
committerKent Overstreet <kent.overstreet@linux.dev>
Sun, 22 Oct 2023 21:09:00 +0000 (17:09 -0400)
Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
fs/bcachefs/btree_iter.c
fs/bcachefs/trace.h

index dabf0e18c1ff2285b36523a57a5e77e3030f1174..f82976aab7d93b50c624ceedeb5236dae5b45bf0 100644 (file)
@@ -2111,11 +2111,14 @@ struct btree_iter *__bch2_trans_copy_iter(struct btree_trans *trans,
        return iter;
 }
 
-static int bch2_trans_preload_mem(struct btree_trans *trans, size_t size)
+void *bch2_trans_kmalloc(struct btree_trans *trans, size_t size)
 {
-       if (size > trans->mem_bytes) {
+       size_t new_top = trans->mem_top + size;
+       void *p;
+
+       if (new_top > trans->mem_bytes) {
                size_t old_bytes = trans->mem_bytes;
-               size_t new_bytes = roundup_pow_of_two(size);
+               size_t new_bytes = roundup_pow_of_two(new_top);
                void *new_mem;
 
                WARN_ON_ONCE(new_bytes > BTREE_TRANS_MEM_MAX);
@@ -2128,29 +2131,17 @@ static int bch2_trans_preload_mem(struct btree_trans *trans, size_t size)
                }
 
                if (!new_mem)
-                       return -ENOMEM;
+                       return ERR_PTR(-ENOMEM);
 
                trans->mem = new_mem;
                trans->mem_bytes = new_bytes;
 
                if (old_bytes) {
-                       trace_trans_restart_mem_realloced(trans->ip, new_bytes);
-                       return -EINTR;
+                       trace_trans_restart_mem_realloced(trans->ip, _RET_IP_, new_bytes);
+                       return ERR_PTR(-EINTR);
                }
        }
 
-       return 0;
-}
-
-void *bch2_trans_kmalloc(struct btree_trans *trans, size_t size)
-{
-       void *p;
-       int ret;
-
-       ret = bch2_trans_preload_mem(trans, trans->mem_top + size);
-       if (ret)
-               return ERR_PTR(ret);
-
        p = trans->mem + trans->mem_top;
        trans->mem_top += size;
        return p;
index 02f2662e7bde6445d2e1778cb133e34fba9e7262..887c0adddf123203ed20b433512b058710db58cc 100644 (file)
@@ -627,38 +627,27 @@ TRACE_EVENT(trans_restart_would_deadlock,
                  __entry->want_pos_snapshot)
 );
 
-TRACE_EVENT(trans_restart_iters_realloced,
-       TP_PROTO(unsigned long ip, unsigned nr),
-       TP_ARGS(ip, nr),
-
-       TP_STRUCT__entry(
-               __field(unsigned long,          ip      )
-               __field(unsigned,               nr      )
-       ),
-
-       TP_fast_assign(
-               __entry->ip     = ip;
-               __entry->nr     = nr;
-       ),
-
-       TP_printk("%pS nr %u", (void *) __entry->ip, __entry->nr)
-);
-
 TRACE_EVENT(trans_restart_mem_realloced,
-       TP_PROTO(unsigned long ip, unsigned long bytes),
-       TP_ARGS(ip, bytes),
+       TP_PROTO(unsigned long trans_ip, unsigned long caller_ip,
+                unsigned long bytes),
+       TP_ARGS(trans_ip, caller_ip, bytes),
 
        TP_STRUCT__entry(
-               __field(unsigned long,          ip      )
-               __field(unsigned long,          bytes   )
+               __field(unsigned long,          trans_ip        )
+               __field(unsigned long,          caller_ip       )
+               __field(unsigned long,          bytes           )
        ),
 
        TP_fast_assign(
-               __entry->ip     = ip;
-               __entry->bytes  = bytes;
+               __entry->trans_ip       = trans_ip;
+               __entry->caller_ip      = caller_ip;
+               __entry->bytes          = bytes;
        ),
 
-       TP_printk("%pS bytes %lu", (void *) __entry->ip, __entry->bytes)
+       TP_printk("%pS %pS bytes %lu",
+                 (void *) __entry->trans_ip,
+                 (void *) __entry->caller_ip,
+                 __entry->bytes)
 );
 
 DEFINE_EVENT(transaction_restart,      trans_restart_journal_res_get,