Commit 1d6165851cd8e3f919d446cd6da35dee44e8837e

Authored by Dmitry Monakhov
Committed by Jens Axboe
1 parent c84a301d4a

block: fix bio_add_page for non trivial merge_bvec_fn case

We have to properly decrease bi_size in order to merge_bvec_fn return
right result.  Otherwise this result in false merge rejects for two
absolutely valid bio_vecs.  This may cause significant performance
penalty for example fs_block_size == 1k and block device is raid0 with
small chunk_size = 8k. Then it is impossible to merge 7-th fs-block in
to bio which already has 6 fs-blocks.

Cc: <stable@kernel.org>
Signed-off-by: Dmitry Monakhov <dmonakhov@openvz.org>
Signed-off-by: Jens Axboe <jens.axboe@oracle.com>

Showing 1 changed file with 6 additions and 1 deletions Side-by-side Diff

... ... @@ -542,13 +542,18 @@
542 542  
543 543 if (page == prev->bv_page &&
544 544 offset == prev->bv_offset + prev->bv_len) {
  545 + unsigned int prev_bv_len = prev->bv_len;
545 546 prev->bv_len += len;
546 547  
547 548 if (q->merge_bvec_fn) {
548 549 struct bvec_merge_data bvm = {
  550 + /* prev_bvec is already charged in
  551 + bi_size, discharge it in order to
  552 + simulate merging updated prev_bvec
  553 + as new bvec. */
549 554 .bi_bdev = bio->bi_bdev,
550 555 .bi_sector = bio->bi_sector,
551   - .bi_size = bio->bi_size,
  556 + .bi_size = bio->bi_size - prev_bv_len,
552 557 .bi_rw = bio->bi_rw,
553 558 };
554 559