Commit 5f43f99c authored by Kent Overstreet's avatar Kent Overstreet Committed by Kent Overstreet

bcachefs: bch2_dev_usage_update() no longer depends on bucket_mark

This is one of the last steps in getting rid of the main in-memory
bucket array.

This changes bch2_dev_usage_update() to take bkey_alloc_unpacked instead
of bucket_mark, and for the places where we are in fact working with
bucket_mark and don't have bkey_alloc_unpacked, we add a wrapper that
takes bucket_mark and converts to bkey_alloc_unpacked.
Signed-off-by: default avatarKent Overstreet <kent.overstreet@linux.dev>
parent 5add07d5
...@@ -283,24 +283,24 @@ bch2_fs_usage_read_short(struct bch_fs *c) ...@@ -283,24 +283,24 @@ bch2_fs_usage_read_short(struct bch_fs *c)
return ret; return ret;
} }
static inline int is_unavailable_bucket(struct bucket_mark m) static inline int is_unavailable_bucket(struct bch_alloc_v4 a)
{ {
return !is_available_bucket(m); return a.dirty_sectors || a.stripe;
} }
static inline int bucket_sectors_fragmented(struct bch_dev *ca, static inline int bucket_sectors_fragmented(struct bch_dev *ca,
struct bucket_mark m) struct bch_alloc_v4 a)
{ {
return m.dirty_sectors return a.dirty_sectors
? max(0, (int) ca->mi.bucket_size - (int) m.dirty_sectors) ? max(0, (int) ca->mi.bucket_size - (int) a.dirty_sectors)
: 0; : 0;
} }
static inline enum bch_data_type bucket_type(struct bucket_mark m) static inline enum bch_data_type bucket_type(struct bch_alloc_v4 a)
{ {
return m.cached_sectors && !m.dirty_sectors return a.cached_sectors && !a.dirty_sectors
? BCH_DATA_cached ? BCH_DATA_cached
: m.data_type; : a.data_type;
} }
static inline void account_bucket(struct bch_fs_usage *fs_usage, static inline void account_bucket(struct bch_fs_usage *fs_usage,
...@@ -315,7 +315,8 @@ static inline void account_bucket(struct bch_fs_usage *fs_usage, ...@@ -315,7 +315,8 @@ static inline void account_bucket(struct bch_fs_usage *fs_usage,
} }
static void bch2_dev_usage_update(struct bch_fs *c, struct bch_dev *ca, static void bch2_dev_usage_update(struct bch_fs *c, struct bch_dev *ca,
struct bucket_mark old, struct bucket_mark new, struct bch_alloc_v4 old,
struct bch_alloc_v4 new,
u64 journal_seq, bool gc) u64 journal_seq, bool gc)
{ {
struct bch_fs_usage *fs_usage; struct bch_fs_usage *fs_usage;
...@@ -347,6 +348,28 @@ static void bch2_dev_usage_update(struct bch_fs *c, struct bch_dev *ca, ...@@ -347,6 +348,28 @@ static void bch2_dev_usage_update(struct bch_fs *c, struct bch_dev *ca,
preempt_enable(); preempt_enable();
} }
static void bch2_dev_usage_update_m(struct bch_fs *c, struct bch_dev *ca,
struct bucket_mark old, struct bucket_mark new,
u64 journal_seq, bool gc)
{
struct bch_alloc_v4 old_a = {
.gen = old.gen,
.data_type = old.data_type,
.dirty_sectors = old.dirty_sectors,
.cached_sectors = old.cached_sectors,
.stripe = old.stripe,
};
struct bch_alloc_v4 new_a = {
.gen = new.gen,
.data_type = new.data_type,
.dirty_sectors = new.dirty_sectors,
.cached_sectors = new.cached_sectors,
.stripe = new.stripe,
};
bch2_dev_usage_update(c, ca, old_a, new_a, journal_seq, gc);
}
static inline int __update_replicas(struct bch_fs *c, static inline int __update_replicas(struct bch_fs *c,
struct bch_fs_usage *fs_usage, struct bch_fs_usage *fs_usage,
struct bch_replicas_entry *r, struct bch_replicas_entry *r,
...@@ -562,6 +585,8 @@ int bch2_mark_alloc(struct btree_trans *trans, ...@@ -562,6 +585,8 @@ int bch2_mark_alloc(struct btree_trans *trans,
if (!gc && new_a.gen != old_a.gen) if (!gc && new_a.gen != old_a.gen)
*bucket_gen(ca, new.k->p.offset) = new_a.gen; *bucket_gen(ca, new.k->p.offset) = new_a.gen;
bch2_dev_usage_update(c, ca, old_a, new_a, journal_seq, gc);
g = __bucket(ca, new.k->p.offset, gc); g = __bucket(ca, new.k->p.offset, gc);
old_m = bucket_cmpxchg(g, m, ({ old_m = bucket_cmpxchg(g, m, ({
...@@ -572,8 +597,6 @@ int bch2_mark_alloc(struct btree_trans *trans, ...@@ -572,8 +597,6 @@ int bch2_mark_alloc(struct btree_trans *trans,
m.stripe = new_a.stripe != 0; m.stripe = new_a.stripe != 0;
})); }));
bch2_dev_usage_update(c, ca, old_m, m, journal_seq, gc);
g->io_time[READ] = new_a.io_time[READ]; g->io_time[READ] = new_a.io_time[READ];
g->io_time[WRITE] = new_a.io_time[WRITE]; g->io_time[WRITE] = new_a.io_time[WRITE];
g->gen_valid = 1; g->gen_valid = 1;
...@@ -651,7 +674,7 @@ void bch2_mark_metadata_bucket(struct bch_fs *c, struct bch_dev *ca, ...@@ -651,7 +674,7 @@ void bch2_mark_metadata_bucket(struct bch_fs *c, struct bch_dev *ca,
bch2_data_types[old.data_type ?: data_type], bch2_data_types[old.data_type ?: data_type],
old.dirty_sectors, sectors); old.dirty_sectors, sectors);
bch2_dev_usage_update(c, ca, old, new, 0, true); bch2_dev_usage_update_m(c, ca, old, new, 0, true);
percpu_up_read(&c->mark_lock); percpu_up_read(&c->mark_lock);
} }
...@@ -810,7 +833,7 @@ static int mark_stripe_bucket(struct btree_trans *trans, ...@@ -810,7 +833,7 @@ static int mark_stripe_bucket(struct btree_trans *trans,
g->stripe = k.k->p.offset; g->stripe = k.k->p.offset;
g->stripe_redundancy = s->nr_redundant; g->stripe_redundancy = s->nr_redundant;
bch2_dev_usage_update(c, ca, old, new, journal_seq, true); bch2_dev_usage_update_m(c, ca, old, new, journal_seq, true);
err: err:
percpu_up_read(&c->mark_lock); percpu_up_read(&c->mark_lock);
printbuf_exit(&buf); printbuf_exit(&buf);
...@@ -883,7 +906,7 @@ static int bch2_mark_pointer(struct btree_trans *trans, ...@@ -883,7 +906,7 @@ static int bch2_mark_pointer(struct btree_trans *trans,
old.v.counter, old.v.counter,
new.v.counter)) != old.v.counter); new.v.counter)) != old.v.counter);
bch2_dev_usage_update(c, ca, old, new, journal_seq, true); bch2_dev_usage_update_m(c, ca, old, new, journal_seq, true);
err: err:
percpu_up_read(&c->mark_lock); percpu_up_read(&c->mark_lock);
......
...@@ -134,13 +134,6 @@ static inline u8 ptr_stale(struct bch_dev *ca, ...@@ -134,13 +134,6 @@ static inline u8 ptr_stale(struct bch_dev *ca,
return ret; return ret;
} }
/* bucket gc marks */
static inline bool is_available_bucket(struct bucket_mark mark)
{
return !mark.dirty_sectors && !mark.stripe;
}
/* Device usage: */ /* Device usage: */
struct bch_dev_usage bch2_dev_usage_read(struct bch_dev *); struct bch_dev_usage bch2_dev_usage_read(struct bch_dev *);
......
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