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

bcachefs: Fix some reserve calculations

Signed-off-by: default avatarKent Overstreet <kent.overstreet@linux.dev>
parent 0519b72d
...@@ -107,6 +107,7 @@ void __bch2_open_bucket_put(struct bch_fs *c, struct open_bucket *ob) ...@@ -107,6 +107,7 @@ void __bch2_open_bucket_put(struct bch_fs *c, struct open_bucket *ob)
bch2_mark_alloc_bucket(c, ca, PTR_BUCKET_NR(ca, &ob->ptr), bch2_mark_alloc_bucket(c, ca, PTR_BUCKET_NR(ca, &ob->ptr),
false, gc_pos_alloc(c, ob), 0); false, gc_pos_alloc(c, ob), 0);
ob->valid = false; ob->valid = false;
ob->type = 0;
spin_unlock(&ob->lock); spin_unlock(&ob->lock);
percpu_up_read(&c->mark_lock); percpu_up_read(&c->mark_lock);
...@@ -142,6 +143,7 @@ static struct open_bucket *bch2_open_bucket_alloc(struct bch_fs *c) ...@@ -142,6 +143,7 @@ static struct open_bucket *bch2_open_bucket_alloc(struct bch_fs *c)
ob = c->open_buckets + c->open_buckets_freelist; ob = c->open_buckets + c->open_buckets_freelist;
c->open_buckets_freelist = ob->freelist; c->open_buckets_freelist = ob->freelist;
atomic_set(&ob->pin, 1); atomic_set(&ob->pin, 1);
ob->type = 0;
c->open_buckets_nr_free--; c->open_buckets_nr_free--;
return ob; return ob;
...@@ -210,9 +212,9 @@ static inline unsigned open_buckets_reserved(enum alloc_reserve reserve) ...@@ -210,9 +212,9 @@ static inline unsigned open_buckets_reserved(enum alloc_reserve reserve)
case RESERVE_ALLOC: case RESERVE_ALLOC:
return 0; return 0;
case RESERVE_BTREE: case RESERVE_BTREE:
return BTREE_NODE_RESERVE / 2; return BTREE_NODE_OPEN_BUCKET_RESERVE;
default: default:
return BTREE_NODE_RESERVE; return BTREE_NODE_OPEN_BUCKET_RESERVE * 2;
} }
} }
......
...@@ -86,6 +86,7 @@ static inline void bch2_open_bucket_get(struct bch_fs *c, ...@@ -86,6 +86,7 @@ static inline void bch2_open_bucket_get(struct bch_fs *c,
unsigned i; unsigned i;
open_bucket_for_each(c, &wp->ptrs, ob, i) { open_bucket_for_each(c, &wp->ptrs, ob, i) {
ob->type = wp->type;
atomic_inc(&ob->pin); atomic_inc(&ob->pin);
ob_push(c, ptrs, ob); ob_push(c, ptrs, ob);
} }
......
...@@ -56,9 +56,10 @@ struct open_bucket { ...@@ -56,9 +56,10 @@ struct open_bucket {
spinlock_t lock; spinlock_t lock;
atomic_t pin; atomic_t pin;
u8 freelist; u8 freelist;
bool valid;
bool on_partial_list;
u8 ec_idx; u8 ec_idx;
u8 type;
unsigned valid:1;
unsigned on_partial_list:1;
unsigned sectors_free; unsigned sectors_free;
struct bch_extent_ptr ptr; struct bch_extent_ptr ptr;
struct ec_stripe_new *ec; struct ec_stripe_new *ec;
......
...@@ -333,6 +333,8 @@ enum bch_time_stats { ...@@ -333,6 +333,8 @@ enum bch_time_stats {
/* Size of the freelist we allocate btree nodes from: */ /* Size of the freelist we allocate btree nodes from: */
#define BTREE_NODE_RESERVE BTREE_RESERVE_MAX #define BTREE_NODE_RESERVE BTREE_RESERVE_MAX
#define BTREE_NODE_OPEN_BUCKET_RESERVE (BTREE_RESERVE_MAX * BCH_REPLICAS_MAX)
struct btree; struct btree;
enum gc_phase { enum gc_phase {
......
...@@ -797,6 +797,12 @@ static ssize_t show_dev_alloc_debug(struct bch_dev *ca, char *buf) ...@@ -797,6 +797,12 @@ static ssize_t show_dev_alloc_debug(struct bch_dev *ca, char *buf)
{ {
struct bch_fs *c = ca->fs; struct bch_fs *c = ca->fs;
struct bch_dev_usage stats = bch2_dev_usage_read(c, ca); struct bch_dev_usage stats = bch2_dev_usage_read(c, ca);
unsigned i, nr[BCH_DATA_NR];
memset(nr, 0, sizeof(nr));
for (i = 0; i < ARRAY_SIZE(c->open_buckets); i++)
nr[c->open_buckets[i].type]++;
return scnprintf(buf, PAGE_SIZE, return scnprintf(buf, PAGE_SIZE,
"free_inc: %zu/%zu\n" "free_inc: %zu/%zu\n"
...@@ -823,7 +829,10 @@ static ssize_t show_dev_alloc_debug(struct bch_dev *ca, char *buf) ...@@ -823,7 +829,10 @@ static ssize_t show_dev_alloc_debug(struct bch_dev *ca, char *buf)
" copygc threshold: %llu\n" " copygc threshold: %llu\n"
"freelist_wait: %s\n" "freelist_wait: %s\n"
"open buckets: %u/%u (reserved %u)\n" "open buckets: %u/%u (reserved %u)\n"
"open_buckets_wait: %s\n", "open_buckets_wait: %s\n"
"open_buckets_btree: %u\n"
"open_buckets_user: %u\n"
"btree reserve cache: %u\n",
fifo_used(&ca->free_inc), ca->free_inc.size, fifo_used(&ca->free_inc), ca->free_inc.size,
fifo_used(&ca->free[RESERVE_BTREE]), ca->free[RESERVE_BTREE].size, fifo_used(&ca->free[RESERVE_BTREE]), ca->free[RESERVE_BTREE].size,
fifo_used(&ca->free[RESERVE_MOVINGGC]), ca->free[RESERVE_MOVINGGC].size, fifo_used(&ca->free[RESERVE_MOVINGGC]), ca->free[RESERVE_MOVINGGC].size,
...@@ -845,8 +854,12 @@ static ssize_t show_dev_alloc_debug(struct bch_dev *ca, char *buf) ...@@ -845,8 +854,12 @@ static ssize_t show_dev_alloc_debug(struct bch_dev *ca, char *buf)
stats.sectors_fragmented, stats.sectors_fragmented,
ca->copygc_threshold, ca->copygc_threshold,
c->freelist_wait.list.first ? "waiting" : "empty", c->freelist_wait.list.first ? "waiting" : "empty",
c->open_buckets_nr_free, OPEN_BUCKETS_COUNT, BTREE_NODE_RESERVE, c->open_buckets_nr_free, OPEN_BUCKETS_COUNT,
c->open_buckets_wait.list.first ? "waiting" : "empty"); BTREE_NODE_OPEN_BUCKET_RESERVE,
c->open_buckets_wait.list.first ? "waiting" : "empty",
nr[BCH_DATA_BTREE],
nr[BCH_DATA_USER],
c->btree_reserve_cache_nr);
} }
static const char * const bch2_rw[] = { static const char * const bch2_rw[] = {
......
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