diff options
author | Kent Overstreet <kent.overstreet@gmail.com> | 2018-11-04 23:10:09 -0500 |
---|---|---|
committer | Kent Overstreet <kent.overstreet@linux.dev> | 2023-10-22 17:08:11 -0400 |
commit | 4628529f152782933865257796000f1f6702a9ee (patch) | |
tree | c109a396839fb65592b35b6dd1db384766dabbf4 /fs | |
parent | 8b335baef22768deb7140e45f32f37ea51a1faf4 (diff) |
bcachefs: Disk usage in compressed sectors, not uncompressed
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
Diffstat (limited to 'fs')
-rw-r--r-- | fs/bcachefs/buckets.c | 9 | ||||
-rw-r--r-- | fs/bcachefs/extents.c | 5 | ||||
-rw-r--r-- | fs/bcachefs/move.c | 21 |
3 files changed, 29 insertions, 6 deletions
diff --git a/fs/bcachefs/buckets.c b/fs/bcachefs/buckets.c index 28ec8a58319c..54eb1b6b820b 100644 --- a/fs/bcachefs/buckets.c +++ b/fs/bcachefs/buckets.c @@ -339,12 +339,17 @@ void bch2_fs_usage_apply(struct bch_fs *c, { struct fs_usage_sum sum = __fs_usage_sum(*stats); s64 added = sum.data + sum.reserved; + s64 should_not_have_added; /* * Not allowed to reduce sectors_available except by getting a * reservation: */ - BUG_ON(added > (s64) (disk_res ? disk_res->sectors : 0)); + should_not_have_added = added - (s64) (disk_res ? disk_res->sectors : 0); + if (WARN_ON(should_not_have_added > 0)) { + atomic64_sub(should_not_have_added, &c->sectors_available); + added -= should_not_have_added; + } if (added > 0) { disk_res->sectors -= added; @@ -667,7 +672,7 @@ static void bch2_mark_extent(struct bch_fs *c, struct bkey_s_c k, stats->replicas [!p.ptr.cached && replicas ? replicas - 1 : 0].data [!p.ptr.cached ? data_type : BCH_DATA_CACHED] += - sectors; + disk_sectors; bch2_mark_pointer(c, e, p, disk_sectors, data_type, stats, journal_seq, flags); diff --git a/fs/bcachefs/extents.c b/fs/bcachefs/extents.c index e2bb1502eaad..1606826e7802 100644 --- a/fs/bcachefs/extents.c +++ b/fs/bcachefs/extents.c @@ -235,7 +235,7 @@ unsigned bch2_extent_is_compressed(struct bkey_s_c k) if (!p.ptr.cached && p.crc.compression_type != BCH_COMPRESSION_NONE && p.crc.compressed_size < p.crc.live_size) - ret = max_t(unsigned, ret, p.crc.compressed_size); + ret += p.crc.compressed_size; } } @@ -1275,8 +1275,7 @@ bch2_extent_can_insert(struct btree_insert *trans, switch (bch2_disk_reservation_add(trans->c, trans->disk_res, - sectors * bch2_extent_nr_dirty_ptrs(k), - flags)) { + sectors, flags)) { case 0: break; case -ENOSPC: diff --git a/fs/bcachefs/move.c b/fs/bcachefs/move.c index b2bf0944d59d..1f6bad1ae388 100644 --- a/fs/bcachefs/move.c +++ b/fs/bcachefs/move.c @@ -5,6 +5,7 @@ #include "btree_gc.h" #include "btree_update.h" #include "buckets.h" +#include "disk_groups.h" #include "inode.h" #include "io.h" #include "journal_reclaim.h" @@ -260,8 +261,26 @@ int bch2_migrate_write_init(struct bch_fs *c, struct migrate_write *m, } break; } - case DATA_REWRITE: + case DATA_REWRITE: { + const union bch_extent_entry *entry; + struct extent_ptr_decoded p; + unsigned compressed_sectors = 0; + + extent_for_each_ptr_decode(bkey_s_c_to_extent(k), p, entry) + if (!p.ptr.cached && + p.crc.compression_type != BCH_COMPRESSION_NONE && + bch2_dev_in_target(c, p.ptr.dev, data_opts.target)) + compressed_sectors += p.crc.compressed_size; + + if (compressed_sectors) { + ret = bch2_disk_reservation_add(c, &m->op.res, + compressed_sectors, + BCH_DISK_RESERVATION_NOFAIL); + if (ret) + return ret; + } break; + } case DATA_PROMOTE: m->op.flags |= BCH_WRITE_ALLOC_NOWAIT; m->op.flags |= BCH_WRITE_CACHED; |