summaryrefslogtreecommitdiffstats
path: root/fs/bcachefs/movinggc.c
diff options
context:
space:
mode:
authorKent Overstreet <kent.overstreet@gmail.com>2022-04-01 01:29:59 -0400
committerKent Overstreet <kent.overstreet@linux.dev>2023-10-22 17:09:30 -0400
commit822835ffeae411bbc8af104da9331fdf63a7bc12 (patch)
tree57d2b7fd487fc05d58464ea179d435ff4d149bc9 /fs/bcachefs/movinggc.c
parent8058ea64c31c8700eaab48c38a143d1c3817f1de (diff)
downloadlinux-822835ffeae411bbc8af104da9331fdf63a7bc12.tar.gz
linux-822835ffeae411bbc8af104da9331fdf63a7bc12.tar.bz2
linux-822835ffeae411bbc8af104da9331fdf63a7bc12.zip
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/movinggc.c')
-rw-r--r--fs/bcachefs/movinggc.c11
1 files changed, 9 insertions, 2 deletions
diff --git a/fs/bcachefs/movinggc.c b/fs/bcachefs/movinggc.c
index cd7a9d81dfe8..6209cb51efcb 100644
--- a/fs/bcachefs/movinggc.c
+++ b/fs/bcachefs/movinggc.c
@@ -235,8 +235,15 @@ static int bch2_copygc(struct bch_fs *c)
}
for_each_rw_member(ca, c, dev_idx) {
- s64 avail = min(dev_buckets_available(ca, RESERVE_movinggc),
- ca->mi.nbuckets >> 6);
+ struct bch_dev_usage usage = bch2_dev_usage_read(ca);
+
+ u64 avail = max_t(s64, 0,
+ usage.d[BCH_DATA_free].buckets +
+ usage.d[BCH_DATA_need_discard].buckets -
+ ca->nr_open_buckets -
+ bch2_dev_buckets_reserved(ca, RESERVE_movinggc));
+
+ avail = min(avail, ca->mi.nbuckets >> 6);
sectors_reserved += avail * ca->mi.bucket_size;
}