Commit 14d8f26a authored by Kent Overstreet's avatar Kent Overstreet

bcachefs: Inline bch2_trans_kmalloc() fast path

Small performance optimization.
Signed-off-by: default avatarKent Overstreet <kent.overstreet@linux.dev>
parent f3b8403e
...@@ -2668,17 +2668,15 @@ void bch2_trans_copy_iter(struct btree_iter *dst, struct btree_iter *src) ...@@ -2668,17 +2668,15 @@ void bch2_trans_copy_iter(struct btree_iter *dst, struct btree_iter *src)
dst->key_cache_path = NULL; dst->key_cache_path = NULL;
} }
void *bch2_trans_kmalloc(struct btree_trans *trans, size_t size) void *__bch2_trans_kmalloc(struct btree_trans *trans, size_t size)
{ {
unsigned 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 old_bytes = trans->mem_bytes;
size_t new_bytes = roundup_pow_of_two(new_top); size_t new_bytes = roundup_pow_of_two(new_top);
void *new_mem; void *new_mem;
void *p;
trans->mem_max = max(trans->mem_max, new_top);
WARN_ON_ONCE(new_bytes > BTREE_TRANS_MEM_MAX); WARN_ON_ONCE(new_bytes > BTREE_TRANS_MEM_MAX);
...@@ -2699,7 +2697,6 @@ void *bch2_trans_kmalloc(struct btree_trans *trans, size_t size) ...@@ -2699,7 +2697,6 @@ void *bch2_trans_kmalloc(struct btree_trans *trans, size_t size)
trace_and_count(trans->c, trans_restart_mem_realloced, trans, _RET_IP_, new_bytes); trace_and_count(trans->c, trans_restart_mem_realloced, trans, _RET_IP_, new_bytes);
return ERR_PTR(btree_trans_restart(trans, BCH_ERR_transaction_restart_mem_realloced)); return ERR_PTR(btree_trans_restart(trans, BCH_ERR_transaction_restart_mem_realloced));
} }
}
p = trans->mem + trans->mem_top; p = trans->mem + trans->mem_top;
trans->mem_top += size; trans->mem_top += size;
......
...@@ -328,7 +328,23 @@ static inline void set_btree_iter_dontneed(struct btree_iter *iter) ...@@ -328,7 +328,23 @@ static inline void set_btree_iter_dontneed(struct btree_iter *iter)
iter->path->preserve = false; iter->path->preserve = false;
} }
void *bch2_trans_kmalloc(struct btree_trans *, size_t); void *__bch2_trans_kmalloc(struct btree_trans *, size_t);
static inline void *bch2_trans_kmalloc(struct btree_trans *trans, size_t size)
{
unsigned new_top = trans->mem_top + size;
void *p = trans->mem + trans->mem_top;
if (likely(new_top <= trans->mem_bytes)) {
trans->mem_top += size;
memset(p, 0, size);
return p;
} else {
return __bch2_trans_kmalloc(trans, size);
}
}
u32 bch2_trans_begin(struct btree_trans *); u32 bch2_trans_begin(struct btree_trans *);
static inline struct btree * static inline struct btree *
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment