diff options
author | Kent Overstreet <kent.overstreet@gmail.com> | 2022-07-17 22:59:01 -0400 |
---|---|---|
committer | Kent Overstreet <kent.overstreet@linux.dev> | 2023-10-22 17:09:36 -0400 |
commit | b962552eabd59f0026dcc21c14775b9d78336baf (patch) | |
tree | 47718967fc85a907e22bebc7d29867079e9bff62 /fs/bcachefs/alloc_background.h | |
parent | 175379db206a3a36a80585b00bb974a6ab6c43c0 (diff) | |
download | lwn-b962552eabd59f0026dcc21c14775b9d78336baf.tar.gz lwn-b962552eabd59f0026dcc21c14775b9d78336baf.zip |
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>
Diffstat (limited to 'fs/bcachefs/alloc_background.h')
-rw-r--r-- | fs/bcachefs/alloc_background.h | 10 |
1 files changed, 6 insertions, 4 deletions
diff --git a/fs/bcachefs/alloc_background.h b/fs/bcachefs/alloc_background.h index ff366e61ace5..488db3211ce4 100644 --- a/fs/bcachefs/alloc_background.h +++ b/fs/bcachefs/alloc_background.h @@ -134,11 +134,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 *); |