bcachefs: Fixes/improvements for journal entry reservations
authorKent Overstreet <kent.overstreet@gmail.com>
Wed, 3 Feb 2021 18:10:55 +0000 (13:10 -0500)
committerKent Overstreet <kent.overstreet@linux.dev>
Sun, 22 Oct 2023 21:08:52 +0000 (17:08 -0400)
This fixes some arithmetic bugs in "bcachefs: Journal updates to dev
usage" - additionally, it cleans things up by switching everything that
goes in every journal entry to the journal_entry_res mechanism.

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

index 0c24a5312e4932cd17ffbe3cbcfed678c6a23c32..cec5c3ddce342a1bc9b1250adaac266f91331a15 100644 (file)
@@ -582,8 +582,9 @@ struct bch_fs {
        struct bch_replicas_cpu replicas_gc;
        struct mutex            replicas_gc_lock;
 
+       struct journal_entry_res btree_root_journal_res;
        struct journal_entry_res replicas_journal_res;
-
+       struct journal_entry_res clock_journal_res;
        struct journal_entry_res dev_usage_journal_res;
 
        struct bch_disk_groups_cpu __rcu *disk_groups;
index 379b9ad2c0f9317058774feaecd6206e9a6c4813..7c805dd741804fbba5c85ed55ab302ede544ff39 100644 (file)
@@ -1119,13 +1119,6 @@ int bch2_fs_journal_init(struct journal *j)
        j->write_delay_ms       = 1000;
        j->reclaim_delay_ms     = 100;
 
-       /* Btree roots: */
-       j->entry_u64s_reserved +=
-               BTREE_ID_NR * (JSET_KEYS_U64s + BKEY_BTREE_PTR_U64s_MAX);
-
-       j->entry_u64s_reserved +=
-               2 * (sizeof(struct jset_entry_clock) / sizeof(u64));
-
        atomic64_set(&j->reservations.counter,
                ((union journal_res_state)
                 { .cur_entry_offset = JOURNAL_ENTRY_CLOSED_VAL }).v);
index e5e437deb9abf81f0a4b4e3fada0bfdf184bfb3a..bf1804c10bfbf8d620a795e9ece4344f75efc310 100644 (file)
@@ -1074,8 +1074,9 @@ unsigned bch2_dev_has_data(struct bch_fs *c, struct bch_dev *ca)
 
 int bch2_fs_replicas_init(struct bch_fs *c)
 {
-       c->journal.entry_u64s_reserved +=
-               reserve_journal_replicas(c, &c->replicas);
+       bch2_journal_entry_res_resize(&c->journal,
+                       &c->replicas_journal_res,
+                       reserve_journal_replicas(c, &c->replicas));
 
        return replicas_table_update(c, &c->replicas);
 }
index eecabeb08c94a5e0aadde558dc231b352a49c10c..e242b72155483ac65d5167532a4d5de1bad8f25f 100644 (file)
@@ -159,8 +159,9 @@ static void bch2_dev_usage_journal_reserve(struct bch_fs *c)
 {
        struct bch_dev *ca;
        unsigned i, nr = 0, u64s =
-               (sizeof(struct jset_entry_dev_usage) +
-                sizeof(struct jset_entry_dev_usage_type) * BCH_DATA_NR);
+               ((sizeof(struct jset_entry_dev_usage) +
+                 sizeof(struct jset_entry_dev_usage_type) * BCH_DATA_NR)) /
+               sizeof(u64);
 
        rcu_read_lock();
        for_each_member_device_rcu(ca, c, i, NULL)
@@ -796,14 +797,20 @@ static struct bch_fs *bch2_fs_alloc(struct bch_sb *sb, struct bch_opts opts)
            bch2_fs_fsio_init(c))
                goto err;
 
-       bch2_dev_usage_journal_reserve(c);
-
        mi = bch2_sb_get_members(c->disk_sb.sb);
        for (i = 0; i < c->sb.nr_devices; i++)
                if (bch2_dev_exists(c->disk_sb.sb, mi, i) &&
                    bch2_dev_alloc(c, i))
                        goto err;
 
+       bch2_journal_entry_res_resize(&c->journal,
+                       &c->btree_root_journal_res,
+                       BTREE_ID_NR * (JSET_KEYS_U64s + BKEY_BTREE_PTR_U64s_MAX));
+       bch2_dev_usage_journal_reserve(c);
+       bch2_journal_entry_res_resize(&c->journal,
+                       &c->clock_journal_res,
+                       (sizeof(struct jset_entry_clock) / sizeof(u64)) * 2);
+
        mutex_lock(&bch_fs_list_lock);
        err = bch2_fs_online(c);
        mutex_unlock(&bch_fs_list_lock);