From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753437AbbJOPOP (ORCPT ); Thu, 15 Oct 2015 11:14:15 -0400 Received: from mx1.redhat.com ([209.132.183.28]:35001 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752289AbbJOPOO (ORCPT ); Thu, 15 Oct 2015 11:14:14 -0400 From: Jeff Moyer To: Ming Lei Cc: Jens Axboe , linux-kernel@vger.kernel.org, Ming Lin , Kent Overstreet , Christoph Hellwig Subject: Re: [PATCH 1/4] block: setup bi_phys_segments after splitting References: <1444793448-9994-1-git-send-email-ming.lei@canonical.com> <1444793448-9994-2-git-send-email-ming.lei@canonical.com> X-PGP-KeyID: 1F78E1B4 X-PGP-CertKey: F6FE 280D 8293 F72C 65FD 5A58 1FF8 A7CA 1F78 E1B4 X-PCLoadLetter: What the f**k does that mean? Date: Thu, 15 Oct 2015 11:14:12 -0400 In-Reply-To: <1444793448-9994-2-git-send-email-ming.lei@canonical.com> (Ming Lei's message of "Wed, 14 Oct 2015 11:30:45 +0800") Message-ID: User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.3 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Ming Lei writes: > The number of bio->bi_phys_segments is always obtained > during bio splitting, so it is natural to setup it > just after bio splitting, then we can avoid to compute > nr_segment again during merge. > > Signed-off-by: Ming Lei Reviewed-by: Jeff Moyer > --- > block/blk-merge.c | 29 ++++++++++++++++++++++------- > 1 file changed, 22 insertions(+), 7 deletions(-) > > diff --git a/block/blk-merge.c b/block/blk-merge.c > index c4e9c37..22293fd 100644 > --- a/block/blk-merge.c > +++ b/block/blk-merge.c > @@ -11,13 +11,16 @@ > > static struct bio *blk_bio_discard_split(struct request_queue *q, > struct bio *bio, > - struct bio_set *bs) > + struct bio_set *bs, > + unsigned *nsegs) > { > unsigned int max_discard_sectors, granularity; > int alignment; > sector_t tmp; > unsigned split_sectors; > > + *nsegs = 1; > + > /* Zero-sector (unknown) and one-sector granularities are the same. */ > granularity = max(q->limits.discard_granularity >> 9, 1U); > > @@ -51,8 +54,11 @@ static struct bio *blk_bio_discard_split(struct request_queue *q, > > static struct bio *blk_bio_write_same_split(struct request_queue *q, > struct bio *bio, > - struct bio_set *bs) > + struct bio_set *bs, > + unsigned *nsegs) > { > + *nsegs = 1; > + > if (!q->limits.max_write_same_sectors) > return NULL; > > @@ -64,7 +70,8 @@ static struct bio *blk_bio_write_same_split(struct request_queue *q, > > static struct bio *blk_bio_segment_split(struct request_queue *q, > struct bio *bio, > - struct bio_set *bs) > + struct bio_set *bs, > + unsigned *segs) > { > struct bio_vec bv, bvprv, *bvprvp = NULL; > struct bvec_iter iter; > @@ -106,22 +113,30 @@ new_segment: > sectors += bv.bv_len >> 9; > } > > + *segs = nsegs; > return NULL; > split: > + *segs = nsegs; > return bio_split(bio, sectors, GFP_NOIO, bs); > } > > void blk_queue_split(struct request_queue *q, struct bio **bio, > struct bio_set *bs) > { > - struct bio *split; > + struct bio *split, *res; > + unsigned nsegs; > > if ((*bio)->bi_rw & REQ_DISCARD) > - split = blk_bio_discard_split(q, *bio, bs); > + split = blk_bio_discard_split(q, *bio, bs, &nsegs); > else if ((*bio)->bi_rw & REQ_WRITE_SAME) > - split = blk_bio_write_same_split(q, *bio, bs); > + split = blk_bio_write_same_split(q, *bio, bs, &nsegs); > else > - split = blk_bio_segment_split(q, *bio, q->bio_split); > + split = blk_bio_segment_split(q, *bio, q->bio_split, &nsegs); > + > + /* physical segments can be figured out during splitting */ > + res = split ? split : *bio; > + res->bi_phys_segments = nsegs; > + bio_set_flag(res, BIO_SEG_VALID); > > if (split) { > bio_chain(split, *bio);