Commit 2a6870ad authored by Kent Overstreet's avatar Kent Overstreet Committed by Kent Overstreet

bcachefs: Use darray for extra_journal_entries

Signed-off-by: default avatarKent Overstreet <kent.overstreet@gmail.com>
parent d8648425
...@@ -3055,8 +3055,7 @@ void bch2_trans_begin(struct btree_trans *trans) ...@@ -3055,8 +3055,7 @@ void bch2_trans_begin(struct btree_trans *trans)
trans->mem_top = 0; trans->mem_top = 0;
trans->hooks = NULL; trans->hooks = NULL;
trans->extra_journal_entries = NULL; trans->extra_journal_entries.nr = 0;
trans->extra_journal_entry_u64s = 0;
if (trans->fs_usage_deltas) { if (trans->fs_usage_deltas) {
trans->fs_usage_deltas->used = 0; trans->fs_usage_deltas->used = 0;
...@@ -3196,6 +3195,8 @@ void bch2_trans_exit(struct btree_trans *trans) ...@@ -3196,6 +3195,8 @@ void bch2_trans_exit(struct btree_trans *trans)
bch2_journal_preres_put(&c->journal, &trans->journal_preres); bch2_journal_preres_put(&c->journal, &trans->journal_preres);
kfree(trans->extra_journal_entries.data);
if (trans->fs_usage_deltas) { if (trans->fs_usage_deltas) {
if (trans->fs_usage_deltas->size + sizeof(trans->fs_usage_deltas) == if (trans->fs_usage_deltas->size + sizeof(trans->fs_usage_deltas) ==
REPLICAS_DELTA_LIST_MAX) REPLICAS_DELTA_LIST_MAX)
......
...@@ -7,6 +7,7 @@ ...@@ -7,6 +7,7 @@
#include "bkey_methods.h" #include "bkey_methods.h"
#include "buckets_types.h" #include "buckets_types.h"
#include "darray.h"
#include "journal_types.h" #include "journal_types.h"
#include "six.h" #include "six.h"
...@@ -416,8 +417,7 @@ struct btree_trans { ...@@ -416,8 +417,7 @@ struct btree_trans {
/* update path: */ /* update path: */
struct btree_trans_commit_hook *hooks; struct btree_trans_commit_hook *hooks;
struct jset_entry *extra_journal_entries; DARRAY(u64) extra_journal_entries;
unsigned extra_journal_entry_u64s;
struct journal_entry_pin *journal_pin; struct journal_entry_pin *journal_pin;
struct journal_res journal_res; struct journal_res journal_res;
......
...@@ -518,8 +518,15 @@ static int btree_update_nodes_written_trans(struct btree_trans *trans, ...@@ -518,8 +518,15 @@ static int btree_update_nodes_written_trans(struct btree_trans *trans,
struct bkey_i *k; struct bkey_i *k;
int ret; int ret;
trans->extra_journal_entries = (void *) &as->journal_entries[0]; ret = darray_make_room(&trans->extra_journal_entries, as->journal_u64s);
trans->extra_journal_entry_u64s = as->journal_u64s; if (ret)
return ret;
memcpy(&darray_top(trans->extra_journal_entries),
as->journal_entries,
as->journal_u64s * sizeof(u64));
trans->extra_journal_entries.nr += as->journal_u64s;
trans->journal_pin = &as->journal; trans->journal_pin = &as->journal;
for_each_keylist_key(&as->new_keys, k) { for_each_keylist_key(&as->new_keys, k) {
...@@ -1905,7 +1912,6 @@ static int __bch2_btree_node_update_key(struct btree_trans *trans, ...@@ -1905,7 +1912,6 @@ static int __bch2_btree_node_update_key(struct btree_trans *trans,
struct bch_fs *c = trans->c; struct bch_fs *c = trans->c;
struct btree_iter iter2 = { NULL }; struct btree_iter iter2 = { NULL };
struct btree *parent; struct btree *parent;
u64 journal_entries[BKEY_BTREE_PTR_U64s_MAX];
int ret; int ret;
if (!skip_triggers) { if (!skip_triggers) {
...@@ -1949,12 +1955,16 @@ static int __bch2_btree_node_update_key(struct btree_trans *trans, ...@@ -1949,12 +1955,16 @@ static int __bch2_btree_node_update_key(struct btree_trans *trans,
} else { } else {
BUG_ON(btree_node_root(c, b) != b); BUG_ON(btree_node_root(c, b) != b);
trans->extra_journal_entries = (void *) &journal_entries[0]; ret = darray_make_room(&trans->extra_journal_entries,
trans->extra_journal_entry_u64s = jset_u64s(new_key->k.u64s));
journal_entry_set((void *) &journal_entries[0], if (ret)
BCH_JSET_ENTRY_btree_root, return ret;
b->c.btree_id, b->c.level,
new_key, new_key->k.u64s); journal_entry_set((void *) &darray_top(trans->extra_journal_entries),
BCH_JSET_ENTRY_btree_root,
b->c.btree_id, b->c.level,
new_key, new_key->k.u64s);
trans->extra_journal_entries.nr += jset_u64s(new_key->k.u64s);
} }
ret = bch2_trans_commit(trans, NULL, NULL, ret = bch2_trans_commit(trans, NULL, NULL,
......
...@@ -707,13 +707,13 @@ bch2_trans_commit_write_locked(struct btree_trans *trans, ...@@ -707,13 +707,13 @@ bch2_trans_commit_write_locked(struct btree_trans *trans,
trans->journal_res.seq = c->journal.replay_journal_seq; trans->journal_res.seq = c->journal.replay_journal_seq;
} }
if (unlikely(trans->extra_journal_entry_u64s)) { if (unlikely(trans->extra_journal_entries.nr)) {
memcpy_u64s_small(journal_res_entry(&c->journal, &trans->journal_res), memcpy_u64s_small(journal_res_entry(&c->journal, &trans->journal_res),
trans->extra_journal_entries, trans->extra_journal_entries.data,
trans->extra_journal_entry_u64s); trans->extra_journal_entries.nr);
trans->journal_res.offset += trans->extra_journal_entry_u64s; trans->journal_res.offset += trans->extra_journal_entries.nr;
trans->journal_res.u64s -= trans->extra_journal_entry_u64s; trans->journal_res.u64s -= trans->extra_journal_entries.nr;
} }
/* /*
...@@ -1096,7 +1096,7 @@ int __bch2_trans_commit(struct btree_trans *trans) ...@@ -1096,7 +1096,7 @@ int __bch2_trans_commit(struct btree_trans *trans)
int ret = 0; int ret = 0;
if (!trans->nr_updates && if (!trans->nr_updates &&
!trans->extra_journal_entry_u64s) !trans->extra_journal_entries.nr)
goto out_reset; goto out_reset;
if (trans->flags & BTREE_INSERT_GC_LOCK_HELD) if (trans->flags & BTREE_INSERT_GC_LOCK_HELD)
...@@ -1120,7 +1120,7 @@ int __bch2_trans_commit(struct btree_trans *trans) ...@@ -1120,7 +1120,7 @@ int __bch2_trans_commit(struct btree_trans *trans)
memset(&trans->journal_preres, 0, sizeof(trans->journal_preres)); memset(&trans->journal_preres, 0, sizeof(trans->journal_preres));
trans->journal_u64s = trans->extra_journal_entry_u64s; trans->journal_u64s = trans->extra_journal_entries.nr;
trans->journal_preres_u64s = 0; trans->journal_preres_u64s = 0;
trans->journal_transaction_names = READ_ONCE(c->opts.journal_transaction_names); trans->journal_transaction_names = READ_ONCE(c->opts.journal_transaction_names);
...@@ -1180,8 +1180,7 @@ int __bch2_trans_commit(struct btree_trans *trans) ...@@ -1180,8 +1180,7 @@ int __bch2_trans_commit(struct btree_trans *trans)
trans->extra_journal_res = 0; trans->extra_journal_res = 0;
trans->nr_updates = 0; trans->nr_updates = 0;
trans->hooks = NULL; trans->hooks = NULL;
trans->extra_journal_entries = NULL; trans->extra_journal_entries.nr = 0;
trans->extra_journal_entry_u64s = 0;
if (trans->fs_usage_deltas) { if (trans->fs_usage_deltas) {
trans->fs_usage_deltas->used = 0; trans->fs_usage_deltas->used = 0;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment