Skip to content

Commit 2ffc690

Browse files
Christoph Hellwigcmaiolino
authored andcommitted
xfs: fix number of GC bvecs
GC scratch allocations can wrap around and use the same buffer twice, and the current code fails to account for that. So far this worked due to rounding in the block layer, but changes to the bio allocator drop the over-provisioning and generic/256 or generic/361 will now usually fail when running against the current block tree. Simplify the allocation to always pass the maximum value that is easier to verify, as a saving of up to one bvec per allocation isn't worth the effort to verify a complicated calculated value. Fixes: 102f444 ("xfs: rework zone GC buffer management") Signed-off-by: Christoph Hellwig <hch@lst.de> Reviewed-by: Damien Le Moal <dlemoal@kernel.org> Reviewed-by: Hans Holmberg <hans.holmberg@wdc.com> Signed-off-by: Carlos Maiolino <cem@kernel.org>
1 parent 9de45fa commit 2ffc690

1 file changed

Lines changed: 10 additions & 9 deletions

File tree

fs/xfs/xfs_zone_gc.c

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -706,7 +706,6 @@ xfs_zone_gc_start_chunk(
706706
struct xfs_inode *ip;
707707
struct bio *bio;
708708
xfs_daddr_t daddr;
709-
unsigned int len;
710709
bool is_seq;
711710

712711
if (!xfs_zone_gc_can_start_chunk(data))
@@ -722,15 +721,16 @@ xfs_zone_gc_start_chunk(
722721
return false;
723722
}
724723

725-
len = XFS_FSB_TO_B(mp, irec.rm_blockcount);
726-
bio = bio_alloc_bioset(bdev,
727-
min(howmany(len, XFS_GC_BUF_SIZE) + 1, XFS_GC_NR_BUFS),
728-
REQ_OP_READ, GFP_NOFS, &data->bio_set);
729-
724+
/*
725+
* Scratch allocation can wrap around to the same buffer again,
726+
* provision an extra bvec for that case.
727+
*/
728+
bio = bio_alloc_bioset(bdev, XFS_GC_NR_BUFS + 1, REQ_OP_READ, GFP_NOFS,
729+
&data->bio_set);
730730
chunk = container_of(bio, struct xfs_gc_bio, bio);
731731
chunk->ip = ip;
732732
chunk->offset = XFS_FSB_TO_B(mp, irec.rm_offset);
733-
chunk->len = len;
733+
chunk->len = XFS_FSB_TO_B(mp, irec.rm_blockcount);
734734
chunk->old_startblock =
735735
xfs_rgbno_to_rtb(iter->victim_rtg, irec.rm_startblock);
736736
chunk->new_daddr = daddr;
@@ -744,8 +744,9 @@ xfs_zone_gc_start_chunk(
744744
bio->bi_iter.bi_sector = xfs_rtb_to_daddr(mp, chunk->old_startblock);
745745
bio->bi_end_io = xfs_zone_gc_end_io;
746746
xfs_zone_gc_add_data(chunk);
747-
data->scratch_head = (data->scratch_head + len) % data->scratch_size;
748-
data->scratch_available -= len;
747+
data->scratch_head =
748+
(data->scratch_head + chunk->len) % data->scratch_size;
749+
data->scratch_available -= chunk->len;
749750

750751
XFS_STATS_INC(mp, xs_gc_read_calls);
751752

0 commit comments

Comments
 (0)