Skip to content

Commit bdced43

Browse files
Ming Leiaxboe
authored andcommitted
block: setup bi_phys_segments after splitting
The number of bio->bi_phys_segments is always obtained during bio splitting, so it is natural to setup it just after bio splitting, then we can avoid to compute nr_segment again during merge. Reviewed-by: Jeff Moyer <[email protected]> Signed-off-by: Ming Lei <[email protected]> Signed-off-by: Jens Axboe <[email protected]>
1 parent 0809e3a commit bdced43

File tree

1 file changed

+22
-7
lines changed

1 file changed

+22
-7
lines changed

block/blk-merge.c

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,16 @@
1111

1212
static struct bio *blk_bio_discard_split(struct request_queue *q,
1313
struct bio *bio,
14-
struct bio_set *bs)
14+
struct bio_set *bs,
15+
unsigned *nsegs)
1516
{
1617
unsigned int max_discard_sectors, granularity;
1718
int alignment;
1819
sector_t tmp;
1920
unsigned split_sectors;
2021

22+
*nsegs = 1;
23+
2124
/* Zero-sector (unknown) and one-sector granularities are the same. */
2225
granularity = max(q->limits.discard_granularity >> 9, 1U);
2326

@@ -51,8 +54,11 @@ static struct bio *blk_bio_discard_split(struct request_queue *q,
5154

5255
static struct bio *blk_bio_write_same_split(struct request_queue *q,
5356
struct bio *bio,
54-
struct bio_set *bs)
57+
struct bio_set *bs,
58+
unsigned *nsegs)
5559
{
60+
*nsegs = 1;
61+
5662
if (!q->limits.max_write_same_sectors)
5763
return NULL;
5864

@@ -64,7 +70,8 @@ static struct bio *blk_bio_write_same_split(struct request_queue *q,
6470

6571
static struct bio *blk_bio_segment_split(struct request_queue *q,
6672
struct bio *bio,
67-
struct bio_set *bs)
73+
struct bio_set *bs,
74+
unsigned *segs)
6875
{
6976
struct bio_vec bv, bvprv, *bvprvp = NULL;
7077
struct bvec_iter iter;
@@ -106,22 +113,30 @@ static struct bio *blk_bio_segment_split(struct request_queue *q,
106113
sectors += bv.bv_len >> 9;
107114
}
108115

116+
*segs = nsegs;
109117
return NULL;
110118
split:
119+
*segs = nsegs;
111120
return bio_split(bio, sectors, GFP_NOIO, bs);
112121
}
113122

114123
void blk_queue_split(struct request_queue *q, struct bio **bio,
115124
struct bio_set *bs)
116125
{
117-
struct bio *split;
126+
struct bio *split, *res;
127+
unsigned nsegs;
118128

119129
if ((*bio)->bi_rw & REQ_DISCARD)
120-
split = blk_bio_discard_split(q, *bio, bs);
130+
split = blk_bio_discard_split(q, *bio, bs, &nsegs);
121131
else if ((*bio)->bi_rw & REQ_WRITE_SAME)
122-
split = blk_bio_write_same_split(q, *bio, bs);
132+
split = blk_bio_write_same_split(q, *bio, bs, &nsegs);
123133
else
124-
split = blk_bio_segment_split(q, *bio, q->bio_split);
134+
split = blk_bio_segment_split(q, *bio, q->bio_split, &nsegs);
135+
136+
/* physical segments can be figured out during splitting */
137+
res = split ? split : *bio;
138+
res->bi_phys_segments = nsegs;
139+
bio_set_flag(res, BIO_SEG_VALID);
125140

126141
if (split) {
127142
bio_chain(split, *bio);

0 commit comments

Comments
 (0)