12
12
13
13
#include "blk.h"
14
14
15
- /*
16
- * Check if the two bvecs from two bios can be merged to one segment. If yes,
17
- * no need to check gap between the two bios since the 1st bio and the 1st bvec
18
- * in the 2nd bio can be handled in one segment.
19
- */
20
- static inline bool bios_segs_mergeable (struct request_queue * q ,
21
- struct bio * prev , struct bio_vec * prev_last_bv ,
22
- struct bio_vec * next_first_bv )
23
- {
24
- if (!biovec_phys_mergeable (q , prev_last_bv , next_first_bv ))
25
- return false;
26
- if (prev -> bi_seg_back_size + next_first_bv -> bv_len >
27
- queue_max_segment_size (q ))
28
- return false;
29
- return true;
30
- }
31
-
32
15
static inline bool bio_will_gap (struct request_queue * q ,
33
16
struct request * prev_rq , struct bio * prev , struct bio * next )
34
17
{
@@ -60,7 +43,7 @@ static inline bool bio_will_gap(struct request_queue *q,
60
43
*/
61
44
bio_get_last_bvec (prev , & pb );
62
45
bio_get_first_bvec (next , & nb );
63
- if (bios_segs_mergeable ( q , prev , & pb , & nb ))
46
+ if (biovec_phys_mergeable ( q , & pb , & nb ))
64
47
return false;
65
48
return __bvec_gap_to_prev (q , & pb , nb .bv_offset );
66
49
}
@@ -179,8 +162,7 @@ static unsigned get_max_segment_size(struct request_queue *q,
179
162
* variables.
180
163
*/
181
164
static bool bvec_split_segs (struct request_queue * q , struct bio_vec * bv ,
182
- unsigned * nsegs , unsigned * last_seg_size ,
183
- unsigned * front_seg_size , unsigned * sectors , unsigned max_segs )
165
+ unsigned * nsegs , unsigned * sectors , unsigned max_segs )
184
166
{
185
167
unsigned len = bv -> bv_len ;
186
168
unsigned total_len = 0 ;
@@ -202,28 +184,12 @@ static bool bvec_split_segs(struct request_queue *q, struct bio_vec *bv,
202
184
break ;
203
185
}
204
186
205
- if (!new_nsegs )
206
- return !!len ;
207
-
208
- /* update front segment size */
209
- if (!* nsegs ) {
210
- unsigned first_seg_size ;
211
-
212
- if (new_nsegs == 1 )
213
- first_seg_size = get_max_segment_size (q , bv -> bv_offset );
214
- else
215
- first_seg_size = queue_max_segment_size (q );
216
-
217
- if (* front_seg_size < first_seg_size )
218
- * front_seg_size = first_seg_size ;
187
+ if (new_nsegs ) {
188
+ * nsegs += new_nsegs ;
189
+ if (sectors )
190
+ * sectors += total_len >> 9 ;
219
191
}
220
192
221
- /* update other varibles */
222
- * last_seg_size = seg_size ;
223
- * nsegs += new_nsegs ;
224
- if (sectors )
225
- * sectors += total_len >> 9 ;
226
-
227
193
/* split in the middle of the bvec if len != 0 */
228
194
return !!len ;
229
195
}
@@ -235,8 +201,7 @@ static struct bio *blk_bio_segment_split(struct request_queue *q,
235
201
{
236
202
struct bio_vec bv , bvprv , * bvprvp = NULL ;
237
203
struct bvec_iter iter ;
238
- unsigned seg_size = 0 , nsegs = 0 , sectors = 0 ;
239
- unsigned front_seg_size = bio -> bi_seg_front_size ;
204
+ unsigned nsegs = 0 , sectors = 0 ;
240
205
bool do_split = true;
241
206
struct bio * new = NULL ;
242
207
const unsigned max_sectors = get_max_io_size (q , bio );
@@ -260,8 +225,6 @@ static struct bio *blk_bio_segment_split(struct request_queue *q,
260
225
/* split in the middle of bvec */
261
226
bv .bv_len = (max_sectors - sectors ) << 9 ;
262
227
bvec_split_segs (q , & bv , & nsegs ,
263
- & seg_size ,
264
- & front_seg_size ,
265
228
& sectors , max_segs );
266
229
}
267
230
goto split ;
@@ -275,12 +238,9 @@ static struct bio *blk_bio_segment_split(struct request_queue *q,
275
238
276
239
if (bv .bv_offset + bv .bv_len <= PAGE_SIZE ) {
277
240
nsegs ++ ;
278
- seg_size = bv .bv_len ;
279
241
sectors += bv .bv_len >> 9 ;
280
- if (nsegs == 1 && seg_size > front_seg_size )
281
- front_seg_size = seg_size ;
282
- } else if (bvec_split_segs (q , & bv , & nsegs , & seg_size ,
283
- & front_seg_size , & sectors , max_segs )) {
242
+ } else if (bvec_split_segs (q , & bv , & nsegs , & sectors ,
243
+ max_segs )) {
284
244
goto split ;
285
245
}
286
246
}
@@ -295,10 +255,6 @@ static struct bio *blk_bio_segment_split(struct request_queue *q,
295
255
bio = new ;
296
256
}
297
257
298
- bio -> bi_seg_front_size = front_seg_size ;
299
- if (seg_size > bio -> bi_seg_back_size )
300
- bio -> bi_seg_back_size = seg_size ;
301
-
302
258
return do_split ? new : NULL ;
303
259
}
304
260
@@ -353,18 +309,13 @@ EXPORT_SYMBOL(blk_queue_split);
353
309
static unsigned int __blk_recalc_rq_segments (struct request_queue * q ,
354
310
struct bio * bio )
355
311
{
356
- struct bio_vec uninitialized_var (bv ), bvprv = { NULL };
357
- unsigned int seg_size , nr_phys_segs ;
358
- unsigned front_seg_size ;
359
- struct bio * fbio , * bbio ;
312
+ unsigned int nr_phys_segs = 0 ;
360
313
struct bvec_iter iter ;
361
- bool new_bio = false ;
314
+ struct bio_vec bv ;
362
315
363
316
if (!bio )
364
317
return 0 ;
365
318
366
- front_seg_size = bio -> bi_seg_front_size ;
367
-
368
319
switch (bio_op (bio )) {
369
320
case REQ_OP_DISCARD :
370
321
case REQ_OP_SECURE_ERASE :
@@ -374,42 +325,11 @@ static unsigned int __blk_recalc_rq_segments(struct request_queue *q,
374
325
return 1 ;
375
326
}
376
327
377
- fbio = bio ;
378
- seg_size = 0 ;
379
- nr_phys_segs = 0 ;
380
328
for_each_bio (bio ) {
381
- bio_for_each_bvec (bv , bio , iter ) {
382
- if (new_bio ) {
383
- if (seg_size + bv .bv_len
384
- > queue_max_segment_size (q ))
385
- goto new_segment ;
386
- if (!biovec_phys_mergeable (q , & bvprv , & bv ))
387
- goto new_segment ;
388
-
389
- seg_size += bv .bv_len ;
390
-
391
- if (nr_phys_segs == 1 && seg_size >
392
- front_seg_size )
393
- front_seg_size = seg_size ;
394
-
395
- continue ;
396
- }
397
- new_segment :
398
- bvec_split_segs (q , & bv , & nr_phys_segs , & seg_size ,
399
- & front_seg_size , NULL , UINT_MAX );
400
- new_bio = false;
401
- }
402
- bbio = bio ;
403
- if (likely (bio -> bi_iter .bi_size )) {
404
- bvprv = bv ;
405
- new_bio = true;
406
- }
329
+ bio_for_each_bvec (bv , bio , iter )
330
+ bvec_split_segs (q , & bv , & nr_phys_segs , NULL , UINT_MAX );
407
331
}
408
332
409
- fbio -> bi_seg_front_size = front_seg_size ;
410
- if (seg_size > bbio -> bi_seg_back_size )
411
- bbio -> bi_seg_back_size = seg_size ;
412
-
413
333
return nr_phys_segs ;
414
334
}
415
335
@@ -429,24 +349,6 @@ void blk_recount_segments(struct request_queue *q, struct bio *bio)
429
349
bio_set_flag (bio , BIO_SEG_VALID );
430
350
}
431
351
432
- static int blk_phys_contig_segment (struct request_queue * q , struct bio * bio ,
433
- struct bio * nxt )
434
- {
435
- struct bio_vec end_bv = { NULL }, nxt_bv ;
436
-
437
- if (bio -> bi_seg_back_size + nxt -> bi_seg_front_size >
438
- queue_max_segment_size (q ))
439
- return 0 ;
440
-
441
- if (!bio_has_data (bio ))
442
- return 1 ;
443
-
444
- bio_get_last_bvec (bio , & end_bv );
445
- bio_get_first_bvec (nxt , & nxt_bv );
446
-
447
- return biovec_phys_mergeable (q , & end_bv , & nxt_bv );
448
- }
449
-
450
352
static inline struct scatterlist * blk_next_sg (struct scatterlist * * sg ,
451
353
struct scatterlist * sglist )
452
354
{
@@ -706,8 +608,6 @@ static int ll_merge_requests_fn(struct request_queue *q, struct request *req,
706
608
struct request * next )
707
609
{
708
610
int total_phys_segments ;
709
- unsigned int seg_size =
710
- req -> biotail -> bi_seg_back_size + next -> bio -> bi_seg_front_size ;
711
611
712
612
if (req_gap_back_merge (req , next -> bio ))
713
613
return 0 ;
@@ -720,14 +620,6 @@ static int ll_merge_requests_fn(struct request_queue *q, struct request *req,
720
620
return 0 ;
721
621
722
622
total_phys_segments = req -> nr_phys_segments + next -> nr_phys_segments ;
723
- if (blk_phys_contig_segment (q , req -> biotail , next -> bio )) {
724
- if (req -> nr_phys_segments == 1 )
725
- req -> bio -> bi_seg_front_size = seg_size ;
726
- if (next -> nr_phys_segments == 1 )
727
- next -> biotail -> bi_seg_back_size = seg_size ;
728
- total_phys_segments -- ;
729
- }
730
-
731
623
if (total_phys_segments > queue_max_segments (q ))
732
624
return 0 ;
733
625
0 commit comments