diff options
author | Kent Overstreet <kent.overstreet@linux.dev> | 2022-10-17 07:03:11 -0400 |
---|---|---|
committer | Kent Overstreet <kent.overstreet@linux.dev> | 2023-10-22 17:09:44 -0400 |
commit | 307e3c13192002f684bdfc23865a57274e6bb4ad (patch) | |
tree | 56645bb36c8efcec63ed0aaa4f6db836ad5b81e2 | |
parent | 29aa78f15e1bbd984cc14f395544d62b6f0a2a33 (diff) |
bcachefs: Optimize bch2_trans_init()
Now we store the transaction's fn idx in a local variable, instead of
redoing the lookup every time we call bch2_trans_init().
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
-rw-r--r-- | fs/bcachefs/bcachefs.h | 1 | ||||
-rw-r--r-- | fs/bcachefs/btree_iter.c | 20 | ||||
-rw-r--r-- | fs/bcachefs/btree_iter.h | 15 | ||||
-rw-r--r-- | fs/bcachefs/debug.c | 6 |
4 files changed, 27 insertions, 15 deletions
diff --git a/fs/bcachefs/bcachefs.h b/fs/bcachefs/bcachefs.h index 08fd899d8837..7ca1aa3a847f 100644 --- a/fs/bcachefs/bcachefs.h +++ b/fs/bcachefs/bcachefs.h @@ -929,7 +929,6 @@ mempool_t bio_bounce_pages; struct bch2_time_stats times[BCH_TIME_STAT_NR]; - const char *btree_transaction_fns[BCH_TRANSACTIONS_NR]; struct btree_transaction_stats btree_transaction_stats[BCH_TRANSACTIONS_NR]; }; diff --git a/fs/bcachefs/btree_iter.c b/fs/bcachefs/btree_iter.c index 0bd67600f0db..4402fcee26e3 100644 --- a/fs/bcachefs/btree_iter.c +++ b/fs/bcachefs/btree_iter.c @@ -2841,15 +2841,16 @@ static void bch2_trans_alloc_paths(struct btree_trans *trans, struct bch_fs *c) trans->updates = p; p += updates_bytes; } -static inline unsigned bch2_trans_get_fn_idx(struct btree_trans *trans, struct bch_fs *c, - const char *fn) +const char *bch2_btree_transaction_fns[BCH_TRANSACTIONS_NR]; + +unsigned bch2_trans_get_fn_idx(const char *fn) { unsigned i; - for (i = 0; i < ARRAY_SIZE(c->btree_transaction_fns); i++) - if (!c->btree_transaction_fns[i] || - c->btree_transaction_fns[i] == fn) { - c->btree_transaction_fns[i] = fn; + for (i = 0; i < ARRAY_SIZE(bch2_btree_transaction_fns); i++) + if (!bch2_btree_transaction_fns[i] || + bch2_btree_transaction_fns[i] == fn) { + bch2_btree_transaction_fns[i] = fn; return i; } @@ -2857,16 +2858,17 @@ static inline unsigned bch2_trans_get_fn_idx(struct btree_trans *trans, struct b return i; } -void __bch2_trans_init(struct btree_trans *trans, struct bch_fs *c, const char *fn) +void __bch2_trans_init(struct btree_trans *trans, struct bch_fs *c, unsigned fn_idx) __acquires(&c->btree_trans_barrier) { struct btree_transaction_stats *s; memset(trans, 0, sizeof(*trans)); trans->c = c; - trans->fn = fn; + trans->fn = fn_idx < ARRAY_SIZE(bch2_btree_transaction_fns) + ? bch2_btree_transaction_fns[fn_idx] : NULL; trans->last_begin_time = local_clock(); - trans->fn_idx = bch2_trans_get_fn_idx(trans, c, fn); + trans->fn_idx = fn_idx; trans->locking_wait.task = current; trans->journal_replay_not_finished = !test_bit(JOURNAL_REPLAY_DONE, &c->journal.flags); diff --git a/fs/bcachefs/btree_iter.h b/fs/bcachefs/btree_iter.h index 2e94cd2657e9..cfbd07bc9366 100644 --- a/fs/bcachefs/btree_iter.h +++ b/fs/bcachefs/btree_iter.h @@ -587,10 +587,21 @@ void bch2_btree_path_to_text(struct printbuf *, struct btree_path *); void bch2_trans_paths_to_text(struct printbuf *, struct btree_trans *); void bch2_dump_trans_updates(struct btree_trans *); void bch2_dump_trans_paths_updates(struct btree_trans *); -void __bch2_trans_init(struct btree_trans *, struct bch_fs *, const char *); +void __bch2_trans_init(struct btree_trans *, struct bch_fs *, unsigned); void bch2_trans_exit(struct btree_trans *); -#define bch2_trans_init(_trans, _c, _nr_iters, _mem) __bch2_trans_init(_trans, _c, __func__) +extern const char *bch2_btree_transaction_fns[BCH_TRANSACTIONS_NR]; +unsigned bch2_trans_get_fn_idx(const char *); + +#define bch2_trans_init(_trans, _c, _nr_iters, _mem) \ +do { \ + static unsigned trans_fn_idx; \ + \ + if (unlikely(!trans_fn_idx)) \ + trans_fn_idx = bch2_trans_get_fn_idx(__func__); \ + \ + __bch2_trans_init(_trans, _c, trans_fn_idx); \ +} while (0) void bch2_btree_trans_to_text(struct printbuf *, struct btree_trans *); diff --git a/fs/bcachefs/debug.c b/fs/bcachefs/debug.c index 7abc707d2f38..a9e4180d6a80 100644 --- a/fs/bcachefs/debug.c +++ b/fs/bcachefs/debug.c @@ -638,11 +638,11 @@ static ssize_t lock_held_stats_read(struct file *file, char __user *buf, if (!i->size) break; - if (i->iter == ARRAY_SIZE(c->btree_transaction_fns) || - !c->btree_transaction_fns[i->iter]) + if (i->iter == ARRAY_SIZE(bch2_btree_transaction_fns) || + !bch2_btree_transaction_fns[i->iter]) break; - prt_printf(&i->buf, "%s: ", c->btree_transaction_fns[i->iter]); + prt_printf(&i->buf, "%s: ", bch2_btree_transaction_fns[i->iter]); prt_newline(&i->buf); printbuf_indent_add(&i->buf, 2); |