Skip to content

Commit 6a501bf

Browse files
Ming Leiaxboe
authored andcommitted
blk-merge: compute bio->bi_seg_front_size efficiently
It is enough to check and compute bio->bi_seg_front_size just after the 1st segment is found, but current code checks that for each bvec, which is inefficient. This patch follows the way in __blk_recalc_rq_segments() for computing bio->bi_seg_front_size, and it is more efficient and code becomes more readable too. Signed-off-by: Ming Lei <ming.lei@redhat.com> Signed-off-by: Jens Axboe <axboe@kernel.dk>
1 parent 92681ec commit 6a501bf

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

block/blk-merge.c

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -146,22 +146,21 @@ static struct bio *blk_bio_segment_split(struct request_queue *q,
146146
bvprvp = &bvprv;
147147
sectors += bv.bv_len >> 9;
148148

149-
if (nsegs == 1 && seg_size > front_seg_size)
150-
front_seg_size = seg_size;
151149
continue;
152150
}
153151
new_segment:
154152
if (nsegs == queue_max_segments(q))
155153
goto split;
156154

155+
if (nsegs == 1 && seg_size > front_seg_size)
156+
front_seg_size = seg_size;
157+
157158
nsegs++;
158159
bvprv = bv;
159160
bvprvp = &bvprv;
160161
seg_size = bv.bv_len;
161162
sectors += bv.bv_len >> 9;
162163

163-
if (nsegs == 1 && seg_size > front_seg_size)
164-
front_seg_size = seg_size;
165164
}
166165

167166
do_split = false;
@@ -174,6 +173,8 @@ static struct bio *blk_bio_segment_split(struct request_queue *q,
174173
bio = new;
175174
}
176175

176+
if (nsegs == 1 && seg_size > front_seg_size)
177+
front_seg_size = seg_size;
177178
bio->bi_seg_front_size = front_seg_size;
178179
if (seg_size > bio->bi_seg_back_size)
179180
bio->bi_seg_back_size = seg_size;

0 commit comments

Comments
 (0)