blk-merge.c (5fef06e8c8c52aa7170dbbb068aa996d83738d38) blk-merge.c (8677142710516d986d932d6f1fba7be8382c1fec)
1/*
2 * Functions related to segment and merge handling
3 */
4#include <linux/kernel.h>
5#include <linux/module.h>
6#include <linux/bio.h>
7#include <linux/blkdev.h>
8#include <linux/scatterlist.h>

--- 63 unchanged lines hidden (view full) ---

72 if (!BIOVEC_SEG_BOUNDARY(q, bvprv, bv))
73 goto new_segment;
74
75 seg_size += bv->bv_len;
76 bvprv = bv;
77 continue;
78 }
79new_segment:
1/*
2 * Functions related to segment and merge handling
3 */
4#include <linux/kernel.h>
5#include <linux/module.h>
6#include <linux/bio.h>
7#include <linux/blkdev.h>
8#include <linux/scatterlist.h>

--- 63 unchanged lines hidden (view full) ---

72 if (!BIOVEC_SEG_BOUNDARY(q, bvprv, bv))
73 goto new_segment;
74
75 seg_size += bv->bv_len;
76 bvprv = bv;
77 continue;
78 }
79new_segment:
80 if (nr_phys_segs == 1 && seg_size > rq->bio->bi_seg_front_size)
81 rq->bio->bi_seg_front_size = seg_size;
82
80 nr_phys_segs++;
81 bvprv = bv;
82 seg_size = bv->bv_len;
83 highprv = high;
84 }
85
83 nr_phys_segs++;
84 bvprv = bv;
85 seg_size = bv->bv_len;
86 highprv = high;
87 }
88
89 if (nr_phys_segs == 1 && seg_size > rq->bio->bi_seg_front_size)
90 rq->bio->bi_seg_front_size = seg_size;
91 if (seg_size > rq->biotail->bi_seg_back_size)
92 rq->biotail->bi_seg_back_size = seg_size;
93
86 rq->nr_phys_segments = nr_phys_segs;
87}
88
89void blk_recount_segments(struct request_queue *q, struct bio *bio)
90{
91 struct request rq;
92 struct bio *nxt = bio->bi_next;
93 rq.q = q;

--- 7 unchanged lines hidden (view full) ---

101EXPORT_SYMBOL(blk_recount_segments);
102
103static int blk_phys_contig_segment(struct request_queue *q, struct bio *bio,
104 struct bio *nxt)
105{
106 if (!test_bit(QUEUE_FLAG_CLUSTER, &q->queue_flags))
107 return 0;
108
94 rq->nr_phys_segments = nr_phys_segs;
95}
96
97void blk_recount_segments(struct request_queue *q, struct bio *bio)
98{
99 struct request rq;
100 struct bio *nxt = bio->bi_next;
101 rq.q = q;

--- 7 unchanged lines hidden (view full) ---

109EXPORT_SYMBOL(blk_recount_segments);
110
111static int blk_phys_contig_segment(struct request_queue *q, struct bio *bio,
112 struct bio *nxt)
113{
114 if (!test_bit(QUEUE_FLAG_CLUSTER, &q->queue_flags))
115 return 0;
116
109 if (bio->bi_size + nxt->bi_size > q->max_segment_size)
117 if (bio->bi_seg_back_size + nxt->bi_seg_front_size >
118 q->max_segment_size)
110 return 0;
111
112 if (!bio_has_data(bio))
113 return 1;
114
115 if (!BIOVEC_PHYS_MERGEABLE(__BVEC_END(bio), __BVEC_START(nxt)))
116 return 0;
117

--- 186 unchanged lines hidden (view full) ---

304
305 return ll_new_hw_segment(q, req, bio);
306}
307
308static int ll_merge_requests_fn(struct request_queue *q, struct request *req,
309 struct request *next)
310{
311 int total_phys_segments;
119 return 0;
120
121 if (!bio_has_data(bio))
122 return 1;
123
124 if (!BIOVEC_PHYS_MERGEABLE(__BVEC_END(bio), __BVEC_START(nxt)))
125 return 0;
126

--- 186 unchanged lines hidden (view full) ---

313
314 return ll_new_hw_segment(q, req, bio);
315}
316
317static int ll_merge_requests_fn(struct request_queue *q, struct request *req,
318 struct request *next)
319{
320 int total_phys_segments;
321 unsigned int seg_size =
322 req->biotail->bi_seg_back_size + next->bio->bi_seg_front_size;
312
313 /*
314 * First check if the either of the requests are re-queued
315 * requests. Can't merge them if they are.
316 */
317 if (req->special || next->special)
318 return 0;
319
320 /*
321 * Will it become too large?
322 */
323 if ((req->nr_sectors + next->nr_sectors) > q->max_sectors)
324 return 0;
325
326 total_phys_segments = req->nr_phys_segments + next->nr_phys_segments;
323
324 /*
325 * First check if the either of the requests are re-queued
326 * requests. Can't merge them if they are.
327 */
328 if (req->special || next->special)
329 return 0;
330
331 /*
332 * Will it become too large?
333 */
334 if ((req->nr_sectors + next->nr_sectors) > q->max_sectors)
335 return 0;
336
337 total_phys_segments = req->nr_phys_segments + next->nr_phys_segments;
327 if (blk_phys_contig_segment(q, req->biotail, next->bio))
338 if (blk_phys_contig_segment(q, req->biotail, next->bio)) {
339 if (req->nr_phys_segments == 1)
340 req->bio->bi_seg_front_size = seg_size;
341 if (next->nr_phys_segments == 1)
342 next->biotail->bi_seg_back_size = seg_size;
328 total_phys_segments--;
343 total_phys_segments--;
344 }
329
330 if (total_phys_segments > q->max_phys_segments)
331 return 0;
332
333 if (total_phys_segments > q->max_hw_segments)
334 return 0;
335
336 /* Merge is OK... */

--- 92 unchanged lines hidden ---
345
346 if (total_phys_segments > q->max_phys_segments)
347 return 0;
348
349 if (total_phys_segments > q->max_hw_segments)
350 return 0;
351
352 /* Merge is OK... */

--- 92 unchanged lines hidden ---