Skip to content

Commit e990700

Browse files
Christoph Hellwigaxboe
authored andcommitted
block: move req_gap_{back,front}_merge to blk-merge.c
Keep it close to the actual users instead of exposing the function to all drivers. Signed-off-by: Christoph Hellwig <hch@lst.de> Signed-off-by: Jens Axboe <axboe@kernel.dk>
1 parent 43b729b commit e990700

2 files changed

Lines changed: 65 additions & 69 deletions

File tree

‎block/blk-merge.c‎

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,71 @@
1212

1313
#include "blk.h"
1414

15+
/*
16+
* Check if the two bvecs from two bios can be merged to one segment. If yes,
17+
* no need to check gap between the two bios since the 1st bio and the 1st bvec
18+
* in the 2nd bio can be handled in one segment.
19+
*/
20+
static inline bool bios_segs_mergeable(struct request_queue *q,
21+
struct bio *prev, struct bio_vec *prev_last_bv,
22+
struct bio_vec *next_first_bv)
23+
{
24+
if (!BIOVEC_PHYS_MERGEABLE(prev_last_bv, next_first_bv))
25+
return false;
26+
if (!BIOVEC_SEG_BOUNDARY(q, prev_last_bv, next_first_bv))
27+
return false;
28+
if (prev->bi_seg_back_size + next_first_bv->bv_len >
29+
queue_max_segment_size(q))
30+
return false;
31+
return true;
32+
}
33+
34+
static inline bool bio_will_gap(struct request_queue *q,
35+
struct request *prev_rq, struct bio *prev, struct bio *next)
36+
{
37+
struct bio_vec pb, nb;
38+
39+
if (!bio_has_data(prev) || !queue_virt_boundary(q))
40+
return false;
41+
42+
/*
43+
* Don't merge if the 1st bio starts with non-zero offset, otherwise it
44+
* is quite difficult to respect the sg gap limit. We work hard to
45+
* merge a huge number of small single bios in case of mkfs.
46+
*/
47+
if (prev_rq)
48+
bio_get_first_bvec(prev_rq->bio, &pb);
49+
else
50+
bio_get_first_bvec(prev, &pb);
51+
if (pb.bv_offset)
52+
return true;
53+
54+
/*
55+
* We don't need to worry about the situation that the merged segment
56+
* ends in unaligned virt boundary:
57+
*
58+
* - if 'pb' ends aligned, the merged segment ends aligned
59+
* - if 'pb' ends unaligned, the next bio must include
60+
* one single bvec of 'nb', otherwise the 'nb' can't
61+
* merge with 'pb'
62+
*/
63+
bio_get_last_bvec(prev, &pb);
64+
bio_get_first_bvec(next, &nb);
65+
if (bios_segs_mergeable(q, prev, &pb, &nb))
66+
return false;
67+
return __bvec_gap_to_prev(q, &pb, nb.bv_offset);
68+
}
69+
70+
static inline bool req_gap_back_merge(struct request *req, struct bio *bio)
71+
{
72+
return bio_will_gap(req->q, req, req->biotail, bio);
73+
}
74+
75+
static inline bool req_gap_front_merge(struct request *req, struct bio *bio)
76+
{
77+
return bio_will_gap(req->q, NULL, bio, req->bio);
78+
}
79+
1580
static struct bio *blk_bio_discard_split(struct request_queue *q,
1681
struct bio *bio,
1782
struct bio_set *bs,

‎include/linux/blkdev.h‎

Lines changed: 0 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -1695,75 +1695,6 @@ static inline bool bvec_gap_to_prev(struct request_queue *q,
16951695
return __bvec_gap_to_prev(q, bprv, offset);
16961696
}
16971697

1698-
/*
1699-
* Check if the two bvecs from two bios can be merged to one segment.
1700-
* If yes, no need to check gap between the two bios since the 1st bio
1701-
* and the 1st bvec in the 2nd bio can be handled in one segment.
1702-
*/
1703-
static inline bool bios_segs_mergeable(struct request_queue *q,
1704-
struct bio *prev, struct bio_vec *prev_last_bv,
1705-
struct bio_vec *next_first_bv)
1706-
{
1707-
if (!BIOVEC_PHYS_MERGEABLE(prev_last_bv, next_first_bv))
1708-
return false;
1709-
if (!BIOVEC_SEG_BOUNDARY(q, prev_last_bv, next_first_bv))
1710-
return false;
1711-
if (prev->bi_seg_back_size + next_first_bv->bv_len >
1712-
queue_max_segment_size(q))
1713-
return false;
1714-
return true;
1715-
}
1716-
1717-
static inline bool bio_will_gap(struct request_queue *q,
1718-
struct request *prev_rq,
1719-
struct bio *prev,
1720-
struct bio *next)
1721-
{
1722-
if (bio_has_data(prev) && queue_virt_boundary(q)) {
1723-
struct bio_vec pb, nb;
1724-
1725-
/*
1726-
* don't merge if the 1st bio starts with non-zero
1727-
* offset, otherwise it is quite difficult to respect
1728-
* sg gap limit. We work hard to merge a huge number of small
1729-
* single bios in case of mkfs.
1730-
*/
1731-
if (prev_rq)
1732-
bio_get_first_bvec(prev_rq->bio, &pb);
1733-
else
1734-
bio_get_first_bvec(prev, &pb);
1735-
if (pb.bv_offset)
1736-
return true;
1737-
1738-
/*
1739-
* We don't need to worry about the situation that the
1740-
* merged segment ends in unaligned virt boundary:
1741-
*
1742-
* - if 'pb' ends aligned, the merged segment ends aligned
1743-
* - if 'pb' ends unaligned, the next bio must include
1744-
* one single bvec of 'nb', otherwise the 'nb' can't
1745-
* merge with 'pb'
1746-
*/
1747-
bio_get_last_bvec(prev, &pb);
1748-
bio_get_first_bvec(next, &nb);
1749-
1750-
if (!bios_segs_mergeable(q, prev, &pb, &nb))
1751-
return __bvec_gap_to_prev(q, &pb, nb.bv_offset);
1752-
}
1753-
1754-
return false;
1755-
}
1756-
1757-
static inline bool req_gap_back_merge(struct request *req, struct bio *bio)
1758-
{
1759-
return bio_will_gap(req->q, req, req->biotail, bio);
1760-
}
1761-
1762-
static inline bool req_gap_front_merge(struct request *req, struct bio *bio)
1763-
{
1764-
return bio_will_gap(req->q, NULL, bio, req->bio);
1765-
}
1766-
17671698
int kblockd_schedule_work(struct work_struct *work);
17681699
int kblockd_schedule_work_on(int cpu, struct work_struct *work);
17691700
int kblockd_mod_delayed_work_on(int cpu, struct delayed_work *dwork, unsigned long delay);

0 commit comments

Comments
 (0)