diff options
author | Kent Overstreet <kent.overstreet@gmail.com> | 2022-06-14 17:51:20 -0400 |
---|---|---|
committer | Kent Overstreet <kent.overstreet@linux.dev> | 2023-10-22 17:09:34 -0400 |
commit | 30f0349d62429effd729ae9272c6fb57f47d1436 (patch) | |
tree | 7a7e0227b9877102e4f8f603d0ae5ff971f39074 /fs/bcachefs/buckets.h | |
parent | 8f7f566f5774d36196bfa87bc097522fd497d4dc (diff) | |
download | linux-stable-30f0349d62429effd729ae9272c6fb57f47d1436.tar.gz linux-stable-30f0349d62429effd729ae9272c6fb57f47d1436.tar.bz2 linux-stable-30f0349d62429effd729ae9272c6fb57f47d1436.zip |
bcachefs: Split out dev_buckets_free()
Previously, dev_buckets_available() only counted buckets that are
eligible to be allocated right now - i.e. buckets that don't have cached
data, or need discard, or need gc gens, etc.
But most users of this function want to know how many buckets are
eligible to be allocated from without moving data around - copygc,
allocator striping, which means we should be including cached data
buckets etc.
Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
Diffstat (limited to 'fs/bcachefs/buckets.h')
-rw-r--r-- | fs/bcachefs/buckets.h | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/fs/bcachefs/buckets.h b/fs/bcachefs/buckets.h index 327022cd0f7a..080bcb20a5b0 100644 --- a/fs/bcachefs/buckets.h +++ b/fs/bcachefs/buckets.h @@ -144,12 +144,25 @@ static inline u64 bch2_dev_buckets_reserved(struct bch_dev *ca, enum alloc_reser return reserved; } +static inline u64 dev_buckets_free(struct bch_dev *ca, + struct bch_dev_usage usage, + enum alloc_reserve reserve) +{ + return max_t(s64, 0, + usage.d[BCH_DATA_free].buckets - + ca->nr_open_buckets - + bch2_dev_buckets_reserved(ca, reserve)); +} + static inline u64 __dev_buckets_available(struct bch_dev *ca, struct bch_dev_usage usage, enum alloc_reserve reserve) { return max_t(s64, 0, usage.d[BCH_DATA_free].buckets - + usage.d[BCH_DATA_cached].buckets - + usage.d[BCH_DATA_need_gc_gens].buckets - + usage.d[BCH_DATA_need_discard].buckets - ca->nr_open_buckets - bch2_dev_buckets_reserved(ca, reserve)); } |