bcachefs: Fix for copygc getting stuck waiting for reserve to be filled
authorKent Overstreet <kent.overstreet@gmail.com>
Sun, 18 Apr 2021 22:01:49 +0000 (18:01 -0400)
committerKent Overstreet <kent.overstreet@linux.dev>
Sun, 22 Oct 2023 21:08:54 +0000 (17:08 -0400)
This fixes a regression from the patch
  bcachefs: Fix copygc dying on startup

In general only the allocator thread itself should be updating
ca->allocator_state, the thread waking up the allocator setting it is an
ugly hack only needed to avoid racing with the copygc threads when we're
first starting up.

Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
fs/bcachefs/alloc_background.h
fs/bcachefs/super.c

index 73e1c27c96e31e7bc922617ece21031e679cc0d7..ad15a80602c0c53d3d3205f7f0f1bfd62984694e 100644 (file)
@@ -100,10 +100,8 @@ static inline void bch2_wake_allocator(struct bch_dev *ca)
 
        rcu_read_lock();
        p = rcu_dereference(ca->alloc_thread);
-       if (p) {
+       if (p)
                wake_up_process(p);
-               ca->allocator_state = ALLOCATOR_running;
-       }
        rcu_read_unlock();
 }
 
index 650a559737fd2c791c8718353b91dd0d3e7b063b..0ff80816a54f32363fb2d3160c5539f3e962acdf 100644 (file)
@@ -908,9 +908,16 @@ int bch2_fs_start(struct bch_fs *c)
        /*
         * Allocator threads don't start filling copygc reserve until after we
         * set BCH_FS_STARTED - wake them now:
+        *
+        * XXX ugly hack:
+        * Need to set ca->allocator_state here instead of relying on the
+        * allocator threads to do it to avoid racing with the copygc threads
+        * checking it and thinking they have no alloc reserve:
         */
-       for_each_online_member(ca, c, i)
+       for_each_online_member(ca, c, i) {
+               ca->allocator_state = ALLOCATOR_running;
                bch2_wake_allocator(ca);
+       }
 
        if (c->opts.read_only || c->opts.nochanges) {
                bch2_fs_read_only(c);