Skip to content

Commit 64d2c84

Browse files
naotakdave
authored andcommitted
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: cb6cbab ("btrfs: adjust overcommit logic when very close to full") CC: [email protected] # 6.9 Signed-off-by: Naohiro Aota <[email protected]> Reviewed-by: Boris Burkov <[email protected]> Signed-off-by: David Sterba <[email protected]>
1 parent 48f091f commit 64d2c84

File tree

1 file changed

+21
-3
lines changed

1 file changed

+21
-3
lines changed

fs/btrfs/space-info.c

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -373,11 +373,18 @@ static u64 calc_available_free_space(struct btrfs_fs_info *fs_info,
373373
* "optimal" chunk size based on the fs size. However when we actually
374374
* allocate the chunk we will strip this down further, making it no more
375375
* than 10% of the disk or 1G, whichever is smaller.
376+
*
377+
* On the zoned mode, we need to use zone_size (=
378+
* data_sinfo->chunk_size) as it is.
376379
*/
377380
data_sinfo = btrfs_find_space_info(fs_info, BTRFS_BLOCK_GROUP_DATA);
378-
data_chunk_size = min(data_sinfo->chunk_size,
379-
mult_perc(fs_info->fs_devices->total_rw_bytes, 10));
380-
data_chunk_size = min_t(u64, data_chunk_size, SZ_1G);
381+
if (!btrfs_is_zoned(fs_info)) {
382+
data_chunk_size = min(data_sinfo->chunk_size,
383+
mult_perc(fs_info->fs_devices->total_rw_bytes, 10));
384+
data_chunk_size = min_t(u64, data_chunk_size, SZ_1G);
385+
} else {
386+
data_chunk_size = data_sinfo->chunk_size;
387+
}
381388

382389
/*
383390
* Since data allocations immediately use block groups as part of the
@@ -405,6 +412,17 @@ static u64 calc_available_free_space(struct btrfs_fs_info *fs_info,
405412
avail >>= 3;
406413
else
407414
avail >>= 1;
415+
416+
/*
417+
* On the zoned mode, we always allocate one zone as one chunk.
418+
* Returning non-zone size alingned bytes here will result in
419+
* less pressure for the async metadata reclaim process, and it
420+
* will over-commit too much leading to ENOSPC. Align down to the
421+
* zone size to avoid that.
422+
*/
423+
if (btrfs_is_zoned(fs_info))
424+
avail = ALIGN_DOWN(avail, fs_info->zone_size);
425+
408426
return avail;
409427
}
410428

0 commit comments

Comments
 (0)