Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp540054imu; Mon, 26 Nov 2018 14:40:39 -0800 (PST) X-Google-Smtp-Source: AFSGD/V5XgWhTmJrZoSJKeBKLBnsai2fs5jjjYziEUbXcPWb/jblSXAUVs9hzrDEMa/VMlwDXjsQ X-Received: by 2002:a63:dc54:: with SMTP id f20mr27051765pgj.410.1543272039662; Mon, 26 Nov 2018 14:40:39 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1543272039; cv=none; d=google.com; s=arc-20160816; b=QKoSBisWO45izCCl1d9exM+d3ZM7auZZTgkBM9wxOu5fLErX0ldfXjM1mkXEZMFmFH eCiXkICw1DhthTErpVL40bXqySwmJ36QUrsaPcjATd7F3B/fN/reuRTks2riKdCVKL3r uM+wn7HTYeAFMf4bTwkqrtC54egDj9iuYZyzH8pI6sXBhYQK9FaVQkGXWn9vFto0f469 mXfHcpeWnI3qzKFrt7CPdbwh3DcC8xxzeykzCjhbzRQx+3NkzfjFpleS4xMK6LKXiprL cTzyLZy4IE9BiTEt4fKp8WIXNeJqm5j93LZvWaShVOZXFv9cMPJbhuRmXFgc5e3Chfiu vV8Q== 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=RUaiQARROohQiAOdny5us6dTb3HLIuGpGt6crRAlRs8=; b=pt5d1TjuVHtoMbU7n4pdomeKuCwfbcGd8Uz1+nGCfbK1wpPMNyRRd2A/sdi4s/HnNX MlioJvye0HKh5wGR1NSJKc6x+KS2nO9z1sKmZAPryljwYETtggb85eBO6DFw2zxXFfk5 vh5XU7cYdkA2+s/T8RIO5NysrUBphML7LagtFmg99kCg6P3u7YSb70W9nH6GQSeJUdA5 8BRX2im5iJ7Zocbxt3AWkf8Abh04EX0L+/Imem4zmC5pXhDKgekHWduYjkT/V+akiTck jWxbpmK5Edym/YGTd6D62IMBEYJXwg7t0w94VEDONyPGq0cwUx2yDaJYvXsCBY5/KpUq J5gg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@osandov-com.20150623.gappssmtp.com header.s=20150623 header.b="kWu3M/Pg"; 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 bi2si1608065plb.200.2018.11.26.14.40.24; Mon, 26 Nov 2018 14:40:39 -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="kWu3M/Pg"; 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 S1727471AbeK0JfX (ORCPT + 99 others); Tue, 27 Nov 2018 04:35:23 -0500 Received: from mail-pf1-f193.google.com ([209.85.210.193]:43234 "EHLO mail-pf1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726665AbeK0JfU (ORCPT ); Tue, 27 Nov 2018 04:35:20 -0500 Received: by mail-pf1-f193.google.com with SMTP id w73so7287755pfk.10 for ; Mon, 26 Nov 2018 14:39:41 -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=RUaiQARROohQiAOdny5us6dTb3HLIuGpGt6crRAlRs8=; b=kWu3M/Pg7YRitikkahpKiBl5cCUnoiBMDo/k7D4nxQKGNeUrhzsp3IHHN3doNwb/kD e+9EBrzpQwB1ZBTyEn44PpIKLid6y29HqBgkdjvAB+Bg1igpAKj3RVm/PKOxRyqGPY2T X1rggbUOJC5rYhwhHSW/Hh59KSJuPHtxnoOYRn7BqHzxEdVNZLywgqCv6o62Cd/XzV6n PeAdxxPpGLw9a7YBjD1adzo7n6tgd5+FvwuuKMouy46sgY8NzvhWen76DwmWnzzNYePH acjs1KTVl6/uL/knjosfu1aMoXstmrlISal/OL9bYMv4RMuinjL5cWOJWhT0eMGeDgNx vt+Q== 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=RUaiQARROohQiAOdny5us6dTb3HLIuGpGt6crRAlRs8=; b=q17/hT7+5DTjAgWcaGEUWpfTBHD6kofmYf2fBdkvJGBw47A/0ZkpKMijAXKUJ9/U9F XHWzlkGq1P+mmOyZzfdEGmPmNg2KwqQqoTLQ19KIl7EWrr08FgM76uVM5fXLbupybI61 MNumqT9ANNpWpFGu0QGSjs7pTKn29UQbMRall2Ha8ZJgFaSMTiQ1/VCvynHkUGjkXG2R Gef/pDMRwOxrP/wv9ID6etFit4o3KPFBHRMLJgygalXKHifnC020lBIL6TLlRdc/gTLh mqsjKZK/EmG4SBNtK6jy3sTNE5SdOAXUOJRofOi48twnlkgtAZx8Gv62xJTlqFLmy3xf klqQ== X-Gm-Message-State: AA+aEWaYTMUi8rWaM1TSHP2bs/z0pTHENBaiLQVfcJKXGM1HdPCBTk2s Z9PU0cYBeJxoWHkOnQkOTVBrgQ== X-Received: by 2002:a62:4b4d:: with SMTP id y74mr28649197pfa.186.1543271980701; Mon, 26 Nov 2018 14:39:40 -0800 (PST) Received: from vader ([2601:602:8b00:55d3:e6a7:a0ff:fe0b:c9a8]) by smtp.gmail.com with ESMTPSA id y12sm2059602pfk.70.2018.11.26.14.39.39 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 26 Nov 2018 14:39:40 -0800 (PST) Date: Mon, 26 Nov 2018 14:39:38 -0800 From: Omar Sandoval To: Ming Lei Cc: Jens Axboe , linux-block@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org, Theodore Ts'o , Omar Sandoval , Sagi Grimberg , Dave Chinner , Kent Overstreet , Mike Snitzer , dm-devel@redhat.com, Alexander Viro , linux-fsdevel@vger.kernel.org, Shaohua Li , linux-raid@vger.kernel.org, David Sterba , linux-btrfs@vger.kernel.org, "Darrick J . Wong" , linux-xfs@vger.kernel.org, Gao Xiang , Christoph Hellwig , linux-ext4@vger.kernel.org, Coly Li , linux-bcache@vger.kernel.org, Boaz Harrosh , Bob Peterson , cluster-devel@redhat.com Subject: Re: [PATCH V12 13/20] block: loop: pass multi-page bvec to iov_iter Message-ID: <20181126223938.GJ30411@vader> References: <20181126021720.19471-1-ming.lei@redhat.com> <20181126021720.19471-14-ming.lei@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20181126021720.19471-14-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 Mon, Nov 26, 2018 at 10:17:13AM +0800, Ming Lei wrote: > iov_iter is implemented on bvec itererator helpers, so it is safe to pass > multi-page bvec to it, and this way is much more efficient than passing one > page in each bvec. > > Reviewed-by: Christoph Hellwig Reviewed-by: Omar Sandoval > Signed-off-by: Ming Lei > --- > drivers/block/loop.c | 20 ++++++++++---------- > 1 file changed, 10 insertions(+), 10 deletions(-) > > diff --git a/drivers/block/loop.c b/drivers/block/loop.c > index 176ab1f28eca..e3683211f12d 100644 > --- a/drivers/block/loop.c > +++ b/drivers/block/loop.c > @@ -510,21 +510,22 @@ static int lo_rw_aio(struct loop_device *lo, struct loop_cmd *cmd, > loff_t pos, bool rw) > { > struct iov_iter iter; > + struct req_iterator rq_iter; > struct bio_vec *bvec; > struct request *rq = blk_mq_rq_from_pdu(cmd); > struct bio *bio = rq->bio; > struct file *file = lo->lo_backing_file; > + struct bio_vec tmp; > unsigned int offset; > - int segments = 0; > + int nr_bvec = 0; > int ret; > > + rq_for_each_bvec(tmp, rq, rq_iter) > + nr_bvec++; > + > if (rq->bio != rq->biotail) { > - struct req_iterator iter; > - struct bio_vec tmp; > > - __rq_for_each_bio(bio, rq) > - segments += bio_segments(bio); > - bvec = kmalloc_array(segments, sizeof(struct bio_vec), > + bvec = kmalloc_array(nr_bvec, sizeof(struct bio_vec), > GFP_NOIO); > if (!bvec) > return -EIO; > @@ -533,10 +534,10 @@ static int lo_rw_aio(struct loop_device *lo, struct loop_cmd *cmd, > /* > * The bios of the request may be started from the middle of > * the 'bvec' because of bio splitting, so we can't directly > - * copy bio->bi_iov_vec to new bvec. The rq_for_each_segment > + * copy bio->bi_iov_vec to new bvec. The rq_for_each_bvec > * API will take care of all details for us. > */ > - rq_for_each_segment(tmp, rq, iter) { > + rq_for_each_bvec(tmp, rq, rq_iter) { > *bvec = tmp; > bvec++; > } > @@ -550,11 +551,10 @@ static int lo_rw_aio(struct loop_device *lo, struct loop_cmd *cmd, > */ > offset = bio->bi_iter.bi_bvec_done; > bvec = __bvec_iter_bvec(bio->bi_io_vec, bio->bi_iter); > - segments = bio_segments(bio); > } > atomic_set(&cmd->ref, 2); > > - iov_iter_bvec(&iter, rw, bvec, segments, blk_rq_bytes(rq)); > + iov_iter_bvec(&iter, rw, bvec, nr_bvec, blk_rq_bytes(rq)); > iter.iov_offset = offset; > > cmd->iocb.ki_pos = pos; > -- > 2.9.5 >