bcachefs: Single open_bucket_partial list

Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
This commit is contained in:
Kent Overstreet 2023-02-25 00:32:34 -05:00
parent 0d763863af
commit 39a1ea129a
3 changed files with 28 additions and 26 deletions

View File

@ -2175,21 +2175,25 @@ void bch2_dev_allocator_remove(struct bch_fs *c, struct bch_dev *ca)
} }
mutex_unlock(&c->btree_reserve_cache_lock); mutex_unlock(&c->btree_reserve_cache_lock);
while (1) { spin_lock(&c->freelist_lock);
struct open_bucket *ob; i = 0;
while (i < c->open_buckets_partial_nr) {
struct open_bucket *ob =
c->open_buckets + c->open_buckets_partial[i];
spin_lock(&c->freelist_lock); if (ob->dev == ca->dev_idx) {
if (!ca->open_buckets_partial_nr) { --c->open_buckets_partial_nr;
swap(c->open_buckets_partial[i],
c->open_buckets_partial[c->open_buckets_partial_nr]);
ob->on_partial_list = false;
spin_unlock(&c->freelist_lock); spin_unlock(&c->freelist_lock);
break; bch2_open_bucket_put(c, ob);
spin_lock(&c->freelist_lock);
} else {
i++;
} }
ob = c->open_buckets +
ca->open_buckets_partial[--ca->open_buckets_partial_nr];
ob->on_partial_list = false;
spin_unlock(&c->freelist_lock);
bch2_open_bucket_put(c, ob);
} }
spin_unlock(&c->freelist_lock);
bch2_ec_stop_dev(c, ca); bch2_ec_stop_dev(c, ca);

View File

@ -154,18 +154,15 @@ static void open_bucket_free_unused(struct bch_fs *c,
struct write_point *wp, struct write_point *wp,
struct open_bucket *ob) struct open_bucket *ob)
{ {
struct bch_dev *ca = bch_dev_bkey_exists(c, ob->dev);
bool may_realloc = wp->data_type == BCH_DATA_user; bool may_realloc = wp->data_type == BCH_DATA_user;
BUG_ON(ca->open_buckets_partial_nr > BUG_ON(c->open_buckets_partial_nr >=
ARRAY_SIZE(ca->open_buckets_partial)); ARRAY_SIZE(c->open_buckets_partial));
if (ca->open_buckets_partial_nr < if (may_realloc) {
ARRAY_SIZE(ca->open_buckets_partial) &&
may_realloc) {
spin_lock(&c->freelist_lock); spin_lock(&c->freelist_lock);
ob->on_partial_list = true; ob->on_partial_list = true;
ca->open_buckets_partial[ca->open_buckets_partial_nr++] = c->open_buckets_partial[c->open_buckets_partial_nr++] =
ob - c->open_buckets; ob - c->open_buckets;
spin_unlock(&c->freelist_lock); spin_unlock(&c->freelist_lock);
@ -394,12 +391,13 @@ static struct open_bucket *try_alloc_partial_bucket(struct bch_fs *c, struct bch
spin_lock(&c->freelist_lock); spin_lock(&c->freelist_lock);
for (i = ca->open_buckets_partial_nr - 1; i >= 0; --i) { for (i = c->open_buckets_partial_nr - 1; i >= 0; --i) {
ob = c->open_buckets + ca->open_buckets_partial[i]; ob = c->open_buckets + c->open_buckets_partial[i];
if (reserve <= ob->alloc_reserve) { if (ob->dev == ca->dev_idx &&
array_remove_item(ca->open_buckets_partial, reserve <= ob->alloc_reserve) {
ca->open_buckets_partial_nr, array_remove_item(c->open_buckets_partial,
c->open_buckets_partial_nr,
i); i);
ob->on_partial_list = false; ob->on_partial_list = false;
ob->alloc_reserve = reserve; ob->alloc_reserve = reserve;

View File

@ -516,9 +516,6 @@ struct bch_dev {
unsigned nr_open_buckets; unsigned nr_open_buckets;
unsigned nr_btree_reserve; unsigned nr_btree_reserve;
open_bucket_idx_t open_buckets_partial[OPEN_BUCKETS_COUNT];
open_bucket_idx_t open_buckets_partial_nr;
size_t inc_gen_needs_gc; size_t inc_gen_needs_gc;
size_t inc_gen_really_needs_gc; size_t inc_gen_really_needs_gc;
size_t buckets_waiting_on_journal; size_t buckets_waiting_on_journal;
@ -859,6 +856,9 @@ struct bch_fs {
struct open_bucket open_buckets[OPEN_BUCKETS_COUNT]; struct open_bucket open_buckets[OPEN_BUCKETS_COUNT];
open_bucket_idx_t open_buckets_hash[OPEN_BUCKETS_COUNT]; open_bucket_idx_t open_buckets_hash[OPEN_BUCKETS_COUNT];
open_bucket_idx_t open_buckets_partial[OPEN_BUCKETS_COUNT];
open_bucket_idx_t open_buckets_partial_nr;
struct write_point btree_write_point; struct write_point btree_write_point;
struct write_point rebalance_write_point; struct write_point rebalance_write_point;