dm: use bio_split() when splitting out the already processed bio

This change “dm: use bio_split() when splitting out the already processed bio” in Linux kernel is authored by Mike Snitzer <snitzer [at]> on Fri Jun 15 09:35:33 2018 -0400.

dm: use bio_split() when splitting out the already processed bio

Use of bio_clone_bioset() is inefficient if there is no need to clone
the original bio's bio_vec array.  Best to use the bio_clone_fast()
variant.  Also, just using bio_advance() is only part of what is needed
to properly setup the clone -- it doesn't account for the various
bio_integrity() related work that also needs to be performed (see

Address both of these issues by switching from bio_clone_bioset() to

Fixes: 18a25da8 ("dm: ensure bio submission follows a depth-first tree walk")
Cc: # 4.15+, requires removal of '&' before md->queue->bio_split
Reported-by: Christoph Hellwig <>
Reviewed-by: NeilBrown <>
Signed-off-by: Mike Snitzer <>

This Linux change may have been applied to various maintained Linux releases and you can find Linux releases including commit f21c601.

There are 5 lines of Linux source code added/deleted in this change. Code changes to Linux kernel are as follows.

 drivers/md/dm.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)

diff --git a/drivers/md/dm.c b/drivers/md/dm.c
index e65429a..a3b103e 100644
--- a/drivers/md/dm.c
+++ b/drivers/md/dm.c
@@ -1606,10 +1606,9 @@ static blk_qc_t __split_and_process_bio(struct mapped_device *md,
 				 * the usage of io->orig_bio in dm_remap_zone_report()
 				 * won't be affected by this reassignment.
-				struct bio *b = bio_clone_bioset(bio, GFP_NOIO,
-								 &md->queue->bio_split);
+				struct bio *b = bio_split(bio, bio_sectors(bio) - ci.sector_count,
+							  GFP_NOIO, &md->queue->bio_split);>orig_bio = b;
-				bio_advance(bio, (bio_sectors(bio) - ci.sector_count) << 9);
 				bio_chain(b, bio);
 				ret = generic_make_request(bio);

The commit for this change in Linux stable tree is f21c601 (patch).

Leave a Reply

Your email address will not be published. Required fields are marked *