diff options
author | Kent Overstreet <kent.overstreet@gmail.com> | 2019-03-28 03:08:40 -0400 |
---|---|---|
committer | Kent Overstreet <kent.overstreet@gmail.com> | 2019-03-28 03:10:33 -0400 |
commit | 1c782ec7cee6c3c2759ac811d6827753feb83f3c (patch) | |
tree | 6bbff7b03380bf97e42ac874ef9629572c584f8f | |
parent | 516fce4b72aa2acac7b00ce1aa9a257c3d29e0dd (diff) |
bcachefs: simplify gc locking a bit
-rw-r--r-- | fs/bcachefs/btree_gc.c | 27 |
1 files changed, 11 insertions, 16 deletions
diff --git a/fs/bcachefs/btree_gc.c b/fs/bcachefs/btree_gc.c index aa05d7eedb56..358dfa2b2497 100644 --- a/fs/bcachefs/btree_gc.c +++ b/fs/bcachefs/btree_gc.c @@ -477,12 +477,8 @@ static void bch2_gc_free(struct bch_fs *c) ca->usage[1] = NULL; } - percpu_down_write(&c->mark_lock); - free_percpu(c->usage[1]); c->usage[1] = NULL; - - percpu_up_write(&c->mark_lock); } static void bch2_gc_done(struct bch_fs *c, bool initial) @@ -523,8 +519,6 @@ static void bch2_gc_done(struct bch_fs *c, bool initial) #define copy_fs_field(_f, _msg, ...) \ copy_field(_f, "fs has wrong " _msg, ##__VA_ARGS__) - percpu_down_write(&c->mark_lock); - { struct genradix_iter dst_iter = genradix_iter_init(&c->stripes[0], 0); struct genradix_iter src_iter = genradix_iter_init(&c->stripes[1], 0); @@ -632,8 +626,6 @@ static void bch2_gc_done(struct bch_fs *c, bool initial) } } - percpu_up_write(&c->mark_lock); - #undef copy_fs_field #undef copy_dev_field #undef copy_bucket_field @@ -646,8 +638,6 @@ static int bch2_gc_start(struct bch_fs *c) struct bch_dev *ca; unsigned i; - percpu_down_write(&c->mark_lock); - /* * indicate to stripe code that we need to allocate for the gc stripes * radix tree, too @@ -658,8 +648,6 @@ static int bch2_gc_start(struct bch_fs *c) c->usage[1] = __alloc_percpu_gfp(fs_usage_u64s(c) * sizeof(u64), sizeof(u64), GFP_KERNEL); - percpu_up_write(&c->mark_lock); - if (!c->usage[1]) return -ENOMEM; @@ -682,8 +670,6 @@ static int bch2_gc_start(struct bch_fs *c) } } - percpu_down_write(&c->mark_lock); - for_each_member_device(ca, c, i) { struct bucket_array *dst = __bucket_array(ca, 1); struct bucket_array *src = __bucket_array(ca, 0); @@ -700,8 +686,6 @@ static int bch2_gc_start(struct bch_fs *c) } }; - percpu_up_write(&c->mark_lock); - return bch2_ec_mem_alloc(c, true); } @@ -734,7 +718,10 @@ int bch2_gc(struct bch_fs *c, struct list_head *journal, bool initial) down_write(&c->gc_lock); again: + percpu_down_write(&c->mark_lock); ret = bch2_gc_start(c); + percpu_up_write(&c->mark_lock); + if (ret) goto out; @@ -759,7 +746,11 @@ out: bch_info(c, "Fixed gens, restarting mark and sweep:"); clear_bit(BCH_FS_FIXED_GENS, &c->flags); __gc_pos_set(c, gc_phase(GC_PHASE_NOT_RUNNING)); + + percpu_down_write(&c->mark_lock); bch2_gc_free(c); + percpu_up_write(&c->mark_lock); + goto again; } @@ -767,6 +758,8 @@ out: ret = -EINVAL; } + percpu_down_write(&c->mark_lock); + if (!ret) bch2_gc_done(c, initial); @@ -774,6 +767,8 @@ out: __gc_pos_set(c, gc_phase(GC_PHASE_NOT_RUNNING)); bch2_gc_free(c); + percpu_up_write(&c->mark_lock); + up_write(&c->gc_lock); trace_gc_end(c); |