diff options
Diffstat (limited to 'libbcachefs/alloc_background.c')
-rw-r--r-- | libbcachefs/alloc_background.c | 23 |
1 files changed, 20 insertions, 3 deletions
diff --git a/libbcachefs/alloc_background.c b/libbcachefs/alloc_background.c index 1297638b..62f639b8 100644 --- a/libbcachefs/alloc_background.c +++ b/libbcachefs/alloc_background.c @@ -938,7 +938,7 @@ retry: else memset(&u, 0, sizeof(u)); - invalidating_cached_data = u.cached_sectors != 0; + invalidating_cached_data = m.cached_sectors != 0; //BUG_ON(u.dirty_sectors); u.data_type = 0; @@ -946,20 +946,33 @@ retry: u.cached_sectors = 0; u.read_time = c->bucket_clock[READ].hand; u.write_time = c->bucket_clock[WRITE].hand; - u.gen++; + + /* + * The allocator has to start before journal replay is finished - thus, + * we have to trust the in memory bucket @m, not the version in the + * btree: + */ + u.gen = m.gen + 1; a = bkey_alloc_init(&alloc_key.k); a->k.p = iter->pos; bch2_alloc_pack(a, u); + /* + * XXX: + * when using deferred btree updates, we have journal reclaim doing + * btree updates and thus requiring the allocator to make forward + * progress, and here the allocator is requiring space in the journal - + * so we need a journal pre-reservation: + */ ret = bch2_btree_insert_at(c, NULL, invalidating_cached_data ? journal_seq : NULL, BTREE_INSERT_ATOMIC| + BTREE_INSERT_NOUNLOCK| BTREE_INSERT_NOCHECK_RW| BTREE_INSERT_NOFAIL| BTREE_INSERT_USE_RESERVE| BTREE_INSERT_USE_ALLOC_RESERVE| - BTREE_INSERT_JOURNAL_RESERVED| flags, BTREE_INSERT_ENTRY(iter, &a->k_i)); if (ret == -EINTR) @@ -975,6 +988,10 @@ retry: if (!top->nr) heap_pop(&ca->alloc_heap, e, bucket_alloc_cmp, NULL); + /* with btree still locked: */ + if (ca->buckets_written) + set_bit(b, ca->buckets_written); + /* * Make sure we flush the last journal entry that updated this * bucket (i.e. deleting the last reference) before writing to |