diff --git a/fs/bcachefs/alloc_foreground.c b/fs/bcachefs/alloc_foreground.c index f37110497b51..f40fca9328f9 100644 --- a/fs/bcachefs/alloc_foreground.c +++ b/fs/bcachefs/alloc_foreground.c @@ -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), false, gc_pos_alloc(c, ob), 0); ob->valid = false; + ob->type = 0; spin_unlock(&ob->lock); percpu_up_read(&c->mark_lock); @@ -142,6 +143,7 @@ static struct open_bucket *bch2_open_bucket_alloc(struct bch_fs *c) ob = c->open_buckets + c->open_buckets_freelist; c->open_buckets_freelist = ob->freelist; atomic_set(&ob->pin, 1); + ob->type = 0; c->open_buckets_nr_free--; return ob; @@ -210,9 +212,9 @@ static inline unsigned open_buckets_reserved(enum alloc_reserve reserve) case RESERVE_ALLOC: return 0; case RESERVE_BTREE: - return BTREE_NODE_RESERVE / 2; + return BTREE_NODE_OPEN_BUCKET_RESERVE; default: - return BTREE_NODE_RESERVE; + return BTREE_NODE_OPEN_BUCKET_RESERVE * 2; } } diff --git a/fs/bcachefs/alloc_foreground.h b/fs/bcachefs/alloc_foreground.h index 94389052fa94..6d8ffb0cd06d 100644 --- a/fs/bcachefs/alloc_foreground.h +++ b/fs/bcachefs/alloc_foreground.h @@ -86,6 +86,7 @@ static inline void bch2_open_bucket_get(struct bch_fs *c, unsigned i; open_bucket_for_each(c, &wp->ptrs, ob, i) { + ob->type = wp->type; atomic_inc(&ob->pin); ob_push(c, ptrs, ob); } diff --git a/fs/bcachefs/alloc_types.h b/fs/bcachefs/alloc_types.h index ef3e400c7d3d..832568dc9551 100644 --- a/fs/bcachefs/alloc_types.h +++ b/fs/bcachefs/alloc_types.h @@ -56,9 +56,10 @@ struct open_bucket { spinlock_t lock; atomic_t pin; u8 freelist; - bool valid; - bool on_partial_list; u8 ec_idx; + u8 type; + unsigned valid:1; + unsigned on_partial_list:1; unsigned sectors_free; struct bch_extent_ptr ptr; struct ec_stripe_new *ec; diff --git a/fs/bcachefs/bcachefs.h b/fs/bcachefs/bcachefs.h index 64836a8c69d8..a5203fbc089e 100644 --- a/fs/bcachefs/bcachefs.h +++ b/fs/bcachefs/bcachefs.h @@ -333,6 +333,8 @@ enum bch_time_stats { /* Size of the freelist we allocate btree nodes from: */ #define BTREE_NODE_RESERVE BTREE_RESERVE_MAX +#define BTREE_NODE_OPEN_BUCKET_RESERVE (BTREE_RESERVE_MAX * BCH_REPLICAS_MAX) + struct btree; enum gc_phase { diff --git a/fs/bcachefs/sysfs.c b/fs/bcachefs/sysfs.c index b59b7a5a4cbb..27fd6dfe83f5 100644 --- a/fs/bcachefs/sysfs.c +++ b/fs/bcachefs/sysfs.c @@ -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_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, "free_inc: %zu/%zu\n" @@ -823,7 +829,10 @@ static ssize_t show_dev_alloc_debug(struct bch_dev *ca, char *buf) " copygc threshold: %llu\n" "freelist_wait: %s\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[RESERVE_BTREE]), ca->free[RESERVE_BTREE].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) stats.sectors_fragmented, ca->copygc_threshold, c->freelist_wait.list.first ? "waiting" : "empty", - c->open_buckets_nr_free, OPEN_BUCKETS_COUNT, BTREE_NODE_RESERVE, - c->open_buckets_wait.list.first ? "waiting" : "empty"); + c->open_buckets_nr_free, OPEN_BUCKETS_COUNT, + 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[] = {