bcachefs: Track maximum transaction memory
This patch - tracks maximum bch2_trans_kmalloc() memory used in btree_transaction_stats - makes it available in debugfs - switches bch2_trans_init() to using that for the amount of memory to preallocate, instead of the parameter passed in This drastically reduces transaction restarts, and means we no longer need to track this in the source code. Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
This commit is contained in:
parent
e3738c6909
commit
616928c30f
@ -533,6 +533,7 @@ struct btree_transaction_stats {
|
||||
struct bch2_time_stats lock_hold_times;
|
||||
struct mutex lock;
|
||||
unsigned nr_max_paths;
|
||||
unsigned max_mem;
|
||||
char *max_paths_text;
|
||||
};
|
||||
|
||||
|
@ -2747,9 +2747,11 @@ void bch2_trans_copy_iter(struct btree_iter *dst, struct btree_iter *src)
|
||||
|
||||
void *bch2_trans_kmalloc(struct btree_trans *trans, size_t size)
|
||||
{
|
||||
size_t new_top = trans->mem_top + size;
|
||||
unsigned new_top = trans->mem_top + size;
|
||||
void *p;
|
||||
|
||||
trans->mem_max = max(trans->mem_max, new_top);
|
||||
|
||||
if (new_top > trans->mem_bytes) {
|
||||
size_t old_bytes = trans->mem_bytes;
|
||||
size_t new_bytes = roundup_pow_of_two(new_top);
|
||||
@ -2887,10 +2889,7 @@ 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,
|
||||
unsigned expected_nr_iters,
|
||||
size_t expected_mem_bytes,
|
||||
const char *fn)
|
||||
void __bch2_trans_init(struct btree_trans *trans, struct bch_fs *c, const char *fn)
|
||||
__acquires(&c->btree_trans_barrier)
|
||||
{
|
||||
struct btree_transaction_stats *s;
|
||||
@ -2906,8 +2905,10 @@ void __bch2_trans_init(struct btree_trans *trans, struct bch_fs *c,
|
||||
|
||||
bch2_trans_alloc_paths(trans, c);
|
||||
|
||||
if (expected_mem_bytes) {
|
||||
expected_mem_bytes = roundup_pow_of_two(expected_mem_bytes);
|
||||
s = btree_trans_stats(trans);
|
||||
if (s) {
|
||||
unsigned expected_mem_bytes = roundup_pow_of_two(s->max_mem);
|
||||
|
||||
trans->mem = kmalloc(expected_mem_bytes, GFP_KERNEL);
|
||||
|
||||
if (!unlikely(trans->mem)) {
|
||||
@ -2916,11 +2917,9 @@ void __bch2_trans_init(struct btree_trans *trans, struct bch_fs *c,
|
||||
} else {
|
||||
trans->mem_bytes = expected_mem_bytes;
|
||||
}
|
||||
}
|
||||
|
||||
s = btree_trans_stats(trans);
|
||||
if (s)
|
||||
trans->nr_max_paths = s->nr_max_paths;
|
||||
}
|
||||
|
||||
trans->srcu_idx = srcu_read_lock(&c->btree_trans_barrier);
|
||||
|
||||
@ -2967,9 +2966,13 @@ void bch2_trans_exit(struct btree_trans *trans)
|
||||
{
|
||||
struct btree_insert_entry *i;
|
||||
struct bch_fs *c = trans->c;
|
||||
struct btree_transaction_stats *s = btree_trans_stats(trans);
|
||||
|
||||
bch2_trans_unlock(trans);
|
||||
|
||||
if (s)
|
||||
s->max_mem = max(s->max_mem, trans->mem_max);
|
||||
|
||||
trans_for_each_update(trans, i)
|
||||
__btree_path_put(i->path, true);
|
||||
trans->nr_updates = 0;
|
||||
|
@ -564,11 +564,10 @@ 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 *,
|
||||
unsigned, size_t, const char *);
|
||||
void __bch2_trans_init(struct btree_trans *, struct bch_fs *, const char *);
|
||||
void bch2_trans_exit(struct btree_trans *);
|
||||
|
||||
#define bch2_trans_init(...) __bch2_trans_init(__VA_ARGS__, __func__)
|
||||
#define bch2_trans_init(_trans, _c, _nr_iters, _mem) __bch2_trans_init(_trans, _c, __func__)
|
||||
|
||||
void bch2_btree_trans_to_text(struct printbuf *, struct btree_trans *);
|
||||
|
||||
|
@ -420,6 +420,7 @@ struct btree_trans {
|
||||
u64 paths_allocated;
|
||||
|
||||
unsigned mem_top;
|
||||
unsigned mem_max;
|
||||
unsigned mem_bytes;
|
||||
void *mem;
|
||||
|
||||
|
@ -667,6 +667,9 @@ static ssize_t lock_held_stats_read(struct file *file, char __user *buf,
|
||||
|
||||
mutex_lock(&s->lock);
|
||||
|
||||
prt_printf(&i->buf, "Max mem used: %u", s->max_mem);
|
||||
prt_newline(&i->buf);
|
||||
|
||||
if (IS_ENABLED(CONFIG_BCACHEFS_LOCK_TIME_STATS)) {
|
||||
prt_printf(&i->buf, "Lock hold times:");
|
||||
prt_newline(&i->buf);
|
||||
|
Loading…
x
Reference in New Issue
Block a user