summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKent Overstreet <kent.overstreet@gmail.com>2022-07-17 22:59:01 -0400
committerKent Overstreet <kent.overstreet@linux.dev>2022-10-03 22:52:26 -0400
commit040e2a26a38fe515d4ac6a345fe214e7b30e59dd (patch)
tree7444997d7824ae48bb2fd0f0db6867e028172ea1
parentc929859be371699e7750023af982e210dbfe5713 (diff)
bcachefs: Fix should_invalidate_buckets()
Like bch2_copygc_wait_amount, should_invalidate_buckets() needs to try to ensure that there are always more buckets free than the largest reserve. Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
-rw-r--r--fs/bcachefs/alloc_background.h10
1 files changed, 6 insertions, 4 deletions
diff --git a/fs/bcachefs/alloc_background.h b/fs/bcachefs/alloc_background.h
index 2ac6b5046c67..044bc72992d4 100644
--- a/fs/bcachefs/alloc_background.h
+++ b/fs/bcachefs/alloc_background.h
@@ -150,11 +150,13 @@ void bch2_do_discards(struct bch_fs *);
static inline u64 should_invalidate_buckets(struct bch_dev *ca,
struct bch_dev_usage u)
{
- u64 free = u.d[BCH_DATA_free].buckets +
- u.d[BCH_DATA_need_discard].buckets;
+ u64 want_free = ca->mi.nbuckets >> 7;
+ u64 free = max_t(s64, 0,
+ u.d[BCH_DATA_free].buckets
+ + u.d[BCH_DATA_need_discard].buckets
+ - bch2_dev_buckets_reserved(ca, RESERVE_none));
- return clamp_t(s64, (ca->mi.nbuckets >> 7) - free,
- 0, u.d[BCH_DATA_cached].buckets);
+ return clamp_t(s64, want_free - free, 0, u.d[BCH_DATA_cached].buckets);
}
void bch2_do_invalidates(struct bch_fs *);