mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git
synced 2024-10-02 23:27:06 +00:00
bcachefs: should_compact_all()
This factors out a properly-documented helper for deciding when we want to sort a btree node with MAX_BSETS bsets down to a single bset. Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
This commit is contained in:
parent
46fee692ee
commit
2cb7517969
1 changed files with 24 additions and 12 deletions
|
@ -444,6 +444,24 @@ void bch2_btree_build_aux_trees(struct btree *b)
|
||||||
t == bset_tree_last(b));
|
t == bset_tree_last(b));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* If we have MAX_BSETS (3) bsets, should we sort them all down to just one?
|
||||||
|
*
|
||||||
|
* The first bset is going to be of similar order to the size of the node, the
|
||||||
|
* last bset is bounded by btree_write_set_buffer(), which is set to keep the
|
||||||
|
* memmove on insert from being too expensive: the middle bset should, ideally,
|
||||||
|
* be the geometric mean of the first and the last.
|
||||||
|
*
|
||||||
|
* Returns true if the middle bset is greater than that geometric mean:
|
||||||
|
*/
|
||||||
|
static inline bool should_compact_all(struct bch_fs *c, struct btree *b)
|
||||||
|
{
|
||||||
|
unsigned mid_u64s_bits =
|
||||||
|
(ilog2(btree_max_u64s(c)) + BTREE_WRITE_SET_U64s_BITS) / 2;
|
||||||
|
|
||||||
|
return bset_u64s(&b->set[1]) > 1U << mid_u64s_bits;
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* @bch_btree_init_next - initialize a new (unwritten) bset that can then be
|
* @bch_btree_init_next - initialize a new (unwritten) bset that can then be
|
||||||
* inserted into
|
* inserted into
|
||||||
|
@ -461,21 +479,15 @@ void bch2_btree_init_next(struct btree_trans *trans, struct btree *b)
|
||||||
|
|
||||||
EBUG_ON(!(b->c.lock.state.seq & 1));
|
EBUG_ON(!(b->c.lock.state.seq & 1));
|
||||||
BUG_ON(bset_written(b, bset(b, &b->set[1])));
|
BUG_ON(bset_written(b, bset(b, &b->set[1])));
|
||||||
|
BUG_ON(btree_node_just_written(b));
|
||||||
|
|
||||||
if (b->nsets == MAX_BSETS &&
|
if (b->nsets == MAX_BSETS &&
|
||||||
!btree_node_write_in_flight(b)) {
|
!btree_node_write_in_flight(b) &&
|
||||||
unsigned log_u64s[] = {
|
should_compact_all(c, b)) {
|
||||||
ilog2(bset_u64s(&b->set[0])),
|
|
||||||
ilog2(bset_u64s(&b->set[1])),
|
|
||||||
ilog2(bset_u64s(&b->set[2])),
|
|
||||||
};
|
|
||||||
|
|
||||||
if (log_u64s[1] >= (log_u64s[0] + log_u64s[2]) / 2) {
|
|
||||||
bch2_btree_node_write(c, b, SIX_LOCK_write,
|
bch2_btree_node_write(c, b, SIX_LOCK_write,
|
||||||
BTREE_WRITE_init_next_bset);
|
BTREE_WRITE_init_next_bset);
|
||||||
reinit_iter = true;
|
reinit_iter = true;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
if (b->nsets == MAX_BSETS &&
|
if (b->nsets == MAX_BSETS &&
|
||||||
btree_node_compact(c, b))
|
btree_node_compact(c, b))
|
||||||
|
|
Loading…
Reference in a new issue