From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.5 required=3.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_PASS,URIBL_BLOCKED, USER_AGENT_MUTT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 7EB12C43441 for ; Mon, 19 Nov 2018 08:26:19 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 4820C20871 for ; Mon, 19 Nov 2018 08:26:19 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 4820C20871 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727019AbeKSStL (ORCPT ); Mon, 19 Nov 2018 13:49:11 -0500 Received: from mx1.redhat.com ([209.132.183.28]:34112 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726175AbeKSStL (ORCPT ); Mon, 19 Nov 2018 13:49:11 -0500 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 67A8730820D3; Mon, 19 Nov 2018 08:26:16 +0000 (UTC) Received: from ming.t460p (ovpn-8-26.pek2.redhat.com [10.72.8.26]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 8F6B41974E; Mon, 19 Nov 2018 08:25:54 +0000 (UTC) Date: Mon, 19 Nov 2018 16:25:49 +0800 From: Ming Lei To: Omar Sandoval 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 10/19] block: loop: pass multi-page bvec to iov_iter Message-ID: <20181119082548.GD16736@ming.t460p> References: <20181115085306.9910-1-ming.lei@redhat.com> <20181115085306.9910-11-ming.lei@redhat.com> <20181116004022.GE23828@vader> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20181116004022.GE23828@vader> User-Agent: Mutt/1.9.1 (2017-09-22) X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.47]); Mon, 19 Nov 2018 08:26:16 +0000 (UTC) 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:40:22PM -0800, Omar Sandoval wrote: > On Thu, Nov 15, 2018 at 04:52:57PM +0800, Ming Lei wrote: > > iov_iter is implemented with bvec itererator, so it is safe to pass > > multipage bvec to it, and this way is much more efficient than > > passing one page in each bvec. > > > > 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 > > Comments below. > > > Signed-off-by: Ming Lei > > --- > > drivers/block/loop.c | 23 ++++++++++++----------- > > 1 file changed, 12 insertions(+), 11 deletions(-) > > > > diff --git a/drivers/block/loop.c b/drivers/block/loop.c > > index bf6bc35aaf88..a3fd418ec637 100644 > > --- a/drivers/block/loop.c > > +++ b/drivers/block/loop.c > > @@ -515,16 +515,16 @@ static int lo_rw_aio(struct loop_device *lo, struct loop_cmd *cmd, > > struct bio *bio = rq->bio; > > struct file *file = lo->lo_backing_file; > > unsigned int offset; > > - int segments = 0; > > + int nr_bvec = 0; > > int ret; > > > > if (rq->bio != rq->biotail) { > > - struct req_iterator iter; > > + struct bvec_iter iter; > > struct bio_vec tmp; > > > > __rq_for_each_bio(bio, rq) > > - segments += bio_segments(bio); > > - bvec = kmalloc_array(segments, sizeof(struct bio_vec), > > + nr_bvec += bio_bvecs(bio); > > + bvec = kmalloc_array(nr_bvec, sizeof(struct bio_vec), > > GFP_NOIO); > > if (!bvec) > > return -EIO; > > @@ -533,13 +533,14 @@ 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 bio_for_each_bvec > > * API will take care of all details for us. > > */ > > - rq_for_each_segment(tmp, rq, iter) { > > - *bvec = tmp; > > - bvec++; > > - } > > + __rq_for_each_bio(bio, rq) > > + bio_for_each_bvec(tmp, bio, iter) { > > + *bvec = tmp; > > + bvec++; > > + } > > Even if they're not strictly necessary, could you please include the > curly braces for __rq_for_each_bio() here? Sure, will do it. > > > bvec = cmd->bvec; > > offset = 0; > > } else { > > @@ -550,11 +551,11 @@ 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); > > + nr_bvec = bio_bvecs(bio); > > This scared me for a second, but it's fine to do here because we haven't > actually enabled multipage bvecs yet, right? Well, it is fine, all helpers supporting multi-page bvec actually works well when it isn't enabled, cause single-page bvec is one special case in which multi-page bevc helpers have to deal with. Thanks, Ming