Commit 581edb63 authored by Kent Overstreet's avatar Kent Overstreet Committed by Kent Overstreet

bcachefs: mempoolify btree_trans

Signed-off-by: default avatarKent Overstreet <kent.overstreet@linux.dev>
parent cc1add4a
...@@ -580,6 +580,8 @@ struct bch_fs { ...@@ -580,6 +580,8 @@ struct bch_fs {
struct mutex btree_interior_update_lock; struct mutex btree_interior_update_lock;
struct closure_waitlist btree_interior_update_wait; struct closure_waitlist btree_interior_update_wait;
mempool_t btree_iters_pool;
struct workqueue_struct *wq; struct workqueue_struct *wq;
/* copygc needs its own workqueue for index updates.. */ /* copygc needs its own workqueue for index updates.. */
struct workqueue_struct *copygc_wq; struct workqueue_struct *copygc_wq;
......
...@@ -1648,10 +1648,7 @@ static int btree_trans_realloc_iters(struct btree_trans *trans) ...@@ -1648,10 +1648,7 @@ static int btree_trans_realloc_iters(struct btree_trans *trans)
bch2_trans_unlock(trans); bch2_trans_unlock(trans);
new_iters = kmalloc(sizeof(struct btree_iter) * BTREE_ITER_MAX, new_iters = mempool_alloc(&trans->c->btree_iters_pool, GFP_NOFS);
GFP_NOFS);
if (!new_iters)
return -ENOMEM;
memcpy(new_iters, trans->iters, memcpy(new_iters, trans->iters,
sizeof(struct btree_iter) * trans->nr_iters); sizeof(struct btree_iter) * trans->nr_iters);
...@@ -1679,12 +1676,10 @@ static int btree_trans_realloc_iters(struct btree_trans *trans) ...@@ -1679,12 +1676,10 @@ static int btree_trans_realloc_iters(struct btree_trans *trans)
return 0; return 0;
} }
int bch2_trans_preload_iters(struct btree_trans *trans) void bch2_trans_preload_iters(struct btree_trans *trans)
{ {
if (trans->iters != trans->iters_onstack) if (trans->iters == trans->iters_onstack)
return 0; btree_trans_realloc_iters(trans);
return btree_trans_realloc_iters(trans);
} }
static struct btree_iter *__btree_trans_get_iter(struct btree_trans *trans, static struct btree_iter *__btree_trans_get_iter(struct btree_trans *trans,
...@@ -1868,7 +1863,7 @@ int bch2_trans_exit(struct btree_trans *trans) ...@@ -1868,7 +1863,7 @@ int bch2_trans_exit(struct btree_trans *trans)
kfree(trans->mem); kfree(trans->mem);
if (trans->iters != trans->iters_onstack) if (trans->iters != trans->iters_onstack)
kfree(trans->iters); mempool_free(trans->iters, &trans->c->btree_iters_pool);
trans->mem = (void *) 0x1; trans->mem = (void *) 0x1;
trans->iters = (void *) 0x1; trans->iters = (void *) 0x1;
return ret; return ret;
......
...@@ -270,7 +270,7 @@ static inline int btree_iter_err(struct bkey_s_c k) ...@@ -270,7 +270,7 @@ static inline int btree_iter_err(struct bkey_s_c k)
/* new multiple iterator interface: */ /* new multiple iterator interface: */
int bch2_trans_preload_iters(struct btree_trans *); void bch2_trans_preload_iters(struct btree_trans *);
void bch2_trans_iter_free(struct btree_trans *, void bch2_trans_iter_free(struct btree_trans *,
struct btree_iter *); struct btree_iter *);
......
...@@ -398,7 +398,7 @@ static int check_dirents(struct bch_fs *c) ...@@ -398,7 +398,7 @@ static int check_dirents(struct bch_fs *c)
bch2_trans_init(&trans, c); bch2_trans_init(&trans, c);
BUG_ON(bch2_trans_preload_iters(&trans)); bch2_trans_preload_iters(&trans);
iter = bch2_trans_get_iter(&trans, BTREE_ID_DIRENTS, iter = bch2_trans_get_iter(&trans, BTREE_ID_DIRENTS,
POS(BCACHEFS_ROOT_INO, 0), 0); POS(BCACHEFS_ROOT_INO, 0), 0);
...@@ -539,7 +539,7 @@ static int check_xattrs(struct bch_fs *c) ...@@ -539,7 +539,7 @@ static int check_xattrs(struct bch_fs *c)
bch2_trans_init(&trans, c); bch2_trans_init(&trans, c);
BUG_ON(bch2_trans_preload_iters(&trans)); bch2_trans_preload_iters(&trans);
iter = bch2_trans_get_iter(&trans, BTREE_ID_XATTRS, iter = bch2_trans_get_iter(&trans, BTREE_ID_XATTRS,
POS(BCACHEFS_ROOT_INO, 0), 0); POS(BCACHEFS_ROOT_INO, 0), 0);
......
...@@ -372,6 +372,7 @@ static void bch2_fs_free(struct bch_fs *c) ...@@ -372,6 +372,7 @@ static void bch2_fs_free(struct bch_fs *c)
bch2_fs_compress_exit(c); bch2_fs_compress_exit(c);
percpu_free_rwsem(&c->usage_lock); percpu_free_rwsem(&c->usage_lock);
free_percpu(c->usage_percpu); free_percpu(c->usage_percpu);
mempool_exit(&c->btree_iters_pool);
mempool_exit(&c->btree_bounce_pool); mempool_exit(&c->btree_bounce_pool);
bioset_exit(&c->btree_bio); bioset_exit(&c->btree_bio);
mempool_exit(&c->btree_interior_update_pool); mempool_exit(&c->btree_interior_update_pool);
...@@ -600,6 +601,8 @@ static struct bch_fs *bch2_fs_alloc(struct bch_sb *sb, struct bch_opts opts) ...@@ -600,6 +601,8 @@ static struct bch_fs *bch2_fs_alloc(struct bch_sb *sb, struct bch_opts opts)
percpu_init_rwsem(&c->usage_lock) || percpu_init_rwsem(&c->usage_lock) ||
mempool_init_kvpmalloc_pool(&c->btree_bounce_pool, 1, mempool_init_kvpmalloc_pool(&c->btree_bounce_pool, 1,
btree_bytes(c)) || btree_bytes(c)) ||
mempool_init_kmalloc_pool(&c->btree_iters_pool, 1,
sizeof(struct btree_iter) * BTREE_ITER_MAX) ||
bch2_io_clock_init(&c->io_clock[READ]) || bch2_io_clock_init(&c->io_clock[READ]) ||
bch2_io_clock_init(&c->io_clock[WRITE]) || bch2_io_clock_init(&c->io_clock[WRITE]) ||
bch2_fs_journal_init(&c->journal) || bch2_fs_journal_init(&c->journal) ||
......
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