1

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>
This commit is contained in:
Kent Overstreet 2022-06-14 17:51:20 -04:00 committed by Kent Overstreet
parent 8f7f566f57
commit 30f0349d62
2 changed files with 14 additions and 1 deletions

View File

@ -526,7 +526,7 @@ static struct open_bucket *bch2_bucket_alloc_trans(struct btree_trans *trans,
bool waiting = false;
again:
usage = bch2_dev_usage_read(ca);
avail = __dev_buckets_available(ca, usage,reserve);
avail = dev_buckets_free(ca, usage,reserve);
if (usage.d[BCH_DATA_need_discard].buckets > avail)
bch2_do_discards(c);

View File

@ -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));
}