Commit 4e1510c3 authored by Kent Overstreet's avatar Kent Overstreet Committed by Kent Overstreet

bcachefs: Add a hint for allocating new stripes

This way we aren't doing a full linear scan every time we create a new
stripe.
Signed-off-by: default avatarKent Overstreet <kent.overstreet@linux.dev>
parent 3fb5ebcd
...@@ -745,6 +745,7 @@ struct bch_fs { ...@@ -745,6 +745,7 @@ struct bch_fs {
/* ERASURE CODING */ /* ERASURE CODING */
struct list_head ec_new_stripe_list; struct list_head ec_new_stripe_list;
struct mutex ec_new_stripe_lock; struct mutex ec_new_stripe_lock;
u64 ec_stripe_hint;
struct bio_set ec_bioset; struct bio_set ec_bioset;
......
...@@ -704,26 +704,34 @@ static int ec_stripe_bkey_insert(struct bch_fs *c, ...@@ -704,26 +704,34 @@ static int ec_stripe_bkey_insert(struct bch_fs *c,
struct btree_trans trans; struct btree_trans trans;
struct btree_iter *iter; struct btree_iter *iter;
struct bkey_s_c k; struct bkey_s_c k;
struct bpos start_pos = POS(0, c->ec_stripe_hint);
int ret; int ret;
bch2_trans_init(&trans, c, 0, 0); bch2_trans_init(&trans, c, 0, 0);
retry: retry:
bch2_trans_begin(&trans); bch2_trans_begin(&trans);
/* XXX: start pos hint */ for_each_btree_key(&trans, iter, BTREE_ID_EC, start_pos,
for_each_btree_key(&trans, iter, BTREE_ID_EC, POS_MIN,
BTREE_ITER_SLOTS|BTREE_ITER_INTENT, k, ret) { BTREE_ITER_SLOTS|BTREE_ITER_INTENT, k, ret) {
if (bkey_cmp(k.k->p, POS(0, U32_MAX)) > 0) if (bkey_cmp(k.k->p, POS(0, U32_MAX)) > 0) {
if (start_pos.offset) {
start_pos = POS_MIN;
bch2_btree_iter_set_pos(iter, start_pos);
continue;
}
ret = -ENOSPC;
break; break;
}
if (bkey_deleted(k.k)) if (bkey_deleted(k.k))
goto found_slot; goto found_slot;
} }
if (!ret)
ret = -ENOSPC;
goto err; goto err;
found_slot: found_slot:
start_pos = iter->pos;
ret = ec_stripe_mem_alloc(c, iter); ret = ec_stripe_mem_alloc(c, iter);
if (ret) if (ret)
goto err; goto err;
...@@ -738,6 +746,8 @@ static int ec_stripe_bkey_insert(struct bch_fs *c, ...@@ -738,6 +746,8 @@ static int ec_stripe_bkey_insert(struct bch_fs *c,
err: err:
if (ret == -EINTR) if (ret == -EINTR)
goto retry; goto retry;
c->ec_stripe_hint = ret ? start_pos.offset : start_pos.offset + 1;
bch2_trans_exit(&trans); bch2_trans_exit(&trans);
return ret; return ret;
......
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