summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKent Overstreet <kent.overstreet@gmail.com>2018-12-05 12:30:02 -0500
committerKent Overstreet <kent.overstreet@gmail.com>2018-12-27 11:38:36 -0500
commit26f69ebc3efa4bbde71b7b5029399342883758bd (patch)
tree44cffd6968dad8369f2249a470588e0393f9fe33
parent3246dfb8fa420288fc5bff3f19b0a29acb002dff (diff)
bcachefs: Compression fixes
regressions from switching disk space accounting to be in compressed sectors
-rw-r--r--fs/bcachefs/extents.c3
-rw-r--r--fs/bcachefs/move.c20
2 files changed, 16 insertions, 7 deletions
diff --git a/fs/bcachefs/extents.c b/fs/bcachefs/extents.c
index 6ae5481889e0..065c023c8a49 100644
--- a/fs/bcachefs/extents.c
+++ b/fs/bcachefs/extents.c
@@ -305,8 +305,7 @@ unsigned bch2_extent_is_compressed(struct bkey_s_c k)
extent_for_each_ptr_decode(e, p, entry)
if (!p.ptr.cached &&
- p.crc.compression_type != BCH_COMPRESSION_NONE &&
- p.crc.compressed_size < p.crc.live_size)
+ p.crc.compression_type != BCH_COMPRESSION_NONE)
ret += p.crc.compressed_size;
}
}
diff --git a/fs/bcachefs/move.c b/fs/bcachefs/move.c
index 8c95aa92f6d9..80909ae4fb6d 100644
--- a/fs/bcachefs/move.c
+++ b/fs/bcachefs/move.c
@@ -128,13 +128,15 @@ static int bch2_migrate_index_update(struct bch_write_op *op)
op->opts.data_replicas);
/*
- * It's possible we race, and for whatever reason the extent now
- * has fewer replicas than when we last looked at it - meaning
- * we need to get a disk reservation here:
+ * If we're not fully overwriting @k, and it's compressed, we
+ * need a reservation for all the pointers in @insert
*/
nr = bch2_bkey_nr_dirty_ptrs(bkey_i_to_s_c(&insert->k_i)) -
- (bch2_bkey_nr_dirty_ptrs(k) + m->nr_ptrs_reserved);
- if (nr > 0) {
+ m->nr_ptrs_reserved;
+
+ if (insert->k.size < k.k->size &&
+ bch2_extent_is_compressed(k) &&
+ nr > 0) {
/*
* can't call bch2_disk_reservation_add() with btree
* locks held, at least not without a song and dance
@@ -242,8 +244,16 @@ int bch2_migrate_write_init(struct bch_fs *c, struct migrate_write *m,
switch (data_cmd) {
case DATA_ADD_REPLICAS: {
+ /*
+ * DATA_ADD_REPLICAS is used for moving data to a different
+ * device in the background, and due to compression the new copy
+ * might take up more space than the old copy:
+ */
+#if 0
int nr = (int) io_opts.data_replicas -
bch2_bkey_nr_dirty_ptrs(k);
+#endif
+ int nr = (int) io_opts.data_replicas;
if (nr > 0) {
m->op.nr_replicas = m->nr_ptrs_reserved = nr;