Commit 9623ab27 authored by Kent Overstreet's avatar Kent Overstreet Committed by Kent Overstreet

bcachefs: Btree update path cleanup

Signed-off-by: default avatarKent Overstreet <kent.overstreet@linux.dev>
parent 0dc17247
...@@ -289,12 +289,12 @@ struct btree_trans { ...@@ -289,12 +289,12 @@ struct btree_trans {
struct btree_iter *iters; struct btree_iter *iters;
struct btree_insert_entry *updates; struct btree_insert_entry *updates;
struct disk_reservation *disk_res;
/* update path: */ /* update path: */
struct journal_res journal_res; struct journal_res journal_res;
struct journal_preres journal_preres; struct journal_preres journal_preres;
u64 *journal_seq; u64 *journal_seq;
struct disk_reservation *disk_res;
unsigned flags; unsigned flags;
struct btree_iter iters_onstack[2]; struct btree_iter iters_onstack[2];
...@@ -501,6 +501,7 @@ enum btree_insert_ret { ...@@ -501,6 +501,7 @@ enum btree_insert_ret {
BTREE_INSERT_BTREE_NODE_FULL, BTREE_INSERT_BTREE_NODE_FULL,
BTREE_INSERT_ENOSPC, BTREE_INSERT_ENOSPC,
BTREE_INSERT_NEED_MARK_REPLICAS, BTREE_INSERT_NEED_MARK_REPLICAS,
BTREE_INSERT_NEED_JOURNAL_RES,
}; };
enum btree_gc_coalesce_fail_reason { enum btree_gc_coalesce_fail_reason {
......
...@@ -128,4 +128,39 @@ int bch2_trans_commit(struct btree_trans *, ...@@ -128,4 +128,39 @@ int bch2_trans_commit(struct btree_trans *,
_ret; \ _ret; \
}) })
/*
* We sort transaction entries so that if multiple iterators point to the same
* leaf node they'll be adjacent:
*/
static inline bool same_leaf_as_prev(struct btree_trans *trans,
struct btree_insert_entry *i)
{
return i != trans->updates &&
!i->deferred &&
i[0].iter->l[0].b == i[-1].iter->l[0].b;
}
#define __trans_next_update(_trans, _i, _filter) \
({ \
while ((_i) < (_trans)->updates + (_trans->nr_updates) && !(_filter))\
(_i)++; \
\
(_i) < (_trans)->updates + (_trans->nr_updates); \
})
#define __trans_for_each_update(_trans, _i, _filter) \
for ((_i) = (_trans)->updates; \
__trans_next_update(_trans, _i, _filter); \
(_i)++)
#define trans_for_each_update(trans, i) \
__trans_for_each_update(trans, i, true)
#define trans_for_each_update_iter(trans, i) \
__trans_for_each_update(trans, i, !(i)->deferred)
#define trans_for_each_update_leaf(trans, i) \
__trans_for_each_update(trans, i, !(i)->deferred && \
!same_leaf_as_prev(trans, i))
#endif /* _BCACHEFS_BTREE_UPDATE_H */ #endif /* _BCACHEFS_BTREE_UPDATE_H */
This diff is collapsed.
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