bcachefs: Take a SRCU lock in btree transactions
Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com> Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
This commit is contained in:
parent
d8b4600464
commit
876c7af3a6
@ -19,6 +19,7 @@ config BCACHEFS_FS
|
||||
select KEYS
|
||||
select RAID6_PQ
|
||||
select XOR_BLOCKS
|
||||
select SRCU
|
||||
help
|
||||
The bcachefs filesystem - a modern, copy on write filesystem, with
|
||||
support for multiple devices, compression, checksumming, etc.
|
||||
|
@ -193,6 +193,7 @@
|
||||
#include <linux/rwsem.h>
|
||||
#include <linux/seqlock.h>
|
||||
#include <linux/shrinker.h>
|
||||
#include <linux/srcu.h>
|
||||
#include <linux/types.h>
|
||||
#include <linux/workqueue.h>
|
||||
#include <linux/zstd.h>
|
||||
@ -642,6 +643,8 @@ struct bch_fs {
|
||||
mempool_t btree_iters_pool;
|
||||
struct btree_iter_buf __percpu *btree_iters_bufs;
|
||||
|
||||
struct srcu_struct btree_trans_barrier;
|
||||
|
||||
struct btree_key_cache btree_key_cache;
|
||||
|
||||
struct workqueue_struct *wq;
|
||||
|
@ -2373,6 +2373,8 @@ void bch2_trans_init(struct btree_trans *trans, struct bch_fs *c,
|
||||
if (expected_mem_bytes)
|
||||
bch2_trans_preload_mem(trans, expected_mem_bytes);
|
||||
|
||||
trans->srcu_idx = srcu_read_lock(&c->btree_trans_barrier);
|
||||
|
||||
#ifdef CONFIG_BCACHEFS_DEBUG
|
||||
trans->pid = current->pid;
|
||||
mutex_lock(&c->btree_trans_lock);
|
||||
@ -2393,6 +2395,8 @@ int bch2_trans_exit(struct btree_trans *trans)
|
||||
mutex_unlock(&trans->c->btree_trans_lock);
|
||||
#endif
|
||||
|
||||
srcu_read_unlock(&c->btree_trans_barrier, trans->srcu_idx);
|
||||
|
||||
bch2_journal_preres_put(&trans->c->journal, &trans->journal_preres);
|
||||
|
||||
kfree(trans->fs_usage_deltas);
|
||||
@ -2475,6 +2479,7 @@ void bch2_btree_trans_to_text(struct printbuf *out, struct bch_fs *c)
|
||||
void bch2_fs_btree_iter_exit(struct bch_fs *c)
|
||||
{
|
||||
mempool_exit(&c->btree_iters_pool);
|
||||
cleanup_srcu_struct(&c->btree_trans_barrier);
|
||||
}
|
||||
|
||||
int bch2_fs_btree_iter_init(struct bch_fs *c)
|
||||
@ -2484,7 +2489,8 @@ int bch2_fs_btree_iter_init(struct bch_fs *c)
|
||||
INIT_LIST_HEAD(&c->btree_trans_list);
|
||||
mutex_init(&c->btree_trans_lock);
|
||||
|
||||
return mempool_init_kmalloc_pool(&c->btree_iters_pool, 1,
|
||||
return init_srcu_struct(&c->btree_trans_barrier) ?:
|
||||
mempool_init_kmalloc_pool(&c->btree_iters_pool, 1,
|
||||
sizeof(struct btree_iter) * nr +
|
||||
sizeof(struct btree_insert_entry) * nr +
|
||||
sizeof(struct btree_insert_entry) * nr);
|
||||
|
@ -350,6 +350,7 @@ struct btree_trans {
|
||||
pid_t pid;
|
||||
#endif
|
||||
unsigned long ip;
|
||||
int srcu_idx;
|
||||
|
||||
u64 iters_linked;
|
||||
u64 iters_live;
|
||||
|
Loading…
x
Reference in New Issue
Block a user