Commit 4e980507 authored by Jens Axboe's avatar Jens Axboe Committed by Linus Torvalds

[PATCH] fix bad segment coalescing in blk_recalc_rq_segments()

blk_recalc_rq_segments forgots to take ->max_segment_size into account and
gladly merges segments bigger than we can support, thus underestimating the
number of segments needed to fill it.
Signed-off-by: default avatarJens Axboe <axboe@suse.de>
Signed-off-by: default avatarAndrew Morton <akpm@osdl.org>
Signed-off-by: default avatarLinus Torvalds <torvalds@osdl.org>
parent af39b248
...@@ -2685,22 +2685,36 @@ void blk_recalc_rq_segments(struct request *rq) ...@@ -2685,22 +2685,36 @@ void blk_recalc_rq_segments(struct request *rq)
{ {
struct bio *bio, *prevbio = NULL; struct bio *bio, *prevbio = NULL;
int nr_phys_segs, nr_hw_segs; int nr_phys_segs, nr_hw_segs;
unsigned int phys_size, hw_size;
request_queue_t *q = rq->q;
if (!rq->bio) if (!rq->bio)
return; return;
nr_phys_segs = nr_hw_segs = 0; phys_size = hw_size = nr_phys_segs = nr_hw_segs = 0;
rq_for_each_bio(bio, rq) { rq_for_each_bio(bio, rq) {
/* Force bio hw/phys segs to be recalculated. */ /* Force bio hw/phys segs to be recalculated. */
bio->bi_flags &= ~(1 << BIO_SEG_VALID); bio->bi_flags &= ~(1 << BIO_SEG_VALID);
nr_phys_segs += bio_phys_segments(rq->q, bio); nr_phys_segs += bio_phys_segments(q, bio);
nr_hw_segs += bio_hw_segments(rq->q, bio); nr_hw_segs += bio_hw_segments(q, bio);
if (prevbio) { if (prevbio) {
if (blk_phys_contig_segment(rq->q, prevbio, bio)) int pseg = phys_size + prevbio->bi_size + bio->bi_size;
int hseg = hw_size + prevbio->bi_size + bio->bi_size;
if (blk_phys_contig_segment(q, prevbio, bio) &&
pseg <= q->max_segment_size) {
nr_phys_segs--; nr_phys_segs--;
if (blk_hw_contig_segment(rq->q, prevbio, bio)) phys_size += prevbio->bi_size + bio->bi_size;
} else
phys_size = 0;
if (blk_hw_contig_segment(q, prevbio, bio) &&
hseg <= q->max_segment_size) {
nr_hw_segs--; nr_hw_segs--;
hw_size += prevbio->bi_size + bio->bi_size;
} else
hw_size = 0;
} }
prevbio = bio; prevbio = bio;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment