diff options
author | Kent Overstreet <kent.overstreet@gmail.com> | 2022-04-01 08:29:59 +0300 |
---|---|---|
committer | Kent Overstreet <kent.overstreet@linux.dev> | 2023-10-23 00:09:30 +0300 |
commit | 822835ffeae411bbc8af104da9331fdf63a7bc12 (patch) | |
tree | 57d2b7fd487fc05d58464ea179d435ff4d149bc9 /fs/bcachefs/buckets.h | |
parent | 8058ea64c31c8700eaab48c38a143d1c3817f1de (diff) | |
download | linux-822835ffeae411bbc8af104da9331fdf63a7bc12.tar.xz |
bcachefs: Fold bucket_state in to BCH_DATA_TYPES()
Previously, we were missing accounting for buckets in need_gc_gens and
need_discard states. This matters because buckets in those states need
other btree operations done before they can be used, so they can't be
conuted when checking current number of free buckets against the
allocation watermark.
Also, we weren't directly counting free buckets at all. Now, data type 0
== BCH_DATA_free, and free buckets are counted; this means we can get
rid of the separate (poorly defined) count of unavailable buckets.
This is a new on disk format version, with upgrade and fsck required for
the accounting changes.
Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
Diffstat (limited to 'fs/bcachefs/buckets.h')
-rw-r--r-- | fs/bcachefs/buckets.h | 23 |
1 files changed, 10 insertions, 13 deletions
diff --git a/fs/bcachefs/buckets.h b/fs/bcachefs/buckets.h index 053b6dc215b3..518f5104a2f7 100644 --- a/fs/bcachefs/buckets.h +++ b/fs/bcachefs/buckets.h @@ -121,12 +121,10 @@ static inline u8 ptr_stale(struct bch_dev *ca, /* Device usage: */ struct bch_dev_usage bch2_dev_usage_read(struct bch_dev *); +void bch2_dev_usage_init(struct bch_dev *); -static inline u64 __dev_buckets_available(struct bch_dev *ca, - struct bch_dev_usage stats, - enum alloc_reserve reserve) +static inline u64 bch2_dev_buckets_reserved(struct bch_dev *ca, enum alloc_reserve reserve) { - s64 total = ca->mi.nbuckets - ca->mi.first_bucket; s64 reserved = 0; switch (reserve) { @@ -141,20 +139,19 @@ static inline u64 __dev_buckets_available(struct bch_dev *ca, fallthrough; case RESERVE_btree_movinggc: break; - default: - BUG(); } - if (WARN_ONCE(stats.buckets_unavailable > total, - "buckets_unavailable overflow (%llu > %llu)\n", - stats.buckets_unavailable, total)) - return 0; + return reserved; +} +static inline u64 __dev_buckets_available(struct bch_dev *ca, + struct bch_dev_usage usage, + enum alloc_reserve reserve) +{ return max_t(s64, 0, - total - - stats.buckets_unavailable - + usage.d[BCH_DATA_free].buckets - ca->nr_open_buckets - - reserved); + bch2_dev_buckets_reserved(ca, reserve)); } static inline u64 dev_buckets_available(struct bch_dev *ca, |