diff options
author | Kent Overstreet <kent.overstreet@gmail.com> | 2021-04-15 19:50:09 +0300 |
---|---|---|
committer | Kent Overstreet <kent.overstreet@linux.dev> | 2023-10-23 00:09:00 +0300 |
commit | 73a117d2d8a0d9923648653b6400f534e0038281 (patch) | |
tree | a40bc031eaf7fdcacdea3f82ccefe0ec715415af | |
parent | 558509aa0198b9c062ff7b91bf8feb74513e0965 (diff) | |
download | linux-73a117d2d8a0d9923648653b6400f534e0038281.tar.xz |
bcachefs: Improve trans_restart_mem_realloced tracepoint
Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
-rw-r--r-- | fs/bcachefs/btree_iter.c | 27 | ||||
-rw-r--r-- | fs/bcachefs/trace.h | 37 |
2 files changed, 22 insertions, 42 deletions
diff --git a/fs/bcachefs/btree_iter.c b/fs/bcachefs/btree_iter.c index dabf0e18c1ff..f82976aab7d9 100644 --- a/fs/bcachefs/btree_iter.c +++ b/fs/bcachefs/btree_iter.c @@ -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; diff --git a/fs/bcachefs/trace.h b/fs/bcachefs/trace.h index 02f2662e7bde..887c0adddf12 100644 --- a/fs/bcachefs/trace.h +++ b/fs/bcachefs/trace.h @@ -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, |