block: improve the gap check in __bio_add_pc_page
authorChristoph Hellwig <hch@lst.de>
Mon, 12 Aug 2019 15:39:56 +0000 (17:39 +0200)
committerJens Axboe <axboe@kernel.dk>
Thu, 22 Aug 2019 13:14:36 +0000 (07:14 -0600)
If we can add more data into an existing segment we do not create a gap
per definition, so move the check for a gap after the attempt to merge
into the segment.

Signed-off-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Johannes Thumshirn <jthumshirn@suse.de>
Signed-off-by: Jens Axboe <axboe@kernel.dk>
block/bio.c

index 54769659a434725c5ff08c229f16fd55bc119de6..537d71a30e56bd9a92a4ce11c21f2ac8f47f1d3d 100644 (file)
@@ -710,18 +710,18 @@ static int __bio_add_pc_page(struct request_queue *q, struct bio *bio,
                        goto done;
                }
 
-               /*
-                * If the queue doesn't support SG gaps and adding this
-                * offset would create a gap, disallow it.
-                */
-               if (bvec_gap_to_prev(q, bvec, offset))
-                       return 0;
-
                if (page_is_mergeable(bvec, page, len, offset, &same_page) &&
                    can_add_page_to_seg(q, bvec, page, len, offset)) {
                        bvec->bv_len += len;
                        goto done;
                }
+
+               /*
+                * If the queue doesn't support SG gaps and adding this segment
+                * would create a gap, disallow it.
+                */
+               if (bvec_gap_to_prev(q, bvec, offset))
+                       return 0;
        }
 
        if (bio_full(bio, len))