1b2441318SGreg Kroah-Hartman // SPDX-License-Identifier: GPL-2.0 2d6d48196SJens Axboe /* 3d6d48196SJens Axboe * Functions related to segment and merge handling 4d6d48196SJens Axboe */ 5d6d48196SJens Axboe #include <linux/kernel.h> 6d6d48196SJens Axboe #include <linux/module.h> 7d6d48196SJens Axboe #include <linux/bio.h> 8d6d48196SJens Axboe #include <linux/blkdev.h> 9fe45e630SChristoph Hellwig #include <linux/blk-integrity.h> 10d6d48196SJens Axboe #include <linux/scatterlist.h> 1182d981d4SChristoph Hellwig #include <linux/part_stat.h> 126b2b0459STejun Heo #include <linux/blk-cgroup.h> 13d6d48196SJens Axboe 14cda22646SMike Krinkin #include <trace/events/block.h> 15cda22646SMike Krinkin 16d6d48196SJens Axboe #include "blk.h" 172aa7745bSChristoph Hellwig #include "blk-mq-sched.h" 188e756373SBaolin Wang #include "blk-rq-qos.h" 19a7b36ee6SJens Axboe #include "blk-throttle.h" 20d6d48196SJens Axboe 21ff18d77bSChristoph Hellwig static inline void bio_get_first_bvec(struct bio *bio, struct bio_vec *bv) 22ff18d77bSChristoph Hellwig { 23ff18d77bSChristoph Hellwig *bv = mp_bvec_iter_bvec(bio->bi_io_vec, bio->bi_iter); 24ff18d77bSChristoph Hellwig } 25ff18d77bSChristoph Hellwig 26ff18d77bSChristoph Hellwig static inline void bio_get_last_bvec(struct bio *bio, struct bio_vec *bv) 27ff18d77bSChristoph Hellwig { 28ff18d77bSChristoph Hellwig struct bvec_iter iter = bio->bi_iter; 29ff18d77bSChristoph Hellwig int idx; 30ff18d77bSChristoph Hellwig 31ff18d77bSChristoph Hellwig bio_get_first_bvec(bio, bv); 32ff18d77bSChristoph Hellwig if (bv->bv_len == bio->bi_iter.bi_size) 33ff18d77bSChristoph Hellwig return; /* this bio only has a single bvec */ 34ff18d77bSChristoph Hellwig 35ff18d77bSChristoph Hellwig bio_advance_iter(bio, &iter, iter.bi_size); 36ff18d77bSChristoph Hellwig 37ff18d77bSChristoph Hellwig if (!iter.bi_bvec_done) 38ff18d77bSChristoph Hellwig idx = iter.bi_idx - 1; 39ff18d77bSChristoph Hellwig else /* in the middle of bvec */ 40ff18d77bSChristoph Hellwig idx = iter.bi_idx; 41ff18d77bSChristoph Hellwig 42ff18d77bSChristoph Hellwig *bv = bio->bi_io_vec[idx]; 43ff18d77bSChristoph Hellwig 44ff18d77bSChristoph Hellwig /* 45ff18d77bSChristoph Hellwig * iter.bi_bvec_done records actual length of the last bvec 46ff18d77bSChristoph Hellwig * if this bio ends in the middle of one io vector 47ff18d77bSChristoph Hellwig */ 48ff18d77bSChristoph Hellwig if (iter.bi_bvec_done) 49ff18d77bSChristoph Hellwig bv->bv_len = iter.bi_bvec_done; 50ff18d77bSChristoph Hellwig } 51ff18d77bSChristoph Hellwig 52e9907009SChristoph Hellwig static inline bool bio_will_gap(struct request_queue *q, 53e9907009SChristoph Hellwig struct request *prev_rq, struct bio *prev, struct bio *next) 54e9907009SChristoph Hellwig { 55e9907009SChristoph Hellwig struct bio_vec pb, nb; 56e9907009SChristoph Hellwig 57e9907009SChristoph Hellwig if (!bio_has_data(prev) || !queue_virt_boundary(q)) 58e9907009SChristoph Hellwig return false; 59e9907009SChristoph Hellwig 60e9907009SChristoph Hellwig /* 61e9907009SChristoph Hellwig * Don't merge if the 1st bio starts with non-zero offset, otherwise it 62e9907009SChristoph Hellwig * is quite difficult to respect the sg gap limit. We work hard to 63e9907009SChristoph Hellwig * merge a huge number of small single bios in case of mkfs. 64e9907009SChristoph Hellwig */ 65e9907009SChristoph Hellwig if (prev_rq) 66e9907009SChristoph Hellwig bio_get_first_bvec(prev_rq->bio, &pb); 67e9907009SChristoph Hellwig else 68e9907009SChristoph Hellwig bio_get_first_bvec(prev, &pb); 69df376b2eSJohannes Thumshirn if (pb.bv_offset & queue_virt_boundary(q)) 70e9907009SChristoph Hellwig return true; 71e9907009SChristoph Hellwig 72e9907009SChristoph Hellwig /* 73e9907009SChristoph Hellwig * We don't need to worry about the situation that the merged segment 74e9907009SChristoph Hellwig * ends in unaligned virt boundary: 75e9907009SChristoph Hellwig * 76e9907009SChristoph Hellwig * - if 'pb' ends aligned, the merged segment ends aligned 77e9907009SChristoph Hellwig * - if 'pb' ends unaligned, the next bio must include 78e9907009SChristoph Hellwig * one single bvec of 'nb', otherwise the 'nb' can't 79e9907009SChristoph Hellwig * merge with 'pb' 80e9907009SChristoph Hellwig */ 81e9907009SChristoph Hellwig bio_get_last_bvec(prev, &pb); 82e9907009SChristoph Hellwig bio_get_first_bvec(next, &nb); 83200a9affSChristoph Hellwig if (biovec_phys_mergeable(q, &pb, &nb)) 84e9907009SChristoph Hellwig return false; 85e9907009SChristoph Hellwig return __bvec_gap_to_prev(q, &pb, nb.bv_offset); 86e9907009SChristoph Hellwig } 87e9907009SChristoph Hellwig 88e9907009SChristoph Hellwig static inline bool req_gap_back_merge(struct request *req, struct bio *bio) 89e9907009SChristoph Hellwig { 90e9907009SChristoph Hellwig return bio_will_gap(req->q, req, req->biotail, bio); 91e9907009SChristoph Hellwig } 92e9907009SChristoph Hellwig 93e9907009SChristoph Hellwig static inline bool req_gap_front_merge(struct request *req, struct bio *bio) 94e9907009SChristoph Hellwig { 95e9907009SChristoph Hellwig return bio_will_gap(req->q, NULL, bio, req->bio); 96e9907009SChristoph Hellwig } 97e9907009SChristoph Hellwig 98*b6dc6198SChristoph Hellwig /* 99*b6dc6198SChristoph Hellwig * The max size one bio can handle is UINT_MAX becasue bvec_iter.bi_size 100*b6dc6198SChristoph Hellwig * is defined as 'unsigned int', meantime it has to be aligned to with the 101*b6dc6198SChristoph Hellwig * logical block size, which is the minimum accepted unit by hardware. 102*b6dc6198SChristoph Hellwig */ 103*b6dc6198SChristoph Hellwig static unsigned int bio_allowed_max_sectors(struct request_queue *q) 104*b6dc6198SChristoph Hellwig { 105*b6dc6198SChristoph Hellwig return round_down(UINT_MAX, queue_logical_block_size(q)) >> 9; 106*b6dc6198SChristoph Hellwig } 107*b6dc6198SChristoph Hellwig 1085a97806fSChristoph Hellwig static struct bio *bio_split_discard(struct bio *bio, struct request_queue *q, 1095a97806fSChristoph Hellwig unsigned *nsegs, struct bio_set *bs) 11054efd50bSKent Overstreet { 11154efd50bSKent Overstreet unsigned int max_discard_sectors, granularity; 11254efd50bSKent Overstreet int alignment; 11354efd50bSKent Overstreet sector_t tmp; 11454efd50bSKent Overstreet unsigned split_sectors; 11554efd50bSKent Overstreet 116bdced438SMing Lei *nsegs = 1; 117bdced438SMing Lei 11854efd50bSKent Overstreet /* Zero-sector (unknown) and one-sector granularities are the same. */ 11954efd50bSKent Overstreet granularity = max(q->limits.discard_granularity >> 9, 1U); 12054efd50bSKent Overstreet 1211adfc5e4SMing Lei max_discard_sectors = min(q->limits.max_discard_sectors, 1221adfc5e4SMing Lei bio_allowed_max_sectors(q)); 12354efd50bSKent Overstreet max_discard_sectors -= max_discard_sectors % granularity; 12454efd50bSKent Overstreet 12554efd50bSKent Overstreet if (unlikely(!max_discard_sectors)) { 12654efd50bSKent Overstreet /* XXX: warn */ 12754efd50bSKent Overstreet return NULL; 12854efd50bSKent Overstreet } 12954efd50bSKent Overstreet 13054efd50bSKent Overstreet if (bio_sectors(bio) <= max_discard_sectors) 13154efd50bSKent Overstreet return NULL; 13254efd50bSKent Overstreet 13354efd50bSKent Overstreet split_sectors = max_discard_sectors; 13454efd50bSKent Overstreet 13554efd50bSKent Overstreet /* 13654efd50bSKent Overstreet * If the next starting sector would be misaligned, stop the discard at 13754efd50bSKent Overstreet * the previous aligned sector. 13854efd50bSKent Overstreet */ 13954efd50bSKent Overstreet alignment = (q->limits.discard_alignment >> 9) % granularity; 14054efd50bSKent Overstreet 14154efd50bSKent Overstreet tmp = bio->bi_iter.bi_sector + split_sectors - alignment; 14254efd50bSKent Overstreet tmp = sector_div(tmp, granularity); 14354efd50bSKent Overstreet 14454efd50bSKent Overstreet if (split_sectors > tmp) 14554efd50bSKent Overstreet split_sectors -= tmp; 14654efd50bSKent Overstreet 14754efd50bSKent Overstreet return bio_split(bio, split_sectors, GFP_NOIO, bs); 14854efd50bSKent Overstreet } 14954efd50bSKent Overstreet 1505a97806fSChristoph Hellwig static struct bio *bio_split_write_zeroes(struct bio *bio, 1515a97806fSChristoph Hellwig struct request_queue *q, unsigned *nsegs, struct bio_set *bs) 152885fa13fSChristoph Hellwig { 153d665e12aSChristoph Hellwig *nsegs = 0; 154885fa13fSChristoph Hellwig 155885fa13fSChristoph Hellwig if (!q->limits.max_write_zeroes_sectors) 156885fa13fSChristoph Hellwig return NULL; 157885fa13fSChristoph Hellwig 158885fa13fSChristoph Hellwig if (bio_sectors(bio) <= q->limits.max_write_zeroes_sectors) 159885fa13fSChristoph Hellwig return NULL; 160885fa13fSChristoph Hellwig 161885fa13fSChristoph Hellwig return bio_split(bio, q->limits.max_write_zeroes_sectors, GFP_NOIO, bs); 162885fa13fSChristoph Hellwig } 163885fa13fSChristoph Hellwig 1649cc5169cSBart Van Assche /* 1659cc5169cSBart Van Assche * Return the maximum number of sectors from the start of a bio that may be 1669cc5169cSBart Van Assche * submitted as a single request to a block device. If enough sectors remain, 1679cc5169cSBart Van Assche * align the end to the physical block size. Otherwise align the end to the 1689cc5169cSBart Van Assche * logical block size. This approach minimizes the number of non-aligned 1699cc5169cSBart Van Assche * requests that are submitted to a block device if the start of a bio is not 1709cc5169cSBart Van Assche * aligned to a physical block boundary. 1719cc5169cSBart Van Assche */ 1725a97806fSChristoph Hellwig static inline unsigned get_max_io_size(struct bio *bio, 1735a97806fSChristoph Hellwig struct request_queue *q) 174d0e5fbb0SMing Lei { 1759cc5169cSBart Van Assche unsigned pbs = queue_physical_block_size(q) >> SECTOR_SHIFT; 1769cc5169cSBart Van Assche unsigned lbs = queue_logical_block_size(q) >> SECTOR_SHIFT; 177efef739dSChristoph Hellwig unsigned max_sectors = queue_max_sectors(q), start, end; 178d0e5fbb0SMing Lei 179efef739dSChristoph Hellwig if (q->limits.chunk_sectors) { 180efef739dSChristoph Hellwig max_sectors = min(max_sectors, 181efef739dSChristoph Hellwig blk_chunk_sectors_left(bio->bi_iter.bi_sector, 182efef739dSChristoph Hellwig q->limits.chunk_sectors)); 183efef739dSChristoph Hellwig } 184d0e5fbb0SMing Lei 18584613bedSChristoph Hellwig start = bio->bi_iter.bi_sector & (pbs - 1); 18684613bedSChristoph Hellwig end = (start + max_sectors) & ~(pbs - 1); 18784613bedSChristoph Hellwig if (end > start) 18884613bedSChristoph Hellwig return end - start; 18984613bedSChristoph Hellwig return max_sectors & ~(lbs - 1); 190d0e5fbb0SMing Lei } 191d0e5fbb0SMing Lei 192429120f3SMing Lei static inline unsigned get_max_segment_size(const struct request_queue *q, 193429120f3SMing Lei struct page *start_page, 194429120f3SMing Lei unsigned long offset) 195dcebd755SMing Lei { 196dcebd755SMing Lei unsigned long mask = queue_segment_boundary(q); 197dcebd755SMing Lei 198429120f3SMing Lei offset = mask & (page_to_phys(start_page) + offset); 1994a2f704eSMing Lei 2004a2f704eSMing Lei /* 2014a2f704eSMing Lei * overflow may be triggered in case of zero page physical address 2024a2f704eSMing Lei * on 32bit arch, use queue's max segment size when that happens. 2034a2f704eSMing Lei */ 2044a2f704eSMing Lei return min_not_zero(mask - offset + 1, 2054a2f704eSMing Lei (unsigned long)queue_max_segment_size(q)); 206dcebd755SMing Lei } 207dcebd755SMing Lei 208708b25b3SBart Van Assche /** 209708b25b3SBart Van Assche * bvec_split_segs - verify whether or not a bvec should be split in the middle 210708b25b3SBart Van Assche * @q: [in] request queue associated with the bio associated with @bv 211708b25b3SBart Van Assche * @bv: [in] bvec to examine 212708b25b3SBart Van Assche * @nsegs: [in,out] Number of segments in the bio being built. Incremented 213708b25b3SBart Van Assche * by the number of segments from @bv that may be appended to that 214708b25b3SBart Van Assche * bio without exceeding @max_segs 21567927d22SKeith Busch * @bytes: [in,out] Number of bytes in the bio being built. Incremented 21667927d22SKeith Busch * by the number of bytes from @bv that may be appended to that 21767927d22SKeith Busch * bio without exceeding @max_bytes 218708b25b3SBart Van Assche * @max_segs: [in] upper bound for *@nsegs 21967927d22SKeith Busch * @max_bytes: [in] upper bound for *@bytes 220708b25b3SBart Van Assche * 221708b25b3SBart Van Assche * When splitting a bio, it can happen that a bvec is encountered that is too 222708b25b3SBart Van Assche * big to fit in a single segment and hence that it has to be split in the 223708b25b3SBart Van Assche * middle. This function verifies whether or not that should happen. The value 224708b25b3SBart Van Assche * %true is returned if and only if appending the entire @bv to a bio with 225708b25b3SBart Van Assche * *@nsegs segments and *@sectors sectors would make that bio unacceptable for 226708b25b3SBart Van Assche * the block driver. 227dcebd755SMing Lei */ 228af2c68feSBart Van Assche static bool bvec_split_segs(const struct request_queue *q, 229af2c68feSBart Van Assche const struct bio_vec *bv, unsigned *nsegs, 23067927d22SKeith Busch unsigned *bytes, unsigned max_segs, 23167927d22SKeith Busch unsigned max_bytes) 232dcebd755SMing Lei { 23367927d22SKeith Busch unsigned max_len = min(max_bytes, UINT_MAX) - *bytes; 234708b25b3SBart Van Assche unsigned len = min(bv->bv_len, max_len); 235dcebd755SMing Lei unsigned total_len = 0; 236ff9811b3SBart Van Assche unsigned seg_size = 0; 237dcebd755SMing Lei 238ff9811b3SBart Van Assche while (len && *nsegs < max_segs) { 239429120f3SMing Lei seg_size = get_max_segment_size(q, bv->bv_page, 240429120f3SMing Lei bv->bv_offset + total_len); 241dcebd755SMing Lei seg_size = min(seg_size, len); 242dcebd755SMing Lei 243ff9811b3SBart Van Assche (*nsegs)++; 244dcebd755SMing Lei total_len += seg_size; 245dcebd755SMing Lei len -= seg_size; 246dcebd755SMing Lei 247dcebd755SMing Lei if ((bv->bv_offset + total_len) & queue_virt_boundary(q)) 248dcebd755SMing Lei break; 249dcebd755SMing Lei } 250dcebd755SMing Lei 25167927d22SKeith Busch *bytes += total_len; 252dcebd755SMing Lei 253708b25b3SBart Van Assche /* tell the caller to split the bvec if it is too big to fit */ 254708b25b3SBart Van Assche return len > 0 || bv->bv_len > max_len; 255dcebd755SMing Lei } 256dcebd755SMing Lei 257dad77584SBart Van Assche /** 2585a97806fSChristoph Hellwig * bio_split_rw - split a bio in two bios 259dad77584SBart Van Assche * @bio: [in] bio to be split 2605a97806fSChristoph Hellwig * @q: [in] request queue pointer 261dad77584SBart Van Assche * @segs: [out] number of segments in the bio with the first half of the sectors 2625a97806fSChristoph Hellwig * @bs: [in] bio set to allocate the clone from 263a85b3637SChristoph Hellwig * @max_bytes: [in] maximum number of bytes per bio 264dad77584SBart Van Assche * 265dad77584SBart Van Assche * Clone @bio, update the bi_iter of the clone to represent the first sectors 266dad77584SBart Van Assche * of @bio and update @bio->bi_iter to represent the remaining sectors. The 267dad77584SBart Van Assche * following is guaranteed for the cloned bio: 268a85b3637SChristoph Hellwig * - That it has at most @max_bytes worth of data 269dad77584SBart Van Assche * - That it has at most queue_max_segments(@q) segments. 270dad77584SBart Van Assche * 271dad77584SBart Van Assche * Except for discard requests the cloned bio will point at the bi_io_vec of 272dad77584SBart Van Assche * the original bio. It is the responsibility of the caller to ensure that the 273dad77584SBart Van Assche * original bio is not freed before the cloned bio. The caller is also 274dad77584SBart Van Assche * responsible for ensuring that @bs is only destroyed after processing of the 275dad77584SBart Van Assche * split bio has finished. 276dad77584SBart Van Assche */ 2775a97806fSChristoph Hellwig static struct bio *bio_split_rw(struct bio *bio, struct request_queue *q, 278a85b3637SChristoph Hellwig unsigned *segs, struct bio_set *bs, unsigned max_bytes) 27954efd50bSKent Overstreet { 2805014c311SJens Axboe struct bio_vec bv, bvprv, *bvprvp = NULL; 28154efd50bSKent Overstreet struct bvec_iter iter; 28267927d22SKeith Busch unsigned nsegs = 0, bytes = 0; 28305b700baSMing Lei const unsigned max_segs = queue_max_segments(q); 28454efd50bSKent Overstreet 285dcebd755SMing Lei bio_for_each_bvec(bv, bio, iter) { 28654efd50bSKent Overstreet /* 28754efd50bSKent Overstreet * If the queue doesn't support SG gaps and adding this 28854efd50bSKent Overstreet * offset would create a gap, disallow it. 28954efd50bSKent Overstreet */ 2905014c311SJens Axboe if (bvprvp && bvec_gap_to_prev(q, bvprvp, bv.bv_offset)) 29154efd50bSKent Overstreet goto split; 29254efd50bSKent Overstreet 29305b700baSMing Lei if (nsegs < max_segs && 29467927d22SKeith Busch bytes + bv.bv_len <= max_bytes && 295708b25b3SBart Van Assche bv.bv_offset + bv.bv_len <= PAGE_SIZE) { 296708b25b3SBart Van Assche nsegs++; 29767927d22SKeith Busch bytes += bv.bv_len; 29867927d22SKeith Busch } else if (bvec_split_segs(q, &bv, &nsegs, &bytes, max_segs, 29967927d22SKeith Busch max_bytes)) { 300e36f6204SKeith Busch goto split; 301e36f6204SKeith Busch } 302e36f6204SKeith Busch 30354efd50bSKent Overstreet bvprv = bv; 304578270bfSMing Lei bvprvp = &bvprv; 30554efd50bSKent Overstreet } 30654efd50bSKent Overstreet 307d627065dSChristoph Hellwig *segs = nsegs; 308d627065dSChristoph Hellwig return NULL; 30954efd50bSKent Overstreet split: 310bdced438SMing Lei *segs = nsegs; 311cc29e1bfSJeffle Xu 312cc29e1bfSJeffle Xu /* 31367927d22SKeith Busch * Individual bvecs might not be logical block aligned. Round down the 31467927d22SKeith Busch * split size so that each bio is properly block size aligned, even if 31567927d22SKeith Busch * we do not use the full hardware limits. 31667927d22SKeith Busch */ 31767927d22SKeith Busch bytes = ALIGN_DOWN(bytes, queue_logical_block_size(q)); 31867927d22SKeith Busch 31967927d22SKeith Busch /* 320cc29e1bfSJeffle Xu * Bio splitting may cause subtle trouble such as hang when doing sync 321cc29e1bfSJeffle Xu * iopoll in direct IO routine. Given performance gain of iopoll for 322cc29e1bfSJeffle Xu * big IO can be trival, disable iopoll when split needed. 323cc29e1bfSJeffle Xu */ 3246ce913feSChristoph Hellwig bio_clear_polled(bio); 32567927d22SKeith Busch return bio_split(bio, bytes >> SECTOR_SHIFT, GFP_NOIO, bs); 32654efd50bSKent Overstreet } 32754efd50bSKent Overstreet 328dad77584SBart Van Assche /** 3295a97806fSChristoph Hellwig * __bio_split_to_limits - split a bio to fit the queue limits 3305a97806fSChristoph Hellwig * @bio: bio to be split 3315a97806fSChristoph Hellwig * @q: request_queue new bio is being queued at 3325a97806fSChristoph Hellwig * @nr_segs: returns the number of segments in the returned bio 333dad77584SBart Van Assche * 3345a97806fSChristoph Hellwig * Check if @bio needs splitting based on the queue limits, and if so split off 3355a97806fSChristoph Hellwig * a bio fitting the limits from the beginning of @bio and return it. @bio is 3365a97806fSChristoph Hellwig * shortened to the remainder and re-submitted. 3375a97806fSChristoph Hellwig * 3385a97806fSChristoph Hellwig * The split bio is allocated from @q->bio_split, which is provided by the 3395a97806fSChristoph Hellwig * block layer. 340dad77584SBart Van Assche */ 3415a97806fSChristoph Hellwig struct bio *__bio_split_to_limits(struct bio *bio, struct request_queue *q, 342abd45c15SJens Axboe unsigned int *nr_segs) 34354efd50bSKent Overstreet { 34446754bd0SChristoph Hellwig struct bio_set *bs = &bio->bi_bdev->bd_disk->bio_split; 3455a97806fSChristoph Hellwig struct bio *split; 34654efd50bSKent Overstreet 3475a97806fSChristoph Hellwig switch (bio_op(bio)) { 3487afafc8aSAdrian Hunter case REQ_OP_DISCARD: 3497afafc8aSAdrian Hunter case REQ_OP_SECURE_ERASE: 35046754bd0SChristoph Hellwig split = bio_split_discard(bio, q, nr_segs, bs); 3517afafc8aSAdrian Hunter break; 352a6f0788eSChaitanya Kulkarni case REQ_OP_WRITE_ZEROES: 35346754bd0SChristoph Hellwig split = bio_split_write_zeroes(bio, q, nr_segs, bs); 354a6f0788eSChaitanya Kulkarni break; 3557afafc8aSAdrian Hunter default: 356a85b3637SChristoph Hellwig split = bio_split_rw(bio, q, nr_segs, bs, 357a85b3637SChristoph Hellwig get_max_io_size(bio, q) << SECTOR_SHIFT); 3587afafc8aSAdrian Hunter break; 3597afafc8aSAdrian Hunter } 360bdced438SMing Lei 36154efd50bSKent Overstreet if (split) { 3626ac45aebSMing Lei /* there isn't chance to merge the splitted bio */ 3631eff9d32SJens Axboe split->bi_opf |= REQ_NOMERGE; 3646ac45aebSMing Lei 365957a2b34SMuchun Song blkcg_bio_issue_init(split); 3665a97806fSChristoph Hellwig bio_chain(split, bio); 3675a97806fSChristoph Hellwig trace_block_split(split, bio->bi_iter.bi_sector); 3685a97806fSChristoph Hellwig submit_bio_noacct(bio); 3695a97806fSChristoph Hellwig return split; 37054efd50bSKent Overstreet } 3715a97806fSChristoph Hellwig return bio; 37254efd50bSKent Overstreet } 37314ccb66bSChristoph Hellwig 374dad77584SBart Van Assche /** 3755a97806fSChristoph Hellwig * bio_split_to_limits - split a bio to fit the queue limits 3765a97806fSChristoph Hellwig * @bio: bio to be split 377dad77584SBart Van Assche * 3785a97806fSChristoph Hellwig * Check if @bio needs splitting based on the queue limits of @bio->bi_bdev, and 3795a97806fSChristoph Hellwig * if so split off a bio fitting the limits from the beginning of @bio and 3805a97806fSChristoph Hellwig * return it. @bio is shortened to the remainder and re-submitted. 3815a97806fSChristoph Hellwig * 3825a97806fSChristoph Hellwig * The split bio is allocated from @q->bio_split, which is provided by the 3835a97806fSChristoph Hellwig * block layer. 384dad77584SBart Van Assche */ 3855a97806fSChristoph Hellwig struct bio *bio_split_to_limits(struct bio *bio) 38614ccb66bSChristoph Hellwig { 3875a97806fSChristoph Hellwig struct request_queue *q = bdev_get_queue(bio->bi_bdev); 38814ccb66bSChristoph Hellwig unsigned int nr_segs; 38914ccb66bSChristoph Hellwig 3905a97806fSChristoph Hellwig if (bio_may_exceed_limits(bio, q)) 3915a97806fSChristoph Hellwig return __bio_split_to_limits(bio, q, &nr_segs); 3925a97806fSChristoph Hellwig return bio; 39314ccb66bSChristoph Hellwig } 3945a97806fSChristoph Hellwig EXPORT_SYMBOL(bio_split_to_limits); 39554efd50bSKent Overstreet 396e9cd19c0SChristoph Hellwig unsigned int blk_recalc_rq_segments(struct request *rq) 397d6d48196SJens Axboe { 3986869875fSChristoph Hellwig unsigned int nr_phys_segs = 0; 39967927d22SKeith Busch unsigned int bytes = 0; 400e9cd19c0SChristoph Hellwig struct req_iterator iter; 4016869875fSChristoph Hellwig struct bio_vec bv; 402d6d48196SJens Axboe 403e9cd19c0SChristoph Hellwig if (!rq->bio) 4041e428079SJens Axboe return 0; 405d6d48196SJens Axboe 406e9cd19c0SChristoph Hellwig switch (bio_op(rq->bio)) { 407a6f0788eSChaitanya Kulkarni case REQ_OP_DISCARD: 408a6f0788eSChaitanya Kulkarni case REQ_OP_SECURE_ERASE: 409a958937fSDavid Jeffery if (queue_max_discard_segments(rq->q) > 1) { 410a958937fSDavid Jeffery struct bio *bio = rq->bio; 411a958937fSDavid Jeffery 412a958937fSDavid Jeffery for_each_bio(bio) 413a958937fSDavid Jeffery nr_phys_segs++; 414a958937fSDavid Jeffery return nr_phys_segs; 415a958937fSDavid Jeffery } 416a958937fSDavid Jeffery return 1; 417a6f0788eSChaitanya Kulkarni case REQ_OP_WRITE_ZEROES: 418f9d03f96SChristoph Hellwig return 0; 4192d9b02beSBart Van Assche default: 4202d9b02beSBart Van Assche break; 421a6f0788eSChaitanya Kulkarni } 4225cb8850cSKent Overstreet 423e9cd19c0SChristoph Hellwig rq_for_each_bvec(bv, rq, iter) 42467927d22SKeith Busch bvec_split_segs(rq->q, &bv, &nr_phys_segs, &bytes, 425708b25b3SBart Van Assche UINT_MAX, UINT_MAX); 4261e428079SJens Axboe return nr_phys_segs; 4271e428079SJens Axboe } 4281e428079SJens Axboe 42948d7727cSMing Lei static inline struct scatterlist *blk_next_sg(struct scatterlist **sg, 430862e5a5eSMing Lei struct scatterlist *sglist) 431862e5a5eSMing Lei { 432862e5a5eSMing Lei if (!*sg) 433862e5a5eSMing Lei return sglist; 434862e5a5eSMing Lei 435862e5a5eSMing Lei /* 436862e5a5eSMing Lei * If the driver previously mapped a shorter list, we could see a 437862e5a5eSMing Lei * termination bit prematurely unless it fully inits the sg table 438862e5a5eSMing Lei * on each mapping. We KNOW that there must be more entries here 439862e5a5eSMing Lei * or the driver would be buggy, so force clear the termination bit 440862e5a5eSMing Lei * to avoid doing a full sg_init_table() in drivers for each command. 441862e5a5eSMing Lei */ 442862e5a5eSMing Lei sg_unmark_end(*sg); 443862e5a5eSMing Lei return sg_next(*sg); 444862e5a5eSMing Lei } 445862e5a5eSMing Lei 446862e5a5eSMing Lei static unsigned blk_bvec_map_sg(struct request_queue *q, 447862e5a5eSMing Lei struct bio_vec *bvec, struct scatterlist *sglist, 448862e5a5eSMing Lei struct scatterlist **sg) 449862e5a5eSMing Lei { 450862e5a5eSMing Lei unsigned nbytes = bvec->bv_len; 4518a96a0e4SChristoph Hellwig unsigned nsegs = 0, total = 0; 452862e5a5eSMing Lei 453862e5a5eSMing Lei while (nbytes > 0) { 4548a96a0e4SChristoph Hellwig unsigned offset = bvec->bv_offset + total; 455429120f3SMing Lei unsigned len = min(get_max_segment_size(q, bvec->bv_page, 456429120f3SMing Lei offset), nbytes); 457f9f76879SChristoph Hellwig struct page *page = bvec->bv_page; 458f9f76879SChristoph Hellwig 459f9f76879SChristoph Hellwig /* 460f9f76879SChristoph Hellwig * Unfortunately a fair number of drivers barf on scatterlists 461f9f76879SChristoph Hellwig * that have an offset larger than PAGE_SIZE, despite other 462f9f76879SChristoph Hellwig * subsystems dealing with that invariant just fine. For now 463f9f76879SChristoph Hellwig * stick to the legacy format where we never present those from 464f9f76879SChristoph Hellwig * the block layer, but the code below should be removed once 465f9f76879SChristoph Hellwig * these offenders (mostly MMC/SD drivers) are fixed. 466f9f76879SChristoph Hellwig */ 467f9f76879SChristoph Hellwig page += (offset >> PAGE_SHIFT); 468f9f76879SChristoph Hellwig offset &= ~PAGE_MASK; 469862e5a5eSMing Lei 470862e5a5eSMing Lei *sg = blk_next_sg(sg, sglist); 471f9f76879SChristoph Hellwig sg_set_page(*sg, page, len, offset); 472862e5a5eSMing Lei 4738a96a0e4SChristoph Hellwig total += len; 4748a96a0e4SChristoph Hellwig nbytes -= len; 475862e5a5eSMing Lei nsegs++; 476862e5a5eSMing Lei } 477862e5a5eSMing Lei 478862e5a5eSMing Lei return nsegs; 479862e5a5eSMing Lei } 480862e5a5eSMing Lei 48116e3e418SMing Lei static inline int __blk_bvec_map_sg(struct bio_vec bv, 48216e3e418SMing Lei struct scatterlist *sglist, struct scatterlist **sg) 48316e3e418SMing Lei { 48416e3e418SMing Lei *sg = blk_next_sg(sg, sglist); 48516e3e418SMing Lei sg_set_page(*sg, bv.bv_page, bv.bv_len, bv.bv_offset); 48616e3e418SMing Lei return 1; 48716e3e418SMing Lei } 48816e3e418SMing Lei 489f6970f83SMing Lei /* only try to merge bvecs into one sg if they are from two bios */ 490f6970f83SMing Lei static inline bool 491f6970f83SMing Lei __blk_segment_map_sg_merge(struct request_queue *q, struct bio_vec *bvec, 492f6970f83SMing Lei struct bio_vec *bvprv, struct scatterlist **sg) 493963ab9e5SAsias He { 494963ab9e5SAsias He 495963ab9e5SAsias He int nbytes = bvec->bv_len; 496963ab9e5SAsias He 497f6970f83SMing Lei if (!*sg) 498f6970f83SMing Lei return false; 499f6970f83SMing Lei 500b4b6cb61SMing Lei if ((*sg)->length + nbytes > queue_max_segment_size(q)) 501f6970f83SMing Lei return false; 502f6970f83SMing Lei 5033dccdae5SChristoph Hellwig if (!biovec_phys_mergeable(q, bvprv, bvec)) 504f6970f83SMing Lei return false; 505963ab9e5SAsias He 506963ab9e5SAsias He (*sg)->length += nbytes; 507f6970f83SMing Lei 508f6970f83SMing Lei return true; 509963ab9e5SAsias He } 510963ab9e5SAsias He 5115cb8850cSKent Overstreet static int __blk_bios_map_sg(struct request_queue *q, struct bio *bio, 5125cb8850cSKent Overstreet struct scatterlist *sglist, 5135cb8850cSKent Overstreet struct scatterlist **sg) 5145cb8850cSKent Overstreet { 5153f649ab7SKees Cook struct bio_vec bvec, bvprv = { NULL }; 5165cb8850cSKent Overstreet struct bvec_iter iter; 51738417468SChristoph Hellwig int nsegs = 0; 518f6970f83SMing Lei bool new_bio = false; 5195cb8850cSKent Overstreet 520f6970f83SMing Lei for_each_bio(bio) { 521f6970f83SMing Lei bio_for_each_bvec(bvec, bio, iter) { 522f6970f83SMing Lei /* 523f6970f83SMing Lei * Only try to merge bvecs from two bios given we 524f6970f83SMing Lei * have done bio internal merge when adding pages 525f6970f83SMing Lei * to bio 526f6970f83SMing Lei */ 527f6970f83SMing Lei if (new_bio && 528f6970f83SMing Lei __blk_segment_map_sg_merge(q, &bvec, &bvprv, sg)) 529f6970f83SMing Lei goto next_bvec; 530f6970f83SMing Lei 531f6970f83SMing Lei if (bvec.bv_offset + bvec.bv_len <= PAGE_SIZE) 532f6970f83SMing Lei nsegs += __blk_bvec_map_sg(bvec, sglist, sg); 533f6970f83SMing Lei else 534f6970f83SMing Lei nsegs += blk_bvec_map_sg(q, &bvec, sglist, sg); 535f6970f83SMing Lei next_bvec: 536f6970f83SMing Lei new_bio = false; 537f6970f83SMing Lei } 538b21e11c5SMing Lei if (likely(bio->bi_iter.bi_size)) { 539f6970f83SMing Lei bvprv = bvec; 540f6970f83SMing Lei new_bio = true; 541f6970f83SMing Lei } 542b21e11c5SMing Lei } 5435cb8850cSKent Overstreet 5445cb8850cSKent Overstreet return nsegs; 5455cb8850cSKent Overstreet } 5465cb8850cSKent Overstreet 547d6d48196SJens Axboe /* 548d6d48196SJens Axboe * map a request to scatterlist, return number of sg entries setup. Caller 549d6d48196SJens Axboe * must make sure sg can hold rq->nr_phys_segments entries 550d6d48196SJens Axboe */ 55189de1504SChristoph Hellwig int __blk_rq_map_sg(struct request_queue *q, struct request *rq, 55289de1504SChristoph Hellwig struct scatterlist *sglist, struct scatterlist **last_sg) 553d6d48196SJens Axboe { 5545cb8850cSKent Overstreet int nsegs = 0; 555d6d48196SJens Axboe 556f9d03f96SChristoph Hellwig if (rq->rq_flags & RQF_SPECIAL_PAYLOAD) 55789de1504SChristoph Hellwig nsegs = __blk_bvec_map_sg(rq->special_vec, sglist, last_sg); 558f9d03f96SChristoph Hellwig else if (rq->bio) 55989de1504SChristoph Hellwig nsegs = __blk_bios_map_sg(q, rq->bio, sglist, last_sg); 560f18573abSFUJITA Tomonori 56189de1504SChristoph Hellwig if (*last_sg) 56289de1504SChristoph Hellwig sg_mark_end(*last_sg); 563d6d48196SJens Axboe 56412e57f59SMing Lei /* 56512e57f59SMing Lei * Something must have been wrong if the figured number of 56612e57f59SMing Lei * segment is bigger than number of req's physical segments 56712e57f59SMing Lei */ 568f9d03f96SChristoph Hellwig WARN_ON(nsegs > blk_rq_nr_phys_segments(rq)); 56912e57f59SMing Lei 570d6d48196SJens Axboe return nsegs; 571d6d48196SJens Axboe } 57289de1504SChristoph Hellwig EXPORT_SYMBOL(__blk_rq_map_sg); 573d6d48196SJens Axboe 574943b40c8SMing Lei static inline unsigned int blk_rq_get_max_segments(struct request *rq) 575943b40c8SMing Lei { 576943b40c8SMing Lei if (req_op(rq) == REQ_OP_DISCARD) 577943b40c8SMing Lei return queue_max_discard_segments(rq->q); 578943b40c8SMing Lei return queue_max_segments(rq->q); 579943b40c8SMing Lei } 580943b40c8SMing Lei 581badf7f64SChristoph Hellwig static inline unsigned int blk_rq_get_max_sectors(struct request *rq, 582badf7f64SChristoph Hellwig sector_t offset) 583badf7f64SChristoph Hellwig { 584badf7f64SChristoph Hellwig struct request_queue *q = rq->q; 585c8875190SChristoph Hellwig unsigned int max_sectors; 586badf7f64SChristoph Hellwig 587badf7f64SChristoph Hellwig if (blk_rq_is_passthrough(rq)) 588badf7f64SChristoph Hellwig return q->limits.max_hw_sectors; 589badf7f64SChristoph Hellwig 590c8875190SChristoph Hellwig max_sectors = blk_queue_get_max_sectors(q, req_op(rq)); 591badf7f64SChristoph Hellwig if (!q->limits.chunk_sectors || 592badf7f64SChristoph Hellwig req_op(rq) == REQ_OP_DISCARD || 593badf7f64SChristoph Hellwig req_op(rq) == REQ_OP_SECURE_ERASE) 594c8875190SChristoph Hellwig return max_sectors; 595c8875190SChristoph Hellwig return min(max_sectors, 596c8875190SChristoph Hellwig blk_chunk_sectors_left(offset, q->limits.chunk_sectors)); 597badf7f64SChristoph Hellwig } 598badf7f64SChristoph Hellwig 59914ccb66bSChristoph Hellwig static inline int ll_new_hw_segment(struct request *req, struct bio *bio, 60014ccb66bSChristoph Hellwig unsigned int nr_phys_segs) 601d6d48196SJens Axboe { 6026b2b0459STejun Heo if (!blk_cgroup_mergeable(req, bio)) 6036b2b0459STejun Heo goto no_merge; 6046b2b0459STejun Heo 6052705dfb2SMing Lei if (blk_integrity_merge_bio(req->q, req, bio) == false) 60613f05c8dSMartin K. Petersen goto no_merge; 60713f05c8dSMartin K. Petersen 6082705dfb2SMing Lei /* discard request merge won't add new segment */ 6092705dfb2SMing Lei if (req_op(req) == REQ_OP_DISCARD) 6102705dfb2SMing Lei return 1; 6112705dfb2SMing Lei 6122705dfb2SMing Lei if (req->nr_phys_segments + nr_phys_segs > blk_rq_get_max_segments(req)) 61313f05c8dSMartin K. Petersen goto no_merge; 614d6d48196SJens Axboe 615d6d48196SJens Axboe /* 616d6d48196SJens Axboe * This will form the start of a new hw segment. Bump both 617d6d48196SJens Axboe * counters. 618d6d48196SJens Axboe */ 619d6d48196SJens Axboe req->nr_phys_segments += nr_phys_segs; 620d6d48196SJens Axboe return 1; 62113f05c8dSMartin K. Petersen 62213f05c8dSMartin K. Petersen no_merge: 62314ccb66bSChristoph Hellwig req_set_nomerge(req->q, req); 62413f05c8dSMartin K. Petersen return 0; 625d6d48196SJens Axboe } 626d6d48196SJens Axboe 62714ccb66bSChristoph Hellwig int ll_back_merge_fn(struct request *req, struct bio *bio, unsigned int nr_segs) 628d6d48196SJens Axboe { 6295e7c4274SJens Axboe if (req_gap_back_merge(req, bio)) 6305e7c4274SJens Axboe return 0; 6317f39add3SSagi Grimberg if (blk_integrity_rq(req) && 6327f39add3SSagi Grimberg integrity_req_gap_back_merge(req, bio)) 6337f39add3SSagi Grimberg return 0; 634a892c8d5SSatya Tangirala if (!bio_crypt_ctx_back_mergeable(req, bio)) 635a892c8d5SSatya Tangirala return 0; 636f31dc1cdSMartin K. Petersen if (blk_rq_sectors(req) + bio_sectors(bio) > 63717007f39SDamien Le Moal blk_rq_get_max_sectors(req, blk_rq_pos(req))) { 63814ccb66bSChristoph Hellwig req_set_nomerge(req->q, req); 639d6d48196SJens Axboe return 0; 640d6d48196SJens Axboe } 641d6d48196SJens Axboe 64214ccb66bSChristoph Hellwig return ll_new_hw_segment(req, bio, nr_segs); 643d6d48196SJens Axboe } 644d6d48196SJens Axboe 645eda5cc99SChristoph Hellwig static int ll_front_merge_fn(struct request *req, struct bio *bio, 646eda5cc99SChristoph Hellwig unsigned int nr_segs) 647d6d48196SJens Axboe { 6485e7c4274SJens Axboe if (req_gap_front_merge(req, bio)) 6495e7c4274SJens Axboe return 0; 6507f39add3SSagi Grimberg if (blk_integrity_rq(req) && 6517f39add3SSagi Grimberg integrity_req_gap_front_merge(req, bio)) 6527f39add3SSagi Grimberg return 0; 653a892c8d5SSatya Tangirala if (!bio_crypt_ctx_front_mergeable(req, bio)) 654a892c8d5SSatya Tangirala return 0; 655f31dc1cdSMartin K. Petersen if (blk_rq_sectors(req) + bio_sectors(bio) > 65617007f39SDamien Le Moal blk_rq_get_max_sectors(req, bio->bi_iter.bi_sector)) { 65714ccb66bSChristoph Hellwig req_set_nomerge(req->q, req); 658d6d48196SJens Axboe return 0; 659d6d48196SJens Axboe } 660d6d48196SJens Axboe 66114ccb66bSChristoph Hellwig return ll_new_hw_segment(req, bio, nr_segs); 662d6d48196SJens Axboe } 663d6d48196SJens Axboe 664445251d0SJens Axboe static bool req_attempt_discard_merge(struct request_queue *q, struct request *req, 665445251d0SJens Axboe struct request *next) 666445251d0SJens Axboe { 667445251d0SJens Axboe unsigned short segments = blk_rq_nr_discard_segments(req); 668445251d0SJens Axboe 669445251d0SJens Axboe if (segments >= queue_max_discard_segments(q)) 670445251d0SJens Axboe goto no_merge; 671445251d0SJens Axboe if (blk_rq_sectors(req) + bio_sectors(next->bio) > 672445251d0SJens Axboe blk_rq_get_max_sectors(req, blk_rq_pos(req))) 673445251d0SJens Axboe goto no_merge; 674445251d0SJens Axboe 675445251d0SJens Axboe req->nr_phys_segments = segments + blk_rq_nr_discard_segments(next); 676445251d0SJens Axboe return true; 677445251d0SJens Axboe no_merge: 678445251d0SJens Axboe req_set_nomerge(q, req); 679445251d0SJens Axboe return false; 680445251d0SJens Axboe } 681445251d0SJens Axboe 682d6d48196SJens Axboe static int ll_merge_requests_fn(struct request_queue *q, struct request *req, 683d6d48196SJens Axboe struct request *next) 684d6d48196SJens Axboe { 685d6d48196SJens Axboe int total_phys_segments; 686d6d48196SJens Axboe 6875e7c4274SJens Axboe if (req_gap_back_merge(req, next->bio)) 688854fbb9cSKeith Busch return 0; 689854fbb9cSKeith Busch 690d6d48196SJens Axboe /* 691d6d48196SJens Axboe * Will it become too large? 692d6d48196SJens Axboe */ 693f31dc1cdSMartin K. Petersen if ((blk_rq_sectors(req) + blk_rq_sectors(next)) > 69417007f39SDamien Le Moal blk_rq_get_max_sectors(req, blk_rq_pos(req))) 695d6d48196SJens Axboe return 0; 696d6d48196SJens Axboe 697d6d48196SJens Axboe total_phys_segments = req->nr_phys_segments + next->nr_phys_segments; 698943b40c8SMing Lei if (total_phys_segments > blk_rq_get_max_segments(req)) 699d6d48196SJens Axboe return 0; 700d6d48196SJens Axboe 7016b2b0459STejun Heo if (!blk_cgroup_mergeable(req, next->bio)) 7026b2b0459STejun Heo return 0; 7036b2b0459STejun Heo 7044eaf99beSMartin K. Petersen if (blk_integrity_merge_rq(q, req, next) == false) 70513f05c8dSMartin K. Petersen return 0; 70613f05c8dSMartin K. Petersen 707a892c8d5SSatya Tangirala if (!bio_crypt_ctx_merge_rq(req, next)) 708a892c8d5SSatya Tangirala return 0; 709a892c8d5SSatya Tangirala 710d6d48196SJens Axboe /* Merge is OK... */ 711d6d48196SJens Axboe req->nr_phys_segments = total_phys_segments; 712d6d48196SJens Axboe return 1; 713d6d48196SJens Axboe } 714d6d48196SJens Axboe 71580a761fdSTejun Heo /** 71680a761fdSTejun Heo * blk_rq_set_mixed_merge - mark a request as mixed merge 71780a761fdSTejun Heo * @rq: request to mark as mixed merge 71880a761fdSTejun Heo * 71980a761fdSTejun Heo * Description: 72080a761fdSTejun Heo * @rq is about to be mixed merged. Make sure the attributes 72180a761fdSTejun Heo * which can be mixed are set in each bio and mark @rq as mixed 72280a761fdSTejun Heo * merged. 72380a761fdSTejun Heo */ 72480a761fdSTejun Heo void blk_rq_set_mixed_merge(struct request *rq) 72580a761fdSTejun Heo { 72616458cf3SBart Van Assche blk_opf_t ff = rq->cmd_flags & REQ_FAILFAST_MASK; 72780a761fdSTejun Heo struct bio *bio; 72880a761fdSTejun Heo 729e8064021SChristoph Hellwig if (rq->rq_flags & RQF_MIXED_MERGE) 73080a761fdSTejun Heo return; 73180a761fdSTejun Heo 73280a761fdSTejun Heo /* 73380a761fdSTejun Heo * @rq will no longer represent mixable attributes for all the 73480a761fdSTejun Heo * contained bios. It will just track those of the first one. 73580a761fdSTejun Heo * Distributes the attributs to each bio. 73680a761fdSTejun Heo */ 73780a761fdSTejun Heo for (bio = rq->bio; bio; bio = bio->bi_next) { 7381eff9d32SJens Axboe WARN_ON_ONCE((bio->bi_opf & REQ_FAILFAST_MASK) && 7391eff9d32SJens Axboe (bio->bi_opf & REQ_FAILFAST_MASK) != ff); 7401eff9d32SJens Axboe bio->bi_opf |= ff; 74180a761fdSTejun Heo } 742e8064021SChristoph Hellwig rq->rq_flags |= RQF_MIXED_MERGE; 74380a761fdSTejun Heo } 74480a761fdSTejun Heo 745b9c54f56SKonstantin Khlebnikov static void blk_account_io_merge_request(struct request *req) 74626308eabSJerome Marchand { 74726308eabSJerome Marchand if (blk_do_io_stat(req)) { 748112f158fSMike Snitzer part_stat_lock(); 749b9c54f56SKonstantin Khlebnikov part_stat_inc(req->part, merges[op_stat_group(req_op(req))]); 75026308eabSJerome Marchand part_stat_unlock(); 75126308eabSJerome Marchand } 75226308eabSJerome Marchand } 753b9c54f56SKonstantin Khlebnikov 754e96c0d83SEric Biggers static enum elv_merge blk_try_req_merge(struct request *req, 755e96c0d83SEric Biggers struct request *next) 75669840466SJianchao Wang { 75769840466SJianchao Wang if (blk_discard_mergable(req)) 75869840466SJianchao Wang return ELEVATOR_DISCARD_MERGE; 75969840466SJianchao Wang else if (blk_rq_pos(req) + blk_rq_sectors(req) == blk_rq_pos(next)) 76069840466SJianchao Wang return ELEVATOR_BACK_MERGE; 76169840466SJianchao Wang 76269840466SJianchao Wang return ELEVATOR_NO_MERGE; 76369840466SJianchao Wang } 76426308eabSJerome Marchand 765d6d48196SJens Axboe /* 766b973cb7eSJens Axboe * For non-mq, this has to be called with the request spinlock acquired. 767b973cb7eSJens Axboe * For mq with scheduling, the appropriate queue wide lock should be held. 768d6d48196SJens Axboe */ 769b973cb7eSJens Axboe static struct request *attempt_merge(struct request_queue *q, 770b973cb7eSJens Axboe struct request *req, struct request *next) 771d6d48196SJens Axboe { 772d6d48196SJens Axboe if (!rq_mergeable(req) || !rq_mergeable(next)) 773b973cb7eSJens Axboe return NULL; 774d6d48196SJens Axboe 775288dab8aSChristoph Hellwig if (req_op(req) != req_op(next)) 776b973cb7eSJens Axboe return NULL; 777f31dc1cdSMartin K. Petersen 77879bb1dbdSChristoph Hellwig if (rq_data_dir(req) != rq_data_dir(next)) 779b973cb7eSJens Axboe return NULL; 780d6d48196SJens Axboe 781668ffc03SDamien Le Moal if (req->ioprio != next->ioprio) 782668ffc03SDamien Le Moal return NULL; 783668ffc03SDamien Le Moal 784cb6934f8SJens Axboe /* 785d6d48196SJens Axboe * If we are allowed to merge, then append bio list 786d6d48196SJens Axboe * from next to rq and release next. merge_requests_fn 787d6d48196SJens Axboe * will have updated segment counts, update sector 788445251d0SJens Axboe * counts here. Handle DISCARDs separately, as they 789445251d0SJens Axboe * have separate settings. 790d6d48196SJens Axboe */ 79169840466SJianchao Wang 79269840466SJianchao Wang switch (blk_try_req_merge(req, next)) { 79369840466SJianchao Wang case ELEVATOR_DISCARD_MERGE: 794445251d0SJens Axboe if (!req_attempt_discard_merge(q, req, next)) 795445251d0SJens Axboe return NULL; 79669840466SJianchao Wang break; 79769840466SJianchao Wang case ELEVATOR_BACK_MERGE: 79869840466SJianchao Wang if (!ll_merge_requests_fn(q, req, next)) 799b973cb7eSJens Axboe return NULL; 80069840466SJianchao Wang break; 80169840466SJianchao Wang default: 80269840466SJianchao Wang return NULL; 80369840466SJianchao Wang } 804d6d48196SJens Axboe 805d6d48196SJens Axboe /* 80680a761fdSTejun Heo * If failfast settings disagree or any of the two is already 80780a761fdSTejun Heo * a mixed merge, mark both as mixed before proceeding. This 80880a761fdSTejun Heo * makes sure that all involved bios have mixable attributes 80980a761fdSTejun Heo * set properly. 81080a761fdSTejun Heo */ 811e8064021SChristoph Hellwig if (((req->rq_flags | next->rq_flags) & RQF_MIXED_MERGE) || 81280a761fdSTejun Heo (req->cmd_flags & REQ_FAILFAST_MASK) != 81380a761fdSTejun Heo (next->cmd_flags & REQ_FAILFAST_MASK)) { 81480a761fdSTejun Heo blk_rq_set_mixed_merge(req); 81580a761fdSTejun Heo blk_rq_set_mixed_merge(next); 81680a761fdSTejun Heo } 81780a761fdSTejun Heo 81880a761fdSTejun Heo /* 819522a7775SOmar Sandoval * At this point we have either done a back merge or front merge. We 820522a7775SOmar Sandoval * need the smaller start_time_ns of the merged requests to be the 821522a7775SOmar Sandoval * current request for accounting purposes. 822d6d48196SJens Axboe */ 823522a7775SOmar Sandoval if (next->start_time_ns < req->start_time_ns) 824522a7775SOmar Sandoval req->start_time_ns = next->start_time_ns; 825d6d48196SJens Axboe 826d6d48196SJens Axboe req->biotail->bi_next = next->bio; 827d6d48196SJens Axboe req->biotail = next->biotail; 828d6d48196SJens Axboe 829a2dec7b3STejun Heo req->__data_len += blk_rq_bytes(next); 830d6d48196SJens Axboe 8312a5cf35cSMing Lei if (!blk_discard_mergable(req)) 832d6d48196SJens Axboe elv_merge_requests(q, req, next); 833d6d48196SJens Axboe 83442dad764SJerome Marchand /* 83542dad764SJerome Marchand * 'next' is going away, so update stats accordingly 83642dad764SJerome Marchand */ 837b9c54f56SKonstantin Khlebnikov blk_account_io_merge_request(next); 838d6d48196SJens Axboe 839a54895faSChristoph Hellwig trace_block_rq_merge(next); 840f3bdc62fSJan Kara 841e4d750c9SJens Axboe /* 842e4d750c9SJens Axboe * ownership of bio passed from next to req, return 'next' for 843e4d750c9SJens Axboe * the caller to free 844e4d750c9SJens Axboe */ 8451cd96c24SBoaz Harrosh next->bio = NULL; 846b973cb7eSJens Axboe return next; 847d6d48196SJens Axboe } 848d6d48196SJens Axboe 849eda5cc99SChristoph Hellwig static struct request *attempt_back_merge(struct request_queue *q, 850eda5cc99SChristoph Hellwig struct request *rq) 851d6d48196SJens Axboe { 852d6d48196SJens Axboe struct request *next = elv_latter_request(q, rq); 853d6d48196SJens Axboe 854d6d48196SJens Axboe if (next) 855d6d48196SJens Axboe return attempt_merge(q, rq, next); 856d6d48196SJens Axboe 857b973cb7eSJens Axboe return NULL; 858d6d48196SJens Axboe } 859d6d48196SJens Axboe 860eda5cc99SChristoph Hellwig static struct request *attempt_front_merge(struct request_queue *q, 861eda5cc99SChristoph Hellwig struct request *rq) 862d6d48196SJens Axboe { 863d6d48196SJens Axboe struct request *prev = elv_former_request(q, rq); 864d6d48196SJens Axboe 865d6d48196SJens Axboe if (prev) 866d6d48196SJens Axboe return attempt_merge(q, prev, rq); 867d6d48196SJens Axboe 868b973cb7eSJens Axboe return NULL; 869d6d48196SJens Axboe } 8705e84ea3aSJens Axboe 871fd2ef39cSJan Kara /* 872fd2ef39cSJan Kara * Try to merge 'next' into 'rq'. Return true if the merge happened, false 873fd2ef39cSJan Kara * otherwise. The caller is responsible for freeing 'next' if the merge 874fd2ef39cSJan Kara * happened. 875fd2ef39cSJan Kara */ 876fd2ef39cSJan Kara bool blk_attempt_req_merge(struct request_queue *q, struct request *rq, 8775e84ea3aSJens Axboe struct request *next) 8785e84ea3aSJens Axboe { 879fd2ef39cSJan Kara return attempt_merge(q, rq, next); 8805e84ea3aSJens Axboe } 881050c8ea8STejun Heo 882050c8ea8STejun Heo bool blk_rq_merge_ok(struct request *rq, struct bio *bio) 883050c8ea8STejun Heo { 884e2a60da7SMartin K. Petersen if (!rq_mergeable(rq) || !bio_mergeable(bio)) 885050c8ea8STejun Heo return false; 886050c8ea8STejun Heo 887288dab8aSChristoph Hellwig if (req_op(rq) != bio_op(bio)) 888f31dc1cdSMartin K. Petersen return false; 889f31dc1cdSMartin K. Petersen 890050c8ea8STejun Heo /* different data direction or already started, don't merge */ 891050c8ea8STejun Heo if (bio_data_dir(bio) != rq_data_dir(rq)) 892050c8ea8STejun Heo return false; 893050c8ea8STejun Heo 8946b2b0459STejun Heo /* don't merge across cgroup boundaries */ 8956b2b0459STejun Heo if (!blk_cgroup_mergeable(rq, bio)) 8966b2b0459STejun Heo return false; 8976b2b0459STejun Heo 898050c8ea8STejun Heo /* only merge integrity protected bio into ditto rq */ 8994eaf99beSMartin K. Petersen if (blk_integrity_merge_bio(rq->q, rq, bio) == false) 900050c8ea8STejun Heo return false; 901050c8ea8STejun Heo 902a892c8d5SSatya Tangirala /* Only merge if the crypt contexts are compatible */ 903a892c8d5SSatya Tangirala if (!bio_crypt_rq_ctx_compatible(rq, bio)) 904a892c8d5SSatya Tangirala return false; 905a892c8d5SSatya Tangirala 906668ffc03SDamien Le Moal if (rq->ioprio != bio_prio(bio)) 907668ffc03SDamien Le Moal return false; 908668ffc03SDamien Le Moal 909050c8ea8STejun Heo return true; 910050c8ea8STejun Heo } 911050c8ea8STejun Heo 91234fe7c05SChristoph Hellwig enum elv_merge blk_try_merge(struct request *rq, struct bio *bio) 913050c8ea8STejun Heo { 91469840466SJianchao Wang if (blk_discard_mergable(rq)) 9151e739730SChristoph Hellwig return ELEVATOR_DISCARD_MERGE; 9161e739730SChristoph Hellwig else if (blk_rq_pos(rq) + blk_rq_sectors(rq) == bio->bi_iter.bi_sector) 917050c8ea8STejun Heo return ELEVATOR_BACK_MERGE; 9184f024f37SKent Overstreet else if (blk_rq_pos(rq) - bio_sectors(bio) == bio->bi_iter.bi_sector) 919050c8ea8STejun Heo return ELEVATOR_FRONT_MERGE; 920050c8ea8STejun Heo return ELEVATOR_NO_MERGE; 921050c8ea8STejun Heo } 9228e756373SBaolin Wang 9238e756373SBaolin Wang static void blk_account_io_merge_bio(struct request *req) 9248e756373SBaolin Wang { 9258e756373SBaolin Wang if (!blk_do_io_stat(req)) 9268e756373SBaolin Wang return; 9278e756373SBaolin Wang 9288e756373SBaolin Wang part_stat_lock(); 9298e756373SBaolin Wang part_stat_inc(req->part, merges[op_stat_group(req_op(req))]); 9308e756373SBaolin Wang part_stat_unlock(); 9318e756373SBaolin Wang } 9328e756373SBaolin Wang 933eda5cc99SChristoph Hellwig enum bio_merge_status { 934eda5cc99SChristoph Hellwig BIO_MERGE_OK, 935eda5cc99SChristoph Hellwig BIO_MERGE_NONE, 936eda5cc99SChristoph Hellwig BIO_MERGE_FAILED, 937eda5cc99SChristoph Hellwig }; 938eda5cc99SChristoph Hellwig 939eda5cc99SChristoph Hellwig static enum bio_merge_status bio_attempt_back_merge(struct request *req, 940eda5cc99SChristoph Hellwig struct bio *bio, unsigned int nr_segs) 9418e756373SBaolin Wang { 94216458cf3SBart Van Assche const blk_opf_t ff = bio->bi_opf & REQ_FAILFAST_MASK; 9438e756373SBaolin Wang 9448e756373SBaolin Wang if (!ll_back_merge_fn(req, bio, nr_segs)) 9457d7ca7c5SBaolin Wang return BIO_MERGE_FAILED; 9468e756373SBaolin Wang 947e8a676d6SChristoph Hellwig trace_block_bio_backmerge(bio); 9488e756373SBaolin Wang rq_qos_merge(req->q, req, bio); 9498e756373SBaolin Wang 9508e756373SBaolin Wang if ((req->cmd_flags & REQ_FAILFAST_MASK) != ff) 9518e756373SBaolin Wang blk_rq_set_mixed_merge(req); 9528e756373SBaolin Wang 9538e756373SBaolin Wang req->biotail->bi_next = bio; 9548e756373SBaolin Wang req->biotail = bio; 9558e756373SBaolin Wang req->__data_len += bio->bi_iter.bi_size; 9568e756373SBaolin Wang 9578e756373SBaolin Wang bio_crypt_free_ctx(bio); 9588e756373SBaolin Wang 9598e756373SBaolin Wang blk_account_io_merge_bio(req); 9607d7ca7c5SBaolin Wang return BIO_MERGE_OK; 9618e756373SBaolin Wang } 9628e756373SBaolin Wang 963eda5cc99SChristoph Hellwig static enum bio_merge_status bio_attempt_front_merge(struct request *req, 964eda5cc99SChristoph Hellwig struct bio *bio, unsigned int nr_segs) 9658e756373SBaolin Wang { 96616458cf3SBart Van Assche const blk_opf_t ff = bio->bi_opf & REQ_FAILFAST_MASK; 9678e756373SBaolin Wang 9688e756373SBaolin Wang if (!ll_front_merge_fn(req, bio, nr_segs)) 9697d7ca7c5SBaolin Wang return BIO_MERGE_FAILED; 9708e756373SBaolin Wang 971e8a676d6SChristoph Hellwig trace_block_bio_frontmerge(bio); 9728e756373SBaolin Wang rq_qos_merge(req->q, req, bio); 9738e756373SBaolin Wang 9748e756373SBaolin Wang if ((req->cmd_flags & REQ_FAILFAST_MASK) != ff) 9758e756373SBaolin Wang blk_rq_set_mixed_merge(req); 9768e756373SBaolin Wang 9778e756373SBaolin Wang bio->bi_next = req->bio; 9788e756373SBaolin Wang req->bio = bio; 9798e756373SBaolin Wang 9808e756373SBaolin Wang req->__sector = bio->bi_iter.bi_sector; 9818e756373SBaolin Wang req->__data_len += bio->bi_iter.bi_size; 9828e756373SBaolin Wang 9838e756373SBaolin Wang bio_crypt_do_front_merge(req, bio); 9848e756373SBaolin Wang 9858e756373SBaolin Wang blk_account_io_merge_bio(req); 9867d7ca7c5SBaolin Wang return BIO_MERGE_OK; 9878e756373SBaolin Wang } 9888e756373SBaolin Wang 989eda5cc99SChristoph Hellwig static enum bio_merge_status bio_attempt_discard_merge(struct request_queue *q, 990eda5cc99SChristoph Hellwig struct request *req, struct bio *bio) 9918e756373SBaolin Wang { 9928e756373SBaolin Wang unsigned short segments = blk_rq_nr_discard_segments(req); 9938e756373SBaolin Wang 9948e756373SBaolin Wang if (segments >= queue_max_discard_segments(q)) 9958e756373SBaolin Wang goto no_merge; 9968e756373SBaolin Wang if (blk_rq_sectors(req) + bio_sectors(bio) > 9978e756373SBaolin Wang blk_rq_get_max_sectors(req, blk_rq_pos(req))) 9988e756373SBaolin Wang goto no_merge; 9998e756373SBaolin Wang 10008e756373SBaolin Wang rq_qos_merge(q, req, bio); 10018e756373SBaolin Wang 10028e756373SBaolin Wang req->biotail->bi_next = bio; 10038e756373SBaolin Wang req->biotail = bio; 10048e756373SBaolin Wang req->__data_len += bio->bi_iter.bi_size; 10058e756373SBaolin Wang req->nr_phys_segments = segments + 1; 10068e756373SBaolin Wang 10078e756373SBaolin Wang blk_account_io_merge_bio(req); 10087d7ca7c5SBaolin Wang return BIO_MERGE_OK; 10098e756373SBaolin Wang no_merge: 10108e756373SBaolin Wang req_set_nomerge(q, req); 10117d7ca7c5SBaolin Wang return BIO_MERGE_FAILED; 10127d7ca7c5SBaolin Wang } 10137d7ca7c5SBaolin Wang 10147d7ca7c5SBaolin Wang static enum bio_merge_status blk_attempt_bio_merge(struct request_queue *q, 10157d7ca7c5SBaolin Wang struct request *rq, 10167d7ca7c5SBaolin Wang struct bio *bio, 10177d7ca7c5SBaolin Wang unsigned int nr_segs, 10187d7ca7c5SBaolin Wang bool sched_allow_merge) 10197d7ca7c5SBaolin Wang { 10207d7ca7c5SBaolin Wang if (!blk_rq_merge_ok(rq, bio)) 10217d7ca7c5SBaolin Wang return BIO_MERGE_NONE; 10227d7ca7c5SBaolin Wang 10237d7ca7c5SBaolin Wang switch (blk_try_merge(rq, bio)) { 10247d7ca7c5SBaolin Wang case ELEVATOR_BACK_MERGE: 1025265600b7SBaolin Wang if (!sched_allow_merge || blk_mq_sched_allow_merge(q, rq, bio)) 10267d7ca7c5SBaolin Wang return bio_attempt_back_merge(rq, bio, nr_segs); 10277d7ca7c5SBaolin Wang break; 10287d7ca7c5SBaolin Wang case ELEVATOR_FRONT_MERGE: 1029265600b7SBaolin Wang if (!sched_allow_merge || blk_mq_sched_allow_merge(q, rq, bio)) 10307d7ca7c5SBaolin Wang return bio_attempt_front_merge(rq, bio, nr_segs); 10317d7ca7c5SBaolin Wang break; 10327d7ca7c5SBaolin Wang case ELEVATOR_DISCARD_MERGE: 10337d7ca7c5SBaolin Wang return bio_attempt_discard_merge(q, rq, bio); 10347d7ca7c5SBaolin Wang default: 10357d7ca7c5SBaolin Wang return BIO_MERGE_NONE; 10367d7ca7c5SBaolin Wang } 10377d7ca7c5SBaolin Wang 10387d7ca7c5SBaolin Wang return BIO_MERGE_FAILED; 10398e756373SBaolin Wang } 10408e756373SBaolin Wang 10418e756373SBaolin Wang /** 10428e756373SBaolin Wang * blk_attempt_plug_merge - try to merge with %current's plugged list 10438e756373SBaolin Wang * @q: request_queue new bio is being queued at 10448e756373SBaolin Wang * @bio: new bio being queued 10458e756373SBaolin Wang * @nr_segs: number of segments in @bio 104687c037d1SJens Axboe * from the passed in @q already in the plug list 10478e756373SBaolin Wang * 1048d38a9c04SJens Axboe * Determine whether @bio being queued on @q can be merged with the previous 1049d38a9c04SJens Axboe * request on %current's plugged list. Returns %true if merge was successful, 10508e756373SBaolin Wang * otherwise %false. 10518e756373SBaolin Wang * 10528e756373SBaolin Wang * Plugging coalesces IOs from the same issuer for the same purpose without 10538e756373SBaolin Wang * going through @q->queue_lock. As such it's more of an issuing mechanism 10548e756373SBaolin Wang * than scheduling, and the request, while may have elvpriv data, is not 10558e756373SBaolin Wang * added on the elevator at this point. In addition, we don't have 10568e756373SBaolin Wang * reliable access to the elevator outside queue lock. Only check basic 10578e756373SBaolin Wang * merging parameters without querying the elevator. 10588e756373SBaolin Wang * 10598e756373SBaolin Wang * Caller must ensure !blk_queue_nomerges(q) beforehand. 10608e756373SBaolin Wang */ 10618e756373SBaolin Wang bool blk_attempt_plug_merge(struct request_queue *q, struct bio *bio, 10620c5bcc92SChristoph Hellwig unsigned int nr_segs) 10638e756373SBaolin Wang { 10648e756373SBaolin Wang struct blk_plug *plug; 10658e756373SBaolin Wang struct request *rq; 10668e756373SBaolin Wang 10676deacb3bSChristoph Hellwig plug = blk_mq_plug(bio); 1068bc490f81SJens Axboe if (!plug || rq_list_empty(plug->mq_list)) 10698e756373SBaolin Wang return false; 10708e756373SBaolin Wang 10715b205071SJens Axboe rq_list_for_each(&plug->mq_list, rq) { 107287c037d1SJens Axboe if (rq->q == q) { 1073a1cb6537SMing Lei if (blk_attempt_bio_merge(q, rq, bio, nr_segs, false) == 1074a1cb6537SMing Lei BIO_MERGE_OK) 10758e756373SBaolin Wang return true; 10765b205071SJens Axboe break; 10775b205071SJens Axboe } 10785b205071SJens Axboe 10795b205071SJens Axboe /* 10805b205071SJens Axboe * Only keep iterating plug list for merges if we have multiple 10815b205071SJens Axboe * queues 10825b205071SJens Axboe */ 10835b205071SJens Axboe if (!plug->multiple_queues) 10845b205071SJens Axboe break; 1085a1cb6537SMing Lei } 10868e756373SBaolin Wang return false; 10878e756373SBaolin Wang } 1088bdc6a287SBaolin Wang 1089bdc6a287SBaolin Wang /* 1090bdc6a287SBaolin Wang * Iterate list of requests and see if we can merge this bio with any 1091bdc6a287SBaolin Wang * of them. 1092bdc6a287SBaolin Wang */ 1093bdc6a287SBaolin Wang bool blk_bio_list_merge(struct request_queue *q, struct list_head *list, 1094bdc6a287SBaolin Wang struct bio *bio, unsigned int nr_segs) 1095bdc6a287SBaolin Wang { 1096bdc6a287SBaolin Wang struct request *rq; 1097bdc6a287SBaolin Wang int checked = 8; 1098bdc6a287SBaolin Wang 1099bdc6a287SBaolin Wang list_for_each_entry_reverse(rq, list, queuelist) { 1100bdc6a287SBaolin Wang if (!checked--) 1101bdc6a287SBaolin Wang break; 1102bdc6a287SBaolin Wang 11037d7ca7c5SBaolin Wang switch (blk_attempt_bio_merge(q, rq, bio, nr_segs, true)) { 11047d7ca7c5SBaolin Wang case BIO_MERGE_NONE: 1105bdc6a287SBaolin Wang continue; 11067d7ca7c5SBaolin Wang case BIO_MERGE_OK: 11077d7ca7c5SBaolin Wang return true; 11087d7ca7c5SBaolin Wang case BIO_MERGE_FAILED: 11097d7ca7c5SBaolin Wang return false; 1110bdc6a287SBaolin Wang } 1111bdc6a287SBaolin Wang 1112bdc6a287SBaolin Wang } 1113bdc6a287SBaolin Wang 1114bdc6a287SBaolin Wang return false; 1115bdc6a287SBaolin Wang } 1116bdc6a287SBaolin Wang EXPORT_SYMBOL_GPL(blk_bio_list_merge); 1117eda5cc99SChristoph Hellwig 1118eda5cc99SChristoph Hellwig bool blk_mq_sched_try_merge(struct request_queue *q, struct bio *bio, 1119eda5cc99SChristoph Hellwig unsigned int nr_segs, struct request **merged_request) 1120eda5cc99SChristoph Hellwig { 1121eda5cc99SChristoph Hellwig struct request *rq; 1122eda5cc99SChristoph Hellwig 1123eda5cc99SChristoph Hellwig switch (elv_merge(q, &rq, bio)) { 1124eda5cc99SChristoph Hellwig case ELEVATOR_BACK_MERGE: 1125eda5cc99SChristoph Hellwig if (!blk_mq_sched_allow_merge(q, rq, bio)) 1126eda5cc99SChristoph Hellwig return false; 1127eda5cc99SChristoph Hellwig if (bio_attempt_back_merge(rq, bio, nr_segs) != BIO_MERGE_OK) 1128eda5cc99SChristoph Hellwig return false; 1129eda5cc99SChristoph Hellwig *merged_request = attempt_back_merge(q, rq); 1130eda5cc99SChristoph Hellwig if (!*merged_request) 1131eda5cc99SChristoph Hellwig elv_merged_request(q, rq, ELEVATOR_BACK_MERGE); 1132eda5cc99SChristoph Hellwig return true; 1133eda5cc99SChristoph Hellwig case ELEVATOR_FRONT_MERGE: 1134eda5cc99SChristoph Hellwig if (!blk_mq_sched_allow_merge(q, rq, bio)) 1135eda5cc99SChristoph Hellwig return false; 1136eda5cc99SChristoph Hellwig if (bio_attempt_front_merge(rq, bio, nr_segs) != BIO_MERGE_OK) 1137eda5cc99SChristoph Hellwig return false; 1138eda5cc99SChristoph Hellwig *merged_request = attempt_front_merge(q, rq); 1139eda5cc99SChristoph Hellwig if (!*merged_request) 1140eda5cc99SChristoph Hellwig elv_merged_request(q, rq, ELEVATOR_FRONT_MERGE); 1141eda5cc99SChristoph Hellwig return true; 1142eda5cc99SChristoph Hellwig case ELEVATOR_DISCARD_MERGE: 1143eda5cc99SChristoph Hellwig return bio_attempt_discard_merge(q, rq, bio) == BIO_MERGE_OK; 1144eda5cc99SChristoph Hellwig default: 1145eda5cc99SChristoph Hellwig return false; 1146eda5cc99SChristoph Hellwig } 1147eda5cc99SChristoph Hellwig } 1148eda5cc99SChristoph Hellwig EXPORT_SYMBOL_GPL(blk_mq_sched_try_merge); 1149