Commit 3636ed48 authored by Kent Overstreet's avatar Kent Overstreet Committed by Kent Overstreet

bcachefs: Deferred btree updates

Will be used in the future for inode updates, which will be very helpful
for multithreaded workloads that have to update the inode with every
extent update (appends, or updates that change i_sectors)

Also will be used eventually for fully persistent alloc info

However - we still need a mechanism for reserving space in the journal
prior to getting a journal reservation, so it's not technically safe to
make use of this just yet, we could deadlock with the journal full
(although not likely to be an issue in practice)
Signed-off-by: default avatarKent Overstreet <kent.overstreet@linux.dev>
parent eb863265
...@@ -245,9 +245,28 @@ struct btree_iter { ...@@ -245,9 +245,28 @@ struct btree_iter {
#define BTREE_ITER_MAX 8 #define BTREE_ITER_MAX 8
struct deferred_update {
struct journal_entry_pin journal;
spinlock_t lock;
unsigned gen;
u8 allocated_u64s;
enum btree_id btree_id;
/* must be last: */
struct bkey_i k;
};
struct btree_insert_entry { struct btree_insert_entry {
struct btree_iter *iter;
struct bkey_i *k; struct bkey_i *k;
union {
struct btree_iter *iter;
struct deferred_update *d;
};
bool deferred;
}; };
struct btree_trans { struct btree_trans {
......
...@@ -16,6 +16,11 @@ bool bch2_btree_bset_insert_key(struct btree_iter *, struct btree *, ...@@ -16,6 +16,11 @@ bool bch2_btree_bset_insert_key(struct btree_iter *, struct btree *,
void bch2_btree_journal_key(struct btree_insert *trans, struct btree_iter *, void bch2_btree_journal_key(struct btree_insert *trans, struct btree_iter *,
struct bkey_i *); struct bkey_i *);
void bch2_deferred_update_free(struct bch_fs *,
struct deferred_update *);
struct deferred_update *
bch2_deferred_update_alloc(struct bch_fs *, enum btree_id, unsigned);
/* Normal update interface: */ /* Normal update interface: */
struct btree_insert { struct btree_insert {
...@@ -38,6 +43,13 @@ int __bch2_btree_insert_at(struct btree_insert *); ...@@ -38,6 +43,13 @@ int __bch2_btree_insert_at(struct btree_insert *);
.k = (_k), \ .k = (_k), \
}) })
#define BTREE_INSERT_DEFERRED(_d, _k) \
((struct btree_insert_entry) { \
.k = (_k), \
.d = (_d), \
.deferred = true, \
})
/** /**
* bch_btree_insert_at - insert one or more keys at iterator positions * bch_btree_insert_at - insert one or more keys at iterator positions
* @iter: btree iterator * @iter: btree iterator
......
This diff is collapsed.
...@@ -75,6 +75,25 @@ void bch2_journal_pin_drop(struct journal *j, ...@@ -75,6 +75,25 @@ void bch2_journal_pin_drop(struct journal *j,
spin_unlock(&j->lock); spin_unlock(&j->lock);
} }
void bch2_journal_pin_update(struct journal *j, u64 seq,
struct journal_entry_pin *pin,
journal_pin_flush_fn flush_fn)
{
spin_lock(&j->lock);
if (pin->seq != seq) {
__journal_pin_drop(j, pin);
__journal_pin_add(j, seq, pin, flush_fn);
} else {
struct journal_entry_pin_list *pin_list =
journal_seq_pin(j, seq);
list_move(&pin->list, &pin_list->list);
}
spin_unlock(&j->lock);
}
void bch2_journal_pin_add_if_older(struct journal *j, void bch2_journal_pin_add_if_older(struct journal *j,
struct journal_entry_pin *src_pin, struct journal_entry_pin *src_pin,
struct journal_entry_pin *pin, struct journal_entry_pin *pin,
......
...@@ -19,6 +19,8 @@ journal_seq_pin(struct journal *j, u64 seq) ...@@ -19,6 +19,8 @@ journal_seq_pin(struct journal *j, u64 seq)
void bch2_journal_pin_add(struct journal *, u64, struct journal_entry_pin *, void bch2_journal_pin_add(struct journal *, u64, struct journal_entry_pin *,
journal_pin_flush_fn); journal_pin_flush_fn);
void bch2_journal_pin_update(struct journal *, u64, struct journal_entry_pin *,
journal_pin_flush_fn);
void bch2_journal_pin_drop(struct journal *, struct journal_entry_pin *); void bch2_journal_pin_drop(struct journal *, struct journal_entry_pin *);
void bch2_journal_pin_add_if_older(struct journal *, void bch2_journal_pin_add_if_older(struct journal *,
struct journal_entry_pin *, struct journal_entry_pin *,
......
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