summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKent Overstreet <kent.overstreet@linux.dev>2022-08-23 04:49:55 +0300
committerKent Overstreet <kent.overstreet@linux.dev>2023-10-23 00:09:39 +0300
commit616928c30f594775953ca75eb7ccc312a8abeb73 (patch)
tree0fe31e512c6f2b543b3dcf77a0e18c9f4bc32f3e
parente3738c6909d69e980d8b56d33df2e438a2c1c798 (diff)
downloadlinux-616928c30f594775953ca75eb7ccc312a8abeb73.tar.xz
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>
-rw-r--r--fs/bcachefs/bcachefs.h1
-rw-r--r--fs/bcachefs/btree_iter.c23
-rw-r--r--fs/bcachefs/btree_iter.h5
-rw-r--r--fs/bcachefs/btree_types.h1
-rw-r--r--fs/bcachefs/debug.c3
5 files changed, 20 insertions, 13 deletions
diff --git a/fs/bcachefs/bcachefs.h b/fs/bcachefs/bcachefs.h
index f8b7434534eb..9e6c10dfa443 100644
--- a/fs/bcachefs/bcachefs.h
+++ b/fs/bcachefs/bcachefs.h
@@ -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;
};
diff --git a/fs/bcachefs/btree_iter.c b/fs/bcachefs/btree_iter.c
index 1dc243f63b2d..f62f75ff82b2 100644
--- a/fs/bcachefs/btree_iter.c
+++ b/fs/bcachefs/btree_iter.c
@@ -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;
diff --git a/fs/bcachefs/btree_iter.h b/fs/bcachefs/btree_iter.h
index c083e49475d1..87b456998ef4 100644
--- a/fs/bcachefs/btree_iter.h
+++ b/fs/bcachefs/btree_iter.h
@@ -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 *);
diff --git a/fs/bcachefs/btree_types.h b/fs/bcachefs/btree_types.h
index ce148c21fd3b..42459a5bf035 100644
--- a/fs/bcachefs/btree_types.h
+++ b/fs/bcachefs/btree_types.h
@@ -420,6 +420,7 @@ struct btree_trans {
u64 paths_allocated;
unsigned mem_top;
+ unsigned mem_max;
unsigned mem_bytes;
void *mem;
diff --git a/fs/bcachefs/debug.c b/fs/bcachefs/debug.c
index 86c4b023ac7c..4fe20d36212e 100644
--- a/fs/bcachefs/debug.c
+++ b/fs/bcachefs/debug.c
@@ -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);