Commit 890e3f5b authored by Kent Overstreet's avatar Kent Overstreet Committed by Kent Overstreet

bcachefs: Reserve some open buckets for btree allocations

This reverts part of the change from "bcachefs: Don't use
BTREE_INSERT_USE_RESERVE so much" - it turns out we still should be
reserving open buckets for btree node allocations, because otherwise
data bucket allocations (especially with erasure coding enabled) can use
up all our open buckets and we won't be able to do the metadata update
that lets us release those open bucket references. Oops.
Signed-off-by: default avatarKent Overstreet <kent.overstreet@gmail.com>
Signed-off-by: default avatarKent Overstreet <kent.overstreet@linux.dev>
parent fd54c40e
...@@ -204,8 +204,11 @@ long bch2_bucket_alloc_new_fs(struct bch_dev *ca) ...@@ -204,8 +204,11 @@ long bch2_bucket_alloc_new_fs(struct bch_dev *ca)
static inline unsigned open_buckets_reserved(enum alloc_reserve reserve) static inline unsigned open_buckets_reserved(enum alloc_reserve reserve)
{ {
switch (reserve) { switch (reserve) {
case RESERVE_MOVINGGC: case RESERVE_BTREE:
case RESERVE_BTREE_MOVINGGC:
return 0; return 0;
case RESERVE_MOVINGGC:
return OPEN_BUCKETS_COUNT / 4;
default: default:
return OPEN_BUCKETS_COUNT / 2; return OPEN_BUCKETS_COUNT / 2;
} }
...@@ -261,6 +264,7 @@ struct open_bucket *bch2_bucket_alloc(struct bch_fs *c, struct bch_dev *ca, ...@@ -261,6 +264,7 @@ struct open_bucket *bch2_bucket_alloc(struct bch_fs *c, struct bch_dev *ca,
goto out; goto out;
switch (reserve) { switch (reserve) {
case RESERVE_BTREE_MOVINGGC:
case RESERVE_MOVINGGC: case RESERVE_MOVINGGC:
if (fifo_pop(&ca->free[RESERVE_MOVINGGC], bucket)) if (fifo_pop(&ca->free[RESERVE_MOVINGGC], bucket))
goto out; goto out;
......
...@@ -34,9 +34,9 @@ struct bucket_clock { ...@@ -34,9 +34,9 @@ struct bucket_clock {
struct mutex lock; struct mutex lock;
}; };
/* There is one reserve for each type of btree, one for prios and gens
* and one for moving GC */
enum alloc_reserve { enum alloc_reserve {
RESERVE_BTREE_MOVINGGC = -2,
RESERVE_BTREE = -1,
RESERVE_MOVINGGC = 0, RESERVE_MOVINGGC = 0,
RESERVE_NONE = 1, RESERVE_NONE = 1,
RESERVE_NR = 2, RESERVE_NR = 2,
......
...@@ -203,10 +203,10 @@ static struct btree *__bch2_btree_node_alloc(struct bch_fs *c, ...@@ -203,10 +203,10 @@ static struct btree *__bch2_btree_node_alloc(struct bch_fs *c,
if (flags & BTREE_INSERT_USE_RESERVE) { if (flags & BTREE_INSERT_USE_RESERVE) {
nr_reserve = 0; nr_reserve = 0;
alloc_reserve = RESERVE_MOVINGGC; alloc_reserve = RESERVE_BTREE_MOVINGGC;
} else { } else {
nr_reserve = BTREE_NODE_RESERVE; nr_reserve = BTREE_NODE_RESERVE;
alloc_reserve = RESERVE_NONE; alloc_reserve = RESERVE_BTREE;
} }
mutex_lock(&c->btree_reserve_cache_lock); mutex_lock(&c->btree_reserve_cache_lock);
......
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