*/
        bch2_journal_flush_all_pins(&c->journal);
 
+       if (!test_bit(BCH_FS_ALLOCATOR_RUNNING, &c->flags))
+               goto allocator_not_running;
+
        do {
                ret = bch2_alloc_write(c, false, &wrote);
                if (ret) {
                closure_wait_event(&c->btree_interior_update_wait,
                                   !bch2_btree_interior_updates_nr_pending(c));
        } while (wrote);
-
+allocator_not_running:
        for_each_member_device(ca, c, i)
                bch2_dev_allocator_stop(ca);
 
+       clear_bit(BCH_FS_ALLOCATOR_RUNNING, &c->flags);
+
        bch2_fs_journal_stop(&c->journal);
 
        /* XXX: mark super that alloc info is persistent */
                        goto err;
                }
 
+       set_bit(BCH_FS_ALLOCATOR_RUNNING, &c->flags);
+
        err = "error starting btree GC thread";
        if (bch2_gc_thread_start(c))
                goto err;