Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp8613257imu; Thu, 15 Nov 2018 14:35:12 -0800 (PST) X-Google-Smtp-Source: AJdET5cvTwv9FjMoB5ODfmxCAo+Z8/XX3xL/WWrU8gEN9ZEGwCLHuGEgPiwxeCtZqTCzi9BEtc7p X-Received: by 2002:a17:902:748b:: with SMTP id h11mr8025034pll.325.1542321312232; Thu, 15 Nov 2018 14:35:12 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1542321312; cv=none; d=google.com; s=arc-20160816; b=ILTKtheRbsw6rMjQ4wWSZa49z95bFtXHrKLHdXgtFSMRBDtQu65a+PqjdHG9QXg2mu Wvmdn946CczUgkhvNzAnqucdPWgi7sd2hjKvxveXV84UY57a0h2LYsBn84zhgg3QjOTq b/TUcK4MZsEmmzTems+CHRSQnR4ffGs87p2evJDU8mop4hM3+ZtINYdU5ZU6kk18Djv0 KO+bHRcE8WApxVRgFpr61s4zD2A262gz465+Jd3MJdZ+DHEGNGLFySjPOBW0oNbR8glJ 7jIyQnijWiKMHdBtLU7NpAv8q50yUfYFkRB3sciXn71qvXQ/UgQqCAVv78v+iRbvREc+ GGPQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature; bh=a098WawebiQEI35+UC6o+h5gSwtB4cT8kXe3OZC4l0Y=; b=brRoRpB4B6bIo+Loi3npCAjuYXrv3VHvLxL5Scocyl3wL8yOeCnI5UXVzARw9DQn71 8oV4XQH3P9rtd+YbersQeblZF0F5odfVOzGNObt/lKn/62J7gAiqEZ5MLQQiuVQV/6Af VsBv3vqlZBz8LZ57IIy6f4ijZZQ5raLtDJkAnNLsnQEXvKTHdL4YfLEdFgChay0c34Rr n2+IaH5YKl4tziGF0xfkU7nfMJxOwXz49s+peRMbYUMeiyOSfJUQ2ETvxG9VH8LlhnZN lE9VrakNjV8tTsCEH/P0Y4ITujNSoH+oWzBbS7vaQSsEZAHvXZCDt+siiwG8BEbM9yrY Sg1g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@osandov-com.20150623.gappssmtp.com header.s=20150623 header.b=kuiKUdcP; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id n28si5783832pfb.88.2018.11.15.14.34.58; Thu, 15 Nov 2018 14:35:12 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@osandov-com.20150623.gappssmtp.com header.s=20150623 header.b=kuiKUdcP; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729045AbeKPInp (ORCPT + 99 others); Fri, 16 Nov 2018 03:43:45 -0500 Received: from mail-pl1-f195.google.com ([209.85.214.195]:46545 "EHLO mail-pl1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726910AbeKPInp (ORCPT ); Fri, 16 Nov 2018 03:43:45 -0500 Received: by mail-pl1-f195.google.com with SMTP id t13so7175389ply.13 for ; Thu, 15 Nov 2018 14:34:02 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=osandov-com.20150623.gappssmtp.com; s=20150623; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=a098WawebiQEI35+UC6o+h5gSwtB4cT8kXe3OZC4l0Y=; b=kuiKUdcPwp6i0ipF7JnmuAigwlNOsM4+m6qSabIm42If8aj+totidZe5lZiL7oO3kz BAhagr77MnqmgZ7eJWQg3VCHfO5DQAu5B/ELsVk1Ogyjyde/Jq4fE19hf3kEDo9ep/C3 calrtB9C3oEy/4eL96VN4o8NMKFKYA8fxw68HkD+pWc0fD9c9qT2nDmt2/bQQ6GcYiEv aOXHIkQkKlwuRbZLR0ZwByLvFrDZQeTCmWv+ruWgn2KZ5YUt2NnmCOEigJr7YfMzztyX gw6owHpEOl6KBog3pwkQmq66aF+B1cskdGh1Ug/PjRWSu/6ZuRFFodoysD09sNm4r7oP s01g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=a098WawebiQEI35+UC6o+h5gSwtB4cT8kXe3OZC4l0Y=; b=sdSujejd74b4exjn3fHbCQ0ow6z+5Ub1/NDcQDTpsnuZIpU2avqyNpGVrmMcU1PsDL WLK1gyvq3vLqIqG50maJVbjtsD7vSm4M/cz0nXJz0q0ppEX1U4PDVLEMkVy63NGWsYWu x64w3C84Rw10rxpUQqKb1cqvq6Z0IIOLLGXr9CD1lT6yi8mjzFL83Rgxhvr1NOXr6a1A iQGIdLTHdLniHSxEOzHW57wmCwUnXN/DRej0bC71DSFQ18z2MZfo2lJKx5xw0gBNXKSv kAiuQqRzfg783xHLgv1n+qtbbkYCpje3mHeaa9ggFAb3fg6P7hGbQocEilGVPA0xnPYc +CNw== X-Gm-Message-State: AGRZ1gLUZ1klI1GyIZIKpGaugtyELRZUJrCAerstOcZNz4q7HLs1Dwiy I/MF2sGj+jr7Tj1q1AgQXmjYZg== X-Received: by 2002:a17:902:128c:: with SMTP id g12-v6mr7885468pla.143.1542321241844; Thu, 15 Nov 2018 14:34:01 -0800 (PST) Received: from vader ([64.114.255.97]) by smtp.gmail.com with ESMTPSA id h128sm32821115pgc.15.2018.11.15.14.34.00 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 15 Nov 2018 14:34:01 -0800 (PST) Date: Thu, 15 Nov 2018 14:33:58 -0800 From: Omar Sandoval To: Ming Lei Cc: Jens Axboe , linux-block@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org, Dave Chinner , Kent Overstreet , Mike Snitzer , dm-devel@redhat.com, Alexander Viro , linux-fsdevel@vger.kernel.org, Shaohua Li , linux-raid@vger.kernel.org, linux-erofs@lists.ozlabs.org, David Sterba , linux-btrfs@vger.kernel.org, "Darrick J . Wong" , linux-xfs@vger.kernel.org, Gao Xiang , Christoph Hellwig , Theodore Ts'o , linux-ext4@vger.kernel.org, Coly Li , linux-bcache@vger.kernel.org, Boaz Harrosh , Bob Peterson , cluster-devel@redhat.com Subject: Re: [PATCH V10 04/19] block: use bio_for_each_bvec() to map sg Message-ID: <20181115223358.GE9348@vader> References: <20181115085306.9910-1-ming.lei@redhat.com> <20181115085306.9910-5-ming.lei@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20181115085306.9910-5-ming.lei@redhat.com> User-Agent: Mutt/1.10.1 (2018-07-13) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Nov 15, 2018 at 04:52:51PM +0800, Ming Lei wrote: > It is more efficient to use bio_for_each_bvec() to map sg, meantime > we have to consider splitting multipage bvec as done in blk_bio_segment_split(). > > Cc: Dave Chinner > Cc: Kent Overstreet > Cc: Mike Snitzer > Cc: dm-devel@redhat.com > Cc: Alexander Viro > Cc: linux-fsdevel@vger.kernel.org > Cc: Shaohua Li > Cc: linux-raid@vger.kernel.org > Cc: linux-erofs@lists.ozlabs.org > Cc: David Sterba > Cc: linux-btrfs@vger.kernel.org > Cc: Darrick J. Wong > Cc: linux-xfs@vger.kernel.org > Cc: Gao Xiang > Cc: Christoph Hellwig > Cc: Theodore Ts'o > Cc: linux-ext4@vger.kernel.org > Cc: Coly Li > Cc: linux-bcache@vger.kernel.org > Cc: Boaz Harrosh > Cc: Bob Peterson > Cc: cluster-devel@redhat.com Reviewed-by: Omar Sandoval > Signed-off-by: Ming Lei > --- > block/blk-merge.c | 72 +++++++++++++++++++++++++++++++++++++++---------------- > 1 file changed, 52 insertions(+), 20 deletions(-) > > diff --git a/block/blk-merge.c b/block/blk-merge.c > index 6f7deb94a23f..cb9f49bcfd36 100644 > --- a/block/blk-merge.c > +++ b/block/blk-merge.c > @@ -473,6 +473,56 @@ static int blk_phys_contig_segment(struct request_queue *q, struct bio *bio, > return biovec_phys_mergeable(q, &end_bv, &nxt_bv); > } > > +static struct scatterlist *blk_next_sg(struct scatterlist **sg, > + struct scatterlist *sglist) > +{ > + if (!*sg) > + return sglist; > + else { > + /* > + * If the driver previously mapped a shorter > + * list, we could see a termination bit > + * prematurely unless it fully inits the sg > + * table on each mapping. We KNOW that there > + * must be more entries here or the driver > + * would be buggy, so force clear the > + * termination bit to avoid doing a full > + * sg_init_table() in drivers for each command. > + */ > + sg_unmark_end(*sg); > + return sg_next(*sg); > + } > +} > + > +static unsigned blk_bvec_map_sg(struct request_queue *q, > + struct bio_vec *bvec, struct scatterlist *sglist, > + struct scatterlist **sg) > +{ > + unsigned nbytes = bvec->bv_len; > + unsigned nsegs = 0, total = 0; > + > + while (nbytes > 0) { > + unsigned seg_size; > + struct page *pg; > + unsigned offset, idx; > + > + *sg = blk_next_sg(sg, sglist); > + > + seg_size = min(nbytes, queue_max_segment_size(q)); > + offset = (total + bvec->bv_offset) % PAGE_SIZE; > + idx = (total + bvec->bv_offset) / PAGE_SIZE; > + pg = nth_page(bvec->bv_page, idx); > + > + sg_set_page(*sg, pg, seg_size, offset); > + > + total += seg_size; > + nbytes -= seg_size; > + nsegs++; > + } > + > + return nsegs; > +} > + > static inline void > __blk_segment_map_sg(struct request_queue *q, struct bio_vec *bvec, > struct scatterlist *sglist, struct bio_vec *bvprv, > @@ -490,25 +540,7 @@ __blk_segment_map_sg(struct request_queue *q, struct bio_vec *bvec, > (*sg)->length += nbytes; > } else { > new_segment: > - if (!*sg) > - *sg = sglist; > - else { > - /* > - * If the driver previously mapped a shorter > - * list, we could see a termination bit > - * prematurely unless it fully inits the sg > - * table on each mapping. We KNOW that there > - * must be more entries here or the driver > - * would be buggy, so force clear the > - * termination bit to avoid doing a full > - * sg_init_table() in drivers for each command. > - */ > - sg_unmark_end(*sg); > - *sg = sg_next(*sg); > - } > - > - sg_set_page(*sg, bvec->bv_page, nbytes, bvec->bv_offset); > - (*nsegs)++; > + (*nsegs) += blk_bvec_map_sg(q, bvec, sglist, sg); > } > *bvprv = *bvec; > } > @@ -530,7 +562,7 @@ static int __blk_bios_map_sg(struct request_queue *q, struct bio *bio, > int cluster = blk_queue_cluster(q), nsegs = 0; > > for_each_bio(bio) > - bio_for_each_segment(bvec, bio, iter) > + bio_for_each_bvec(bvec, bio, iter) > __blk_segment_map_sg(q, &bvec, sglist, &bvprv, sg, > &nsegs, &cluster); > > -- > 2.9.5 >