Commit ee68105f authored by Kent Overstreet's avatar Kent Overstreet Committed by Kent Overstreet

bcachefs: Simplify parameters to bch2_btree_update_start()

We don't need to pass the number of nodes required to
bch2_btree_update_start, just whether we're doing a split at @level.
This is prep work for a fix to our usage of six lock's percpu mode,
which is going to require us to count up and allocate interior nodes and
leaf nodes seperately.
Signed-off-by: default avatarKent Overstreet <kent.overstreet@linux.dev>
parent 05a49d22
...@@ -934,7 +934,7 @@ static void bch2_btree_update_done(struct btree_update *as) ...@@ -934,7 +934,7 @@ static void bch2_btree_update_done(struct btree_update *as)
static struct btree_update * static struct btree_update *
bch2_btree_update_start(struct btree_trans *trans, struct btree_path *path, bch2_btree_update_start(struct btree_trans *trans, struct btree_path *path,
unsigned level, unsigned nr_nodes, unsigned flags) unsigned level, bool split, unsigned flags)
{ {
struct bch_fs *c = trans->c; struct bch_fs *c = trans->c;
struct btree_update *as; struct btree_update *as;
...@@ -942,6 +942,8 @@ bch2_btree_update_start(struct btree_trans *trans, struct btree_path *path, ...@@ -942,6 +942,8 @@ bch2_btree_update_start(struct btree_trans *trans, struct btree_path *path,
u64 start_time = local_clock(); u64 start_time = local_clock();
int disk_res_flags = (flags & BTREE_INSERT_NOFAIL) int disk_res_flags = (flags & BTREE_INSERT_NOFAIL)
? BCH_DISK_RESERVATION_NOFAIL : 0; ? BCH_DISK_RESERVATION_NOFAIL : 0;
unsigned nr_nodes;
unsigned update_level = level;
int journal_flags = 0; int journal_flags = 0;
int ret = 0; int ret = 0;
...@@ -952,11 +954,26 @@ bch2_btree_update_start(struct btree_trans *trans, struct btree_path *path, ...@@ -952,11 +954,26 @@ bch2_btree_update_start(struct btree_trans *trans, struct btree_path *path,
closure_init_stack(&cl); closure_init_stack(&cl);
retry: retry:
nr_nodes = 0;
while (1) {
nr_nodes += 1 + split;
update_level++;
if (!btree_path_node(path, update_level))
break;
/*
* XXX: figure out how far we might need to split,
* instead of locking/reserving all the way to the root:
*/
split = update_level + 1 < BTREE_MAX_DEPTH;
}
/* Might have to allocate a new root: */
if (update_level < BTREE_MAX_DEPTH)
nr_nodes += 1;
/*
* XXX: figure out how far we might need to split,
* instead of locking/reserving all the way to the root:
*/
if (!bch2_btree_path_upgrade(trans, path, U8_MAX)) { if (!bch2_btree_path_upgrade(trans, path, U8_MAX)) {
trace_trans_restart_iter_upgrade(trans->fn, _RET_IP_, trace_trans_restart_iter_upgrade(trans->fn, _RET_IP_,
path->btree_id, &path->pos); path->btree_id, &path->pos);
...@@ -1559,14 +1576,13 @@ int bch2_btree_split_leaf(struct btree_trans *trans, ...@@ -1559,14 +1576,13 @@ int bch2_btree_split_leaf(struct btree_trans *trans,
struct btree_path *path, struct btree_path *path,
unsigned flags) unsigned flags)
{ {
struct bch_fs *c = trans->c;
struct btree *b = path_l(path)->b; struct btree *b = path_l(path)->b;
struct btree_update *as; struct btree_update *as;
unsigned l; unsigned l;
int ret = 0; int ret = 0;
as = bch2_btree_update_start(trans, path, path->level, as = bch2_btree_update_start(trans, path, path->level,
btree_update_reserve_required(c, b), flags); true, flags);
if (IS_ERR(as)) if (IS_ERR(as))
return PTR_ERR(as); return PTR_ERR(as);
...@@ -1677,11 +1693,10 @@ int __bch2_foreground_maybe_merge(struct btree_trans *trans, ...@@ -1677,11 +1693,10 @@ int __bch2_foreground_maybe_merge(struct btree_trans *trans,
goto out; goto out;
parent = btree_node_parent(path, b); parent = btree_node_parent(path, b);
as = bch2_btree_update_start(trans, path, level, as = bch2_btree_update_start(trans, path, level, false,
btree_update_reserve_required(c, parent) + 1,
flags|
BTREE_INSERT_NOFAIL| BTREE_INSERT_NOFAIL|
BTREE_INSERT_USE_RESERVE); BTREE_INSERT_USE_RESERVE|
flags);
ret = PTR_ERR_OR_ZERO(as); ret = PTR_ERR_OR_ZERO(as);
if (ret) if (ret)
goto err; goto err;
...@@ -1764,10 +1779,7 @@ int bch2_btree_node_rewrite(struct btree_trans *trans, ...@@ -1764,10 +1779,7 @@ int bch2_btree_node_rewrite(struct btree_trans *trans,
parent = btree_node_parent(iter->path, b); parent = btree_node_parent(iter->path, b);
as = bch2_btree_update_start(trans, iter->path, b->c.level, as = bch2_btree_update_start(trans, iter->path, b->c.level,
(parent false, flags);
? btree_update_reserve_required(c, parent)
: 0) + 1,
flags);
ret = PTR_ERR_OR_ZERO(as); ret = PTR_ERR_OR_ZERO(as);
if (ret) { if (ret) {
trace_btree_gc_rewrite_node_fail(c, b); trace_btree_gc_rewrite_node_fail(c, b);
......
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