Commit 8f196539 authored by Kent Overstreet's avatar Kent Overstreet Committed by Kent Overstreet

bcachefs: Make btree_node_type_needs_gc() cheaper

Signed-off-by: default avatarKent Overstreet <kent.overstreet@linux.dev>
parent 77d63522
......@@ -460,19 +460,22 @@ static inline bool btree_node_is_extents(struct btree *b)
return btree_node_type_is_extents(btree_node_type(b));
}
#define BTREE_NODE_TYPE_HAS_TRIGGERS \
((1U << BKEY_TYPE_EXTENTS)| \
(1U << BKEY_TYPE_ALLOC)| \
(1U << BKEY_TYPE_INODES)| \
(1U << BKEY_TYPE_REFLINK)| \
(1U << BKEY_TYPE_EC)| \
(1U << BKEY_TYPE_BTREE))
#define BTREE_NODE_TYPE_HAS_TRANS_TRIGGERS \
((1U << BKEY_TYPE_EXTENTS)| \
(1U << BKEY_TYPE_INODES)| \
(1U << BKEY_TYPE_REFLINK))
static inline bool btree_node_type_needs_gc(enum btree_node_type type)
{
switch (type) {
case BKEY_TYPE_ALLOC:
case BKEY_TYPE_BTREE:
case BKEY_TYPE_EXTENTS:
case BKEY_TYPE_INODES:
case BKEY_TYPE_EC:
case BKEY_TYPE_REFLINK:
return true;
default:
return false;
}
return BTREE_NODE_TYPE_HAS_TRIGGERS & (1U << type);
}
struct btree_root {
......
......@@ -27,7 +27,6 @@ enum {
__BTREE_INSERT_JOURNAL_RESERVED,
__BTREE_INSERT_NOMARK_OVERWRITES,
__BTREE_INSERT_NOMARK,
__BTREE_INSERT_MARK_INMEM,
__BTREE_INSERT_NO_CLEAR_REPLICAS,
__BTREE_INSERT_BUCKET_INVALIDATE,
__BTREE_INSERT_NOWAIT,
......@@ -68,9 +67,6 @@ enum {
/* Don't call mark new key at all: */
#define BTREE_INSERT_NOMARK (1 << __BTREE_INSERT_NOMARK)
/* Don't mark transactionally: */
#define BTREE_INSERT_MARK_INMEM (1 << __BTREE_INSERT_MARK_INMEM)
#define BTREE_INSERT_NO_CLEAR_REPLICAS (1 << __BTREE_INSERT_NO_CLEAR_REPLICAS)
#define BTREE_INSERT_BUCKET_INVALIDATE (1 << __BTREE_INSERT_BUCKET_INVALIDATE)
......
......@@ -426,20 +426,16 @@ static inline void do_btree_insert_one(struct btree_trans *trans,
btree_insert_key_leaf(trans, insert);
}
static inline bool update_triggers_transactional(struct btree_trans *trans,
struct btree_insert_entry *i)
static inline bool update_has_trans_triggers(struct btree_insert_entry *i)
{
return likely(!(trans->flags & BTREE_INSERT_MARK_INMEM)) &&
(i->iter->btree_id == BTREE_ID_EXTENTS ||
i->iter->btree_id == BTREE_ID_INODES ||
i->iter->btree_id == BTREE_ID_REFLINK);
return BTREE_NODE_TYPE_HAS_TRANS_TRIGGERS & (1U << i->iter->btree_id);
}
static inline bool update_has_triggers(struct btree_trans *trans,
struct btree_insert_entry *i)
static inline bool update_has_nontrans_triggers(struct btree_insert_entry *i)
{
return likely(!(trans->flags & BTREE_INSERT_NOMARK)) &&
btree_node_type_needs_gc(i->iter->btree_id);
return (BTREE_NODE_TYPE_HAS_TRIGGERS &
~BTREE_NODE_TYPE_HAS_TRANS_TRIGGERS) &
(1U << i->iter->btree_id);
}
/*
......@@ -465,8 +461,8 @@ static inline int do_btree_insert_at(struct btree_trans *trans,
* updates as we're walking it:
*/
trans_for_each_update(trans, i)
if (update_has_triggers(trans, i) &&
update_triggers_transactional(trans, i)) {
if (likely(!(trans->flags & BTREE_INSERT_NOMARK)) &&
update_has_trans_triggers(i)) {
ret = bch2_trans_mark_update(trans, i->iter, i->k);
if (ret == -EINTR)
trace_trans_restart_mark(trans->ip);
......@@ -551,8 +547,8 @@ static inline int do_btree_insert_at(struct btree_trans *trans,
}
trans_for_each_update(trans, i)
if (update_has_triggers(trans, i) &&
!update_triggers_transactional(trans, i))
if (likely(!(trans->flags & BTREE_INSERT_NOMARK)) &&
update_has_nontrans_triggers(i))
bch2_mark_update(trans, i, &fs_usage->u, mark_flags);
if (fs_usage && trans->fs_usage_deltas)
......
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