Commit 6cacd0c4 authored by Kent Overstreet's avatar Kent Overstreet

bcachefs: unify reservation trigger

Signed-off-by: default avatarKent Overstreet <kent.overstreet@linux.dev>
parent 7bc4d18a
...@@ -1121,45 +1121,6 @@ int bch2_mark_stripe(struct btree_trans *trans, ...@@ -1121,45 +1121,6 @@ int bch2_mark_stripe(struct btree_trans *trans,
return 0; return 0;
} }
static int __mark_reservation(struct btree_trans *trans,
enum btree_id btree_id, unsigned level,
struct bkey_s_c k, unsigned flags)
{
struct bch_fs *c = trans->c;
struct bch_fs_usage *fs_usage;
unsigned replicas = bkey_s_c_to_reservation(k).v->nr_replicas;
s64 sectors = (s64) k.k->size;
BUG_ON(!(flags & BTREE_TRIGGER_GC));
if (flags & BTREE_TRIGGER_OVERWRITE)
sectors = -sectors;
sectors *= replicas;
percpu_down_read(&c->mark_lock);
preempt_disable();
fs_usage = fs_usage_ptr(c, trans->journal_res.seq, flags & BTREE_TRIGGER_GC);
replicas = clamp_t(unsigned, replicas, 1,
ARRAY_SIZE(fs_usage->persistent_reserved));
fs_usage->reserved += sectors;
fs_usage->persistent_reserved[replicas - 1] += sectors;
preempt_enable();
percpu_up_read(&c->mark_lock);
return 0;
}
int bch2_mark_reservation(struct btree_trans *trans,
enum btree_id btree_id, unsigned level,
struct bkey_s_c old, struct bkey_s new,
unsigned flags)
{
return trigger_run_overwrite_then_insert(__mark_reservation, trans, btree_id, level, old, new, flags);
}
void bch2_trans_fs_usage_revert(struct btree_trans *trans, void bch2_trans_fs_usage_revert(struct btree_trans *trans,
struct replicas_delta_list *deltas) struct replicas_delta_list *deltas)
{ {
...@@ -1593,40 +1554,57 @@ int bch2_trans_mark_stripe(struct btree_trans *trans, ...@@ -1593,40 +1554,57 @@ int bch2_trans_mark_stripe(struct btree_trans *trans,
return ret; return ret;
} }
static int __trans_mark_reservation(struct btree_trans *trans, /* KEY_TYPE_reservation */
enum btree_id btree_id, unsigned level,
struct bkey_s_c k, unsigned flags) static int __trigger_reservation(struct btree_trans *trans,
enum btree_id btree_id, unsigned level,
struct bkey_s_c k, unsigned flags)
{ {
struct bch_fs *c = trans->c;
unsigned replicas = bkey_s_c_to_reservation(k).v->nr_replicas; unsigned replicas = bkey_s_c_to_reservation(k).v->nr_replicas;
s64 sectors = (s64) k.k->size; s64 sectors = (s64) k.k->size * replicas;
struct replicas_delta_list *d;
int ret;
if (flags & BTREE_TRIGGER_OVERWRITE) if (flags & BTREE_TRIGGER_OVERWRITE)
sectors = -sectors; sectors = -sectors;
sectors *= replicas;
ret = bch2_replicas_deltas_realloc(trans, 0); if (flags & BTREE_TRIGGER_TRANSACTIONAL) {
if (ret) int ret = bch2_replicas_deltas_realloc(trans, 0);
return ret; if (ret)
return ret;
d = trans->fs_usage_deltas; struct replicas_delta_list *d = trans->fs_usage_deltas;
replicas = clamp_t(unsigned, replicas, 1, replicas = min(replicas, ARRAY_SIZE(d->persistent_reserved));
ARRAY_SIZE(d->persistent_reserved));
d->persistent_reserved[replicas - 1] += sectors;
}
if (flags & BTREE_TRIGGER_GC) {
percpu_down_read(&c->mark_lock);
preempt_disable();
struct bch_fs_usage *fs_usage = this_cpu_ptr(c->usage_gc);
replicas = min(replicas, ARRAY_SIZE(fs_usage->persistent_reserved));
fs_usage->reserved += sectors;
fs_usage->persistent_reserved[replicas - 1] += sectors;
preempt_enable();
percpu_up_read(&c->mark_lock);
}
d->persistent_reserved[replicas - 1] += sectors;
return 0; return 0;
} }
int bch2_trans_mark_reservation(struct btree_trans *trans, int bch2_trigger_reservation(struct btree_trans *trans,
enum btree_id btree_id, unsigned level, enum btree_id btree_id, unsigned level,
struct bkey_s_c old, struct bkey_s_c old, struct bkey_s new,
struct bkey_s new, unsigned flags)
unsigned flags)
{ {
return trigger_run_overwrite_then_insert(__trans_mark_reservation, trans, btree_id, level, old, new, flags); return trigger_run_overwrite_then_insert(__trigger_reservation, trans, btree_id, level, old, new, flags);
} }
/* Mark superblocks: */
static int __bch2_trans_mark_metadata_bucket(struct btree_trans *trans, static int __bch2_trans_mark_metadata_bucket(struct btree_trans *trans,
struct bch_dev *ca, size_t b, struct bch_dev *ca, size_t b,
enum bch_data_type type, enum bch_data_type type,
......
...@@ -333,12 +333,11 @@ int bch2_mark_extent(struct btree_trans *, enum btree_id, unsigned, ...@@ -333,12 +333,11 @@ int bch2_mark_extent(struct btree_trans *, enum btree_id, unsigned,
struct bkey_s_c, struct bkey_s, unsigned); struct bkey_s_c, struct bkey_s, unsigned);
int bch2_mark_stripe(struct btree_trans *, enum btree_id, unsigned, int bch2_mark_stripe(struct btree_trans *, enum btree_id, unsigned,
struct bkey_s_c, struct bkey_s, unsigned); struct bkey_s_c, struct bkey_s, unsigned);
int bch2_mark_reservation(struct btree_trans *, enum btree_id, unsigned, int bch2_trigger_reservation(struct btree_trans *, enum btree_id, unsigned,
struct bkey_s_c, struct bkey_s, unsigned); struct bkey_s_c, struct bkey_s, unsigned);
int bch2_trans_mark_extent(struct btree_trans *, enum btree_id, unsigned, struct bkey_s_c, struct bkey_s, unsigned); int bch2_trans_mark_extent(struct btree_trans *, enum btree_id, unsigned, struct bkey_s_c, struct bkey_s, unsigned);
int bch2_trans_mark_stripe(struct btree_trans *, enum btree_id, unsigned, struct bkey_s_c, struct bkey_s, unsigned); int bch2_trans_mark_stripe(struct btree_trans *, enum btree_id, unsigned, struct bkey_s_c, struct bkey_s, unsigned);
int bch2_trans_mark_reservation(struct btree_trans *, enum btree_id, unsigned, struct bkey_s_c, struct bkey_s, unsigned);
#define trigger_run_overwrite_then_insert(_fn, _trans, _btree_id, _level, _old, _new, _flags)\ #define trigger_run_overwrite_then_insert(_fn, _trans, _btree_id, _level, _old, _new, _flags)\
({ \ ({ \
int ret = 0; \ int ret = 0; \
......
...@@ -454,8 +454,8 @@ bool bch2_reservation_merge(struct bch_fs *, struct bkey_s, struct bkey_s_c); ...@@ -454,8 +454,8 @@ bool bch2_reservation_merge(struct bch_fs *, struct bkey_s, struct bkey_s_c);
.key_invalid = bch2_reservation_invalid, \ .key_invalid = bch2_reservation_invalid, \
.val_to_text = bch2_reservation_to_text, \ .val_to_text = bch2_reservation_to_text, \
.key_merge = bch2_reservation_merge, \ .key_merge = bch2_reservation_merge, \
.trans_trigger = bch2_trans_mark_reservation, \ .trans_trigger = bch2_trigger_reservation, \
.atomic_trigger = bch2_mark_reservation, \ .atomic_trigger = bch2_trigger_reservation, \
.min_val_size = 8, \ .min_val_size = 8, \
}) })
......
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