-
Notifications
You must be signed in to change notification settings - Fork 0
block: avoid to use bi_vcnt in bio_may_need_split() #441
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: linus-master_base
Are you sure you want to change the base?
Conversation
|
Upstream branch: d26143b |
4a5ddea to
0ab4e8c
Compare
|
Upstream branch: aacb0a6 |
ffba986 to
4a89ef8
Compare
|
Upstream branch: aacb0a6 |
4a89ef8 to
3d3d1c6
Compare
0ab4e8c to
a2a6d78
Compare
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/ [1] Signed-off-by: Ming Lei <ming.lei@redhat.com> Reviewed-by: Nitesh Shetty <nj.shetty@samsung.com>
bio_iov_bvec_set() creates a cloned bio that borrows a bvec array from an iov_iter. For cloned bios, bi_vcnt is meaningless because iteration is controlled entirely by bi_iter (bi_idx, bi_size, bi_bvec_done), not by bi_vcnt. Remove the incorrect bi_vcnt assignment. Explicitly initialize bi_iter.bi_idx to 0 to ensure iteration starts at the first bvec. While bi_idx is typically already zero from bio initialization, making this explicit improves clarity and correctness. This change also avoids accessing iter->nr_segs, which is an iov_iter implementation detail that block code should not depend on. Signed-off-by: Ming Lei <ming.lei@redhat.com> Reviewed-by: Nitesh Shetty <nj.shetty@samsung.com>
io_import_kbuf() recalculates iter->nr_segs to reflect only the bvecs needed for the requested byte range. This was added to provide an accurate segment count to bio_iov_bvec_set(), which copied nr_segs to bio->bi_vcnt for use as a bio split hint. The previous two patches eliminated this dependency: - bio_may_need_split() now uses bi_iter instead of bi_vcnt for split decisions - bio_iov_bvec_set() no longer copies nr_segs to bi_vcnt Since nr_segs is no longer used for bio split decisions, the recalculation loop is unnecessary. The iov_iter already has the correct bi_size to cap iteration, so an oversized nr_segs is harmless. Link: https://lkml.org/lkml/2025/4/16/351 Signed-off-by: Ming Lei <ming.lei@redhat.com> Reviewed-by: Nitesh Shetty <nj.shetty@samsung.com>
|
Upstream branch: aacb0a6 |
3d3d1c6 to
9ad00c8
Compare
Pull request for series with
subject: block: avoid to use bi_vcnt in bio_may_need_split()
version: 2
url: https://patchwork.kernel.org/project/linux-block/list/?series=1037526