]> git.ipfire.org Git - thirdparty/kernel/linux.git/commit
block: use bvec iterator helper for bio_may_need_split()
authorMing Lei <ming.lei@redhat.com>
Wed, 31 Dec 2025 03:00:55 +0000 (11:00 +0800)
committerJens Axboe <axboe@kernel.dk>
Wed, 7 Jan 2026 15:06:33 +0000 (08:06 -0700)
commitee623c892aa59003fca173de0041abc2ccc2c72d
treeaf9f4c724f1a723f04ff14ccc238891107bf45c3
parent69d26698e4fd44935510553809007151b2fe4db5
block: use bvec iterator helper for bio_may_need_split()

bio_may_need_split() uses bi_vcnt to determine if a bio has a single
segment, but bi_vcnt is unreliable for cloned bios. Cloned bios share
the parent's bi_io_vec array but iterate over a subset via bi_iter,
so bi_vcnt may not reflect the actual segment count being iterated.

Replace the bi_vcnt check with bvec iterator access via
__bvec_iter_bvec(), comparing bi_iter.bi_size against the current
bvec's length. This correctly handles both cloned and non-cloned bios.

Move bi_io_vec into the first cache line adjacent to bi_iter. This is
a sensible layout since bi_io_vec and bi_iter are commonly accessed
together throughout the block layer - every bvec iteration requires
both fields. This displaces bi_end_io to the second cache line, which
is acceptable since bi_end_io and bi_private are always fetched
together in bio_endio() anyway.

The struct layout change requires bio_reset() to preserve and restore
bi_io_vec across the memset, since it now falls within BIO_RESET_BYTES.

Nitesh verified that this patch doesn't regress NVMe 512-byte IO perf [1].

Link: https://lore.kernel.org/linux-block/20251220081607.tvnrltcngl3cc2fh@green245.gost/
Signed-off-by: Ming Lei <ming.lei@redhat.com>
Reviewed-by: Nitesh Shetty <nj.shetty@samsung.com>
Signed-off-by: Jens Axboe <axboe@kernel.dk>
block/bio.c
block/blk.h
include/linux/blk_types.h