]> www.infradead.org Git - nvme.git/commit
btrfs: zoned: fix calc_available_free_space() for zoned mode
authorNaohiro Aota <naohiro.aota@wdc.com>
Thu, 20 Jun 2024 06:05:45 +0000 (15:05 +0900)
committerDavid Sterba <dsterba@suse.com>
Tue, 2 Jul 2024 17:13:11 +0000 (19:13 +0200)
commit64d2c847ba380e07b9072d65a50aa6469d2aa43f
tree16b2a81ff69b42edbcaa46204db6baa93138f051
parent48f091fd50b2eb33ae5eaea9ed3c4f81603acf38
btrfs: zoned: fix calc_available_free_space() for zoned mode

calc_available_free_space() returns the total size of metadata (or
system) block groups, which can be allocated from unallocated disk
space. The logic is wrong on zoned mode in two places.

First, the calculation of data_chunk_size is wrong. We always allocate
one zone as one chunk, and no partial allocation of a zone. So, we
should use zone_size (= data_sinfo->chunk_size) as it is.

Second, the result "avail" may not be zone aligned. Since we always
allocate one zone as one chunk on zoned mode, returning non-zone size
aligned bytes will result in less pressure on the async metadata reclaim
process.

This is serious for the nearly full state with a large zone size device.
Allowing over-commit too much will result in less async reclaim work and
end up in ENOSPC. We can align down to the zone size to avoid that.

Fixes: cb6cbab79055 ("btrfs: adjust overcommit logic when very close to full")
CC: stable@vger.kernel.org # 6.9
Signed-off-by: Naohiro Aota <naohiro.aota@wdc.com>
Reviewed-by: Boris Burkov <boris@bur.io>
Signed-off-by: David Sterba <dsterba@suse.com>
fs/btrfs/space-info.c