diff options
author | Kent Overstreet <kent.overstreet@gmail.com> | 2018-05-24 22:46:45 -0400 |
---|---|---|
committer | Kent Overstreet <kent.overstreet@gmail.com> | 2018-06-01 17:28:35 -0400 |
commit | 1f42dfc424a8b776f10702becfc432c24f0fc7f5 (patch) | |
tree | 74e081d337054fdb457711ed2eed057ef39237dd | |
parent | 772f0e8b1f455f702c7e940c8585310d6ebd16e3 (diff) |
bcachefs: tighten up reserve sizes
-rw-r--r-- | fs/bcachefs/bcachefs.h | 11 | ||||
-rw-r--r-- | fs/bcachefs/btree_update_interior.c | 26 | ||||
-rw-r--r-- | fs/bcachefs/btree_update_interior.h | 9 |
3 files changed, 24 insertions, 22 deletions
diff --git a/fs/bcachefs/bcachefs.h b/fs/bcachefs/bcachefs.h index 6beff8810c09..4702b016945e 100644 --- a/fs/bcachefs/bcachefs.h +++ b/fs/bcachefs/bcachefs.h @@ -302,21 +302,14 @@ enum bch_time_stats { #include "rebalance_types.h" #include "super_types.h" -/* - * Number of nodes we might have to allocate in a worst case btree split - * operation - we split all the way up to the root, then allocate a new root. - */ -#define btree_reserve_required_nodes(depth) (((depth) + 1) * 2 + 1) - /* Number of nodes btree coalesce will try to coalesce at once */ #define GC_MERGE_NODES 4U /* Maximum number of nodes we might need to allocate atomically: */ -#define BTREE_RESERVE_MAX \ - (btree_reserve_required_nodes(BTREE_MAX_DEPTH) + GC_MERGE_NODES) +#define BTREE_RESERVE_MAX (BTREE_MAX_DEPTH + (BTREE_MAX_DEPTH - 1)) /* Size of the freelist we allocate btree nodes from: */ -#define BTREE_NODE_RESERVE (BTREE_RESERVE_MAX * 4) +#define BTREE_NODE_RESERVE (BTREE_RESERVE_MAX * 4) struct btree; diff --git a/fs/bcachefs/btree_update_interior.c b/fs/bcachefs/btree_update_interior.c index c3ecc1e96726..817c3dee553e 100644 --- a/fs/bcachefs/btree_update_interior.c +++ b/fs/bcachefs/btree_update_interior.c @@ -1704,10 +1704,10 @@ retry: } as = bch2_btree_update_start(c, iter->btree_id, - btree_update_reserve_required(c, b), - BTREE_INSERT_NOFAIL| - BTREE_INSERT_USE_RESERVE, - &cl); + btree_update_reserve_required(c, parent) + 1, + BTREE_INSERT_NOFAIL| + BTREE_INSERT_USE_RESERVE, + &cl); if (IS_ERR(as)) { ret = PTR_ERR(as); goto out_unlock; @@ -1778,8 +1778,10 @@ static int __btree_node_rewrite(struct bch_fs *c, struct btree_iter *iter, struct btree_update *as; as = bch2_btree_update_start(c, iter->btree_id, - btree_update_reserve_required(c, b), - flags, cl); + (parent + ? btree_update_reserve_required(c, parent) + : 0) + 1, + flags, cl); if (IS_ERR(as)) { trace_btree_gc_rewrite_node_fail(c, b); return PTR_ERR(as); @@ -1966,6 +1968,7 @@ static void __bch2_btree_node_update_key(struct bch_fs *c, int bch2_btree_node_update_key(struct bch_fs *c, struct btree_iter *iter, struct btree *b, struct bkey_i_extent *new_key) { + struct btree *parent = btree_node_parent(iter, b); struct btree_update *as = NULL; struct btree *new_hash = NULL; struct closure cl; @@ -2003,11 +2006,12 @@ int bch2_btree_node_update_key(struct bch_fs *c, struct btree_iter *iter, } as = bch2_btree_update_start(c, iter->btree_id, - btree_update_reserve_required(c, b), - BTREE_INSERT_NOFAIL| - BTREE_INSERT_USE_RESERVE| - BTREE_INSERT_USE_ALLOC_RESERVE, - &cl); + parent ? btree_update_reserve_required(c, parent) : 0, + BTREE_INSERT_NOFAIL| + BTREE_INSERT_USE_RESERVE| + BTREE_INSERT_USE_ALLOC_RESERVE, + &cl); + if (IS_ERR(as)) { ret = PTR_ERR(as); if (ret == -EAGAIN) diff --git a/fs/bcachefs/btree_update_interior.h b/fs/bcachefs/btree_update_interior.h index 25bfc7ab9ee0..abf14e4c41dc 100644 --- a/fs/bcachefs/btree_update_interior.h +++ b/fs/bcachefs/btree_update_interior.h @@ -183,9 +183,14 @@ void bch2_btree_root_alloc(struct bch_fs *, enum btree_id); static inline unsigned btree_update_reserve_required(struct bch_fs *c, struct btree *b) { - unsigned depth = btree_node_root(c, b)->level - b->level; + unsigned depth = btree_node_root(c, b)->level - b->level + 1; - return btree_reserve_required_nodes(depth); + /* + * Number of nodes we might have to allocate in a worst case btree + * split operation - we split all the way up to the root, then allocate + * a new root. + */ + return depth * 2 + 1; } static inline void btree_node_reset_sib_u64s(struct btree *b) |