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

bcachefs: better BTREE_INSERT_NO_CLEAR_REPLICAS

Signed-off-by: default avatarKent Overstreet <kent.overstreet@linux.dev>
parent cdeeb75e
...@@ -544,13 +544,6 @@ static inline int do_btree_insert_at(struct btree_trans *trans, ...@@ -544,13 +544,6 @@ static inline int do_btree_insert_at(struct btree_trans *trans,
struct btree_insert_entry *i; struct btree_insert_entry *i;
int ret; int ret;
if (likely(!(trans->flags & BTREE_INSERT_NO_CLEAR_REPLICAS)) &&
trans->fs_usage_deltas) {
memset(&trans->fs_usage_deltas->fs_usage, 0,
sizeof(trans->fs_usage_deltas->fs_usage));
trans->fs_usage_deltas->used = 0;
}
trans_for_each_update_iter(trans, i) trans_for_each_update_iter(trans, i)
BUG_ON(i->iter->uptodate >= BTREE_ITER_NEED_RELOCK); BUG_ON(i->iter->uptodate >= BTREE_ITER_NEED_RELOCK);
...@@ -561,7 +554,7 @@ static inline int do_btree_insert_at(struct btree_trans *trans, ...@@ -561,7 +554,7 @@ static inline int do_btree_insert_at(struct btree_trans *trans,
if (ret == -EINTR) if (ret == -EINTR)
trace_trans_restart_mark(trans->ip); trace_trans_restart_mark(trans->ip);
if (ret) if (ret)
return ret; goto out_clear_replicas;
} }
btree_trans_lock_write(c, trans); btree_trans_lock_write(c, trans);
...@@ -655,6 +648,12 @@ static inline int do_btree_insert_at(struct btree_trans *trans, ...@@ -655,6 +648,12 @@ static inline int do_btree_insert_at(struct btree_trans *trans,
} }
bch2_journal_res_put(&c->journal, &trans->journal_res); bch2_journal_res_put(&c->journal, &trans->journal_res);
out_clear_replicas:
if (trans->fs_usage_deltas) {
memset(&trans->fs_usage_deltas->fs_usage, 0,
sizeof(trans->fs_usage_deltas->fs_usage));
trans->fs_usage_deltas->used = 0;
}
return ret; return ret;
} }
......
...@@ -1260,30 +1260,31 @@ void bch2_trans_fs_usage_apply(struct btree_trans *trans, ...@@ -1260,30 +1260,31 @@ void bch2_trans_fs_usage_apply(struct btree_trans *trans,
/* trans_mark: */ /* trans_mark: */
static void replicas_deltas_realloc(struct btree_trans *trans) static struct replicas_delta_list *
replicas_deltas_realloc(struct btree_trans *trans, unsigned more)
{ {
struct replicas_delta_list *d = trans->fs_usage_deltas; struct replicas_delta_list *d = trans->fs_usage_deltas;
unsigned new_size = d ? d->size * 2 : 128; unsigned new_size = d ? (d->size + more) * 2 : 128;
d = krealloc(d, sizeof(*d) + new_size, GFP_NOIO|__GFP_ZERO); if (!d || d->used + more > d->size) {
BUG_ON(!d); d = krealloc(d, sizeof(*d) + new_size, GFP_NOIO|__GFP_ZERO);
BUG_ON(!d);
d->size = new_size; d->size = new_size;
trans->fs_usage_deltas = d; trans->fs_usage_deltas = d;
}
return d;
} }
static inline void update_replicas_list(struct btree_trans *trans, static inline void update_replicas_list(struct btree_trans *trans,
struct bch_replicas_entry *r, struct bch_replicas_entry *r,
s64 sectors) s64 sectors)
{ {
struct replicas_delta_list *d = trans->fs_usage_deltas; struct replicas_delta_list *d;
struct replicas_delta *n; struct replicas_delta *n;
unsigned b = replicas_entry_bytes(r) + 8; unsigned b = replicas_entry_bytes(r) + 8;
if (!d || d->used + b > d->size) { d = replicas_deltas_realloc(trans, b);
replicas_deltas_realloc(trans);
d = trans->fs_usage_deltas;
}
n = (void *) d->d + d->used; n = (void *) d->d + d->used;
n->delta = sectors; n->delta = sectors;
...@@ -1566,9 +1567,7 @@ int bch2_trans_mark_key(struct btree_trans *trans, ...@@ -1566,9 +1567,7 @@ int bch2_trans_mark_key(struct btree_trans *trans,
return bch2_trans_mark_extent(trans, k, return bch2_trans_mark_extent(trans, k,
sectors, BCH_DATA_USER); sectors, BCH_DATA_USER);
case KEY_TYPE_inode: case KEY_TYPE_inode:
if (!trans->fs_usage_deltas) d = replicas_deltas_realloc(trans, 0);
replicas_deltas_realloc(trans);
d = trans->fs_usage_deltas;
if (inserting) if (inserting)
d->fs_usage.nr_inodes++; d->fs_usage.nr_inodes++;
...@@ -1578,9 +1577,7 @@ int bch2_trans_mark_key(struct btree_trans *trans, ...@@ -1578,9 +1577,7 @@ int bch2_trans_mark_key(struct btree_trans *trans,
case KEY_TYPE_reservation: { case KEY_TYPE_reservation: {
unsigned replicas = bkey_s_c_to_reservation(k).v->nr_replicas; unsigned replicas = bkey_s_c_to_reservation(k).v->nr_replicas;
if (!trans->fs_usage_deltas) d = replicas_deltas_realloc(trans, 0);
replicas_deltas_realloc(trans);
d = trans->fs_usage_deltas;
sectors *= replicas; sectors *= replicas;
replicas = clamp_t(unsigned, replicas, 1, replicas = clamp_t(unsigned, replicas, 1,
......
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