Skip to content

Commit

Permalink
block: Simplify bvec_split_segs()
Browse files Browse the repository at this point in the history
Simplify this function by by removing two if-tests. Other than requiring
that the @sectors pointer is not NULL, this patch does not change the
behavior of bvec_split_segs().

Reviewed-by: Johannes Thumshirn <jthumshirn@suse.de>
Cc: Christoph Hellwig <hch@lst.de>
Cc: Ming Lei <ming.lei@redhat.com>
Cc: Hannes Reinecke <hare@suse.com>
Signed-off-by: Bart Van Assche <bvanassche@acm.org>
Signed-off-by: Jens Axboe <axboe@kernel.dk>
  • Loading branch information
Bart Van Assche authored and Jens Axboe committed Aug 5, 2019
1 parent dad7758 commit ff9811b
Showing 1 changed file with 7 additions and 9 deletions.
16 changes: 7 additions & 9 deletions block/blk-merge.c
Original file line number Diff line number Diff line change
Expand Up @@ -167,29 +167,25 @@ static bool bvec_split_segs(const struct request_queue *q,
{
unsigned len = bv->bv_len;
unsigned total_len = 0;
unsigned new_nsegs = 0, seg_size = 0;
unsigned seg_size = 0;

/*
* Multi-page bvec may be too big to hold in one segment, so the
* current bvec has to be splitted as multiple segments.
*/
while (len && new_nsegs + *nsegs < max_segs) {
while (len && *nsegs < max_segs) {
seg_size = get_max_segment_size(q, bv->bv_offset + total_len);
seg_size = min(seg_size, len);

new_nsegs++;
(*nsegs)++;
total_len += seg_size;
len -= seg_size;

if ((bv->bv_offset + total_len) & queue_virt_boundary(q))
break;
}

if (new_nsegs) {
*nsegs += new_nsegs;
if (sectors)
*sectors += total_len >> 9;
}
*sectors += total_len >> 9;

/* split in the middle of the bvec if len != 0 */
return !!len;
Expand Down Expand Up @@ -349,6 +345,7 @@ EXPORT_SYMBOL(blk_queue_split);
unsigned int blk_recalc_rq_segments(struct request *rq)
{
unsigned int nr_phys_segs = 0;
unsigned int nr_sectors = 0;
struct req_iterator iter;
struct bio_vec bv;

Expand All @@ -365,7 +362,8 @@ unsigned int blk_recalc_rq_segments(struct request *rq)
}

rq_for_each_bvec(bv, rq, iter)
bvec_split_segs(rq->q, &bv, &nr_phys_segs, NULL, UINT_MAX);
bvec_split_segs(rq->q, &bv, &nr_phys_segs, &nr_sectors,
UINT_MAX);
return nr_phys_segs;
}

Expand Down

0 comments on commit ff9811b

Please sign in to comment.