Micro-optimize the code in bvec_gap_to_prev using two tricks: - OR the offset and previous length + offset so that there is no need for a branch to check both with separate logical and checks. - Always OR in the virtual boundary mask, as the instruction for that is cheaper than the branch to check for a 0 value. This together then removes the need for the separate __-handler as skipping the branch for the 0 check is gone. The first optimization was stolen from Keith Busch's virtual boundary series. Signed-off-by: Christoph Hellwig --- block/blk-merge.c | 2 +- block/blk.h | 12 ++---------- 2 files changed, 3 insertions(+), 11 deletions(-) diff --git a/block/blk-merge.c b/block/blk-merge.c index 37864c5d287e..002c59479824 100644 --- a/block/blk-merge.c +++ b/block/blk-merge.c @@ -81,7 +81,7 @@ static inline bool bio_will_gap(struct request_queue *q, bio_get_first_bvec(next, &nb); if (biovec_phys_mergeable(q, &pb, &nb)) return false; - return __bvec_gap_to_prev(&q->limits, &pb, nb.bv_offset); + return bvec_gap_to_prev(&q->limits, &pb, nb.bv_offset); } static inline bool req_gap_back_merge(struct request *req, struct bio *bio) diff --git a/block/blk.h b/block/blk.h index 170794632135..d95788caa129 100644 --- a/block/blk.h +++ b/block/blk.h @@ -140,13 +140,6 @@ static inline bool biovec_phys_mergeable(struct request_queue *q, return true; } -static inline bool __bvec_gap_to_prev(const struct queue_limits *lim, - struct bio_vec *bprv, unsigned int offset) -{ - return (offset & lim->virt_boundary_mask) || - ((bprv->bv_offset + bprv->bv_len) & lim->virt_boundary_mask); -} - /* * Check if adding a bio_vec after bprv with offset would create a gap in * the SG list. Most drivers don't care about this, but some do. @@ -154,9 +147,8 @@ static inline bool __bvec_gap_to_prev(const struct queue_limits *lim, static inline bool bvec_gap_to_prev(const struct queue_limits *lim, struct bio_vec *bprv, unsigned int offset) { - if (!lim->virt_boundary_mask) - return false; - return __bvec_gap_to_prev(lim, bprv, offset); + return (offset | (bprv->bv_offset + bprv->bv_len)) & + lim->virt_boundary_mask; } static inline bool rq_mergeable(struct request *rq) -- 2.47.3